/* Layout: a settings sheet (諸元・会場・日程) stacked above the time grid; the grid is the working surface,
   times run down the page like a printed program, rooms run across. */
:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f5f7fa;
  --sunk: #e4e8ee;
  --fg: #18202b;
  --muted: #5b6676;
  --faint: #8a94a3;
  --line: #d3d9e1;
  --line-soft: #e5e9ef;
  --accent: #1d4b86;
  --accent-soft: #dfe8f5;
  --accent-fg: #ffffff;
  --ok: #2a7a4b;
  --warn: #a8560c;
  --bad: #c0332e;
  --warn-soft: #fbefe1;
  --bad-soft: #fbe6e5;
  --ok-soft: #e3f2e8;
  --hatch: rgba(24, 32, 43, 0.06);
  --shadow: 0 1px 2px rgba(20, 30, 45, 0.08), 0 4px 16px rgba(20, 30, 45, 0.08);

  --font-ui: "IBM Plex Sans JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --fs-xs: 0.72rem;
  --fs-sm: 0.8rem;
  --fs-md: 0.9rem;
  --fs-lg: 1.05rem;
  --radius: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c;
    --surface: #1a2028;
    --surface-2: #1f2630;
    --sunk: #151a21;
    --fg: #e5e9ef;
    --muted: #a1abb9;
    --faint: #76808e;
    --line: #333c48;
    --line-soft: #29313b;
    --accent: #8cb4ea;
    --accent-soft: #23344b;
    --accent-fg: #0f1722;
    --ok: #6cc28e;
    --warn: #e5a052;
    --bad: #f07a73;
    --warn-soft: #3a2a17;
    --bad-soft: #3d1f1f;
    --ok-soft: #1b3325;
    --hatch: rgba(229, 233, 239, 0.06);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c;
  --surface: #1a2028;
  --surface-2: #1f2630;
  --sunk: #151a21;
  --fg: #e5e9ef;
  --muted: #a1abb9;
  --faint: #76808e;
  --line: #333c48;
  --line-soft: #29313b;
  --accent: #8cb4ea;
  --accent-soft: #23344b;
  --accent-fg: #0f1722;
  --ok: #6cc28e;
  --warn: #e5a052;
  --bad: #f07a73;
  --warn-soft: #3a2a17;
  --bad-soft: #3d1f1f;
  --ok-soft: #1b3325;
  --hatch: rgba(229, 233, 239, 0.06);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; color: inherit; }
h2 { font-size: var(--fs-md); margin: 0; font-weight: 700; letter-spacing: 0.02em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-inline: 16px;
  padding-block: 0 32px;
  max-width: 1600px;
  margin: 0 auto;
}

/* ---- top bar ---- */
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding-block: 10px;
  margin-inline: -16px;
  padding-inline: 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 320px; }
.brand-mark {
  width: 28px; height: 28px; flex: none; border-radius: 5px;
  background:
    linear-gradient(var(--accent), var(--accent)) 5px 6px / 8px 10px no-repeat,
    linear-gradient(var(--accent), var(--accent)) 15px 6px / 8px 16px no-repeat,
    linear-gradient(var(--faint), var(--faint)) 5px 18px / 8px 4px no-repeat,
    var(--accent-soft);
}
.brand-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.brand-name { font-size: var(--fs-xs); color: var(--muted); letter-spacing: 0.08em; }
.title-input {
  border: 1px solid transparent; background: transparent; border-radius: 4px;
  font-size: var(--fs-lg); font-weight: 700; padding: 0 4px; margin-left: -5px;
  min-width: 0; width: 100%;
}
.title-input:hover { border-color: var(--line); }
.title-input:focus { border-color: var(--accent); background: var(--surface); outline: none; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  border-radius: var(--radius); padding: 6px 12px; cursor: pointer;
  font-size: var(--fs-sm); font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: default; border-color: var(--line); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--fg); border-color: var(--line); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.small { padding: 3px 8px; font-size: var(--fs-xs); }
