/* /assets/styles.css */

/* ==========================
   Theme tokens
   ========================== */
:root{
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: rgba(0,0,0,.10);

  --primary: #2563eb;
  --primaryText: #ffffff;

  --danger: #b00020;
  --dangerText: #ffffff;

  --shadow: 0 8px 20px rgba(0,0,0,.08);

  --radius: 14px;

  --tap: 44px; /* iOS推奨 */
  --gap: 12px;
  --container: 980px;
}

/* OSダークに追従（デフォルト自動） */
@media (prefers-color-scheme: dark){
  :root{
    --bg: #0b1220;
    --surface: #0f172a;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: rgba(255,255,255,.12);

    --primary: #60a5fa;
    --primaryText: #06101f;

    --danger: #ff5c77;
    --dangerText: #1a0b10;

    --shadow: 0 10px 24px rgba(0,0,0,.55);
  }
}

/* 手動切替用（任意：後でJSで付ける） */
html[data-theme="light"]{
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: rgba(0,0,0,.10);
  --primary: #2563eb;
  --primaryText: #ffffff;
  --danger: #b00020;
  --dangerText: #ffffff;
  --shadow: 0 8px 20px rgba(0,0,0,.08);
}
html[data-theme="dark"]{
  --bg: #0b1220;
  --surface: #0f172a;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: rgba(255,255,255,.12);
  --primary: #60a5fa;
  --primaryText: #06101f;
  --danger: #ff5c77;
  --dangerText: #1a0b10;
  --shadow: 0 10px 24px rgba(0,0,0,.55);
}

/* ==========================
   Base
   ========================== */
*{ box-sizing:border-box; }
html, body{ height:100%; }
body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

/* links */
a{ color: inherit; }
a:focus, button:focus, input:focus, select:focus{
  outline: 2px solid rgba(96,165,250,.6);
  outline-offset: 2px;
}

/* ==========================
   Layout
   ========================== */
.container{
  width: min(var(--container), 100%);
  margin: 0 auto;
  padding: 14px 14px 42px;
}

.header{
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 6px 16px rgba(0,0,0,.06);
}

.header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
  padding: 12px 14px;
}

/* Wide screens: keep the main menu visually centered.
   Flex "space-between" shifts the menu when the right actions are wider than the logo.
   Use a 3-column grid (left / center / right) so nav stays in the viewport center.
*/
@media (min-width: 980px){
  .header{
    display:grid;
    grid-template-columns: 1fr auto 1fr;
    align-items:center;
  }
  .logo{ justify-self:start; }
  .nav{ justify-self:center; justify-content:center; }
  .header-actions{ justify-self:end; }
}

/* Desktop header spacing */
@media (min-width: 769px){
  .header{
    padding-top: 10px!important;
    top: 8px;
  }
}

.logo{
  font-size: 18px;
  font-weight: 800;
  letter-spacing: .3px;
  margin:0;
  text-decoration: none;
  color: var(--text);
}

/* ==========================
   Nav (tap-friendly)
   ========================== */
.nav{
  display:flex;
  align-items:center;
  gap: 8px;
  flex-wrap: wrap;
}

.nav a{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: 999px;
  text-decoration:none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
}

.nav a.active{
  background: var(--primary);
  color: var(--primaryText);
  border-color: transparent;
}

.nav a:hover{
  filter: brightness(1.02);
}

/* ==========================
   Header actions (theme / logout)
   ========================== */
.header-actions{
  display:flex;
  align-items:center;
  gap: 8px;
  flex: 0 0 auto;
}

/* small screens: allow wrapping without breaking layout */
@media (max-width: 640px){
  .header{
    flex-wrap: wrap;
  }
  .header-actions{
    width: 100%;
    justify-content: flex-end;
  }
}

/* ==========================
   Cards
   ========================== */
.card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.card h2{
  margin: 0 0 6px;
  font-size: 18px;
}
.mini{
  color: var(--muted);
  font-size: 16px;
}

/* ==========================
   Form fields
   ========================== */
.field{ margin-top: 10px; }
label{ display:block; margin: 0 0 6px; }

input, select, textarea{
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.02);
  color: var(--text);
  font-size: 16px; /* iOSで勝手にズームしない */
}

/* Radios/Checkboxes: never inherit the generic input box styling */
input[type="radio"], input[type="checkbox"]{
  width: auto;
  min-height: auto;
  padding: 0;
  border-radius: initial;
  border: initial;
  background: initial;
}


textarea{ min-height: 110px; }

input::placeholder, textarea::placeholder{
  color: color-mix(in srgb, var(--muted) 75%, transparent);
}

/* ==========================
   Buttons (tap-friendly)
   ========================== */
.btn{
  text-decoration: none;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height: var(--tap);
  padding: 10px 14px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: var(--primaryText);
  font-weight: 800;
  letter-spacing: .2px;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(0,0,0,.12);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover{ filter: brightness(1.02); }
.btn:disabled{
  opacity: .6;
  cursor: not-allowed;
  box-shadow: none;
}

.btn.mini{
  min-height: 38px;
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 10px;
  box-shadow: none;
}

/* danger button helper */
.btn-danger{
  background: var(--danger);
  color: var(--dangerText);
}

/* ==========================
   Template selector area (buttons wrap nicely)
   ========================== */
#template-selector,
#history-template-selector{
  display:flex;
  flex-wrap: wrap;
  gap: 8px;
}

#template-selector .btn,
#history-template-selector .btn{
  border-radius: 999px;
}

/* ==========================
   Toast
   ========================== */
.toast{
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: rgba(17,24,39,.92);
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
  font-weight: 800;
  box-shadow: 0 14px 28px rgba(0,0,0,.28);
  max-width: calc(100% - 24px);
  text-align:center;
  z-index: 999;
}
.hidden{ display:none !important; }

/* ==========================
   Mobile tuning
   ========================== */
@media (max-width: 520px){
  .header{
    padding: 10px 12px;
    gap: 8px;
  }
  .logo{
    font-size: 16px;
  }

  .nav{
    gap: 6px;
  }
  .nav a{
    padding: 10px 10px;
    font-size: 13px;
  }

  .container{
    padding: 12px 12px 36px;
  }

  .card{
    padding: 12px;
  }

  /* 長いボタンが詰まる時は折り返し */
  #template-selector .btn,
  #history-template-selector .btn{
    padding: 10px 12px;
  }
}

/* ==========================
   Reduce motion (accessibility)
   ========================== */
@media (prefers-reduced-motion: reduce){
  *{ scroll-behavior: auto !important; }
}

/* =========================================================
   Mobile Optimization (Tap targets / Layout)
   - Append this block to the END of styles.css
   ========================================================= */

/* iOS Safari: tap highlight & text scaling quirks */
html {
  -webkit-text-size-adjust: 100%;
}
a, button {
  -webkit-tap-highlight-color: rgba(0,0,0,0.12);
}

/* Make interactive elements comfortably tappable */
a, button, .btn, input, select, textarea {
  touch-action: manipulation;
}

/* Optional: reduce accidental double-tap zoom on buttons/links */
button, .btn, .nav a {
  user-select: none;
  -webkit-user-select: none;
}

/* ---------------------------------------------------------
   Header / Nav: sticky + safe area + bigger tap targets
   --------------------------------------------------------- */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
}

/* Nav links: ensure 44px+ tap target */
.nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
}

/* Active state visibility (works in both light/dark if you use variables) */
.nav a.active {
  font-weight: 700;
}

/* ---------------------------------------------------------
   Buttons / Inputs: 44px tap target, spacing, readability
   --------------------------------------------------------- */
.btn {
  min-height: 44px;
  padding: 12px 14px;
  border-radius: 12px;
  line-height: 1.1;
}

/* Mini buttons should still be tappable */
.btn.mini,
.btn.mini * {
  min-height: 40px;
}
.btn.mini {
  padding: 10px 12px;
  border-radius: 10px;
}

/* Inputs: prevent iOS zoom by using 16px font-size */
input, select, textarea {
  font-size: 16px;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
}

/* Label spacing on mobile */
label.mini {
  display: inline-block;
  margin-bottom: 6px;
}

/* ---------------------------------------------------------
   Cards / Lists: spacing and easy tapping
   --------------------------------------------------------- */
.card {
  border-radius: 14px;
}

/* Make "card rows" easier to tap if you use them */
.card .row,
.card .item {
  padding: 10px 0;
}

/* ---------------------------------------------------------
   Toast: safe area bottom & mobile-friendly
   --------------------------------------------------------- */
.toast {
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: min(92vw, 520px);
}

/* ---------------------------------------------------------
   Mobile-only layout adjustments
   --------------------------------------------------------- */
@media (max-width: 768px) {

  /* Container padding for thumbs */
  .container {
    padding-left: 14px;
    padding-right: 14px;
  }

  /* Stack nav nicely if it wraps */
  .nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .nav a {
    flex: 1 1 auto;
    text-align: center;
  }

  /* Template selector buttons: wrap + comfortable */
  #template-selector .btn,
  #history-template-selector .btn {
    min-height: 44px;
    margin-right: 6px;
    margin-bottom: 6px;
  }

  /* History list cards: bigger "open" button and spacing */
  #history-list .btn.mini {
    min-height: 44px;
    padding: 12px 14px;
  }

  /* Reduce dense text blocks */
  .mini {
    line-height: 1.55;
  }

  /* Prevent accidental horizontal scroll */
  body {
    overflow-x: hidden;
  }
}

/* ---------------------------------------------------------
   Very small phones
   --------------------------------------------------------- */
@media (max-width: 390px) {
  .nav a {
    padding: 10px 10px;
  }
  .btn {
    padding: 12px 12px;
  }
}

/* ===== History Calendar (for new history.js) ===== */

.cal{
  margin-top:10px;
  user-select:none;
}

/* 曜日ヘッダー */
.cal-head{
  display:grid;
  grid-template-columns: repeat(7, 1fr);
  gap:8px;
  margin-bottom:8px;
}
.cal-h{
  font-size:12px;
  color: var(--muted);
  text-align:center;
  padding:6px 0;
}

/* 日付グリッド */
.cal-grid{
  display:grid;
  grid-template-columns: repeat(7, 1fr);
  gap:8px;
}

