:root {
  --bg: #0b1016; --sidebar: #10171d; --card: #10171d; --card2: #141d26;
  --border: #1d2833; --line: #26313b;
  --text: #eef3f9; --muted: #8fa0b4; --faint: #5d6e82;
  --accent: #4d9aff; --accent-ink: #06101c; --accent-soft: rgba(77, 154, 255, .14);
  --ok: #3ecf8e; --warn: #f2b441; --danger: #ff6370; --toggle: #4b6a85;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --radius: 12px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f6fa; --sidebar: #ffffff; --card: #ffffff; --card2: #f5f8fb;
  --border: #e1e7ee; --line: #d3dce6;
  --text: #0f1720; --muted: #566679; --faint: #8796a8;
  --accent: #1f6feb; --accent-ink: #ffffff; --accent-soft: rgba(31, 111, 235, .10);
  --ok: #17935f; --warn: #b7791f; --danger: #d6343f; --toggle: #7aa2c6;
  --shadow: 0 10px 40px rgba(20, 40, 70, .15);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--sidebar); color: var(--text);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
svg.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- shell ---------- */
.app { display: flex; height: 100vh; background: var(--sidebar); }
.sidebar {
  width: 248px; flex: none; display: flex; flex-direction: column; padding: 14px 12px 12px;
  background: var(--sidebar); overflow-y: auto; transition: margin-left .2s ease; z-index: 30;
}
.app.collapsed .sidebar { margin-left: -248px; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: .2px; padding: 10px 14px 14px; border-bottom: 1px solid var(--line); margin: 0 4px 10px; }
.nav { display: flex; flex-direction: column; gap: 1px; flex: 1; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--faint); padding: 14px 14px 5px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 8px 14px; border-radius: 9px;
  color: var(--text); text-decoration: none; cursor: pointer; border: 0; background: none; width: 100%; text-align: left;
}
.nav-item .ic { color: var(--muted); }
.nav-item:hover { background: var(--card2); }
.nav-item.active { background: var(--accent-soft); }
.nav-item.active .ic { color: var(--accent); }
.sidebar-foot { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; display: flex; flex-direction: column; gap: 1px; }
.foot-item { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 9px; cursor: pointer; border: 0; background: none; color: var(--text); width: 100%; text-align: left; }
.foot-item:hover { background: var(--card2); }
.foot-item .ic { color: var(--muted); }
.foot-item.active { background: var(--accent-soft); }
.foot-item .grow { flex: 1; }
.switch { width: 34px; height: 20px; border-radius: 20px; background: var(--toggle); position: relative; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 17px; width: 14px; height: 14px; border-radius: 50%; background: var(--bg); transition: left .15s; }
:root[data-theme="light"] .switch::after { left: 3px; background: #fff; }
.userchip { display: flex; align-items: center; gap: 10px; padding: 9px 10px; margin-bottom: 4px; border-radius: 10px; background: var(--card2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.userchip .who { min-width: 0; flex: 1; }
.userchip .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.userchip .who span { color: var(--muted); font-size: 12px; text-transform: capitalize; }

.main {
  flex: 1; min-width: 0; display: flex; flex-direction: column; margin: 8px 8px 8px 0;
  background: var(--bg); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; position: relative;
}
.topbar { height: 56px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--line); position: relative; z-index: 3; background: var(--bg); }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; border: 0; background: none; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--card2); color: var(--text); }
.sep { width: 1px; height: 18px; background: var(--line); }
.crumb { font-weight: 500; }
.crumb .dim { color: var(--muted); }
.grow { flex: 1; }
.searchpill {
  display: flex; align-items: center; gap: 10px; width: 190px; padding: 7px 10px 7px 12px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--line); color: var(--muted); cursor: pointer;
}
.searchpill:hover { border-color: var(--accent); }
.kbd { margin-left: auto; display: flex; gap: 3px; }
.kbd i { font-style: normal; font-size: 11px; padding: 1px 6px; border-radius: 5px; background: var(--card2); color: var(--muted); }
.view { flex: 1; overflow-y: auto; padding: 26px 28px 60px; position: relative; z-index: 2; }
.view > h1.title, .page-head h1 { font-size: 30px; font-weight: 700; letter-spacing: -.4px; }
.page-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- dolls ---------- */
.dolls { position: fixed; right: 18px; bottom: 8px; width: min(24vw, 330px); height: min(50vh, 500px); pointer-events: none; z-index: 1; }
.dolls img {
  position: absolute; right: 0; bottom: 0; max-width: 100%; max-height: 100%; object-fit: contain; object-position: right bottom;
  opacity: 0; transition: opacity .8s ease; filter: drop-shadow(0 6px 18px rgba(0, 0, 0, .45)); user-select: none;
}
.dolls img.on { opacity: 1; }
.dolls.off { display: none; }
@media (max-width: 760px) { .dolls { display: none; } }
@media (prefers-reduced-motion: reduce) { .dolls img { transition: none; } }