.btn.icon { padding: 6px 8px; }
.btn.icon svg { width: 16px; height: 16px; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn + .btn { margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.btn-group .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.btn-group .btn:hover { position: relative; z-index: 1; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); position: relative; z-index: 1; }

/* ---- workspace: 諸元（左）とタイムテーブル（右）を並べる ---- */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: start; }
@media (min-width: 1100px) {
  .workspace { grid-template-columns: minmax(340px, 400px) minmax(0, 1fr); }
  .setup {
    position: sticky; top: calc(var(--topbar-h, 64px) + 8px + env(safe-area-inset-top, 0px));
    max-height: calc(100vh - var(--topbar-h, 64px) - 24px); display: flex; flex-direction: column;
  }
  .setup-body { overflow: auto; overscroll-behavior: contain; }
  .grid-scroll { max-height: calc(100vh - var(--topbar-h, 64px) - 150px); }
}

/* ---- setup ---- */
.setup { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.setup-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 10px 0; border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 2px; overflow-x: auto; }
.tab {
  border: 0; background: transparent; padding: 8px 14px 9px; cursor: pointer;
  font-size: var(--fs-sm); font-weight: 500; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--fg); }
.tab[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); font-weight: 700; }
.setup-body { padding: 12px; }
.setup.collapsed .setup-body { display: none; }
.setup.collapsed .setup-head { border-bottom: 0; padding-bottom: 6px; }

.spec-total {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 6px; margin-bottom: 10px;
  padding: 8px 10px; background: var(--sunk); border-radius: 6px; font-size: var(--fs-xs); color: var(--muted);
}
.spec-total > span:first-child { font-weight: 700; color: var(--fg); margin-right: 4px; }
.spec-total b { font-family: var(--font-num); font-variant-numeric: tabular-nums; color: var(--fg); font-size: var(--fs-sm); }
.tcards { display: flex; flex-direction: column; gap: 8px; }
.tcard {
  border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
  border-top: 3px solid var(--c);
}
.tcard-head { display: flex; align-items: center; gap: 6px; padding: 6px 6px 0 8px; }
.tcard-head .field { flex: 1; }
.twisty { width: 28px; font-size: var(--fs-sm); }
.tcard-sum {
  display: flex; flex-wrap: wrap; gap: 2px 12px; padding: 2px 10px 6px 42px;
  font-size: var(--fs-xs); color: var(--muted);
}
.tcard-sum b, .calc { font-family: var(--font-num); font-variant-numeric: tabular-nums; color: var(--fg); font-weight: 600; }
.tcard-body { border-top: 1px solid var(--line-soft); padding: 8px 10px 8px; }
.tgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
.trow { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.trow.wide { grid-column: 1 / -1; }
.tlabel { font-size: var(--fs-xs); color: var(--muted); }
.tctl { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-height: 28px; }
.tcard-foot {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px;
  margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line-soft);
}
.tcard-total { font-size: var(--fs-xs); color: var(--muted); }
.tcard-total b { font-family: var(--font-num); color: var(--fg); }
.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); }
.stepper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.stepper .field.num { border: 0; border-radius: 0; width: 46px; text-align: center; box-shadow: none; padding-inline: 2px; -moz-appearance: textfield; }
.stepper .field.num::-webkit-inner-spin-button, .stepper .field.num::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.step {
  border: 0; background: var(--surface-2); color: var(--muted); width: 24px; cursor: pointer; font-size: var(--fs-sm); line-height: 1;
}
.step:first-child { border-right: 1px solid var(--line-soft); border-radius: 3px 0 0 3px; }
.step:last-child { border-left: 1px solid var(--line-soft); border-radius: 0 3px 3px 0; }
.step:hover { color: var(--fg); background: var(--accent-soft); }

