:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #111827;
  --muted: #5b6474;
  --border: #e3e6eb;
  --primary: #1d4ed8;
  --primary-soft: #e6edfd;
  --on-primary: #ffffff;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --ok: #047857;
  --ok-soft: #e3f5ee;
  --warn: #a15c07;
  --warn-soft: #fdf3e2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1017; --surface: #141a24; --surface-2: #1b2330; --text: #eef1f5; --muted: #9aa4b2;
    --border: #273041; --primary: #6ea8ff; --primary-soft: #1a2a45; --on-primary: #0c1017;
    --danger: #f87171; --danger-soft: #3a1c1f; --ok: #34d399; --ok-soft: #10302a; --warn: #fbbf24; --warn-soft: #3a2e12;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c1017; --surface: #141a24; --surface-2: #1b2330; --text: #eef1f5; --muted: #9aa4b2;
  --border: #273041; --primary: #6ea8ff; --primary-soft: #1a2a45; --on-primary: #0c1017;
  --danger: #f87171; --danger-soft: #3a1c1f; --ok: #34d399; --ok-soft: #10302a; --warn: #fbbf24; --warn-soft: #3a2e12;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif;
}
a { color: var(--primary); }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; }
pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow: auto; max-height: 360px; margin: 0; white-space: pre-wrap; word-break: break-word; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* Layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px;
  position: sticky; top: 0; height: 100vh; overflow: auto;
}
.brand { font-weight: 700; font-size: 15px; padding: 4px 8px 16px; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.nav a {
  display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; margin-bottom: 2px;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav .group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 4px; }
.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.menu-btn { display: none; }
.content { padding: 24px; max-width: 1280px; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 20; width: 240px; left: -260px; transition: left .2s; box-shadow: var(--shadow); }
  .side.open { left: 0; }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
}

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat.warn { border-color: var(--warn); }
.stat.bad { border-color: var(--danger); }

/* Buttons and inputs */
button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover { background: var(--surface-2); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.danger:hover { background: var(--danger-soft); }
button.ghost { border-color: transparent; background: transparent; }
button.sm { padding: 4px 8px; font-size: 12.5px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0;
}
input[type="checkbox"], input[type="radio"] { width: auto; }
input[type="color"] { padding: 2px; width: 44px; height: 32px; }
textarea { min-height: 90px; resize: vertical; }
textarea.code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; min-height: 320px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
label.field { display: block; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 700px) { .grid2, .grid3, .grid4 { grid-template-columns: 1fr; } }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
td.actions button + button { margin-left: 4px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--primary-soft); color: var(--primary); }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--border); vertical-align: -2px; }

/* Alerts, toasts, modals */
.alert { padding: 10px 12px; border-radius: 8px; background: var(--surface-2); border-left: 3px solid var(--muted); }
.alert.bad { background: var(--danger-soft); border-color: var(--danger); }
.alert.warn { background: var(--warn-soft); border-color: var(--warn); }
.alert.ok { background: var(--ok-soft); border-color: var(--ok); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 8px; padding: 10px 12px; box-shadow: var(--shadow); }
.toast.bad { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 640px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.modal.wide { max-width: 1100px; }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal header h2 { margin: 0; }
.modal .body { padding: 18px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.secret { font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 10px; border-radius: 8px; word-break: break-all; user-select: all; }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; }

/* Calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.cal-title { font-size: 18px; font-weight: 700; }
.cal-title small { display: block; font-size: 12.5px; font-weight: 400; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button.on { background: var(--primary); color: var(--on-primary); }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--border); gap: 1px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal .dow { background: var(--surface-2); padding: 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-align: center; }
.cal .cell { background: var(--surface); min-height: 104px; padding: 4px 5px; cursor: pointer; min-width: 0; }
.cal .cell:hover { background: var(--surface-2); }
.cal .cell.out { opacity: .45; }
.cal .cell .num { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; }
.cal .cell .num small { font-weight: 400; color: var(--muted); font-size: 11px; }
.cal .cell.today .num > span:first-child { background: var(--primary); color: var(--on-primary); border-radius: 99px; padding: 0 7px; }
.cal .cell.holiday .num > span:first-child, .cal .cell.weekend .num > span:first-child { color: var(--danger); }
.cal .cell.today.holiday .num > span:first-child, .cal .cell.today.weekend .num > span:first-child { color: var(--on-primary); }
.chip { display: block; font-size: 11.5px; padding: 1px 6px; border-radius: 5px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #fff; }
.chip.draft { background: transparent !important; border: 1px dashed currentColor; }
.chip.archived { opacity: .55; text-decoration: line-through; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
@media (max-width: 700px) {
  .cal .cell { min-height: 64px; }
  .chip { font-size: 0; height: 6px; padding: 0; }
}

/* UI config editor */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; }
@media (max-width: 960px) { .editor { grid-template-columns: 1fr; } }
.palette { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 12px; }
.palette label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.palette input[type="text"] { width: 90px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; padding: 4px 6px; }
.preview { border-radius: 12px; padding: 12px; border: 1px solid; }
.preview .pv-head { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 8px; }
.preview .pv-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; text-align: center; font-size: 12px; }
.preview .pv-grid span { padding: 4px 0; }
.preview .pv-btn { margin-top: 10px; text-align: center; padding: 7px; font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; }
.tabs button.on { border-bottom-color: var(--primary); color: var(--primary); font-weight: 600; }
.days-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
@media (max-width: 700px) { .days-grid { grid-template-columns: repeat(4, 1fr); } }