/* ---------- cards & grids ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card > h3, .card-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card-title .sub { color: var(--muted); font-weight: 400; margin-left: auto; font-size: 12px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stat .big { font-size: 24px; font-weight: 700; margin: 2px 0; }
.stat .lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .07em; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); display: inline-block; flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(62, 207, 142, .15); }
.dot.bad { background: var(--danger); }
.dot.warn { background: var(--warn); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.list { display: flex; flex-direction: column; }
.list .li { padding: 10px 0; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.list .li:last-child { border-bottom: 0; }
.empty { color: var(--muted); padding: 22px 8px; text-align: center; }
.banner { border: 1px solid var(--line); border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; }
.banner.warn { border-left-color: var(--warn); background: rgba(242, 180, 65, .09); }
.banner.bad { border-left-color: var(--danger); background: rgba(255, 99, 112, .09); }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.nowrap { white-space: nowrap; }
td .acts { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label, .lbl2 { font-size: 12px; font-weight: 600; color: var(--muted); }
.hint { font-size: 12px; color: var(--faint); }
input[type=text], input[type=password], input[type=url], input[type=number], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; outline: none;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled, select:disabled, textarea:disabled { opacity: .6; cursor: not-allowed; }
input[type=color] { width: 44px; height: 36px; padding: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.formgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }

/* ---------- buttons, badges, tabs ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--card2); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 500; background: var(--card2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: rgba(62, 207, 142, .35); background: rgba(62, 207, 142, .08); }
.badge.bad { color: var(--danger); border-color: rgba(255, 99, 112, .35); background: rgba(255, 99, 112, .08); }
.badge.warn { color: var(--warn); border-color: rgba(242, 180, 65, .35); background: rgba(242, 180, 65, .08); }
.badge.info { color: var(--accent); border-color: rgba(77, 154, 255, .35); background: var(--accent-soft); }
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { padding: 9px 14px; border: 0; background: none; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { padding: 5px 12px; border-radius: 20px; border: 1px solid var(--line); background: none; color: var(--muted); cursor: pointer; }
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* ---------- modal, toast, palette ---------- */
.overlay { position: fixed; inset: 0; background: rgba(2, 6, 12, .62); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal { width: min(640px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.modal.wide { width: min(820px, 100%); }
.modal-head { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 16px; flex: 1; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; }
.toasts { position: fixed; right: 18px; top: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100vw - 36px)); }
.toast { background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 10px; padding: 11px 14px; box-shadow: var(--shadow); }
.toast.ok { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--danger); }
.palette { width: min(540px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; margin-top: 8vh; }
.palette input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 14px 16px; background: transparent; }
.palette input:focus { box-shadow: none; }
.palette .opts { max-height: 340px; overflow-y: auto; padding: 6px; }
.palette .opt { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.palette .opt.sel { background: var(--accent-soft); }
.palette .opt .g { margin-left: auto; color: var(--faint); font-size: 12px; }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.cal-head h2 { font-size: 18px; min-width: 170px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { padding: 6px 13px; border: 0; background: none; cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--accent-soft); color: var(--accent); }
.month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--card); }
.month .dow { padding: 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); border-bottom: 1px solid var(--line); background: var(--card2); }
.day { min-height: 104px; padding: 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); cursor: pointer; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.day:hover { background: var(--card2); }
.day.out { opacity: .45; }
.day.today .num { background: var(--accent); color: var(--accent-ink); }
.day .num { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; font-size: 12px; }
.evchip { font-size: 12px; padding: 2px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); border: 0; text-align: left; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.evchip:hover { filter: brightness(1.2); }
.more { font-size: 11px; color: var(--muted); }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.week .col { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 240px; display: flex; flex-direction: column; gap: 6px; }
.week .col h4 { margin: 0 0 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.week .col.today h4 { color: var(--accent); }
.evcard { text-align: left; border: 1px solid var(--line); background: var(--card2); border-radius: 9px; padding: 7px 9px; cursor: pointer; }
.evcard:hover { border-color: var(--accent); }
.evcard b { display: block; font-weight: 600; font-size: 13px; }
.evcard span { font-size: 12px; color: var(--muted); }
@media (max-width: 900px) { .week { grid-template-columns: 1fr; } .day { min-height: 70px; } }

/* ---------- embed preview ---------- */
.embed-prev { background: #2b2d31; color: #dbdee1; border-radius: 6px; padding: 12px 14px; font-family: system-ui, sans-serif; }
.embed-prev .msg { margin-bottom: 8px; white-space: pre-wrap; }
.embed-card { display: grid; border-left: 4px solid var(--accent); background: #1e1f22; border-radius: 4px; padding: 10px 14px; gap: 6px; max-width: 480px; }
.embed-card .t { font-weight: 600; color: #fff; }
.embed-card .d { white-space: pre-wrap; font-size: 14px; }
.embed-card .f { font-size: 12px; color: #949ba4; }
.embed-card img { max-width: 100%; border-radius: 4px; }

/* ---------- permission matrix ---------- */
.matrix th, .matrix td { padding: 8px 12px; }
.matrix td.c { text-align: center; }
.matrix .grp td { background: var(--card2); font-weight: 600; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* ---------- auth pages ---------- */
.auth-card { max-width: 420px; margin-top: 22px; }
.auth-copy { color: var(--muted); max-width: 560px; margin-top: 10px; }
.err { color: var(--danger); min-height: 20px; margin: 4px 0 10px; font-size: 13px; }

/* ---------- mobile ---------- */
.scrim { display: none; }
@media (max-width: 860px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; margin-left: -260px; width: 250px; box-shadow: var(--shadow); }
  .app.drawer .sidebar { margin-left: 0; }
  .app.collapsed .sidebar { margin-left: -260px; }
  .app.drawer .scrim { display: block; position: fixed; inset: 0; background: rgba(2, 6, 12, .55); z-index: 20; }
  .main { margin: 0; border-radius: 0; border: 0; }
  .view { padding: 20px 16px 60px; }
  .searchpill { width: auto; } .searchpill .lbl, .searchpill .kbd { display: none; }
  .page-head h1, .view > h1.title { font-size: 24px; }
}
.hide-nav { visibility: hidden; }
ul.muted { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }

/* link-style buttons and login card spacing */
a.btn { text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.auth-card .row { margin-top: 10px; }
.auth-card > .muted { margin: 0 0 12px; }