.switch { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--fg); cursor: pointer; font-weight: 500; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  width: 30px; height: 18px; border-radius: 999px; background: var(--line); position: relative; flex: none; transition: background 0.15s;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 0.15s;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(12px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.table-scroll { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: 6px; }
.spec {
  border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%;
  font-size: var(--fs-sm);
}
.spec th, .spec td { padding: 4px 6px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.spec tbody tr:last-child th, .spec tbody tr:last-child td { border-bottom: 0; }
.spec th[scope="row"] {
  position: sticky; left: 0; z-index: 1; background: var(--surface-2);
  text-align: left; font-weight: 500; white-space: nowrap; color: var(--muted);
  border-right: 1px solid var(--line-soft); min-width: 168px;
}
.spec th[scope="row"] small { display: block; font-weight: 400; color: var(--faint); font-size: var(--fs-xs); }
.spec thead th { background: var(--surface-2); padding: 6px; text-align: left; min-width: 150px; }
.spec thead th:first-child { position: sticky; left: 0; z-index: 2; }
.spec td { min-width: 150px; }
.spec tr.computed td, .spec tr.computed th { background: var(--surface-2); }
.spec tr.computed td { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 600; }
.spec tr.group-start th, .spec tr.group-start td { border-top: 1px solid var(--line); }
.type-head { display: flex; align-items: center; gap: 6px; }
.type-head input[type="text"] { font-weight: 700; }
.swatch { width: 26px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; cursor: pointer; flex: none; }
.swatch::-webkit-color-swatch-wrapper { padding: 2px; }
.swatch::-webkit-color-swatch { border: 0; border-radius: 2px; }

.field {
  width: 100%; min-width: 0; border: 1px solid var(--line); background: var(--surface);
  border-radius: 4px; padding: 3px 6px; font-size: var(--fs-sm);
}
.field:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px var(--accent-soft); }
.field.num { width: 64px; font-family: var(--font-num); font-variant-numeric: tabular-nums; text-align: right; }
.field.time { width: 96px; font-family: var(--font-num); }
.unit { color: var(--faint); font-size: var(--fs-xs); margin-left: 4px; }
.inline { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); color: var(--muted); cursor: pointer; }
.daypick { display: flex; gap: 3px; flex-wrap: wrap; }
.daypick label {
  display: inline-flex; align-items: center; justify-content: center; min-width: 30px; padding: 2px 6px;
  border: 1px solid var(--line); border-radius: 4px; font-size: var(--fs-xs); cursor: pointer; user-select: none;
  font-family: var(--font-num);
}
.daypick input { position: absolute; opacity: 0; pointer-events: none; }
.daypick label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.daypick label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.setup-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-top: 10px; font-size: var(--fs-xs); color: var(--muted); }
.mismatch { color: var(--warn); }
.match { color: var(--ok); }

