:root {
  --accent: #2f6fed;
  --accent-soft: #e6eeff;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #dfe3ea;
  --text: #1f2733;
  --muted: #6b7480;
  --error: #d64545;
  --warning: #e69a2e;
  --success: #2e9e5b;
  --cancelled: #c9ced6;
  --radius: 8px;
  --avail-0: #f3c3c3;
  --avail-1: #ffffff;
  --avail-2: #c8e9d2;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

#app { height: 100%; display: flex; }

/* ---- layout ---- */
.sidebar {
  width: 220px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.brand { padding: 18px 16px 10px; font-weight: 700; font-size: 17px; display: flex; gap: 8px; align-items: center; }
.brand .logo { width: 22px; height: 22px; border-radius: 5px; background: var(--accent); }
.plan-switch { padding: 0 12px 10px; }
.plan-switch select { width: 100%; }
.nav { display: flex; flex-direction: column; padding: 4px 0; flex: 1; }
.nav a {
  padding: 10px 16px; color: var(--text); text-decoration: none; font-size: 14px; border-left: 3px solid transparent;
}
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--accent-soft); border-left-color: var(--accent); }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; align-items: center; }
.main { flex: 1; min-width: 0; overflow: auto; display: flex; flex-direction: column; }
.page { padding: 16px 24px 24px; display: flex; flex-direction: column; gap: 12px; min-height: 100%; }
.page-header { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.page-header h1 { font-size: 22px; font-weight: 600; margin: 0; flex: 1; }
.section-title { font-size: 14px; font-weight: 600; color: var(--muted); margin: 6px 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; }
.split { display: flex; gap: 16px; align-items: stretch; min-height: 0; flex: 1; }
.split > .side { width: 320px; flex: none; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.split > .grow { min-width: 0; display: flex; flex-direction: column; }
.split > .grow > .tt-grid { flex: 1; }

/* ---- controls ---- */
button.btn {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
button.btn:hover { background: var(--accent-soft); }
button.btn:disabled { color: var(--muted); cursor: default; background: var(--panel); }
button.btn.primary { background: var(--accent); color: white; border-color: var(--accent); font-weight: 600; }
button.btn.primary:hover { background: #255bd0; }
button.btn.danger { color: var(--error); }
button.btn.small { padding: 3px 8px; font-size: 12px; }
button.btn.icon { width: 32px; padding: 6px 0; text-align: center; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], select, textarea {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type=number] { width: 80px; }
label.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.form { display: grid; grid-template-columns: max-content 1fr; gap: 10px 16px; align-items: center; }
.form > .full { grid-column: 1 / -1; }
.form label { color: var(--text); }
.hint { color: var(--muted); font-size: 12px; }
.status { color: var(--muted); }

/* ---- lists & tables ---- */
.list { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; overflow: auto; }
.list-item { padding: 7px 10px; display: flex; gap: 8px; align-items: center; cursor: pointer; border-bottom: 1px solid #f0f2f5; }
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--bg); }
.list-item.selected { background: var(--accent-soft); }
.list-item.muted { color: var(--muted); }
.list-item .dot { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.list-item .swatch { width: 14px; height: 14px; border-radius: 3px; flex: none; }
.list-empty { padding: 12px; color: var(--muted); }
table.table { border-collapse: collapse; width: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; }
table.table th { text-align: left; padding: 8px; font-weight: 600; background: var(--bg); border-bottom: 1px solid var(--border); }
table.table td { padding: 5px 8px; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
table.table tr.selected td { background: var(--accent-soft); }
table.table tr:hover td { background: #fafbfd; }
table.table td.center, table.table th.center { text-align: center; }
table.table select, table.table input { width: 100%; }
table.table input[type=number] { width: 70px; }

/* ---- entity pages ---- */
.entity { display: flex; gap: 16px; flex: 1; min-height: 0; }
.entity .entity-list { width: 280px; flex: none; display: flex; flex-direction: column; gap: 8px; }
.entity .entity-list .list { flex: 1; min-height: 200px; }
.entity .entity-form { flex: 1; min-width: 0; overflow: auto; }

/* ---- timetable grid ---- */
.tt-grid {
  display: grid;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  user-select: none;
  min-height: 0;
}
.tt-head { padding: 8px 4px; text-align: center; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); font-size: 13px; }
.tt-rowhead { padding: 6px 4px; text-align: center; color: var(--muted); border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); display: flex; flex-direction: column; justify-content: space-between; align-items: center; }
.tt-rowhead b { font-size: 13px; }
.tt-rowhead .time { font-size: 10.5px; line-height: 1.3; }
.tt-cell { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 3px; display: flex; flex-direction: column; gap: 2px; min-height: 64px; position: relative; }
.tt-cell.drop-ok { background: rgba(46, 158, 91, 0.12); }
.tt-cell.drop-bad { background: rgba(214, 69, 69, 0.10); }
.tt-cell.drop-ok.over { background: rgba(46, 158, 91, 0.32); }
.tt-cell.drop-bad.over { background: rgba(214, 69, 69, 0.28); }
.tt-card {
  flex: 1; border-radius: 5px; padding: 3px 6px; display: flex; flex-direction: column; justify-content: space-between;
  position: relative; min-height: 0; overflow: hidden; line-height: 1.25; font-size: 12.5px;
}
.tt-card.draggable { cursor: grab; }
.tt-card.dragging { opacity: 0.4; }
.tt-card .l1 { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tt-card .l2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11.5px; }
.tt-card.error { box-shadow: inset 0 0 0 2.5px var(--error); }
.tt-card.warning { box-shadow: inset 0 0 0 2.5px var(--warning); }
.tt-card.highlight { box-shadow: inset 0 0 0 3px var(--accent); }
.tt-card.changed { outline: 1.5px dashed var(--text); outline-offset: -3px; }
.tt-card.cancelled { background: var(--cancelled) !important; color: var(--muted) !important; }
.tt-card.cancelled::after {
  content: ""; position: absolute; left: 8px; right: 8px; top: 50%; border-top: 2px solid var(--muted);
  transform: rotate(-12deg);
}
.tt-card .badges { position: absolute; top: 3px; right: 4px; display: flex; gap: 3px; align-items: center; }
.tt-card .badge { width: 15px; height: 15px; border-radius: 50%; background: var(--text); color: white; font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.tt-card .pin { width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.tt-card .note { position: absolute; right: 5px; bottom: 2px; font-size: 11px; }
.pool-item { cursor: grab; }
.pool-item:active { cursor: grabbing; }
.legend { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend .swatch { width: 14px; height: 14px; border: 1px solid var(--border); border-radius: 3px; display: inline-block; vertical-align: middle; margin-right: 4px; }

/* ---- availability grid ---- */
.avail { display: grid; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; user-select: none; max-width: 760px; }
.avail .head, .avail .rowhead { background: var(--bg); color: var(--muted); font-size: 12px; padding: 5px 4px; text-align: center; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.avail .head { cursor: pointer; font-weight: 600; }
.avail .cell { min-height: 30px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); cursor: pointer; }
.avail .cell[data-v="0"] { background: var(--avail-0); }
.avail .cell[data-v="1"] { background: var(--avail-1); }
.avail .cell[data-v="2"] { background: var(--avail-2); }

/* ---- stat cards ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.card { cursor: pointer; }
.card .num { font-size: 26px; font-weight: 700; color: var(--accent); }
.card .cap { color: var(--muted); }
.progress { height: 14px; background: var(--bg); border: 1px solid var(--border); border-radius: 7px; overflow: hidden; position: relative; }
.progress > div { height: 100%; background: var(--accent); }
.progress.over > div { background: var(--error); }
.progress span { position: absolute; inset: 0; font-size: 11px; text-align: center; line-height: 14px; }

/* ---- context menu, modal, toast ---- */
.ctx { position: fixed; z-index: 50; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.12); min-width: 180px; padding: 4px; }
.ctx .item { padding: 6px 12px; cursor: pointer; border-radius: 4px; white-space: nowrap; display: flex; gap: 8px; align-items: center; }
.ctx .item:hover { background: var(--accent-soft); }
.ctx .item.disabled { color: var(--muted); cursor: default; }
.ctx .item.danger { color: var(--error); }
.ctx .sep { border-top: 1px solid var(--border); margin: 4px 0; }
.ctx .head { padding: 4px 12px; font-size: 11px; color: var(--muted); text-transform: uppercase; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 28, 40, .45); z-index: 60; display: flex; align-items: center; justify-content: center; }
.modal { background: var(--panel); border-radius: 10px; min-width: 380px; max-width: 760px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 16px 48px rgba(0,0,0,.25); }
.modal .modal-title { padding: 14px 20px; font-weight: 600; font-size: 16px; border-bottom: 1px solid var(--border); }
.modal .modal-body { padding: 16px 20px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.modal .modal-actions { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 70; }
.toast { background: var(--text); color: white; padding: 10px 14px; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.2); max-width: 420px; }
.toast.error { background: var(--error); }
.toast.success { background: var(--success); }

/* ---- auth ---- */
.auth-wrap { flex: 1; display: flex; align-items: center; justify-content: center; }
.auth { width: 360px; display: flex; flex-direction: column; gap: 10px; }
.auth h1 { margin: 0 0 6px; font-size: 20px; }
.auth input { width: 100%; }
.auth .error { color: var(--error); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.tabs button { background: none; border: none; padding: 8px 12px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