/* 日付セル（button） */
.cal-cell{
  appearance:none;
  border:1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius:12px;
  min-height:52px;
  padding:10px 6px;
  text-align:center;
  cursor:pointer;

  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;

  user-select:none;
  -webkit-tap-highlight-color: transparent;
}

/* 空マス（div） */
.cal-empty{
  border:none;
  background: transparent;
  min-height:52px;
}

/* 日付数字 */
.cal-num{
  font-weight:800;
  font-size:14px;
  line-height:1;
}

/* 記録ドット（●） */
.dot{
  margin-top:6px;
  font-size:12px;
  line-height:1;
  color: var(--text);
}
.dot.ghost{
  opacity:0;
}

/* 今日 */
.cal-cell.today{
  outline: 2px solid color-mix(in srgb, var(--primary) 70%, transparent);
  outline-offset: 0;
}

/* 記録あり */
.cal-cell.has{
  background: color-mix(in srgb, var(--primary) 10%, transparent);
}

/* 選択中 */
.cal-cell.selected{
  background: color-mix(in srgb, #10b981 16%, transparent);
  border-color: color-mix(in srgb, #10b981 30%, var(--border));
}

/* モバイルで押しやすく */
@media (max-width: 480px){
  .cal-head{ gap:6px; }
  .cal-grid{ gap:6px; }
  .cal-cell{ min-height:56px; padding:12px 6px; }
  .cal-empty{ min-height:56px; }
}
/* ===== grid2 (year/month/search layout) ===== */
.grid2{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

/* iOS Safari: date input can overflow a grid cell and visually overlap */
.grid2 > *{ min-width: 0; }
input[type="date"]{ min-width: 0; max-width: 100%; }

/* History: keep the range date inputs stable in 2-col grid */
.history-range .grid2{ grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

/* iPad/iOS (Safari/Firefox/Chrome): input[type=date] can overflow a grid cell.
   Keep 2 columns on iPad/desktop widths, but prevent overflow.
   Only stack vertically on narrow screens. */
@supports (-webkit-touch-callout: none){
  .history-range .grid2{ grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .history-range .grid2 > *{ min-width: 0; }
  .history-range input[type="date"]{
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow: hidden;
  }
  @media (max-width: 740px){
    .history-range .grid2{ grid-template-columns: 1fr; }
  }
}
  .history-range input[type="date"]{
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
}

/* ===== Record page header (date + template) ===== */
.record-head{
  /* iOS/iPad browsers: input[type=date] can ignore min-width and overflow grid cells.
     Force both columns to allow shrinking (minmax(0, ...)) and ensure children can shrink. */
  grid-template-columns: minmax(0, 1fr) minmax(0, 320px);
  align-items: end;
}
.record-head > *{ min-width: 0; }
.record-head .template-choose{ width:100%; }
.record-head input[type="date"]{
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow: hidden;
}

@media (max-width: 820px){
  .record-head{ grid-template-columns: 1fr; }
}
@media (max-width: 520px){
  .grid2{ grid-template-columns: 1fr; }
}

/* ===== Record fields table (6 columns) ===== */
.rec-table{
  display:flex;
  flex-direction:column;
  gap:12px;
  padding-bottom:4px;
}

/* Classic (3-col) */
.rec-row{
  display:grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap:10px;
  align-items:start;
}
@media (max-width: 768px){
  .rec-row{ grid-template-columns: 1fr; }
}

/* Calc (2-col) */
.rec-row2{
  display:flex;
  gap:12px;
  align-items:flex-start;
  min-width:0;
}
.rec-left{
  flex:0 0 180px;
  min-width:0;
  display:flex;
  flex-direction:column;
  gap:8px;
}
.rec-right{
  flex:1;
  width:100%;
  display:flex;
  flex-direction:column;
  gap:10px;
}
@media (max-width: 768px){
  .rec-row2{ flex-direction:column; }
  .rec-left{ flex:0 0 auto; width:100%; }
}

.rec-inp{
  width:100%;
  min-height:44px;
  padding:10px 12px;
  border-radius:12px;
  border:1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  outline:none;
}

.rec-titlebox{
  min-height:44px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  display:flex;
  align-items:flex-start;
  font-weight: 900;
  /* 項目1は長文でも折り返して表示（1行固定にしない） */
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.rec-subbox{
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px dashed var(--border);
  color: var(--muted);
  font-weight: 800;
  font-size: 12px;
  line-height: 1.2;
  background: rgba(255,255,255,0.02);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rec-numrow{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
}
.rec-numrow .rec-pm{ width:60px; }
.rec-numrow .rec-num{ flex:0 1 120px; min-width:100px; max-width: 120px; }

.rec-unitbox{
  min-height:44px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight: 900;
  white-space: nowrap;
  min-width: 90px;
}


/* Extra fields (time / eval) */
.rec-extra{
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.rec-extra-row{
  margin-bottom: 10px;
}
.rec-extra-label{
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.rec-extra-input{
  display: flex;
  align-items: center;
  gap: 8px;
}
.rec-extra-select{
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
.rec-extra-input .rec-extra-select{
  flex: 1 1 auto;
}
.rec-extra-sep{
  opacity: .75;
}

}


.rec-memo-links{ margin-top: 6px; display:flex; flex-wrap:wrap; gap:6px; }
.rec-memo-links a{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:6px 10px;
  border-radius:999px;
  border:1px solid var(--border);
  background: rgba(255,255,255,0.03);
  color: var(--text);
  text-decoration:none;
  font-size: 12px;
  line-height: 1;
}
.rec-memo-links a:hover{ background: rgba(255,255,255,0.06); }
.rec-inp:focus{
  border-color: color-mix(in srgb, var(--primary) 55%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.rec-inp::placeholder{
  color: var(--muted);
  opacity: 0.9;
}
.rec-ta{
  height:auto;
  min-height:96px;
  resize: vertical;
}
.rec-pm{
  text-align:center;
  font-weight:900;
}

/* ===== Search results (tap-friendly) ===== */
.search-list{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:6px;
}
.search-chip{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  text-decoration:none;
  font-weight:800;
  cursor:pointer;
}
.search-chip:hover{ filter: brightness(1.02); }

/* ==========================
   Calc (計算ページ)
   ========================== */
.kv{
  display:grid;
  grid-template-columns: 120px 1fr;
  gap: 8px;
  margin: 6px 0;
}
.kv > div:nth-child(odd){
  color: var(--muted);
  font-weight: 700;
}

.sparkline{
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  overflow-x: auto;
}
.sparkline canvas{
  width: 100%;
  max-width: 560px;
  height: 90px;
}

.table-mini{
  width:100%;
  border-collapse: collapse;
  margin-top: 8px;
}
.table-mini th,
.table-mini td{
  border-bottom: 1px solid var(--border);
  padding: 8px 6px;
  font-size: 14px;
  text-align:left;
}
.table-mini th{ color: var(--muted); font-weight: 800; }

.hl{
  background: color-mix(in srgb, var(--primary) 22%, transparent);
  color: inherit;
  padding: 0 2px;
  border-radius: 4px;
}

/* ===== Highlight (search / calc) ===== */
mark.hl{
  background: color-mix(in srgb, var(--primary) 22%, transparent);
  color: inherit;
  padding: 0 2px;
  border-radius: 4px;
}

/* ===== Calc UI ===== */
.calc-tabs{ display:flex; gap:8px; flex-wrap:wrap; margin-top:10px; }
.calc-tabs .btn{ border-radius: 999px; }
.calc-grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  margin-top:10px;
}
@media (max-width: 520px){
  .calc-grid{ grid-template-columns: 1fr; }
}
.calc-kpi{
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}
.calc-kpi .k{ color: var(--muted); font-size: 12px; }
.calc-kpi .v{ font-weight: 900; font-size: 18px; margin-top: 2px; }
/* ===== Today View ===== */
.history-today{ margin-top: 12px; }
.history-today-box{ margin-top: 10px; }

.entry-extras{
  display:flex;
  flex-wrap:wrap;
  gap:6px;
  margin-top:8px;
}
.extra-badge{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:4px 8px;
  border-radius:999px;
  border:1px solid var(--border);
  background: rgba(255,255,255,0.03);
  font-size:12px;
  line-height:1.4;
  font-weight:800;
  white-space:nowrap;
}
.extra-badge .k{ color: var(--muted); font-weight:800; }
.extra-badge .v{ color: var(--text); font-weight:900; }

.extra-badge--time .v{ font-variant-numeric: tabular-nums; }
.extra-badge--ox .v{ font-size: 13px; line-height:1; }
.extra-badge--star .v{ color: var(--primary); }

.search-hit-meta{ margin-top:8px; }
.search-hit-snippet{ margin-top:8px; }

.search-row .entry-extras{ margin-top:4px; }
.search-row .search-hit-snippet{ margin-top:4px; }

.history-meta-row{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:10px;
  flex-wrap:wrap;
}
.history-meta-left{ min-width: 0; }
.history-meta-ts{ font-weight:700; }
.history-detail-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  flex-wrap:wrap;
}
.history-detail-title{
  font-weight: 900;
  font-size: 22px;
}
.history-detail-nav{
  display:flex;
  align-items:center;
  gap:8px;
}
.history-detail-date{
  font-weight: 900;
  min-width: 110px;
  text-align:center;
}
@media (max-width: 520px){
  .history-detail-date{ min-width: 92px; }
}

.today-missing{
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border));
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  color: var(--text);
  font-weight: 800;
}
.today-ok{
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, #10b981 35%, var(--border));
  background: color-mix(in srgb, #10b981 10%, transparent);
  color: var(--text);
  font-weight: 800;
}

/* ===== Search hits ===== */
.search-hit-list{
  margin-top: 10px;
  display: grid;
  gap: 10px;
}
.search-hit{
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-radius: 14px;
  padding: 12px;
}
.search-hit-date{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  text-decoration: none;
  font-weight: 900;
}
/* ===== Search highlight ===== */
mark.hl{
  background: color-mix(in srgb, #fbbf24 55%, transparent);
  color: inherit;
  padding: 0 4px;
  border-radius: 6px;
}
/* ===== Attachments ===== */
.attach-grid{
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap:10px;
  margin-top:8px;
}
.attach-thumb{
  display:block;
  border:1px solid var(--border);
  border-radius:12px;
  overflow:hidden;
  background: var(--surface);
}
.attach-thumb img{
  width:100%;
  height:120px;
  object-fit:cover;
  display:block;
}

/* ===== Entry Images (multi) ===== */
.img-grid, .history-images{
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.img-thumb{
  display:block;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow:hidden;
  background: var(--surface);
  position: relative;
}
.img-thumb img{
  display:block;
  width:100%;
  height:auto;
}
.img-thumb .img-badge{
  position:absolute;
  left:8px;
  top:8px;
  font-size:12px;
  padding:4px 8px;
  border-radius:999px;
  background: rgba(0,0,0,.55);
  color:#fff;
}

.img-thumb .img-del{
  position:absolute;
  right:8px;
  top:8px;
  font-size:12px;
  padding:4px 8px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,.55);
  color:#fff;
  cursor:pointer;
}

/* ===== Entry Files (attachments) ===== */
.file-attach{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
}

.file-attach input[type="file"]{
  flex:1 1 auto;
}

.file-list{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.file-item{
  display:flex;
  gap:10px;
  align-items:center;
  justify-content:space-between;
  padding:10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.file-item-main{
  display:flex;
  flex-direction:column;
  gap:4px;
  min-width:0;
}

.file-link{
  font-weight:600;
  text-decoration:none;
  word-break:break-word;
}

.file-meta{
  font-size:12px;
  opacity:0.78;
}

.file-search-note{
  margin-bottom:6px;
}
.img-thumb .img-del:hover{ background: rgba(255,80,80,.45); }

/* ===== Calc UI ===== */
.calc-tabs{ display:flex; gap:8px; flex-wrap:wrap; margin-top:10px; }
.calc-tabs .btn{ background: transparent; color: var(--text); border:1px solid var(--border); box-shadow:none; }
.calc-tabs .btn.active{ background: var(--primary); color: var(--primaryText); border-color: transparent; }
.calc-panel{ margin-top:12px; }
.calc-grid{ display:grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
@media (max-width: 720px){ .calc-grid{ grid-template-columns:1fr; } }
.statbox{ background: rgba(0,0,0,.02); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.statbox .k{ font-size: 12px; color: var(--muted); }
.statbox .v{ font-size: 20px; font-weight: 900; margin-top:2px; }
.calc-help{ display:flex; flex-wrap:wrap; gap:8px; margin-top:8px; }
.calc-help .search-chip{ font-weight:800; }

.calc-series{ margin-top: 12px; }
.calc-series .sparkline{
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  overflow-x: auto;
}
.calc-series canvas{ display:block; width: 100%; height: 80px; }



/* calc (time/eval extras) */
.calc-meta{ margin-top:8px; }
.calc-table.calc-mt12{ margin-top:12px; }

.calc-extras{ margin-top:14px; padding-top:12px; border-top:1px solid #e5e5e5; }
.calc-extras-title{ font-weight:900; font-size:14px; margin:0 0 8px; }
.calc-extras-section{ margin-top:12px; }
.calc-extras-subtitle{ font-weight:800; margin:0 0 6px; }
.calc-extras-footnote{ margin-top:6px; }

.calc-table{
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 13px;
}
.calc-table th, .calc-table td{
  border-bottom: 1px solid var(--border);
  padding: 8px 6px;
  text-align: left;
}
.calc-table th{ color: var(--muted); font-weight: 800; }
.calc-table td:last-child{ text-align: right; font-variant-numeric: tabular-nums; }

/* calc table: horizontal scroll on small screens + sticky first column */
.calc-table-scroll{ overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 720px){
  .calc-table{ width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; }
  .calc-table thead th:first-child,
  .calc-table tbody td:first-child{
    position: sticky;
    left: 0;
    z-index: 3;
    background: var(--surface);
    box-shadow: 10px 0 12px -14px rgba(0,0,0,.55);
  }
  .calc-table thead th:first-child{ z-index: 4; }

  /* 1列目（条件）は固定幅（スマホ時） */
  .calc-table thead th:first-child,
  .calc-table tbody td:first-child{
    width: 120px;
    min-width: 120px;
    max-width: 120px;
  }
  .calc-table tbody td:first-child{
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
/* ===== Calc UX ===== */
.step{ margin-top:14px; padding-top:12px; border-top: 1px solid var(--border); }
.step-title{ font-weight:900; margin-bottom:8px; }

.chip-row{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:8px;
}
.chip-row.is-tight{ margin-top: 0; }
.chip{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  text-decoration:none;
  font-weight:900;
  cursor:pointer;
  user-select:none;
}
.chip.active{
  background: var(--primary);
  color: var(--primaryText);
  border-color: transparent;
}
.chip:hover{ filter: brightness(1.02); }

/* ===== Calc page layout polish (no logic impact) ===== */
.calc-stack{ display:flex; flex-direction:column; gap:14px; }
.calc-stack .step{
  margin-top:14px;
  padding:14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
}
.calc-stack .step:first-of-type{ margin-top: 12px; }
.calc-stack .step-title{ font-size: 14px; }

.calc-btnrow{ display:flex; gap:8px; flex-wrap:wrap; }

/* Selected template chips (specific / group) */
.calc-tpl-chip{ position: relative; padding-right: 40px; }
.calc-tpl-chip-x{
  position:absolute;
  right:10px;
  top:50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: inherit;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-weight: 900;
  cursor: pointer;
}
.calc-tpl-chip-x:hover{ filter: brightness(1.05); }
/* Mobile: keep text and × from overlapping (put × in normal flow) */
@media (max-width: 520px){
  .calc-tpl-chip{
    padding-right: 12px;
    justify-content: flex-start;
  }
  .calc-tpl-chip-x{
    position: static;
    transform: none;
    margin-left: 8px;
  }
}


/* ================================
   Calc scope radios (single/specific/all)
   - Keep radios compact inside chip labels on PC/iPad/mobile
   ================================ */
#calc-scope .chip{
  gap: 10px;
}
#calc-scope .chip input[type="radio"]{
  margin: 0;
}
@media (max-width: 420px){
  #calc-scope{
    gap: 6px;
  }
  #calc-scope .chip{
    padding: 8px 10px;
    font-size: 14px;
  }
}

.field-grid{
  display:grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
@media (max-width: 768px){
  .field-grid{ grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 420px){
  .field-grid{ grid-template-columns: 1fr; }
}

.field-card{
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 14px;
  padding: 12px;
  text-align:left;
  cursor:pointer;
  min-height: 72px;
}
.field-card.active{
  outline: 2px solid color-mix(in srgb, var(--primary) 65%, transparent);
  outline-offset: 0;
}
.field-name{ font-weight: 900; }
.field-sub{ margin-top:4px; }

.kpi{ margin-top:6px; padding: 12px; border: 1px solid var(--border); border-radius: 14px; background: color-mix(in srgb, var(--primary) 6%, transparent); }
.kpi-main{ font-size: 26px; font-weight: 1000; letter-spacing: .2px; }
.kpi-sub{ margin-top:4px; }

.kpi-grid{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top:10px;
}
@media (max-width: 520px){
  .kpi-grid{ grid-template-columns: 1fr; }
}
.kpi-item{
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 10px 12px;
}
.kpi-num{ font-weight: 900; font-size: 18px; margin-top:4px; }

.table-wrap{ overflow:auto; margin-top:8px; }
.simple-table{ width:100%; border-collapse: collapse; }
.simple-table th, .simple-table td{ padding: 10px 8px; border-bottom: 1px solid var(--border); }


/* ===== Calc empty state ===== */
.empty{
  padding: 18px;
  border: 1px dashed rgba(127,127,127,.45);
  border-radius: 12px;
}
.empty-title{
  font-weight: 700;
  margin-bottom: 6px;
}

/* disabled look for date inputs */
.is-disabled{
  opacity: .55;
  cursor: not-allowed;
}



/* ======================
   Auth (index.php)
   ====================== */

.auth-top{
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.auth-top-inner{
  width: min(var(--container), 100%);
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.auth-brand{
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.auth-logo{
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 900;
  letter-spacing: .5px;
  background: var(--primary);
  color: var(--primaryText);
  box-shadow: var(--shadow);
  user-select: none;
}

.auth-title{
  font-size: 16px;
  font-weight: 900;
  line-height: 1.1;
}

.auth-subtitle{
  font-size: 12px;
  color: var(--muted);
  line-height: 1.2;
  margin-top: 2px;
}

.auth-shell{
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: 16px;
  padding-top: 18px;
  padding-bottom: 18px;
}

@media (max-width: 980px){
  .auth-shell{ grid-template-columns: 1fr; }
}

.auth-hero h2{
  margin: 0 0 8px;
  font-size: 20px;
}

.auth-points{
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 14px;
}

.auth-point{
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
}

.auth-point-title{
  font-weight: 900;
  margin-bottom: 4px;
}

.auth-note{
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.auth-forms{
  display: grid;
  gap: 16px;
}

.auth-card{
  padding: 16px;
}

.auth-card-head{
  margin-bottom: 10px;
}

.auth-card h3{
  margin: 0 0 4px;
  font-size: 18px;
}

.auth-label{
  display: block;
  margin: 10px 2px 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 800;
}

.auth-links{
  margin-top: 10px;
  font-size: 13px;
}

.auth-divider{
  display:flex;
  align-items:center;
  gap:10px;
  margin:14px 0 10px;
  color: var(--muted);
  font-size:12px;
  font-weight:800;
}
.auth-divider::before,
.auth-divider::after{
  content:"";
  flex:1;
  height:1px;
  background: var(--border);
}
.auth-google-wrap{
  display:flex;
  flex-direction:column;
  gap:8px;
  align-items:center;
  margin-bottom:6px;
}
.auth-google-wrap > #google-login-button{
  width:100%;
  display:flex;
  justify-content:center;
}


.auth-check{
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 12px;
  font-size: 14px;
  user-select: none;
}
.auth-check input{
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}


.auth-hp{
  position: absolute;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.auth-footer{
  width: min(var(--container), 100%);
  margin: 0 auto;
  padding: 16px;
  text-align: center;
  font-size: 12px;
}

/* ボタンの見た目を auth で少し整える（既存互換） */
.btn.primary{
  background: var(--primary);
  color: var(--primaryText);
  border-color: transparent;
}

.btn.ghost{
  background: transparent;
  color: var(--text);
}
.btn.ghost:hover{
  background: color-mix(in srgb, var(--surface) 70%, transparent);
}


.btn.danger{ background: var(--danger, #b91c1c); color: #fff; }
.btn.danger:hover{ filter: brightness(0.95); }


/* ===== Settings: Template editor split (self / shared) ===== */
.tpl-editor-split{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 10px;
}

.tpl-editor-block{
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: var(--card);
}

.tpl-editor-title{
  margin: 0 0 10px;
  font-size: 14px;
}

.pill{
  display: inline-block;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(127,127,127,0.18);
  border: 1px solid var(--line);
  color: var(--muted);
}

@media (max-width: 860px){
  .tpl-editor-split{
    grid-template-columns: 1fr;
  }
}

/* ===== Settings: Template extra flags (time / evals) ===== */
.tpl-extra-row{
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-top: 10px;
}

.tpl-extra-item{
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
}

.tpl-flag-select{
  width: 100%;
}

.tpl-flag-radio{ margin-top:2px; }

/* Template editor: bottom actions row (save/clear + add item) */
.tpl-bottom-bar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-top:10px;
  flex-wrap:wrap;
}

.tpl-bottom-bar__left{
  display:flex;
  align-items:center;
  gap:8px;
  flex-wrap:wrap;
}

.tpl-bottom-bar__right{
  margin-left:auto;
}

.tpl-add-right{
  margin-top:10px;
  text-align:right;
}


@media (max-width: 520px){
  .tpl-extra-item{ min-width: 140px; }
}




/* ============================================================
   Template editor (settings.php) – dark mode readability fix
   ============================================================ */
@media (prefers-color-scheme: dark){
  /* Field editor rows (generated by assets/settings.js) */
  .field-row input,
  .field-row select{
    color: #000 !important;
    -webkit-text-fill-color: #000 !important; /* iOS Safari */
    /* In system-dark (no manual toggle), inputs may inherit a dark background.
       Keep editor inputs white so black text stays readable from the first load. */
    background: #fff !important;
  }

  /* Keep placeholder readable on light input backgrounds */
  .field-row input::placeholder{
    color: #7a7a7a !important;
    -webkit-text-fill-color: #7a7a7a !important; /* iOS Safari */
    opacity: 1;
  }
}


/* ===== Shared template badges & viewing highlight ===== */
.pill.pill-sharecount{
  display:inline-block;
  margin-left:8px;
  padding:2px 8px;
  font-size:12px;
  border-radius:999px;
  border:1px solid rgba(111,177,255,0.45);
  background: rgba(111,177,255,0.12);
  color: inherit;
}

#history-viewing-badge.viewing-strong{
  display:inline-block;
  padding:6px 10px;
  border-radius:10px;
  border:1px solid rgba(111,177,255,0.55);
  background: rgba(111,177,255,0.15);
  font-weight:700;
}
/* =========================================
   テンプレート作成/編集：項目入力欄の文字色統一
   PC / スマホ 共通
========================================= */

/* 項目名入力（例：体重、歩数など） */
.template-editor .template-item input[type="text"],
.template-editor .template-item input[type="number"],
.template-editor .template-item select {
  color: #000 !important;
}

/* プレースホルダー文字 */
.template-editor .template-item input::placeholder {
  color: #999;
  opacity: 1;
}

/* Safari / iOS 対応 */
.template-editor .template-item input::-webkit-input-placeholder {
  color: #999;
}
/* ============================================================
   Template editor (settings.php) – dark mode readability fix
   PC側（手動ダーク html[data-theme="dark"]）にも適用
   ============================================================ */
html[data-theme="dark"] .field-row input,
html[data-theme="dark"] .field-row select{
  color: #000 !important;
  -webkit-text-fill-color: #000 !important; /* Safari対策 */
  background: #fff !important; /* 入力欄は白で固定 */
}

html[data-theme="dark"] .field-row input::placeholder{
  color: #7a7a7a !important;
  -webkit-text-fill-color: #7a7a7a !important;
  opacity: 1;
}

html[data-theme="dark"] .field-row input::-webkit-input-placeholder{
  color: #7a7a7a !important;
}


/* =========================================================
   Template selector buttons: show selected state clearly
   - Unselected: outline
   - Selected: filled (primary)
   ========================================================= */
#template-selector .tpl-btn,
#history-template-selector .tpl-btn{
  background: transparent !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  box-shadow: none !important;
}

#template-selector .tpl-btn.is-selected,
#history-template-selector .tpl-btn.is-selected{
  background: var(--primary) !important;
  color: var(--primaryText) !important;
  border-color: transparent !important;
  box-shadow: 0 10px 20px rgba(0,0,0,.12) !important;
}


/* Image tags */
.img-wrap{ display:flex; flex-direction:column; gap:6px; }
.img-tags{ width:100%; padding:6px 8px; border:1px solid #ddd; border-radius:8px; }

/* Select search (template search) */
.select-search-wrap{ margin-bottom:6px; }
.select-search-input{ width:100%; margin:0; }
.select-search-hint{ margin-top:4px; }

/* ------------------------------
   Custom autocomplete (record)
------------------------------ */
.ac-box{
  position: absolute;
  z-index: 9999;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 14px 30px rgba(0,0,0,.12);
  max-height: 260px;
  overflow: auto;
  padding: 6px;
}

.ac-item{
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.ac-item:hover,
.ac-item.is-active{
  background: color-mix(in srgb, var(--surface) 70%, var(--bg));
}

.ac-empty{
  padding: 10px;
  color: #777;
  font-size: 12px;
}

/* image hashtag UI */
.img-thumb{ position:relative; }
.img-tag{
  position:absolute;
  top:6px;
  left:6px;
  padding:2px 6px;
  border-radius:999px;
  background:rgba(0,0,0,.55);
  color:#fff;
  font-size:12px;
  line-height:1.6;
  cursor:pointer;
  user-select:none;
}
.img-tags-badge{
  position:absolute;
  bottom:6px;
  left:6px;
  max-width:calc(100% - 12px);
  padding:2px 6px;
  border-radius:999px;
  background:rgba(0,0,0,.45);
  color:#fff;
  font-size:11px;
  line-height:1.6;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.img-search-grid{
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap:10px;
}
.img-search-item{ display:block; }
.img-search-item .mini{ margin-top:4px; }



/* === Image tag search improvements === */
.tag-suggest{
  display:flex;
  flex-wrap:wrap;
  gap:6px;
  margin-top:6px;
}
.tag-suggest button{
  border:1px solid var(--border);
  background: var(--surface);
  padding:4px 8px;
  border-radius:999px;
  font-size:12px;
  cursor:pointer;
}
.tag-suggest button:hover{ background: color-mix(in srgb, var(--surface) 80%, var(--bg)); }

.img-day-group{ margin-top:14px; }
.img-day-head{
  display:flex;
  justify-content:space-between;
  align-items:center;
  margin:6px 0;
}
.img-day-head .day{
  font-weight:600;
}
.img-day-head .day-link{
  text-decoration:underline;
  cursor:pointer;
  color:inherit;
}
.img-day-head .jump{
  font-size:12px;
  text-decoration:underline;
  cursor:pointer;
  color:inherit;
}

.img-search-item{
  border:1px solid var(--border);
  border-radius:10px;
  padding:8px;
  background: var(--surface);
}
.img-search-item img{
  width:100%;
  height:auto;
  border-radius:8px;
  display:block;
}
.tag-badges{
  display:flex;
  flex-wrap:wrap;
  gap:4px;
  margin-top:6px;
}
.tag-badge{
  font-size:11px;
  border:1px solid var(--border);
  padding:2px 6px;
  border-radius:999px;
  background: color-mix(in srgb, var(--surface) 92%, var(--bg));
  white-space:nowrap;
}
.img-search-actions{
  display:flex;
  gap:8px;
  margin-top:6px;
  align-items:center;
}
.img-search-actions button{
  font-size:12px;
  padding:4px 8px;
}
.img-tag-edit{
  display:flex;
  gap:6px;
  margin-top:6px;
}
.img-tag-edit input{
  flex:1;
  min-width:0;
}


/* ===== Template editor helpers ===== */
.fcell{
  border: 1px solid var(--border);
  background: rgba(255,255,255,.02);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.fcell.muted, .fcell-static.muted{ opacity: .65; }
.fcell-static{ user-select: none; }

.mini-btn{
  border: 1px solid var(--border);
  background: rgba(255,255,255,.02);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  line-height: 1;
  cursor: pointer;
}
.mini-btn:disabled{ opacity: .35; cursor: default; }
.mini-btn.danger{ border-color: rgba(255, 80, 80, .6); }



/* ============================================================
   settings.php Template editor row layout fix
   - Keep 項目1〜単位 on ONE line
   - Show メモ/数値 radio options vertically (PC/Tablet/Smartphone)
   NOTE: settings.js generates inline styles; we override with !important.
   ============================================================ */
.tpl-editor-block .field-row{
  align-items: flex-start !important;
}

.tpl-editor-block .field-grid{
  display: grid !important;
  /* 項目1 / 項目2 / メモ / 数値 / 単位 */
  grid-template-columns:
    minmax(120px, 1.15fr)
    minmax(120px, 1.15fr)
    minmax(180px, 1.4fr)
    minmax(110px, 0.9fr)
    minmax(140px, 1fr);
  gap: 10px !important;
  align-items: start !important;

  flex-wrap: nowrap !important; /* override inline */
  width: 100% !important;
}

/* Inline flex/min-width from JS must not fight the grid */
.tpl-editor-block .field-grid > div{
  min-width: 0 !important;
  flex: initial !important;
}

/* Memo column: stack radio options vertically */
.tpl-editor-block .field-grid > div:nth-child(3) > div:last-child{
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  gap: 6px !important;
  white-space: normal !important;
}

/* memo-radio-row: force vertical */
.tpl-editor-block .memo-radio-row{
  display: flex !important;
  flex-direction: column !important;
  flex-wrap: nowrap !important;
  align-items: flex-start !important;
  gap: 6px !important;
  white-space: normal !important;
}


/* Num radio row: same as memo (vertical) */
.tpl-editor-block .radio-row{
  display: flex !important;
  flex-direction: column !important;
  flex-wrap: nowrap !important;
  align-items: flex-start !important;
  gap: 6px !important;
  white-space: normal !important;
}

/* Remove inline margin-left from the 2nd label generated by JS */
.tpl-editor-block .memo-radio-row label,
.tpl-editor-block .radio-row label{
  margin-left: 0 !important;
}
/* Memo radio: compact, one-line */
.tpl-editor-block .field-grid label{
  display: inline-flex !important;
  align-items: center !important;
  gap: 4px !important;
  white-space: nowrap !important;
  line-height: 1.1 !important;
}

/* Use default radio size (user requested). Also remove extra margins. */
.tpl-editor-block .field-grid input[type="radio"]{
  transform: none !important;
  -webkit-transform: none !important;
  margin: 0 !important;
}

/* If the memo labels still wrap on very narrow widths, slightly tighten gaps */
@media (max-width: 900px){
  .tpl-editor-block .field-grid{
    gap: 8px !important;
    grid-template-columns:
      minmax(110px, 1.1fr)
      minmax(110px, 1.1fr)
      minmax(170px, 1.35fr)
      minmax(105px, 0.9fr)
      minmax(130px, 1fr);
  }
  .tpl-editor-block .field-grid > div:nth-child(3) > div:last-child{
    gap: 10px !important;
  }
}



/* ============================
   Record page (R1/R2)
   ============================ */
.rec-badges{
  display:inline-flex;
  gap:6px;
  margin-left:10px;
  vertical-align:middle;
}
.rec-badge{
  display:inline-block;
  font-size:12px;
  line-height:1;
  padding:4px 8px;
  border:1px solid rgba(17,24,39,.12);
  border-radius:999px;
  color: var(--muted);
  background: rgba(17,24,39,.03);
}

/* ============================
   History detail (H3)
   ============================ */
.hline.memo-toggle-wrap{
  display:block;
  margin:6px 0;
}
.hline.memo-toggle-wrap .memo-text{
  display:block;
  margin-bottom:6px;
  white-space:normal;
  word-break:break-word;
}
button.memo-toggle{
  appearance:none;
  border:1px solid rgba(17,24,39,.15);
  background: rgba(17,24,39,.02);
  color: var(--text);
  padding:6px 10px;
  border-radius:10px;
  font-size:12px;
  cursor:pointer;
}
button.memo-toggle:hover{
  background: rgba(17,24,39,.05);
}
button.memo-toggle.memo-toggle-close{
  margin-left:8px;
}


/* ===== calc candidates mobile usability ===== */
.field-card{
  align-self: start; /* avoid grid row stretch on mobile */
}
.field-card-row{ display:flex; align-items:flex-start; gap:8px; }
.field-card-body{ min-width:0; }
.field-card input[type="checkbox"]{
  width:18px;
  height:18px;
  flex:0 0 18px;
  margin-top:2px;
  accent-color: var(--primary);
}
@media (max-width: 768px){
  .field-grid{ grid-template-columns: repeat(2, minmax(0, 1fr)); gap:8px; }
  .field-card{ padding:10px; border-radius:12px; }
  .field-name{ font-size:14px; }
  .field-sub{ font-size:11px; }
}
@media (max-width: 420px){
  .field-grid{ grid-template-columns: 1fr; }
  .chip-row{ gap:6px; }
  .chip{ padding:8px 12px; }
}

/* === calc mobile: fix "自動計算" label wrapping/position (safe: calc step only) === */
@media (max-width: 768px){
  /* The row that contains auto-calc checkbox + run button */
  #calc-actions{
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    gap: 10px;
  }
  #calc-actions label{
    width: 100%;
    justify-content: flex-start;
    white-space: nowrap;
  }
  #calc-actions #calc-run{
    width: 100%;
  }
}
/* ===== Calc actions (auto + run) ===== */
#calc-actions{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}

/* ラベルは横並び・はみ出し防止 */
#calc-actions .calc-auto{
  display:flex;
  align-items:center;
  gap:8px;
  min-width:0;
  white-space:nowrap;
}

/* モバイルは縦積み + ボタン100% */
@media (max-width: 768px){
  #calc-actions{
    flex-direction:column;
    align-items:stretch;
    justify-content:flex-start;
  }
  #calc-actions .calc-auto{
    width:100%;
    justify-content:flex-start;
    overflow:hidden;
    text-overflow:ellipsis;
  }
  #calc-actions #calc-run{
    width:100%;
  }
}

/* ===== Footer ===== */
.app-footer{
  margin-top: 28px;
  padding: 18px 0;
  border-top: 1px solid rgba(0,0,0,0.08);
}
html[data-theme="dark"] .app-footer{
  border-top-color: rgba(255,255,255,0.14);
}
.footer-inner{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
}
.footer-links{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}
.footer-links a{
  color: inherit;
  text-decoration: none;
  opacity: 0.9;
}
.footer-links a:hover{
  text-decoration: underline;
  opacity: 1;
}
.footer-sep{
  opacity: 0.45;
}
.footer-copy{
  font-size: 12px;
  opacity: 0.7;
}

/* ================================
 * Suggest settings (My page)
 * - radio inputs must not inherit width:100% styles
 * ================================ */
.suggest-box .suggest-scope{
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.suggest-box .suggest-opt{
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0;
}

.suggest-box .suggest-opt input[type="radio"]{
  width: auto;
  min-height: auto;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  flex: 0 0 auto;
  margin-top: 2px;
}

.suggest-box .suggest-opt span{
  line-height: 1.4;
}

.suggest-box .suggest-actions{
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}


/* Location map collapse */
.loc-collapse{ margin: 8px 0; }
.loc-collapse-btn{ width: 100%; padding: 10px 12px; }
.leaflet-container.loc-collapsed{ display:none !important; }


/* Location map blocks */
.loc-row{ display:flex; flex-wrap:wrap; gap:10px; align-items:center; }
.loc-map{ width:100%; height:220px; border:1px solid var(--border); border-radius:12px; overflow:hidden; background: var(--surface); }
.loc-map.loc-collapsed{ display:none !important; }


/* ==========================
   Brand logo integration
   ========================== */
.auth-logo-img{
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: block;
  flex: 0 0 auto;
}

.logo{
  display:flex;
  align-items:center;
  gap: 8px;
}

.logo-img{
  width: 24px;
  height: 24px;
  border-radius: 8px;
  display:block;
  flex: 0 0 auto;
}

.logo-text{
  display:inline-block;
  min-width: 0;
}

.auth-actions{
  display:flex;
  align-items:center;
  gap: 10px;
  margin-left: auto;
}

@media (max-width: 700px){
  .auth-actions{
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
  }
}

/* ============================
   Support (お問い合わせ)
   ============================ */
.support-layout{
  display:grid;
  grid-template-columns: 320px 1fr;
  gap:12px;
  align-items:stretch;
}
@media (max-width: 900px){
  .support-layout{ grid-template-columns: 1fr; }
}
.support-sidebar{
  position:sticky;
  top:12px;
}
.support-ticket-list{
  display:flex;
  flex-direction:column;
  gap:8px;
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}
.support-ticket{
  text-align:left;
  border:1px solid rgba(17,24,39,.12);
  border-radius:12px;
  background: var(--surface);
  padding:10px;
  cursor:pointer;
  transition: opacity .18s ease, transform .18s ease, background-color .18s ease;
}
.support-ticket:hover{ background: rgba(17,24,39,.02); }
.support-ticket--active{ outline:2px solid rgba(17,24,39,.12); }
.support-ticket--fade{
  opacity:0;
  transform: translateY(10px);
}
.support-ticket__top{ display:flex; align-items:center; justify-content:space-between; gap:8px; }
.support-ticket__subject{ font-weight:700; }
.support-ticket__meta{ color: var(--muted); font-size:12px; margin-top:4px; }
.support-ticket__meta-row{ display:flex; gap:8px; flex-wrap:wrap; }
.support-ticket__badges{ display:flex; align-items:center; gap:6px; flex-wrap:wrap; }
.support-pill{
  display:inline-flex;
  align-items:center;
  padding:2px 8px;
  border-radius:999px;
  border:1px solid rgba(17,24,39,.12);
  font-size:12px;
  line-height:1.4;
  background: rgba(17,24,39,.03);
}
.support-pill--open{ background: rgba(37,99,235,.08); border-color: rgba(37,99,235,.18); }
.support-pill--closed{ background: rgba(34,197,94,.10); border-color: rgba(34,197,94,.18); }
.support-thread{
  border:1px solid rgba(17,24,39,.12);
  border-radius:12px;
  padding:12px;
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow:auto;
  background: var(--surface);
}
.support-msg{ padding:10px; border-radius:12px; margin:8px 0; border:1px solid rgba(17,24,39,.08); }
.support-msg--admin{ background: rgba(17,24,39,.02); }
.support-msg__meta{ display:flex; justify-content:space-between; gap:8px; color: var(--muted); font-size:12px; margin-bottom:6px; }
.support-msg__body{ font-size:14px; line-height:1.6; }
.support-attaches{ display:flex; flex-wrap:wrap; gap:8px; margin-top:10px; }
.support-attach img, .support-preview img{
  width:84px;
  height:84px;
  object-fit:cover;
  border-radius:10px;
  border:1px solid rgba(17,24,39,.12);
}
.support-preview{ display:inline-block; }
.support-form-row{ display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.support-form-row .input, .support-form-row select{ min-width:240px; }
.support-form-actions{ display:flex; gap:10px; align-items:center; flex-wrap:wrap; margin-top:8px; }
.support-status{ color: var(--muted); font-size:12px; }
.support-help{ color: var(--muted); font-size:12px; }
.support-current-title{ font-weight:700; margin:0 0 10px; }
.support-previews{ display:flex; flex-wrap:wrap; gap:8px; margin-top:8px; }

.support-ticket-toolbar{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
  justify-content:space-between;
}

.support-pager{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:10px;
  padding:8px 0 0;
}
.support-pager__info{
  color: var(--muted);
  font-size:12px;
}

.support-reply{ margin-top:12px; }
.support-reply__label{ margin-top:10px; }
.support-reply .actions{ margin-top:12px; }

.is-hidden{ display:none !important; }

/* Admin support: keep list/thread within viewport (prevent infinite page growth) */
.support-layout > .card{
  display:flex;
  flex-direction:column;
  height: calc(100vh - 170px);
  min-height: 560px;
}
.support-layout > .card .card__b{
  display:flex;
  flex-direction:column;
  gap:10px;
  flex:1;
  min-height:0;
  overflow:hidden;
}

@media (max-width: 900px){
  .support-layout > .card{ height:auto; min-height: 0; }
  .support-ticket-list{ max-height: 46vh; }
  .support-thread{ max-height: 50vh; }
}

@media (max-width: 500px){
  .support-thread{ max-height:420px; }
}

/* ===== me.php UI refinements (suggest / summary / invite) ===== */
.me-section{ margin-top:12px; }
.me-section__title{ font-size:16px; font-weight:700; margin:0 0 6px 0; }
.me-section__desc{ margin:0 0 12px 0; }

.suggest-options{ display:grid; gap:10px; margin-top:10px; }
.suggest-option{
  display:flex; gap:10px; align-items:flex-start;
  padding:12px;
  border:1px solid var(--border);
  border-radius:12px;
  background:rgba(0,0,0,0.02);
  cursor:pointer;
}
.suggest-option input[type="radio"]{ margin-top:3px; }
.suggest-option__title{ font-weight:700; line-height:1.2; }
.suggest-option__desc{ font-size:12px; color:var(--muted); margin-top:2px; }
.suggest-option.is-active{
  background:rgba(59,130,246,0.10);
  border-color:rgba(59,130,246,0.45);
}

.me-actions{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  align-items:center;
  margin-top:12px;
}
.me-sharebox textarea[readonly]{ background:rgba(0,0,0,0.02); }

/* Mobile tweaks */
@media (max-width: 640px){
  .me-actions{ justify-content:space-between; }
}

/* ==========================
   Record page: top flash message
   ========================== */
.flash{
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,.04);
  color: var(--text);
  font-size: 14px;
}
.flash.success{
  border-left: 4px solid var(--primary);
}
.flash.error{
  border-left: 4px solid var(--danger);
}

@media (prefers-color-scheme: dark){
  .flash{ background: rgba(255,255,255,.06); }
}
/* ==========================================================
   Modern polish v1 (SAFE: token overrides + additive styling)
   - Keeps light/dark switching behavior intact.
   - No forcing of html/body theme outside existing token system.
   ========================================================== */

/* Slightly more modern geometry & elevation (tokens) */
:root{
  --radius: 16px;
  --shadow: 0 12px 30px rgba(0,0,0,.10);
  --gap: 14px;
  --container: 1040px;
}

/* Dark token: keep elevation appropriate */
html[data-theme="dark"]{
  --shadow: 0 14px 34px rgba(0,0,0,.55);
  color-scheme: dark;
}
html[data-theme="light"]{
  color-scheme: light;
}

/* Improve text rendering */
body{
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Header: subtle glass effect when supported (no layout changes) */
@supports ((-webkit-backdrop-filter: blur(8px)) or (backdrop-filter: blur(8px))){
  .header{
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
}

/* Logo image + text vertical alignment (works even if no image) */
.logo{
  display:inline-flex;
  align-items:center;
  gap: 8px;
  line-height: 1;
}
.logo img{
  display:block;
  width: 28px;
  height: 28px;
}
.logo .logo-text, .logo span{
  line-height: 1.1;
  position: relative;
  top: -1px; /* visual centering on iOS */
  white-space: nowrap;
}

/* Buttons: clearer hierarchy */
.btn{
  box-shadow: 0 10px 22px rgba(0,0,0,.14);
}
html[data-theme="dark"] .btn{
  box-shadow: 0 12px 26px rgba(0,0,0,.55);
}
.btn.mini{
  border-radius: 12px;
}

/* Inputs: a bit more "app-like" */
input, select, textarea{
  border-radius: 14px;
  transition: box-shadow .15s ease, border-color .15s ease, background .15s ease;
}
input:focus, select:focus, textarea:focus{
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent);
}

/* Cards/sections: consistent spacing */
.card, .panel, .box, .section{
  border-radius: var(--radius);
}
.card + .card, .panel + .panel, .box + .box, .section + .section{
  margin-top: 14px;
}

/* Mobile: slightly larger tap padding and safer footer spacing */
@media (max-width: 640px){
  .container{
    padding-left: 14px;
    padding-right: 14px;
  }
  .nav a{
    padding: 10px 14px;
  }
  .btn{
    padding-left: 16px;
    padding-right: 16px;
  }
}

/* Dark: keep muted text readable */
html[data-theme="dark"] .muted,
html[data-theme="dark"] .sub,
html[data-theme="dark"] .desc,
html[data-theme="dark"] .help,
html[data-theme="dark"] small{
  color: rgba(229,231,235,.82);
  opacity: 1;
}

/* ========================================================== */


/* ===== Settings: Template editor one-row layout (prevent overlap) ===== */
.tpl-editor-block .field-grid,
.tpl-editor-block .field-grid-nowrap{
  display: flex !important;
  flex-wrap: nowrap !important;
  gap: 14px;
  align-items: flex-start;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 6px;
}

/* Each column: fixed width so inner controls (radio + unit) don't overlap neighbors */
.tpl-editor-block .field-grid > div,
.tpl-editor-block .field-grid-nowrap > div{
  flex: 0 0 auto !important;
  min-width: 220px;
  flex-shrink: 0 !important;
}

/* Item1 column can be slightly narrower */
.tpl-editor-block .field-grid > div:first-child,
.tpl-editor-block .field-grid-nowrap > div:first-child{
  min-width: 180px;
}

/* Radio rows: stack vertically to reduce horizontal width */
.tpl-editor-block .memo-radio-row,
.tpl-editor-block .radio-row{
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  gap: 6px !important;
  white-space: normal !important;
}

/* Remove left margins that widen the column */
.tpl-editor-block .radio-inline{
  margin: 0 !important;
}

/* Unit input shown under num/num2/num3: keep within column */
.tpl-editor-block input[type="text"],
.tpl-editor-block input[type="number"]{
  max-width: 100%;
}


/* ===== settings.php 作成済みテンプレート（区分け強化） ===== */
#tpl-list-section.settings-section { margin-top: 12px; }

/* ===== settings.php セクション区分け（1/2/3 & 作成済み） ===== */
/* 重要: light/dark混在防止のため、固定色(#fff/#000)は使わずトークンに統一 */
.settings-section{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 18px 16px;
  margin: 18px 0 22px;
  box-shadow: var(--shadow);
}
.settings-section h2{
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
  font-weight: 800;
}

.settings-badge{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 900;
  color: var(--primaryText);
  background: var(--primary);
  flex: 0 0 auto;
}

.settings-section.is-editor .settings-badge{ background:#2563eb; }
.settings-section.is-created .settings-badge{ background:#0ea5e9; }

.section-desc{
  color: var(--muted);
  font-size: 13px;
  margin: -4px 0 14px;
  line-height: 1.55;
}

/* editor内のサブカード見出し */
.tpl-editor-block.tpl-subcard .tpl-editor-title{
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
  font-weight: 800;
}

.tpl-editor-block.tpl-subcard{ margin-top: 12px; }
.tpl-editor-block.tpl-subcard:first-child{ margin-top: 0; }

.tpl-list-wrap { display: flex; flex-direction: column; gap: 14px; }

.tpl-subcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 14px 12px;
}

.tpl-subhead { display:flex; gap:10px; align-items:flex-start; margin-bottom: 10px; }
.tpl-subtitle { font-weight: 800; font-size: 14px; line-height: 1.2; }
.tpl-subdesc { color: var(--muted); font-size: 12px; margin-top: 4px; line-height: 1.4; }

.tpl-row { margin-top: 8px; }
.tpl-row-actions { display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.tpl-grow { flex:1; min-width:240px; }

/* settings.php: グループテンプレート（共通項目）の操作行 */
.gt-fields-actions{
  display:flex;
  gap:10px;
  align-items:center;
  flex-wrap:wrap;
  margin-top: 10px;
}

.tpl-meta { margin-top: 8px; }

.tpl-btn-dark { background:#444; }
.tpl-btn-danger { background:#2563eb; } /* 既存のボタン色に寄せる。必要なら後で赤系へ */
.tpl-btn-danger:hover { filter: brightness(0.95); }


/* ===== settings.php: 完了チェック / CSVエクスポート もセクションカードに統一 ===== */
#daily-completion,
#csv-export{
  margin-top: 12px;
  scroll-margin-top: 90px;
}

.settings-section.is-completion .settings-badge{ background:#7c3aed; } /* purple */
.settings-section.is-csv .settings-badge{ background:#f59e0b; }        /* amber */

/* ===== settings.php UI polish: mobile spacing + action row alignment ===== */
.st-actions{
  display:flex;
  gap:8px;
  align-items:center;
  justify-content:flex-end;
  flex-wrap:wrap;
}

.st-actions > *{
  margin:0; /* override legacy inline gaps where possible */
}

.st-actions select,
.st-actions input[type="text"]{
  flex: 1 1 260px;
  min-width: 200px;
}

@media (max-width: 768px){
  /* cards: slightly tighter on small screens */
  .settings-section{
    padding: 14px 12px 12px;
    margin: 14px 0 18px;
    border-radius: 12px;
  }

  .settings-section h2,
  .settings-section h3{
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 8px;
  }

  .settings-badge{
    width: 26px;
    height: 26px;
    border-radius: 8px;
    font-size: 13px;
  }

  /* action rows: easier tapping */
  .st-actions{
    justify-content: stretch;
  }

  .st-actions select,
  .st-actions input[type="text"]{
    flex: 1 1 100%;
    min-width: 0;
  }

  .st-actions .btn{
    flex: 1 1 calc(50% - 4px);
    width: auto;
  }
}

/* ===== 共通：ページヘッダー（settingsトーン） ===== */
.page-head{
  display:flex;
  align-items:flex-start;
  gap:12px;
  margin:0 0 12px;
  padding-bottom:10px;
  border-bottom:1px dashed #e5e7eb;
}
.page-badge{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:28px;
  height:28px;
  border-radius:8px;
  font-size:14px;
  font-weight:900;
  color:#fff;
  background:#2563eb;
  flex:0 0 auto;
  user-select:none;
}
.page-badge.is-calc{ background:#2563eb; }
.page-badge.is-share{ background:#0ea5e9; }
.page-badge.is-notices{ background:#7c3aed; }
.page-badge.is-contact{ background:#16a34a; }
.page-badge.is-me{ background:#f59e0b; }
.page-head-text{ min-width:0; }
.page-title{
  margin:0;
  font-weight:900;
  letter-spacing:.02em;
}
.page-desc{
  margin-top:2px;
  color:#475569;
  font-size:13px;
}

@media (max-width: 768px){
  .page-head{ gap:10px; margin-bottom:10px; }
  .page-desc{ font-size:12px; }
}


/* ===== help.php / legal pages tone alignment ===== */
.help-stack .notice{ margin-top: 12px; }
.help-stack ol{ margin-top: .4rem; }
.help-stack ul{ margin: .5rem 0 0 1.1rem; }
.help-stack h2 + p.muted{ margin-top: 8px; }
.legal-stack .legal-table{ margin-top: 12px; }
.legal-stack h3{ margin-top: 16px; }


/* ===== image_viewer.php ===== */
.iv-body{
  margin: 0;
  background: #000;
}

.iv-root{
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none; /* swipe handled by JS */
}

.iv-img{
  max-width: 100vw;
  max-height: 100vh;
  width: auto;
  height: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.iv-top{
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  z-index: 30;
  background: linear-gradient(180deg, rgba(0,0,0,0.55), rgba(0,0,0,0));
  pointer-events: none;
}

.iv-counter{
  pointer-events: auto;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .02em;
  background: rgba(0,0,0,0.35);
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.18);
}

.iv-close{
  pointer-events: auto;
  appearance: none;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.35);
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.iv-nav{
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  appearance: none;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.35);
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.iv-nav.is-hidden{
  display: none;
}

.iv-nav:disabled{
  opacity: .25;
  cursor: default;
}

.iv-prev{ left: 10px; }
.iv-next{ right: 10px; }

.iv-toast{
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 40;
  background: rgba(0,0,0,0.55);
  color: #fff;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}

.iv-toast.is-show{
  opacity: 1;
}

/* error view */
.iv-error{
  padding-top: 24px;
}

.iv-error-title{
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 900;
}

.iv-error-msg{
  margin: 0 0 12px;
}

.iv-error-help{
  margin: 0 0 12px;
}

.iv-error-actions{
  margin-top: 8px;
}

@media (max-width: 768px){
  .iv-top{ padding: 10px 10px; }
  .iv-prev{ left: 8px; }
  .iv-next{ right: 8px; }
  .iv-nav{
    width: 42px;
    height: 42px;
    border-radius: 14px;
    font-size: 26px;
  }
}


/* record.php: 画像アップロード中の表示＆ロック */
.uploading-box{
  margin-top:10px;
  padding:10px 12px;
  border:1px solid #ddd;
  border-radius:10px;
  background: rgba(0,0,0,0.04);
}
#record-image-preview.is-uploading{
  opacity: 0.75;
}

/* ===== History: range search ===== */
.mt12{ margin-top:12px; }

.history-range-actions{
  display:flex;
  gap:10px;
  align-items:center;
  flex-wrap:wrap;
  margin-top:10px;
}

.search-range-month{ margin-top: 10px; }
.search-range-month-title{ margin-bottom: 6px; }


/* === Logly: per-row time/evaluation controls (record/settings) === */

.rec-row-extras{ display:flex; flex-wrap:wrap; gap:10px; margin-top:8px; }
.rec-extra{ display:flex; align-items:center; gap:8px; padding:6px 10px; border:1px solid rgba(0,0,0,0.1); border-radius:8px; background:rgba(255,255,255,0.6); }
.rec-extra__label{ font-size:12px; color:#666; white-space:nowrap; }
.rec-time{ display:flex; align-items:center; gap:6px; }
.rec-time__hh, .rec-time__mm{ width:72px; }
.rec-time__colon{ color:#666; }

/* ===== record.php：各行の「時分/評価1/評価2」を横並びにする ===== */
.rec-row2 .rec-extra-row{
  display:flex;
  flex-wrap:wrap;
  gap:12px 14px;
  align-items:flex-end;
  margin:10px 0 0;
}

.rec-row2 .rec-extra-item{
  display:flex;
  flex-direction:column;
  gap:6px;
  min-width:160px;
}

.rec-row2 .rec-extra-time{ min-width:230px; }

.rec-row2 .rec-extra-label{ margin-bottom:0; }

.rec-row2 .rec-extra-ctrl{
  display:flex;
  align-items:center;
  gap:8px;
}

.rec-row2 .rec-extra-item .rec-sel{
  min-height: var(--tap);
  padding:10px 12px;
  border:1px solid var(--border);
  border-radius:12px;
  background:var(--surface);
  color:var(--text);
}

/* 時分（HH/MM）は横に並べる */
.rec-row2 .rec-extra-ctrl .rec-sel{
  width:auto;
  min-width:84px;
}

.rec-row2 .rec-extra-item > .rec-sel{
  width:100%;
}

.rec-row2 .rec-extra-colon{ opacity:.75; }

/* PC/タブレットは1行で3ブロック横並び */
@media (min-width: 900px){
  .rec-row2 .rec-extra-row{ flex-wrap:nowrap; }
}

/* ===== mail reminders (settings.php) ===== */
.reminder-box{
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: rgba(17,24,39,0.02);
}

/* Make the box title readable (it uses .mini in HTML) */
.reminder-box > .mini:first-child{
  color: var(--text);
}

.reminder-row{
  display: grid;
  grid-template-columns: 240px 280px 1fr 92px;
  gap: 8px;
  align-items: start;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.reminder-row + .reminder-row{ margin-top: 8px; }

.reminder-row textarea{
  width: 100%;
  min-height: 72px;
  resize: vertical;
}

/* recurring schedule UI */
.rem-weekdays{
  display:flex;
  flex-wrap:wrap;
  gap:6px;
  margin-top:6px;
}
.rem-wd{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:4px 8px;
  border:1px solid var(--border);
  border-radius:999px;
  background: rgba(17,24,39,0.02);
  font-size:12px;
}
.rem-wd input{ transform: translateY(1px); }
.rem-opt{ margin-top:8px; }
.rem-extra{ margin-top:6px; }
.rem-mmdd{ display:flex; gap:6px; align-items:center; margin-top:6px; }
.rem-next{ margin-top:6px; }
.rem-summary{ margin-top:6px; }
.rem-pre{ white-space:pre-wrap; line-height:1.5; margin-top:6px; }
.rem-mt6{ margin-top:6px; }

.reminder-row .reminder-badge{
  display: inline-block;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(17,24,39,0.06);
  color: rgba(17,24,39,0.75);
}

.reminder-row.is-sent{ opacity: .78; }

.reminder-row.is-sent input,
.reminder-row.is-sent textarea{
  background: rgba(0,0,0,0.03);
}

@media (max-width: 768px){
  .reminder-row{ grid-template-columns: 1fr; }
}

/* Mail reminder enable/disable */
.reminder-enable{
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.reminder-enable .radio-line{
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.2;
  color: var(--text);
}
.reminder-enable input[type="radio"]{
  transform: translateY(1px);
  accent-color: var(--primary);
}
.reminder-area.is-disabled{
  display: none;
}

/* Dark mode: keep reminder UI readable and avoid "light gray slab" */
@media (prefers-color-scheme: dark){
  .reminder-box{ background: rgba(255,255,255,0.04); }
  .rem-wd{ background: rgba(255,255,255,0.05); }
  .reminder-row .reminder-badge{
    background: rgba(255,255,255,0.10);
    color: rgba(229,231,235,0.92);
  }
  .reminder-row.is-sent input,
  .reminder-row.is-sent textarea{
    background: rgba(255,255,255,0.06);
  }
}

html[data-theme="dark"] .reminder-box{ background: rgba(255,255,255,0.04); }
html[data-theme="dark"] .rem-wd{ background: rgba(255,255,255,0.05); }
html[data-theme="dark"] .reminder-row .reminder-badge{
  background: rgba(255,255,255,0.10);
  color: rgba(229,231,235,0.92);
}
html[data-theme="dark"] .reminder-row.is-sent input,
html[data-theme="dark"] .reminder-row.is-sent textarea{
  background: rgba(255,255,255,0.06);
}

/* ================================
 * Location logs list (multi logs per entry)
 * ================================ */
.loclog-list{ border:1px solid var(--border); border-radius:12px; overflow:hidden; background: var(--surface); }
.loclog-empty{ padding:12px; color: var(--muted); font-size: 13px; }
.loclog-row{ display:flex; flex-wrap:wrap; gap:8px 10px; align-items:center; padding:10px 12px; border-top:1px solid rgba(17,24,39,.08); }
.loclog-row:first-child{ border-top:none; }
.loclog-badge{ display:inline-flex; align-items:center; gap:6px; padding:2px 8px; border-radius:999px; border:1px solid rgba(17,24,39,.12); background:#fff; font-size:12px; flex:0 0 auto; }
.loclog-main{ flex:1 1 auto; min-width: 180px; font-size: 13px; line-height:1.35; color: var(--text); }
.loclog-sub{ flex:1 1 100%; font-size: 12px; color: var(--muted); line-height:1.35; }
.loclog-actions{ flex:0 0 auto; margin-left:auto; display:flex; gap:8px; }
.loclog-del{ padding:6px 10px; border-radius:10px; border:1px solid rgba(220,38,38,.35); background:#fff; color:#b91c1c; cursor:pointer; font-size: 13px; font-weight: 800; line-height: 1; }
.loclog-del:hover{ background: rgba(220,38,38,.06); }
.loclog-link{ display:inline-flex; align-items:center; padding:6px 10px; border-radius:10px; border:1px solid rgba(17,24,39,.12); background:#fff; color: var(--text); text-decoration:none; cursor:pointer; font-size: 13px; font-weight: 800; line-height: 1; }
.loclog-link:hover{ background: rgba(17,24,39,.04); }

/* Dark mode: improve contrast for badges / links in today's location logs */
@media (prefers-color-scheme: dark){
  .loclog-row{ border-top:1px solid rgba(255,255,255,.08); }
  .loclog-badge{ background: rgba(255,255,255,.10); border-color: rgba(255,255,255,.18); }
  .loclog-link{ background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.18); }
  .loclog-link:hover{ background: rgba(255,255,255,.10); }
  .loclog-del{ background: rgba(255,92,119,.10); border-color: rgba(255,92,119,.45); color: var(--danger); }
  .loclog-del:hover{ background: rgba(255,92,119,.16); }
}
html[data-theme="dark"] .loclog-row{ border-top:1px solid rgba(255,255,255,.08); }
html[data-theme="dark"] .loclog-badge{ background: rgba(255,255,255,.10); border-color: rgba(255,255,255,.18); }
html[data-theme="dark"] .loclog-link{ background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.18); }
html[data-theme="dark"] .loclog-link:hover{ background: rgba(255,255,255,.10); }
html[data-theme="dark"] .loclog-del{ background: rgba(255,92,119,.10); border-color: rgba(255,92,119,.45); color: var(--danger); }
html[data-theme="dark"] .loclog-del:hover{ background: rgba(255,92,119,.16); }
@media (max-width: 700px){
  .loclog-actions{ width:100%; margin-left:0; }
  .loclog-del{ width:100%; }
  .loclog-link{ width:100%; justify-content:center; }
}
/* ==========================
   Scroll to Top Button
   ========================== */
#scrollTopBtn{
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 9999;

  width: 44px;
  height: 44px;
  border-radius: 999px;

  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);

  box-shadow: 0 10px 22px rgba(0,0,0,.14);
  cursor: pointer;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  /* ↑ を強調 */
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  text-shadow: 0 1px 0 rgba(0,0,0,.18);

  /* hidden by default */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity .15s ease, transform .15s ease, visibility .15s ease;

  -webkit-tap-highlight-color: transparent;
}

#scrollTopBtn.show{
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1.03);
}

#scrollTopBtn:hover{
  filter: brightness(1.02);
}

@media (max-width: 480px){
  #scrollTopBtn{
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }
}
/* ===== Maintenance mode (admin UI) ===== */
.mt-6{margin-top:6px;}
.mt-8{margin-top:8px;}
.mt-10{margin-top:10px;}
.mt-12{margin-top:12px;}
.mt-14{margin-top:14px;}
.mb-6{margin-bottom:6px;}
.w-100{width:100%;}
.gap-8{gap:8px;}
.gap-10{gap:10px;}
.flex-wrap{display:flex;flex-wrap:wrap;}
.flex-row{display:flex;align-items:center;flex-wrap:wrap;}
.fw-700{font-weight:700;}
.is-hidden{display:none !important;}
.text-danger{ color: var(--danger) !important; }
.notice-box{padding:10px 12px;border:1px solid rgba(0,0,0,.12);border-radius:12px;}
.select-std{min-height:44px;border-radius:12px;padding:0 12px;border:1px solid rgba(0,0,0,.15);}
.auth-brand-link{text-decoration:none;color:inherit;}

/* ===== Weather icon ===== */
.weather-inline{display:inline-flex;align-items:center;gap:6px;}
.weather-ico{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;}
.weather-ico svg{width:18px;height:18px;}
.weather-text{line-height:1;}

/* ===== record.php bottom fixed action bar ===== */
:root{
  --record-actionbar-h: 84px; /* fallback height */
}
.page-record main.container{
 /* 「完了」カード直下の余白は最小限に（フッター側で十分な余白を確保する） */
  padding-bottom: 24px;
}

.page-record .app-footer{
 /* フッターメニューが固定バーに隠れないように、フッター下側に余白を確保 */
  padding-bottom: calc(var(--record-actionbar-h) + 16px);
}

/* record.php ではページトップボタンも固定バーと干渉しない位置へ */
.page-record #scrollTopBtn{
  bottom: calc(12px + var(--record-actionbar-h) + env(safe-area-inset-bottom));
}

.record-actionbar{
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1200;
  background: rgba(255,255,255,.80);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
@media (prefers-color-scheme: dark){
  .record-actionbar{
    background: rgba(15,23,42,.78); /* --surface の暗色に寄せる */
  }
}
html[data-theme="dark"] .record-actionbar{
  background: rgba(15,23,42,.78);
}
html[data-theme="light"] .record-actionbar{
  background: rgba(255,255,255,.80);
}

.record-actionbar-inner{
  max-width: var(--container);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.record-actionbar-buttons{
  display: flex;
  justify-content: center;
  gap: 10px;
  width: 100%;
}
.record-actionbar .btn{
  min-height: 52px;
  padding: 0 18px;
  font-size: 16px;
  border-radius: 14px;
}
.record-actionbar #record-status{
  text-align: center;
}

/* 実測に近い高さ（2行構成＋safe-area）を確保 */
@supports (padding: env(safe-area-inset-bottom)){
  :root{ --record-actionbar-h: 92px; }
}


/* calc trend line chart */
.calc-linechart-card{
  margin-top:12px;
  padding:14px 14px 10px;
  border:1px solid var(--line, #d9dee8);
  border-radius:14px;
  background:var(--panel, #fff);
}
.calc-linechart-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-bottom:10px;
  flex-wrap:wrap;
}
.calc-linechart-title{
  font-weight:700;
}
.calc-linechart-svg{
  display:block;
  width:100%;
  height:320px;
}
.calc-linechart-axis,
.calc-linechart-grid,
.calc-linechart-line,
.calc-linechart-dot,
.calc-linechart-axis-label{
  vector-effect:non-scaling-stroke;
}
.calc-linechart-axis{
  stroke:#aeb8c8;
  stroke-width:1;
}
.calc-linechart-grid{
  stroke:#e7ecf4;
  stroke-width:1;
}
.calc-linechart-line{
  fill:none;
  stroke:#2f6fec;
  stroke-width:2.5;
  stroke-linecap:round;
  stroke-linejoin:round;
}
.calc-linechart-dot{
  fill:#2f6fec;
  stroke:#fff;
  stroke-width:1.5;
}
.calc-linechart-axis-label{
  fill:#6b7280;
  font-size:12px;
}
@media (max-width: 767px){
  .calc-linechart-card{
    padding:12px 10px 8px;
  }
  .calc-linechart-svg{
    height:240px;
  }
  .calc-linechart-axis-label{
    font-size:11px;
  }
}

/* ===== Shared template chat ===== */
.share-room-actions{ display:flex; gap:8px; flex-wrap:wrap; margin-top:8px; }
.share-room-last{ margin-top:4px; }
.share-chat-page{ gap:16px; }
.share-chat-head{ display:flex; justify-content:space-between; align-items:flex-start; gap:12px; flex-wrap:wrap; }
.share-chat-card{ padding:0; overflow:hidden; }
.share-chat-thread{ max-height:62vh; overflow:auto; padding:14px; background:rgba(17,24,39,.02); }
.share-chat-form{ border-top:1px solid var(--border); padding:12px; background:var(--surface); }
.share-chat-form textarea{ width:100%; min-height:96px; resize:vertical; }
.share-chat-actions{ display:flex; justify-content:space-between; align-items:center; gap:10px; margin-top:8px; }
.share-chat-date{ text-align:center; color:var(--muted); font-size:12px; margin:8px 0; }
.share-msg{ max-width:min(82%, 720px); padding:10px 12px; border-radius:14px; margin:10px 0; border:1px solid rgba(17,24,39,.08); background:var(--surface); }
.share-msg--mine{ margin-left:auto; background:rgba(14,165,233,.08); }
.share-msg--other{ margin-right:auto; background:rgba(17,24,39,.03); }
.share-msg__meta{ display:flex; justify-content:space-between; gap:8px; color:var(--muted); font-size:12px; margin-bottom:6px; }
.share-msg__body{ font-size:14px; line-height:1.65; word-break:break-word; }
.share-msg__footer{ margin-top:8px; display:flex; align-items:center; justify-content:space-between; gap:12px; }
.share-msg__read{ font-size:12px; color:var(--muted); }
.share-msg__delete{ border:none; background:none; color:#b91c1c; padding:0; font-size:12px; cursor:pointer; }
.share-msg--unsent{ opacity:.78; }
@media (max-width: 640px){ .share-msg{ max-width:92%; } .share-chat-thread{ max-height:56vh; } }



/* share chat image upload */
.share-chat-upload-row{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:10px}
.share-chat-upload-btn{position:relative;overflow:hidden}
.share-chat-preview{margin-top:10px}
.share-chat-preview-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(120px,1fr));gap:10px}
.share-chat-preview-item{position:relative;border:1px solid #d7deea;border-radius:12px;padding:8px;background:#fff}
.share-chat-preview-item img{display:block;width:100%;height:100px;object-fit:cover;border-radius:8px}
.share-chat-preview-remove{position:absolute;top:6px;right:6px;border:none;border-radius:999px;width:28px;height:28px;background:rgba(0,0,0,.65);color:#fff;font-weight:700;cursor:pointer}
.share-chat-preview-name{margin-top:6px;font-size:12px;color:#5d6b82;word-break:break-all}
.share-msg__images{margin-top:8px;display:grid;grid-template-columns:1fr;gap:10px}
.share-msg__images.is-grid{grid-template-columns:repeat(auto-fit,minmax(140px,1fr))}
.share-msg__image-wrap{position:relative}
.share-msg__image{display:block;width:100%;max-width:320px;border-radius:12px;border:1px solid #d7deea;background:#fff}
.share-msg--mine .share-msg__image{margin-left:auto}
.share-msg__image-delete{margin-top:6px;border:none;border-radius:999px;padding:6px 10px;background:#eef3fb;color:#31425f;cursor:pointer;font-size:12px}
@media (max-width: 768px){
  .share-chat-preview-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
  .share-msg__images.is-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
  .share-msg__image{max-width:none}
}