.rooms-table { border-collapse: collapse; width: 100%; font-size: var(--fs-sm); }
.rooms-table th { text-align: left; font-weight: 500; color: var(--muted); padding: 4px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.rooms-table td { padding: 4px 6px; border-bottom: 1px solid var(--line-soft); }
.rooms-table .field.code { width: 52px; text-align: center; font-family: var(--font-num); }
.row-tools { display: flex; gap: 4px; justify-content: flex-end; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 20px; }
.form-row { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.form-row > span { font-size: var(--fs-xs); color: var(--muted); }
.form-row small { color: var(--faint); font-size: var(--fs-xs); }
.fieldset-title { font-size: var(--fs-xs); color: var(--muted); letter-spacing: 0.06em; margin: 14px 0 6px; font-weight: 700; }
.fieldset-title:first-child { margin-top: 0; }

/* ---- board ---- */
.board { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.board-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 4px 12px; font-size: var(--fs-sm); cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-selected="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.chip .date { font-family: var(--font-num); font-size: var(--fs-xs); opacity: 0.75; margin-left: 4px; }
.board-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.zoom { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--muted); }
.zoom input { width: 110px; }

.status { display: flex; flex-wrap: wrap; gap: 6px; }
.stat {
  display: inline-flex; align-items: baseline; gap: 6px; padding: 4px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  font-size: var(--fs-xs); color: var(--muted);
}
.stat b { color: var(--fg); font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: var(--fs-sm); }
.stat .dot { width: 8px; height: 8px; border-radius: 2px; background: var(--c); align-self: center; }
.stat.under { border-color: var(--warn); background: var(--warn-soft); }
.stat.over { border-color: var(--bad); background: var(--bad-soft); }
.stat .flag { font-weight: 700; }
.stat.under .flag { color: var(--warn); }
.stat.over .flag { color: var(--bad); }
.stat.total { background: var(--sunk); border-color: transparent; }
button.stat { cursor: pointer; font: inherit; font-size: var(--fs-xs); }
button.stat:hover { border-color: var(--c, var(--accent)); }
.bulk-preview { display: flex; flex-direction: column; gap: 2px; font-family: var(--font-ui); font-size: var(--fs-sm); }
.bulk-preview span { white-space: nowrap; }

.grid-scroll {
  position: relative; overflow: auto; max-height: min(78vh, 1100px);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  overscroll-behavior: contain;
}
.grid { display: grid; position: relative; min-width: max-content; }
.g-corner, .g-day, .g-room {
  position: sticky; z-index: 6; background: var(--surface-2);
  border-bottom: 1px solid var(--line); border-right: 1px solid var(--line-soft);
  padding: 4px 6px; font-size: var(--fs-sm); font-weight: 700; text-align: center;
}
.g-corner { left: 0; z-index: 8; font-size: var(--fs-xs); font-weight: 500; color: var(--faint); display: flex; align-items: end; justify-content: center; }
.g-day { top: 0; background: var(--fg); color: var(--bg); border-right-color: var(--bg); }
.g-room { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-room small { display: block; font-weight: 400; color: var(--faint); font-size: var(--fs-xs); }
.g-room.day-start, .g-col.day-start { border-left: 2px solid var(--fg); }
.g-times {
  position: sticky; left: 0; z-index: 5; background: var(--surface-2);
  border-right: 1px solid var(--line);
}
.g-time {
  position: absolute; right: 6px; transform: translateY(-50%);
  font-family: var(--font-num); font-size: var(--fs-xs); color: var(--faint); font-variant-numeric: tabular-nums;
}
.g-time.hour { color: var(--fg); font-weight: 600; }
.g-col { position: relative; border-right: 1px solid var(--line-soft); cursor: copy; }
.g-band {
  position: absolute; left: 0; right: 0; pointer-events: none;
  background: repeating-linear-gradient(135deg, var(--hatch) 0 6px, transparent 6px 12px);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-xs); color: var(--faint); letter-spacing: 0.1em;
}
.g-band.after { background: var(--hatch); }
.g-break {
  position: absolute; left: 3px; right: 3px; pointer-events: none; z-index: 1;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  font-size: var(--fs-xs); line-height: 1; color: var(--muted); letter-spacing: 0.04em;
  background: var(--surface-2); border-radius: 3px;
}
.g-break.break { background: color-mix(in srgb, var(--ok) 10%, var(--surface)); color: color-mix(in srgb, var(--ok) 75%, var(--fg)); }
.g-break.lunch {
  background: repeating-linear-gradient(135deg, var(--hatch) 0 6px, transparent 6px 12px), var(--surface-2);
  color: var(--muted); letter-spacing: 0.1em;
}
.g-break.idle { background: transparent; border: 1px dashed var(--line); color: var(--faint); }
.g-break span { white-space: nowrap; }
.g-mark {
  position: absolute; left: 0; right: 0; height: 0; border-top: 1px dashed var(--faint); pointer-events: none; opacity: 0.6;
}

.blk {
  --c: #2f6db3;
  position: absolute; left: 3px; right: 3px;
  background: color-mix(in srgb, var(--c) 17%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--c) 55%, var(--surface));
  border-radius: 4px; overflow: hidden; cursor: grab; touch-action: none; user-select: none;
  font-size: var(--fs-xs); line-height: 1.35; padding: 3px 6px 6px;
  z-index: 2;
}
.blk:hover { border-color: var(--c); z-index: 3; }
.blk:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; z-index: 4; }
/* 幅が足りないときは「番号／種別」「時刻／編数」の単位で折り返す */
.blk .b-top { display: flex; flex-wrap: wrap; gap: 0 6px; align-items: baseline; }
.blk .b-code { font-family: var(--font-num); font-weight: 600; color: color-mix(in srgb, var(--c) 70%, var(--fg)); }
.blk .b-type { font-weight: 700; }
.blk .b-time { display: flex; flex-wrap: wrap; gap: 0 6px; font-family: var(--font-num); color: var(--muted); font-variant-numeric: tabular-nums; }
.blk .b-code, .blk .b-time span { white-space: nowrap; }
.blk .b-dur { color: var(--fg); font-weight: 600; }
.blk .b-type, .blk .b-title, .blk .b-chair { overflow-wrap: anywhere; }
.blk .b-title { font-weight: 700; }
.blk .b-chair { color: var(--muted); }
.blk .b-slots { position: absolute; inset: 0; pointer-events: none; }
.blk .b-slot { position: absolute; left: 0; right: 0; border-top: 1px solid color-mix(in srgb, var(--c) 22%, transparent); }
.blk .b-buf {
  position: absolute; left: 0; right: 0;
  background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--c) 18%, transparent) 0 4px, transparent 4px 8px);
}
.blk .b-content { position: relative; }
.blk .b-pin {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 3px; z-index: 2;
  display: grid; place-items: center; cursor: pointer; color: color-mix(in srgb, var(--c) 75%, var(--fg));
  background: color-mix(in srgb, var(--c) 22%, var(--surface));
}
.blk .b-pin svg { width: 12px; height: 12px; }
.blk .b-pin:hover { background: var(--surface); color: var(--bad); }
.blk .b-top { padding-right: 16px; }
.modal-grid .check.wide { grid-column: 1 / -1; font-size: var(--fs-sm); color: var(--fg); }
.blk .b-resize {
  position: absolute; left: 0; right: 0; bottom: 0; height: 7px; cursor: ns-resize;
  background: linear-gradient(transparent 2px, color-mix(in srgb, var(--c) 45%, transparent) 2px 3px, transparent 3px 4px, color-mix(in srgb, var(--c) 45%, transparent) 4px 5px, transparent 5px) center / 22px 100% no-repeat;
  opacity: 0; transition: opacity 0.12s;
}
.blk:hover .b-resize, .blk:focus-visible .b-resize { opacity: 1; }
.blk.conflict { border: 2px solid var(--bad); box-shadow: 0 0 0 2px var(--bad-soft); }
.blk.warn { border-color: var(--warn); }
.blk.selected {
  outline: 2px solid var(--accent); outline-offset: 1px; z-index: 4;
  background: color-mix(in srgb, var(--c) 30%, var(--surface));
}
.blk.dragging { opacity: 0.35; }
.ghost-count {
  position: absolute; top: 3px; right: 4px; background: var(--accent); color: var(--accent-fg);
  border-radius: 999px; padding: 0 7px; font-size: var(--fs-xs); font-weight: 700; line-height: 1.6;
}
.selbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 6px 10px;
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 6px; font-size: var(--fs-xs);
}
.selbar b { font-family: var(--font-num); font-size: var(--fs-sm); }
.selbar-hint { color: var(--muted); }
.selbar .inline { margin-left: auto; }
.blk.flash { animation: flash 1.2s ease-out 1; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }
.blk.compact { padding-top: 1px; }
.blk.compact .b-time, .blk.compact .b-title, .blk.compact .b-chair { display: none; }

