:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2024;
  --muted: #65707c;
  --border: #e2e5e9;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --sun: #d1343b;
  --sat: #2563eb;
  --closed-bg: #fdecec;
  --warn-bg: #fff4e0;
  --warn-text: #92400e;
  --period: #d9f4ef;
  --next: #f59e0b;
  --today: #ea580c;
  --visit: #7c3aed;
  --c1: #0f766e; --c2: #f59e0b; --c3: #7c3aed; --c4: #2563eb; --c5: #db2777; --c6: #65a30d;
  color-scheme: light;
}
/* ダーク：システム設定（手動でライト指定時は除く）または手動指定 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111416;
    --surface: #1b1f22;
    --text: #e8eaed;
    --muted: #9aa4ae;
    --border: #2d3338;
    --accent: #2dd4bf;
    --accent-soft: #123a36;
    --sun: #f87171;
    --sat: #60a5fa;
    --closed-bg: #3a1d1f;
    --warn-bg: #3a2a10;
    --warn-text: #fcd34d;
    --period: #133a35;
    --c1: #2dd4bf; --c2: #fbbf24; --c3: #a78bfa; --c4: #60a5fa; --c5: #f472b6; --c6: #a3e635;
    --today: #fb923c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111416;
  --surface: #1b1f22;
  --text: #e8eaed;
  --muted: #9aa4ae;
  --border: #2d3338;
  --accent: #2dd4bf;
  --accent-soft: #123a36;
  --sun: #f87171;
  --sat: #60a5fa;
  --closed-bg: #3a1d1f;
  --warn-bg: #3a2a10;
  --warn-text: #fcd34d;
  --period: #133a35;
  --c1: #2dd4bf; --c2: #fbbf24; --c3: #a78bfa; --c4: #60a5fa; --c5: #f472b6; --c6: #a3e635;
  --today: #fb923c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.theme-btn {
  border: 0; background: none; width: 36px; height: 36px; border-radius: 8px;
  font-size: 18px; line-height: 1; color: var(--muted);
}
.theme-btn:active { background: var(--bg); }
.top h1 { font-size: 17px; margin: 0; color: var(--accent); white-space: nowrap; }
@media (max-width: 400px) { .top h1 { display: none; } }
nav { display: flex; gap: 4px; margin-left: auto; background: var(--bg); padding: 3px; border-radius: 10px; }
[role="tab"] {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; color: var(--muted);
}
[role="tab"][aria-selected="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .12); }

.update {
  display: block; width: 100%; border: 0; padding: 10px 16px;
  background: var(--accent); color: #fff; font-weight: 600;
}
.update[hidden] { display: none; }

main { max-width: 640px; margin: 0 auto; padding: 12px 16px 32px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 16px; margin-bottom: 12px;
}
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 14px 0 6px; }
summary { font-weight: 600; cursor: pointer; }
details[open] summary { margin-bottom: 8px; }
details.sub { margin-top: 10px; }
details.sub summary { font-weight: 400; font-size: 13px; color: var(--muted); }

input[type="date"], input[type="time"], input[type="number"] {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  min-height: 40px;
}
input[type="number"] { width: 5.5em; text-align: right; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }

.field-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.field-row:last-child { margin-bottom: 0; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.grid2 input { width: 100%; font-size: 18px; color: var(--text); }

.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 6px 12px; min-height: 40px;
}
.btn.icon { width: 40px; padding: 0; font-size: 20px; line-height: 1; }
.btn:active, .chip:active { transform: scale(.97); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.chip {
  border: 1px solid var(--border); background: var(--bg); border-radius: 999px;
  padding: 6px 12px; min-height: 36px; font-size: 14px;
}
.suggest .chip { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.result { margin-top: 10px; }
.row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; padding: 4px 0; }
.label { font-size: 13px; color: var(--muted); min-width: 6.5em; }
.big { font-size: 20px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.tag.warn { background: var(--closed-bg); color: var(--sun); font-weight: 600; }
.alert { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-text); font-size: 14px; }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

/* カレンダー */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cal-head h2, .cal-head h3 { margin: 0; flex: 1; text-align: center; }
.title-btn {
  border: 0; background: none; padding: 6px 12px; border-radius: 8px;
  font-size: 15px; font-weight: 700; min-height: 40px;
}
.title-btn:active { background: var(--bg); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.wd { text-align: center; font-size: 12px; color: var(--muted); padding: 2px 0; }
.wd.sun, .day.sun .n { color: var(--sun); }
.wd.sat, .day.sat .n { color: var(--sat); }
.day {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  min-height: 60px; padding: 5px 1px 4px; border: 1px solid var(--border); border-radius: 8px;
  background: transparent; overflow: hidden;
}
.day .n { font-size: 15px; font-weight: 500; }
.day .h { font-size: 9px; line-height: 1.1; color: var(--sun); text-align: center; word-break: break-all; }
.day .off { margin-top: auto; font-size: 9px; line-height: 1.2; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; letter-spacing: -.03em; }
.day.closed { background: var(--closed-bg); }
.day.period { background: var(--period); }
.day.period.closed { background: linear-gradient(135deg, var(--period) 50%, var(--closed-bg) 50%); }
.day.out { opacity: .4; }
.day.today .n {
  display: grid; place-items: center; width: 26px; height: 26px; margin-top: -2px;
  border-radius: 50%; background: var(--accent); color: var(--surface); font-weight: 700;
}
.day.base { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
/* 今日は起点日より優先して表示する */
.day.today { border-color: var(--today); box-shadow: inset 0 0 0 1px var(--today); }
.day.next { border-color: var(--next); box-shadow: inset 0 0 0 1px var(--next); }
.day.visit { border-color: var(--visit); box-shadow: inset 0 0 0 2px var(--visit); }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.lg { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -2px; border: 2px solid transparent; }
.lg.today { border-color: var(--today); }
.lg.base { border-color: var(--accent); }
.lg.period { background: var(--period); }
.lg.next { border-color: var(--next); }
.lg.visit { border-color: var(--visit); }

.months-head { margin-bottom: 12px; }
.months-head h2 { margin: 0; }
.months { display: grid; gap: 0 12px; }
.month h2 { text-align: center; }
@media (min-width: 1000px) {
  main:has(#panel-months:not([hidden])) { max-width: 1100px; }
  .months { grid-template-columns: 1fr 1fr; }
}

.app-footer { text-align: center; padding: 8px 0 0; }

.weeks { display: grid; gap: 6px; }
.week {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  text-align: left; border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 8px 12px;
}
.week .w { font-weight: 700; min-width: 4em; }

.hol-list { list-style: none; padding: 0; margin: 0; }
.hol-list li { display: flex; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.hol-list li:last-child { border-bottom: 0; }
.link { border: 0; background: none; padding: 0; color: var(--accent); min-width: 8.5em; text-align: left; }

/* 当直 */
.stepper { margin-top: 12px; }
.stepper input { width: 3.5em; text-align: center; }
.switch { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; margin: 2px 0 12px; }
.switch .big { font-size: 30px; color: var(--accent); }
.switch .sep { color: var(--muted); }
.bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; gap: 2px; }
.shifts { list-style: none; padding: 0; margin: 12px 0 0; }
.shifts li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px solid var(--border); }
.shifts li:last-child { border-bottom: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.who { font-weight: 600; min-width: 3.5em; }
.range { font-variant-numeric: tabular-nums; }
.len { margin-left: auto; color: var(--muted); font-size: 14px; }
