* { box-sizing: border-box; }
:root {
  --ink: #1c2128;
  --muted: #5d6672;
  --line: #d5d9df;
  --line-soft: #eceef1;
  --accent: #1d4f91;
  --conflict: #c4161c;
  --check: #a85d00;
  --fixed: #ad2929;
  --hour: 54px;
  --label: 15px;
  --head-h: 92px;
  --axis-w: 58px;
  --room-w: 13px;
  --lane-min: 72px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--ink);
}
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; background: #eef0f3; font-size: 14px; }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid #0b57d0; outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
code { font-size: 12px; background: #f1f3f5; padding: 0 3px; border-radius: 3px; }

/* ---------- top bars ---------- */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 14px; background: #fff; border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0; font-size: 17px; }
.nav { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; max-width: 100%; }
.btn { border: 1px solid #b9c0c9; background: #fff; border-radius: 6px; padding: 5px 10px; }
.btn:hover:not(:disabled) { background: #f2f4f7; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #163f75; }
.btn.danger { border-color: #c99; color: #8c1d18; }
.btn.danger:hover:not(:disabled) { background: #fbeeee; }
.btn.small { padding: 3px 8px; font-size: 12.5px; }
.linkish { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; font-size: inherit; }
input.btn { padding: 4px 8px; }
.seg { display: inline-flex; border: 1px solid #b9c0c9; border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 5px 12px; border-right: 1px solid #d6dbe1; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.seg.small button { padding: 3px 10px; font-size: 13px; }
.spacer { flex: 1; }
.hist { display: flex; gap: 6px; }
.save-state { font-size: 12.5px; }
.save-state.ok { color: #185c2e; }
.save-state.bad { color: #8c1d18; font-weight: 600; }

.banner { padding: 8px 14px; background: #fdeeee; border-bottom: 2px solid var(--conflict); }
.banner p { margin: 0 0 6px; }

.subbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; padding: 6px 14px; background: #f8f9fb; border-bottom: 1px solid var(--line); }
.subbar h2 { margin: 0; font-size: 16px; min-width: 15ch; }
.summary { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: 13px; }
.sum-label { color: var(--muted); }
.sum-class { padding-left: 8px; border-left: 4px solid var(--c); }
.sum-combined { padding-left: 10px; border-left: 1px solid var(--line); }
.sum-combined small { color: var(--muted); }
.sum-issues { border: 1px solid #b9c0c9; background: #fff; border-radius: 12px; padding: 2px 10px; font-size: 12.5px; }
.sum-issues.has-conflict { border-color: var(--conflict); color: var(--conflict); font-weight: 600; }

.statusbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; padding: 4px 14px; background: #fff; border-bottom: 1px solid var(--line); min-height: 30px; }
#status { margin: 0; font-size: 13px; flex: 1 1 360px; min-height: 18px; }
#status.ok { color: #185c2e; }
#status.warn { color: #8c1d18; font-weight: 600; }
.key { display: flex; flex-wrap: wrap; gap: 2px 12px; list-style: none; margin: 0; padding: 0; font-size: 11.5px; color: var(--muted); }
.key li { display: flex; align-items: center; gap: 4px; }
.sw { display: inline-block; width: 14px; height: 11px; border: 1px solid #bbb; background: #fff; }
.sw-fixed { border-top: 3px solid var(--fixed); }
.sw-conflict { border: 2px dashed var(--conflict); }
.sw-check { border: 2px dotted var(--check); }
.sw-hold { background: repeating-linear-gradient(135deg, #e3b8a8 0 3px, #fff 3px 6px); }
.sw-dayoff { background: repeating-linear-gradient(135deg, #dfe2e6 0 3px, #f7f8f9 3px 6px); }
.sw-off { background: #fbe7c6; border-color: #e5c58f; }
.sw-closed { background: #f6d9dc; border-color: #e3b6bb; }

/* ---------- layout ---------- */
.main { flex: 1; min-height: 0; display: flex; }
.cal-scroll { flex: 1; min-width: 0; overflow: auto; background: #fff; position: relative; }
.boot-note { padding: 20px; color: var(--muted); }
.side { flex: 0 0 400px; display: flex; flex-direction: column; background: #fff; border-left: 1px solid var(--line); min-height: 0; }
.main.side-closed .side { display: none; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs [role="tab"] { flex: 1; border: 0; background: none; padding: 9px 4px 7px; border-bottom: 3px solid transparent; color: var(--muted); font-size: 13.5px; }
.tabs [role="tab"][aria-selected="true"] { border-bottom-color: var(--accent); color: var(--ink); font-weight: 600; }
.count:not(:empty) { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--conflict); color: #fff; font-size: 11px; font-weight: 700; }
.panel { flex: 1; overflow: auto; padding: 12px 16px 28px; }

.empty-state { max-width: 520px; margin: 48px auto; padding: 22px 26px; border: 1px dashed #b9c0c9; border-radius: 10px; text-align: center; }
.empty-state h2 { margin: 0 0 8px; font-size: 19px; }
.row.center { justify-content: center; }
.load-error { max-width: 560px; margin: 40px auto; padding: 16px 20px; border-left: 5px solid var(--conflict); background: #fdeeee; }

/* ---------- calendar grid ---------- */
.cal-grid { display: flex; width: 100%; min-width: min-content; }
.mode-day { --room-w: 70px; --lane-min: 170px; }
.wide.mode-week { --lane-min: 150px; }
.axis { position: sticky; left: 0; z-index: 6; flex: 0 0 var(--axis-w); background: #fff; border-right: 1px solid var(--line); }
.axis-head { position: sticky; top: 0; z-index: 7; height: var(--head-h); background: #fff; border-bottom: 1px solid #c4c9d0; }
.axis-body { position: relative; }
.axis-label { position: absolute; right: 6px; transform: translateY(-50%); font-size: 12px; color: var(--muted); white-space: nowrap; }
.axis-label:first-child { transform: none; }
.axis-label:last-child { transform: translateY(-100%); }

.day { flex: 1 1 0; display: flex; flex-direction: column; border-right: 2px solid #9aa2ad; }
.day-head { position: sticky; top: 0; z-index: 4; height: var(--head-h); display: flex; flex-direction: column; background: #fff; border-bottom: 1px solid #c4c9d0; }
.closed-day .day-head { background: #fbecee; }
.day-title { margin: 0; padding: 4px 8px 0; font-size: 15px; font-weight: 700; text-align: left; border: 0; background: none; }
button.day-title:hover { text-decoration: underline; }
.day-sub { padding: 0 8px 4px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.closed-text { color: #8c1d18; font-weight: 600; }
.lane-row { display: flex; }
.lane-row.heads { flex: 1; min-height: 0; border-top: 1px solid var(--line-soft); }
.rooms-head, .rooms { flex: 0 0 calc(var(--rooms-n) * var(--room-w)); display: flex; border-right: 1px solid var(--line); background: #fafbfc; }
.rooms-head { font-size: 11px; color: var(--muted); }
.rooms-head span { flex: 1; text-align: center; padding-top: 6px; overflow: hidden; white-space: nowrap; }
.lane-head { flex: 1 1 0; min-width: var(--lane-min); display: flex; flex-direction: column; justify-content: center; gap: 1px; padding: 2px 6px; border-right: 1px solid var(--line-soft); border-top: 4px solid var(--c, #8a929c); overflow: hidden; }
.lh-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lh-hours { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lh-hours.muted { color: var(--muted); }
.lh-hours.changed, td.changed { background: #fff3b0; border-radius: 3px; }
.space-head.kind-shared { border-top-color: #5f8f3e; }
.space-head.kind-offsite, .space-head.kind-none { border-top-color: #b0b6be; }

/* lanes */
.lane {
  position: relative; flex: 1 1 0; min-width: var(--lane-min); border-right: 1px solid #e3e6ea;
  background-image:
    repeating-linear-gradient(to bottom, #e3e6ea 0 1px, transparent 1px var(--hour)),
    repeating-linear-gradient(to bottom, transparent 0 calc(var(--hour) / 2), #f1f2f4 calc(var(--hour) / 2) calc(var(--hour) / 2 + 1px), transparent calc(var(--hour) / 2 + 1px) var(--hour));
}
.lane.off { background-color: #f4f5f6; }
.lane.off.kind-regular::before, .lane.off.kind-outside::before { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(135deg, rgba(120, 128, 140, .13) 0 6px, transparent 6px 14px); }
.lane.off.kind-outside { background-color: #f7f7f8; }
.lane.off.kind-off { background-color: #fbe7c6; }
.lane.off.kind-closure { background-color: #f6d9dc; }
.space-lane.kind-none { background-color: #fafafa; }
.off-label { position: absolute; left: 4px; right: 4px; top: 10px; margin: 0; text-align: center; font-size: 12.5px; font-weight: 600; color: #3c434c; z-index: 1; pointer-events: none; }
.offhours { position: absolute; left: 0; right: 0; background: repeating-linear-gradient(135deg, rgba(0, 0, 0, .06) 0 4px, transparent 4px 9px); pointer-events: none; }
.lane-blocks { position: absolute; inset: 0; z-index: 2; pointer-events: none; }

/* room occupancy strip */
.room-col { position: relative; flex: 1; border-right: 1px solid var(--line-soft); }
.room-col:last-child { border-right: 0; }
.rbar { position: absolute; border-radius: 2px; cursor: pointer; overflow: hidden; color: #fff; font-size: 11px; font-weight: 600; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .6); }
.rbar span { display: block; padding: 2px 4px; text-shadow: 0 0 2px rgba(0, 0, 0, .7); }
.rbar.hold span { color: #222; text-shadow: none; background: rgba(255, 255, 255, .85); }
.rbar.conflict { outline: 2px solid var(--conflict); outline-offset: -1px; }
.rbar.conflict::after { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(45deg, rgba(196, 22, 28, .55) 0 3px, transparent 3px 6px); }
.rbar.selected { outline: 2px solid #111; outline-offset: 0; z-index: 2; }

/* ---------- blocks ---------- */
.block {
  position: absolute; pointer-events: auto; padding: 3px 5px 3px 6px; overflow: hidden;
  background: var(--ev); border-left: 6px solid color-mix(in srgb, var(--ev) 62%, #000);
  border-bottom: 1px solid rgba(0, 0, 0, .2); border-radius: 2px;
  color: #14171a; font-size: var(--label); line-height: 1.18;
  cursor: grab; user-select: none; touch-action: none;
}
.b-title { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; font-weight: 600; overflow-wrap: anywhere; }
.b-time, .b-meta { display: block; font-size: max(11px, calc(var(--label) * .8)); line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-meta { color: #2d333a; }
.block.tiny { padding-top: 0; padding-bottom: 0; line-height: 1.05; }
.block.tiny .b-title { display: block; white-space: nowrap; text-overflow: ellipsis; }
.block.hold { background: repeating-linear-gradient(135deg, var(--ev) 0 6px, #fff 6px 12px); }
.block.shared { box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .18); }
.block.fixed { border-top: 3px solid var(--fixed); cursor: not-allowed; }
.block.has-warning { outline: 2px dotted var(--check); outline-offset: -2px; }
.block.has-conflict { outline: 2px dashed var(--conflict); outline-offset: -2px; }
.block.has-conflict::after { content: ""; position: absolute; top: 0; right: 0; border-style: solid; border-width: 0 12px 12px 0; border-color: transparent var(--conflict) transparent transparent; }
.block.selected { box-shadow: 0 0 0 2px #fff, 0 0 0 4px #111; z-index: 3; }
.block:focus-visible { outline: 3px solid #0b57d0; outline-offset: 1px; z-index: 4; }
.block:hover { filter: brightness(.97); }
.block.drag-source { opacity: .35; }
.tag { display: inline-block; margin-right: 4px; padding: 0 4px; border-radius: 3px; background: var(--c); color: #fff; font-size: max(10.5px, calc(var(--label) * .72)); font-weight: 700; vertical-align: 1px; }

/* drag */
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; }
.ghost { position: absolute; left: 2px; right: 2px; z-index: 8; pointer-events: none; padding: 3px 6px; background: var(--ev); border-left: 6px solid color-mix(in srgb, var(--ev) 62%, #000); border-radius: 3px; font-size: var(--label); line-height: 1.15; opacity: .92; box-shadow: 0 4px 14px rgba(0, 0, 0, .25); overflow: hidden; }
.ghost .g-title { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ghost .g-time { display: block; font-size: 12px; }
.ghost.ok { outline: 3px solid #1d7a3a; }
.ghost.check { outline: 3px dotted var(--check); }
.ghost.warn { outline: 3px dashed var(--conflict); }
.ghost.bad { outline: 3px solid var(--conflict); opacity: .5; }
.dragtip { position: fixed; z-index: 50; max-width: 290px; padding: 6px 9px; background: #1c2128; color: #fff; border-radius: 6px; font-size: 12.5px; pointer-events: none; box-shadow: 0 4px 14px rgba(0, 0, 0, .3); }
.dragtip span { display: block; margin-top: 2px; }
.dragtip.ok span { color: #9be3ad; }
.dragtip.check span { color: #ffd38a; }
.dragtip.warn span, .dragtip.bad span { color: #ffb4b0; }

/* ---------- side panel ---------- */
.panel-title { margin: 0 0 8px; font-size: 17px; line-height: 1.3; overflow-wrap: anywhere; }
.panel h3 { margin: 16px 0 6px; font-size: 14px; }
.panel h4 { margin: 8px 0 4px; font-size: 13.5px; }
.panel p { line-height: 1.45; }
.chip { display: inline-block; padding: 1px 7px; border-radius: 10px; background: var(--c); color: #fff; font-size: 12px; font-weight: 600; white-space: nowrap; }
.protected { padding: 8px 10px; border-left: 4px solid var(--fixed); background: #fbeeee; margin: 0 0 8px; }
.howto { padding-left: 18px; line-height: 1.5; }
.howto li { margin-bottom: 6px; }

.stack { display: flex; flex-direction: column; gap: 8px; }
.stack > label, .grid2 > label, .grid3 > label, .row-item > label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
.stack input:not([type=checkbox]):not([type=radio]):not([type=color]), .stack select, .stack textarea,
.row-item input:not([type=color]), .row-item select, .tools input[type=date], .tools select {
  padding: 5px 7px; border: 1px solid #b9c0c9; border-radius: 5px; background: #fff; color: var(--ink); min-width: 0;
}
.stack textarea { resize: vertical; }
input[type=color] { width: 52px; height: 32px; padding: 2px; border: 1px solid #b9c0c9; border-radius: 5px; background: #fff; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; }
label.check { display: flex; flex-direction: row; align-items: center; gap: 6px; font-size: 13.5px; color: var(--ink); }
label.inline { display: flex; flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
label.inline input { width: 110px; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 14px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 12px 0 0; padding: 10px 12px 12px; min-width: 0; }
fieldset.flat { border: 0; padding: 0; margin: 6px 0; }
legend { font-weight: 700; padding: 0 4px; }
.row { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; align-items: flex-end; }
.tools { margin-top: 14px; }
details.tools { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
details.tools summary { font-weight: 700; cursor: pointer; }
details.tools[open] summary { margin-bottom: 8px; }

.form-errors:empty { display: none; }
.form-errors.show { padding: 8px 10px; border-left: 4px solid var(--conflict); background: #fdeeee; color: #6e1410; font-size: 13px; }
.form-errors ul { margin: 0; padding-left: 18px; }
.preview { margin: 4px 0; padding: 7px 9px; border-radius: 5px; font-size: 13px; border-left: 4px solid #aab1ba; background: #f5f6f8; }
.preview.ok { border-left-color: #1d7a3a; background: #eef8f1; }
.preview.warn { border-left-color: var(--check); background: #fdf5e8; }
.preview.bad { border-left-color: var(--conflict); background: #fdeeee; }

.row-item { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 8px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.row-item .grow { flex: 1 1 150px; }
.setup fieldset { margin-top: 14px; }

.class-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.class-card { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-left: 6px solid var(--c); border-radius: 6px; }
.cc-main { display: flex; flex-direction: column; gap: 1px; font-size: 13px; }
.cc-main b { font-size: 14.5px; }
.cc-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }

.date-chips { list-style: none; padding: 0; margin: 6px 0; display: flex; flex-wrap: wrap; gap: 6px; }
.date-chips li { padding: 2px 8px; border: 1px solid var(--line); border-radius: 12px; font-size: 13px; }
.rp-result { margin-top: 8px; }
.rp-list { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow: auto; border: 1px solid var(--line-soft); border-radius: 6px; }
.rp-list li { padding: 4px 8px; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.rp-list .rp-skip, .rp-list .rp-duplicate { color: var(--muted); }
.rp-list .rp-conflict { background: #fdf3f3; }

.import-confirm { padding: 8px 10px; border-left: 4px solid var(--check); background: #fdf5e8; font-size: 13px; }
.warn-text { color: #6e3b00; }
.file-btn { display: inline-flex; align-items: center; cursor: pointer; }
.file-btn:focus-within { outline: 3px solid #0b57d0; outline-offset: 2px; }

.issue-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.issue { width: 100%; text-align: left; border: 1px solid var(--line); border-left: 4px solid var(--check); border-radius: 5px; background: #fff; padding: 6px 8px; font-size: 13px; line-height: 1.35; }
.issue.conflict { border-left-color: var(--conflict); }
.issue:hover { background: #f6f7f9; }
.issue .sev { font-weight: 700; margin-right: 6px; }
.issue.conflict .sev { color: var(--conflict); }
.issue.warning .sev { color: var(--check); }
.issue .when { color: var(--muted); margin-right: 4px; }

.table-wrap { overflow-x: auto; }
table.hours { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.hours th, table.hours td { padding: 4px 5px; border-bottom: 1px solid var(--line-soft); text-align: right; white-space: nowrap; }
table.hours th[scope="row"], table.hours thead th:first-child { text-align: left; }
table.hours thead th { color: var(--muted); font-weight: 600; }
table.hours td.muted { color: var(--muted); font-size: 11.5px; }
table.hours .total { font-weight: 700; }
table.hours tfoot th, table.hours tfoot td { border-top: 2px solid var(--line); }

@media (max-width: 960px) {
  .main { flex: 1 0 auto; flex-direction: column; min-height: 820px; }
  .cal-scroll { flex: 0 0 460px; }
  .side { flex: 0 0 auto; min-height: 360px; border-left: 0; border-top: 1px solid var(--line); }
  .key { display: none; }
}