.drag-ghost {
  position: fixed; z-index: 100; pointer-events: none; opacity: 0.9; box-shadow: var(--shadow);
  left: 0; top: 0;
}
.placeholder {
  position: absolute; left: 3px; right: 3px; z-index: 4; pointer-events: none;
  border: 2px dashed var(--accent); border-radius: 4px; background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.placeholder span {
  position: absolute; top: -1px; left: -1px; transform: translateY(-100%);
  background: var(--accent); color: var(--accent-fg); font-family: var(--font-num); font-size: var(--fs-xs);
  padding: 0 6px; border-radius: 3px 3px 0 0; white-space: nowrap;
}
.placeholder.bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.placeholder.bad span { background: var(--bad); }
.resizing-label {
  position: absolute; right: 4px; bottom: 8px; font-family: var(--font-num); font-size: var(--fs-xs);
  background: var(--fg); color: var(--bg); padding: 0 5px; border-radius: 3px; z-index: 5;
}
.hint { margin: 0; font-size: var(--fs-xs); color: var(--faint); }

.lower { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 14px; }
@media (max-width: 900px) { .lower { grid-template-columns: minmax(0, 1fr); } }
.tray-wrap, .checks { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.tray-add { display: flex; flex-wrap: wrap; gap: 4px; }
.tray-add .btn { border-color: color-mix(in srgb, var(--c) 50%, var(--line)); }
.tray {
  display: flex; flex-wrap: wrap; gap: 6px; min-height: 64px; padding: 8px;
  border: 1px dashed var(--line); border-radius: 6px; background: var(--surface-2); align-content: flex-start;
}
.tray.over { border-color: var(--accent); background: var(--accent-soft); }
.tray .blk { position: relative; left: auto; right: auto; width: 150px; min-height: 46px; }
.tray-empty { font-size: var(--fs-xs); color: var(--faint); align-self: center; margin: auto; }

.warnings { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow: auto; }
.warnings li button {
  display: flex; gap: 8px; width: 100%; text-align: left; border: 0; background: transparent; cursor: pointer;
  padding: 5px 6px; border-radius: 4px; font-size: var(--fs-xs); align-items: baseline;
}
.warnings li button:hover { background: var(--surface-2); }
.warnings .lv { flex: none; font-weight: 700; padding: 0 6px; border-radius: 3px; }
.warnings .lv.bad { color: var(--bad); background: var(--bad-soft); }
.warnings .lv.warn { color: var(--warn); background: var(--warn-soft); }
.warnings .ok { font-size: var(--fs-xs); color: var(--ok); padding: 5px 6px; background: var(--ok-soft); border-radius: 4px; }
.day-meta { font-size: var(--fs-xs); color: var(--muted); margin-top: 8px; display: grid; gap: 2px; }
.day-meta b { font-family: var(--font-num); color: var(--fg); font-weight: 600; }

/* ---- popover / modal / toast ---- */
.popover {
  position: fixed; z-index: 60; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); padding: 6px; min-width: 200px; max-width: calc(100vw - 32px);
}
.popover h3 { margin: 2px 6px 6px; font-size: var(--fs-xs); color: var(--muted); font-weight: 500; font-family: var(--font-num); }
.popover button {
  display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: transparent; text-align: left;
  padding: 6px 8px; border-radius: 4px; cursor: pointer; font-size: var(--fs-sm);
}
.popover button:hover, .popover button:focus-visible { background: var(--surface-2); }
.popover .dot { width: 10px; height: 10px; border-radius: 2px; background: var(--c); flex: none; }
.popover .meta { margin-left: auto; color: var(--faint); font-family: var(--font-num); font-size: var(--fs-xs); }

.modal {
  position: fixed; inset: 0; z-index: 80; background: rgba(10, 15, 22, 0.45);
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; overflow: auto;
}
.modal-card {
  background: var(--surface); color: var(--fg); border-radius: 10px; box-shadow: var(--shadow);
  width: min(560px, 100%); padding: 18px; border: 1px solid var(--line);
}
.modal-card h3 { margin: 0 0 12px; font-size: var(--fs-lg); display: flex; align-items: center; gap: 8px; }
.modal-card h3 .dot { width: 12px; height: 12px; border-radius: 3px; background: var(--c); }
.modal-card .code { font-family: var(--font-num); color: var(--muted); font-weight: 500; font-size: var(--fs-md); }
.modal-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
.modal-grid .wide { grid-column: 1 / -1; }
@media (max-width: 480px) { .modal-grid { grid-template-columns: minmax(0, 1fr); } }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; margin-top: 16px; }
.modal-actions .right { display: flex; gap: 8px; margin-left: auto; }
.slots { margin-top: 12px; border-top: 1px solid var(--line-soft); padding-top: 10px; }
.slots-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 2px 10px; font-family: var(--font-num); font-size: var(--fs-xs); color: var(--muted); max-height: 160px; overflow: auto; }
.slots-list b { color: var(--fg); font-weight: 600; }
.modal p { margin: 0 0 8px; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  z-index: 90; background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: 6px;
  font-size: var(--fs-sm); box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

@media (max-width: 640px) {
  .actions { width: 100%; }
  .actions #btn-xlsx { margin-left: auto; }
  .grid-scroll { max-height: 70vh; }
}
@media (prefers-reduced-motion: reduce) {
  .blk.flash { animation: none; outline: 2px solid var(--accent); }
  .blk .b-resize, .switch-track, .switch-track::after { transition: none; }
}
