:root{
  --bg-page:#F7F8FA;
  --bg-card:#FFFFFF;
  --text-main:#1F2937;
  --text-muted:#6B7280;
  --border:#E5E7EB;

  --primary:#111827;
  --success:#16A34A;
  --warning:#D97706;
  --danger:#DC2626;

  --radius:10px;
  --shadow:0 1px 2px rgba(0,0,0,.06);

  --sidebar-w:240px;
  --topbar-h:52px;

  --font:13px;
  --pad:10px;
  --gap:12px;
  --btn-h:36px;
}
body.density-comfort{
  --font:14px;
  --pad:14px;
  --gap:14px;
  --btn-h:40px;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-size:var(--font);
  color:var(--text-main);
  background:var(--bg-page);
}
a{color:inherit;text-decoration:none}
.muted{color:var(--text-muted)}
.hidden{display:none!important}

.app-shell{
  display:grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height:100%;
}
.sidebar{
  background:var(--bg-card);
  border-right:1px solid var(--border);
  padding:14px 10px;
  position:sticky; top:0; height:100vh; overflow:auto;
}
.brand{
  display:flex; align-items:center; justify-content:space-between;
  padding:8px 10px 14px;
}
.brand .logo{font-weight:900; letter-spacing:.2px}
.nav{display:flex; flex-direction:column; gap:2px}
.nav a{
  display:flex; align-items:center; gap:10px;
  padding:10px 10px;
  border-radius:12px;
}
.nav a:hover{background:#F1F5F9}
.nav a.active{
  background:#EEF2FF;
  outline:1px solid #E0E7FF;
}
.nav-sep{height:1px;background:var(--border);margin:10px 10px}

.main{display:flex; flex-direction:column; min-width:0}
.topbar{
  height:var(--topbar-h);
  display:flex; align-items:center; justify-content:space-between;
  padding:0 16px;
  border-bottom:1px solid var(--border);
  background:rgba(247,248,250,.85);
  backdrop-filter:saturate(140%) blur(8px);
  position:sticky; top:0; z-index:10;
}
.topbar__left{display:flex; align-items:center; gap:12px; min-width:0}
.h1{font-size:20px; font-weight:900; white-space:nowrap}
.subtitle{color:var(--text-muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:60vw}
.topbar__right{display:flex; align-items:center; gap:10px}

.page{padding:16px; min-width:0}

.card{
  background:var(--bg-card);
  border:1px solid var(--border);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:var(--pad);
}
.grid{display:grid; gap:var(--gap)}
.cards4{grid-template-columns:repeat(4, minmax(0,1fr))}
@media (max-width: 1100px){
  .app-shell{grid-template-columns:1fr}
  .sidebar{display:none}
  .cards4{grid-template-columns:repeat(2, minmax(0,1fr))}
}
@media (max-width: 700px){
  .cards4{grid-template-columns:1fr}
}

.btn{
  height:var(--btn-h);
  padding:0 12px;
  display:inline-flex; align-items:center; justify-content:center;
  gap:8px;
  border-radius:12px;
  border:1px solid var(--border);
  background:var(--bg-card);
  cursor:pointer;
  user-select:none;
}
.btn:hover{background:#F8FAFC}
.btn.primary{background:var(--primary); border-color:transparent; color:#fff}
.btn.danger{background:var(--danger); border-color:transparent; color:#fff}
.btn.ghost{background:transparent; border-color:transparent}

.table{
  width:100%;
  border-collapse:separate;
  border-spacing:0;
  background:var(--bg-card);
  border:1px solid var(--border);
  border-radius:var(--radius);
  overflow:hidden;
  box-shadow:var(--shadow);
}
.table th,.table td{
  padding:10px 12px;
  border-bottom:1px solid var(--border);
  text-align:left;
  vertical-align:middle;
  font-size:13px;
}
.table th{color:var(--text-muted); font-weight:600; background:#F8FAFC}
.table tr:hover td{background:#FAFAFB}
.table tr:last-child td{border-bottom:none}

.badge{
  display:inline-flex; align-items:center; gap:6px;
  padding:4px 8px;
  border-radius:999px;
  border:1px solid var(--border);
  background:#F8FAFC;
  font-size:12px;
}
.dot{width:8px;height:8px;border-radius:999px;background:#CBD5E1}
.dot.ok{background:var(--success)}
.dot.warn{background:var(--warning)}
.dot.bad{background:var(--danger)}

.density-toggle{
  display:flex; gap:6px; align-items:center;
  padding:6px; border:1px solid var(--border);
  border-radius:12px; background:var(--bg-card);
}
.density-btn{
  width:32px; height:28px;
  display:flex; align-items:center; justify-content:center;
  border-radius:10px;
  cursor:pointer;
}
.density-btn:hover{background:#F1F5F9}
.density-btn.active{background:#EEF2FF; outline:1px solid #E0E7FF}

.ico{width:18px; height:18px; display:inline-block}
.ico svg{width:18px;height:18px; display:block}
.ico--muted{opacity:.7}

/* Auth layout */
.auth{height:100%; display:flex; align-items:center; justify-content:center; padding:24px}
.auth-card{
  width:min(420px, 100%);
  background:var(--bg-card);
  border:1px solid var(--border);
  border-radius:16px;
  box-shadow:0 12px 30px rgba(0,0,0,.08);
  padding:18px;
}
.auth-logo{font-weight:900; font-size:22px; margin-bottom:6px}
.auth-sub{color:var(--text-muted); margin-bottom:14px}


/* ===== Schedule V2 ===== */
.sched-toolbar{display:flex;align-items:center;justify-content:space-between;gap:12px}
.sched-title{font-weight:900}
.sched-actions{display:flex;gap:8px;align-items:center}

.sched-presets{display:grid;gap:10px}
.sched-presets-row{display:flex;align-items:flex-start;gap:10px}
.sched-presets-sec{width:90px; padding-top:6px; font-size:12px}
.sched-presets-pills{display:flex;flex-wrap:wrap;gap:8px}

.pill{border:1px solid var(--border);background:var(--bg-card);border-radius:12px;padding:8px 10px;cursor:pointer;text-align:left}
.pill:hover{background:#F8FAFC}
.pill.active{background:#EEF2FF; outline:1px solid #E0E7FF}
.pill-top{display:flex;align-items:center;gap:8px;font-weight:800}
.pill-dot{width:10px;height:10px;border-radius:999px;display:inline-block}
.pill-label{font-size:13px}
.pill-sub{font-size:12px;margin-left:18px;margin-top:2px}

.sched-wrap{border:1px solid var(--border);border-radius:var(--radius);background:var(--bg-card);box-shadow:var(--shadow);overflow:auto; max-height: calc(100vh - 280px);}
.sched-head{position:sticky;top:0;z-index:5;display:grid;grid-auto-flow:column;grid-auto-columns:minmax(24px, 1fr);align-items:stretch;background:#F8FAFC;border-bottom:1px solid var(--border)}
.sched-head-name{position:sticky;left:0;z-index:6;min-width:240px;max-width:240px;padding:8px 10px;font-weight:700;color:var(--text-muted);border-right:1px solid var(--border);background:#F8FAFC}
.sched-head-day{padding:6px 2px; text-align:center; border-right:1px solid rgba(229,231,235,.55)}
.sched-day-num{font-weight:900; line-height:1}
.sched-day-wd{font-size:11px; line-height:1.2}

.sched-body{display:flex;flex-direction:column}
.sched-section{padding:8px 10px; font-weight:900; background:#FFFFFF; border-bottom:1px solid var(--border)}
.sched-section-title{font-size:13px}

.sched-row{display:grid;grid-auto-flow:column;grid-auto-columns:minmax(24px, 1fr);align-items:stretch;border-bottom:1px solid rgba(229,231,235,.7)}
.sched-name{position:sticky;left:0;z-index:4;min-width:240px;max-width:240px;padding:6px 10px;border-right:1px solid var(--border);background:var(--bg-card)}
.sched-name-main{font-weight:800; line-height:1.1}
.sched-name-sub{font-size:12px; line-height:1.1; margin-top:2px}

.cell{height:22px;border-right:1px solid rgba(229,231,235,.55); cursor:pointer; background:#fff}
body.density-comfort .cell{height:26px}
.cell.selected{outline:2px solid #111827; outline-offset:-2px}

/* Context menu */
.ctx{position:fixed;z-index:9999;min-width:260px;background:var(--bg-card);border:1px solid var(--border);border-radius:14px;box-shadow:0 18px 40px rgba(0,0,0,.14);padding:8px}
.ctx-title{font-weight:900;padding:8px 10px}
.ctx-item{width:100%;display:flex;align-items:center;gap:10px;padding:9px 10px;border-radius:12px;border:none;background:transparent;cursor:pointer;text-align:left}
.ctx-item:hover{background:#F1F5F9}
.ctx-dot{width:10px;height:10px;border-radius:999px}
.ctx-sep{height:1px;background:var(--border);margin:6px 8px}

/* Toast */
.toast-host{position:fixed;right:14px;bottom:14px;z-index:9998;display:flex;flex-direction:column;gap:8px}
.toast{opacity:0;transform:translateY(6px);transition:.2s;background:var(--bg-card);border:1px solid var(--border);border-radius:14px;box-shadow:0 18px 40px rgba(0,0,0,.14);padding:10px 12px;max-width:360px}
.toast.show{opacity:1;transform:translateY(0)}

/* ===== Presets settings ===== */
.linkcard{display:block;text-decoration:none;color:inherit}
.linkcard:hover{background:#F8FAFC}

.preset-list{display:flex;flex-direction:column;gap:8px}
.preset-row{display:grid;grid-template-columns:140px 1fr 120px 80px 96px;gap:10px;align-items:center;padding:8px 10px;border:1px solid var(--border);border-radius:12px}
.preset-chip{display:flex;align-items:center;gap:8px}
.chip-dot{width:10px;height:10px;border-radius:999px;display:inline-block}
.row-actions{display:flex;gap:8px;justify-content:flex-end}
.btn.danger{border-color:#FEE2E2;background:#FEF2F2}
.btn.danger:hover{background:#FEE2E2}

.modal{position:fixed;inset:0;background:rgba(15,23,42,.35);display:flex;align-items:center;justify-content:center;z-index:10000;padding:16px}
.modal-card{width:min(760px, 96vw);background:var(--bg-card);border:1px solid var(--border);border-radius:16px;box-shadow:0 18px 40px rgba(0,0,0,.18);padding:14px}
.modal-title{font-weight:900;margin-bottom:10px}
.modal-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:12px}
.form-grid{grid-template-columns:repeat(3, 1fr)}
.color-grid{display:flex;flex-wrap:wrap;gap:8px;margin-top:6px}
.color-dot{width:22px;height:22px;border-radius:999px;border:1px solid rgba(0,0,0,.08);cursor:pointer}
.color-dot.active{outline:2px solid #111827;outline-offset:2px}


/* Presets page helpers */
.swatch{display:inline-block;width:14px;height:14px;border-radius:4px;border:1px solid rgba(0,0,0,.08);margin-right:8px}
.badge{display:inline-block;padding:2px 6px;border-radius:999px;background:rgba(0,0,0,.06);font-size:12px;margin-right:8px}
.color-palette{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:10px}
.color-btn{width:24px;height:24px;border-radius:8px;border:1px solid rgba(0,0,0,.08);cursor:pointer}
.picked-color .picked-box{display:flex;align-items:center;gap:8px;margin-top:6px}
.table.compact td,.table.compact th{padding:6px 8px}
.form-error{color:#b91c1c;margin-top:10px}
.row.gap{gap:10px}
