:root {
  --bg: #f6f7fb;
  --bg-elev: #ffffff;
  --bg-elev-2: #f3f4f9;
  --border: #e7e9f2;
  --border-strong: #d6d9e6;
  --text: #151a2e;
  --text-muted: #5f6781;
  --text-dim: #9aa1b8;
  --accent: #6558f5;
  --accent-2: #7c6cff;
  --accent-hover: #5648e6;
  --accent-soft: rgba(101, 88, 245, 0.10);
  --success: #16a36a;
  --warning: #d98a0b;
  --danger: #e5484d;
  --info: #2b7fe0;
  --success-soft: rgba(22, 163, 106, 0.12);
  --warning-soft: rgba(217, 138, 11, 0.13);
  --danger-soft: rgba(229, 72, 77, 0.11);
  --info-soft: rgba(43, 127, 224, 0.12);
  --neutral-soft: rgba(95, 103, 129, 0.12);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 18px 48px rgba(28, 33, 70, 0.16);
  --shadow-sm: 0 1px 2px rgba(28, 33, 70, 0.04), 0 4px 14px rgba(28, 33, 70, 0.05);
  --overlay: rgba(21, 26, 46, 0.42);
  --chart-line: #6558f5;
  --chart-fill: rgba(101, 88, 245, 0.14);
  --chart-grid: #e7e9f2;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sidebar-w: 256px;
  --tabbar-h: 64px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f111b;
  --bg-elev: #171a28;
  --bg-elev-2: #1e2234;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #eceef8;
  --text-muted: #9aa2bc;
  --text-dim: #626a84;
  --accent: #7b6cff;
  --accent-2: #9285ff;
  --accent-hover: #a094ff;
  --accent-soft: rgba(123, 108, 255, 0.16);
  --success: #3dd598;
  --warning: #f5b544;
  --danger: #ff6b72;
  --info: #5aa9ff;
  --success-soft: rgba(61, 213, 152, 0.13);
  --warning-soft: rgba(245, 181, 68, 0.14);
  --danger-soft: rgba(255, 107, 114, 0.13);
  --info-soft: rgba(90, 169, 255, 0.14);
  --neutral-soft: rgba(154, 162, 188, 0.14);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.22);
  --overlay: rgba(4, 6, 14, 0.66);
  --chart-line: #8a7dff;
  --chart-fill: rgba(123, 108, 255, 0.18);
  --chart-grid: rgba(255, 255, 255, 0.07);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
body { overflow-x: hidden; }
a { color: inherit; text-decoration: none; }
button { font: inherit; }
::selection { background: var(--accent-soft); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg-elev);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 10px 12px; width: 100%; outline: none; transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--text-dim); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
textarea { min-height: 90px; resize: vertical; }
label { display: block; margin-bottom: 14px; }
label > span { display: block; margin-bottom: 6px; color: var(--text-muted); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }

.muted { color: var(--text-muted); }
.error { color: var(--danger); margin-top: 10px; }

body { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
body.login-body { display: flex; align-items: center; justify-content: center; padding: 24px; }

.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 22px 14px 18px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; height: 100dvh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 2px 10px 24px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; flex: 0 0 38px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-weight: 800; display: grid; place-items: center; letter-spacing: .5px;
  box-shadow: 0 6px 16px rgba(101, 88, 245, 0.32), inset 0 1px 0 rgba(255,255,255,.28);
}
.brand-mark svg { width: 21px; height: 21px; stroke: #fff; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.brand h1 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.brand p { margin: 0; font-size: 12px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar .nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 18px; height: 18px; flex: 0 0 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sidebar .nav-item:hover { background: var(--bg-elev-2); color: var(--text); }
.sidebar .nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
:root[data-theme="dark"] .sidebar .nav-item.active { color: var(--accent-hover); }

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 14px; border: 1px solid var(--border); background: var(--bg-elev-2); border-radius: var(--radius); }
.switch-row { display: flex; justify-content: space-between; align-items: center; color: var(--text-muted); font-size: 13px; min-height: 32px; }
.sidebar-footer .btn-ghost { border-color: var(--border-strong); background: var(--bg-elev); }
.sidebar-footer .btn-ghost:hover { border-color: var(--accent); color: var(--text); }

.form-switch {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px; cursor: pointer;
  transition: border-color .15s;
}
.form-switch:hover { border-color: var(--border-strong); }
.form-switch .label { display: flex; flex-direction: column; gap: 2px; }
.form-switch .label strong { color: var(--text); font-weight: 600; font-size: 13px; }
.form-switch .label small { color: var(--text-muted); font-size: 12px; }

.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex: 0 0 44px; vertical-align: middle; margin: 0; }
.switch input {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; border: 0;
  opacity: 0; cursor: pointer; z-index: 2; background: none; -webkit-appearance: none; appearance: none;
}
.switch-slider { position: absolute; inset: 0; margin: 0; display: block; background: var(--border-strong); border-radius: 999px; transition: background-color .2s ease; pointer-events: none; }
.switch-slider::before {
  content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,0.28); transition: left .2s ease;
}
.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider::before { left: 21px; }
.switch input:focus-visible + .switch-slider { box-shadow: 0 0 0 4px var(--accent-soft); }

.main { padding: 0 clamp(16px, 3vw, 40px) 56px; width: 100%; min-width: 0; max-width: 1480px; margin-inline: auto; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 22px 0 16px; margin-bottom: 4px;
  background: linear-gradient(var(--bg) 78%, transparent);
}
.topbar-title { min-width: 0; }
.topbar h2 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.025em; line-height: 1.2; }
.topbar-title p { margin: 2px 0 0; font-size: 13px; }
.topbar-title p:empty { display: none; }
.topbar-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
#topbar-actions { display: flex; gap: 8px; }

.global-search { position: relative; width: 280px; margin: 0; }
.global-search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; stroke: var(--text-dim); fill: none; stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.global-search input { padding-left: 38px; background: var(--bg-elev); box-shadow: var(--shadow-sm); border-color: var(--border); height: 42px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--bg-elev); color: var(--text); cursor: pointer; font-weight: 500;
  transition: transform .08s, background .15s, border-color .15s, box-shadow .15s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn-primary { background: var(--accent); border-color: transparent; color: #fff; box-shadow: 0 6px 16px rgba(101, 88, 245, 0.30); }
.btn-primary:hover { border-color: transparent; background: var(--accent-hover); box-shadow: 0 8px 22px rgba(101, 88, 245, 0.42); }
.btn-success { background: var(--success-soft); border-color: transparent; color: var(--success); box-shadow: none; }
.btn-success:hover { background: var(--success-soft); border-color: var(--success); }
.btn-warning { background: var(--warning-soft); border-color: transparent; color: var(--warning); box-shadow: none; }
.btn-warning:hover { background: var(--warning-soft); border-color: var(--warning); }
.btn-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); box-shadow: none; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-outline-danger { background: transparent; border-color: var(--border-strong); color: var(--text-muted); box-shadow: none; }
.btn-outline-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.action-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 16px; }
.action-sep { width: 1px; height: 22px; background: var(--border-strong); margin: 0 4px; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); box-shadow: none; }
.btn-ghost:hover { background: var(--bg-elev-2); color: var(--text); border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.link-btn:hover { color: var(--accent-hover); }
.link-btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.card h3 { font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-top { align-items: start; }
.list-toggle { margin-top: 12px; padding: 6px 0; }
.grid-wide { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }

.stat { display: flex; flex-direction: column; gap: 6px; padding: 18px 20px; transition: transform .2s, box-shadow .2s, border-color .2s; }
.stat:hover { transform: translateY(-2px); border-color: var(--border-strong); box-shadow: var(--shadow); }
.stat-icon { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; margin-bottom: 6px; background: var(--accent-soft); color: var(--accent); }
.stat-icon svg { width: 19px; height: 19px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
:root[data-theme="dark"] .stat-icon { color: var(--accent-hover); }
.stat.t-success .stat-icon { background: var(--success-soft); color: var(--success); }
.stat.t-danger .stat-icon { background: var(--danger-soft); color: var(--danger); }
.stat.t-warning .stat-icon { background: var(--warning-soft); color: var(--warning); }
.stat-label { color: var(--text-muted); font-size: 13px; font-weight: 500; }
.stat-value { font-size: 32px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--text-dim); }

.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.panel-head h3 { margin: 0; }
.chart-wrap { position: relative; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-svg text { fill: var(--text-dim); font-family: var(--font); font-size: 11px; }
.chart-grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart-line { fill: none; stroke: var(--chart-line); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { fill: var(--chart-fill); }
.chart-dot { fill: var(--chart-line); stroke: var(--bg-elev); stroke-width: 2.5; }
.chart-tip {
  position: absolute; pointer-events: none; transform: translate(-50%, -120%);
  background: var(--bg-elev); border: 1px solid var(--border-strong); box-shadow: var(--shadow);
  border-radius: 8px; padding: 5px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; opacity: 0; transition: opacity .12s;
}
.chart-tip.show { opacity: 1; }
.chart-tip small { display: block; color: var(--text-muted); font-weight: 500; font-size: 11px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow-sm); }
.card .table-wrap { box-shadow: none; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 18px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; background: transparent; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; transition: background .12s; }
tr.clickable:hover { background: var(--bg-elev-2); }
.mono { font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
td.mono { white-space: nowrap; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  text-transform: capitalize; border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.active   { background: var(--success-soft); color: var(--success); }
.badge.disabled { background: var(--neutral-soft); color: var(--text-muted); }
.badge.blocked  { background: var(--danger-soft); color: var(--danger); }
.badge.expired  { background: var(--warning-soft); color: var(--warning); }
.badge.revoked  { background: var(--info-soft); color: var(--info); }

.filter-bar { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.filter-bar > * { flex: 0 0 auto; }
.filter-bar .search { flex: 1 1 240px; width: auto; min-width: 200px; }
.filter-bar select { width: auto; min-width: 170px; }

.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 200px;
  background: var(--bg-elev); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); z-index: 40;
  padding: 6px; display: none;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 6px; color: var(--text); cursor: pointer;
  background: transparent; border: none; width: 100%; text-align: left;
}
.dropdown-item:hover { background: var(--bg-elev-2); }
.dropdown-item.danger { color: var(--danger); }

.modal-backdrop {
  position: fixed; inset: 0; background: var(--overlay); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: fade .15s ease-out;
  display: flex; align-items: center; justify-content: center; z-index: 60; padding: 24px;
}
.modal {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 20px;
  animation: pop .2s cubic-bezier(.2,.9,.3,1.1);
  width: 100%; max-width: 720px; max-height: 90vh; max-height: 90dvh; overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 24px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-elev); z-index: 2; }
.modal-header h3 { margin: 0; font-size: 17px; min-width: 0; overflow-wrap: anywhere; }
.modal-body { padding: 24px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--bg-elev); }

#toast-root { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast {
  padding: 12px 16px; background: var(--bg-elev); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); min-width: 240px; max-width: 380px; transition: opacity .3s, transform .3s; animation: slide 0.2s ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.danger  { border-left-color: var(--danger); }
.toast .toast-title { font-weight: 600; }
.toast .toast-sub { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: translateY(10px) scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rise { from { transform: translateY(100%); } to { transform: none; } }

.login-card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 22px;
  padding: 36px; width: 100%; max-width: 420px; box-shadow: var(--shadow); animation: pop .3s ease-out;
}
.login-card .brand { padding-bottom: 24px; padding-left: 0; }

.section-title { font-size: 12px; font-weight: 600; color: var(--text-muted); margin: 22px 0 10px; letter-spacing: .02em; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.detail-grid > div { padding: 10px 12px; background: var(--bg-elev-2); border-radius: var(--radius-sm); min-width: 0; }
.detail-grid .k { color: var(--text-muted); font-size: 11.5px; margin-bottom: 4px; }
.detail-grid .v { font-size: 13px; word-break: break-word; }

.note {
  padding: 12px 14px; border: 1px solid var(--border); background: var(--bg-elev-2); border-radius: var(--radius-sm);
  margin-bottom: 8px; display: flex; justify-content: space-between; gap: 12px;
}
.note .note-meta { color: var(--text-muted); font-size: 11px; margin-top: 6px; }

.log-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.log-item:last-child { border-bottom: none; padding-bottom: 0; }
.log-item:first-child { padding-top: 0; }
.log-item > div { min-width: 0; }
.log-item .mono { overflow-wrap: anywhere; }
.log-item time { color: var(--text-muted); font-size: 12px; white-space: nowrap; }

.calendar { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.cal-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-dow { text-align: center; padding: 8px 0; font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.cal-day {
  aspect-ratio: 1 / 1; background: var(--bg-elev-2); border-radius: var(--radius-sm);
  padding: 6px 8px; font-size: 12px; position: relative; overflow: hidden;
  border: 1px solid transparent; min-width: 0;
}
.cal-day.other { opacity: .35; }
.cal-day.today { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cal-day .cal-num { font-weight: 600; }
.cal-day .cal-event {
  margin-top: 3px; padding: 2px 6px; border-radius: 4px;
  font-size: 10.5px; line-height: 1.3; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-left: 3px solid transparent;
}
.cal-day .cal-event.exp     { background: var(--warning-soft); color: var(--warning); border-left-color: var(--warning); }
.cal-day .cal-event.new     { background: var(--success-soft); color: var(--success); border-left-color: var(--success); }
.cal-day .cal-event.status  { background: var(--info-soft); color: var(--info); border-left-color: var(--info); }
.cal-day .cal-event.blocked { background: var(--danger-soft); color: var(--danger); border-left-color: var(--danger); }
.cal-day .cal-more { color: var(--text-muted); font-size: 10px; margin-top: 2px; }
.cal-day .cal-checks {
  position: absolute; right: 6px; top: 6px;
  font-size: 10px; color: var(--text-muted); background: var(--bg-elev);
  padding: 1px 5px; border-radius: 8px;
}
.cal-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; font-size: 12px; }
.cal-legend .item { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); }
.cal-legend .swatch { width: 10px; height: 10px; border-radius: 2px; }
.cal-toggles { display: flex; flex-wrap: wrap; gap: 8px; }
.cal-toggle {
  display: inline-flex; align-items: center; gap: 6px; margin: 0;
  padding: 6px 12px; border-radius: 999px;
  background: var(--bg-elev); border: 1px solid var(--border-strong);
  font-size: 12px; cursor: pointer; user-select: none; position: relative;
}
.cal-toggle input { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; padding: 0; border: 0; }
.cal-toggle .swatch { width: 10px; height: 10px; border-radius: 2px; }
.cal-toggle.on { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }

.empty { padding: 40px; text-align: center; color: var(--text-muted); }

.flex { display: flex; }
.gap-1 { gap: 8px; } .gap-2 { gap: 12px; } .gap-3 { gap: 16px; }
.between { justify-content: space-between; }
.center { align-items: center; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }

.notif { position: relative; }
.notif-btn {
  position: relative; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text-muted); cursor: pointer; box-shadow: var(--shadow-sm);
  transition: color .15s, border-color .15s, transform .1s;
}
.notif-btn:hover { color: var(--text); border-color: var(--accent); }
.notif-btn svg { width: 19px; height: 19px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.notif-btn.ring svg { animation: ring 0.9s ease-in-out 2; transform-origin: 50% 10%; color: var(--danger); }
@keyframes ring { 0%,100% { transform: rotate(0); } 15% { transform: rotate(14deg); } 35% { transform: rotate(-12deg); } 55% { transform: rotate(8deg); } 75% { transform: rotate(-5deg); } }
.notif-count {
  position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
  box-shadow: 0 0 0 3px var(--bg);
}
.notif-count[hidden] { display: none; }
.notif-panel {
  position: absolute; right: 0; top: calc(100% + 10px); width: 400px; max-width: calc(100vw - 32px);
  background: var(--bg-elev); border: 1px solid var(--border-strong); border-radius: 18px; box-shadow: var(--shadow);
  display: none; overflow: hidden; z-index: 50; animation: pop .18s ease-out;
}
.notif.open .notif-panel { display: block; }
.notif-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.notif-head strong { font-size: 14px; }
.notif-list { max-height: 440px; overflow-y: auto; }
.notif-item {
  display: flex; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer;
  position: relative; transition: background .12s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg-elev-2); }
.notif-item.unread { background: var(--accent-soft); }
.notif-item.unread::after { content: ""; position: absolute; right: 14px; top: 18px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.notif-icon { flex: 0 0 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; }
.notif-icon svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.notif-icon.danger  { background: var(--danger-soft); color: var(--danger); }
.notif-icon.warning { background: var(--warning-soft); color: var(--warning); }
.notif-icon.info    { background: var(--info-soft); color: var(--info); }
.notif-body { flex: 1; min-width: 0; padding-right: 14px; }
.notif-title { font-weight: 600; font-size: 13px; }
.notif-text { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; word-break: break-word; }
.notif-time { color: var(--text-dim); font-size: 11.5px; margin-top: 6px; }
.notif-empty { padding: 40px 16px; text-align: center; color: var(--text-muted); }

.server-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px; }
.server-row > div { min-width: 0; }
.server-row .pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); flex: 0 0 9px; }
.server-row .pulse.online { background: var(--success); box-shadow: 0 0 0 0 rgba(22,163,106,.5); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(22,163,106,0); } 100% { box-shadow: 0 0 0 0 rgba(22,163,106,0); } }

.discord-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.discord-avatar { width: 34px; height: 34px; border-radius: 50%; flex: 0 0 34px; object-fit: cover; background: var(--bg-elev-2); }
.discord-meta { min-width: 0; }
.discord-name { font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.discord-id { color: var(--text-dim); font-size: 11px; }

.discord-preview { min-height: 0; }
.discord-preview:not(:empty) { margin-top: 2px; padding: 8px 10px; background: var(--bg-elev); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.status-reason { margin-top: 6px; color: var(--text-muted); font-size: 12.5px; line-height: 1.4; }
details.collapse { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 12px; }
details.collapse > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  color: var(--text-muted); font-size: 12px; font-weight: 600;
  padding: 6px 0; user-select: none;
}
details.collapse > summary::-webkit-details-marker { display: none; }
details.collapse > summary::before {
  content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform .15s; margin-right: 2px;
}
details.collapse[open] > summary::before { transform: rotate(45deg); }
details.collapse > summary:hover { color: var(--text); }
details.collapse .count { background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 8px; font-size: 11px; }
details.collapse > :not(summary) { margin-top: 10px; }

.tabbar, .sheet-backdrop { display: none; }

@media (max-width: 1180px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-wide { grid-template-columns: 1fr; }
  .global-search { width: 220px; }
}

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px)); }
  body.login-body, body.status-page { padding-bottom: 0; }
  .sidebar { display: none; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .main { padding: 0 16px 28px; }
  .topbar { padding: calc(14px + env(safe-area-inset-top, 0px)) 0 12px; }
  .topbar h2 { font-size: 22px; }
  .global-search { display: none; }
  .topbar-right { gap: 8px; }
  .notif-btn { width: 40px; height: 40px; }
  .notif-panel { position: fixed; left: 12px; right: 12px; top: calc(64px + env(safe-area-inset-top, 0px)); width: auto; max-width: none; }
  .notif-list { max-height: 60vh; }

  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding: 6px 6px env(safe-area-inset-bottom, 0px);
    background: var(--bg-elev); border-top: 1px solid var(--border);
    box-shadow: 0 -6px 24px rgba(28, 33, 70, 0.06);
  }
  .tabbar .nav-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    background: none; border: 0; color: var(--text-dim); font-size: 10.5px; font-weight: 600;
    border-radius: 12px; min-height: 52px; cursor: pointer; transition: color .15s, background .15s;
  }
  .tabbar .nav-item svg { width: 22px; height: 22px; flex: 0 0 22px; }
  .tabbar .nav-item.active { color: var(--accent); }
  :root[data-theme="dark"] .tabbar .nav-item.active { color: var(--accent-hover); }
  .tabbar .nav-item.active svg { stroke-width: 2.2; }

  .sheet-backdrop { position: fixed; inset: 0; z-index: 70; background: var(--overlay); align-items: flex-end; animation: fade .15s ease-out; }
  .sheet-backdrop:not([hidden]) { display: flex; }
  .sheet {
    width: 100%; background: var(--bg-elev); border-radius: 22px 22px 0 0; border: 1px solid var(--border);
    padding: 10px 14px calc(14px + env(safe-area-inset-bottom, 0px)); animation: rise .22s cubic-bezier(.2,.9,.3,1);
    display: flex; flex-direction: column; gap: 4px;
  }
  .sheet-grip { width: 38px; height: 4px; border-radius: 99px; background: var(--border-strong); margin: 0 auto 8px; }
  .sheet-row {
    display: flex; align-items: center; gap: 14px; width: 100%; min-height: 52px; padding: 0 12px;
    border: 0; background: none; border-radius: 12px; color: var(--text); font-weight: 500; font-size: 15px; text-align: left; cursor: pointer;
  }
  .sheet-row:active { background: var(--bg-elev-2); }
  .sheet-row svg { width: 20px; height: 20px; flex: 0 0 20px; stroke: var(--text-muted); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .sheet-row span:not(.switch-slider) { flex: 1; }
  .sheet-row .switch { margin-left: auto; }

  #toast-root { left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom, 0px)); }
  .toast { max-width: none; min-width: 0; }

  input, select, textarea { font-size: 16px; }
  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; }
  #topbar-actions .btn { padding: 8px 12px; font-size: 13px; white-space: nowrap; }
  .topbar-title { flex: 1 1 auto; }
  .topbar-title p { display: none; }
}

@media (max-width: 720px) {
  .card { padding: 16px; }
  .grid-4 { gap: 12px; }
  .stat { padding: 14px; }
  .stat-value { font-size: 26px; }
  .stat-icon { width: 32px; height: 32px; }
  .filter-bar { gap: 10px; }
  .filter-bar .search { flex: 1 1 100%; width: 100%; min-width: 0; }
  .filter-bar select { flex: 1 1 calc(50% - 5px); width: auto; min-width: 0; }

  .table-wrap { background: transparent; border: 0; box-shadow: none; overflow: visible; border-radius: 0; }
  .card .table-wrap { margin: 0; }
  .table-wrap table, .table-wrap tbody { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    display: block; margin-bottom: 12px; padding: 6px 14px;
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  }
  .table-wrap tr:last-child { margin-bottom: 0; }
  .table-wrap td {
    display: flex; justify-content: space-between; align-items: center; gap: 16px; text-align: right;
    padding: 10px 0; border-bottom: 1px solid var(--border); min-width: 0;
  }
  .table-wrap td:last-child { border-bottom: 0; }
  .table-wrap td[data-label]::before { content: attr(data-label); color: var(--text-muted); font-size: 12px; font-weight: 500; text-align: left; flex: 0 0 auto; }
  .table-wrap td > * { min-width: 0; }
  td.mono { white-space: normal; overflow-wrap: anywhere; }
  .discord-name { max-width: 150px; }
  .discord-cell { text-align: right; flex-direction: row-reverse; }
  .card .table-wrap tr { box-shadow: none; background: var(--bg-elev-2); }

  .detail-grid { grid-template-columns: 1fr; }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-width: none; border-radius: 22px 22px 0 0; max-height: 92vh; max-height: 92dvh; animation: rise .22s cubic-bezier(.2,.9,.3,1); }
  .modal-header { padding: 14px 16px; }
  .modal-body { padding: 16px; }
  .modal-footer { padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); }
  .modal-footer .btn { flex: 1 1 auto; }
  .modal .grid-2 { grid-template-columns: 1fr; gap: 0; }
  .login-card { padding: 26px 20px; }

  .calendar { padding: 12px; }
  .cal-grid { gap: 4px; }
  .cal-day { aspect-ratio: auto; min-height: 52px; padding: 4px; }
  .cal-day .cal-num { font-size: 11px; }
  .cal-day .cal-checks { display: none; }
  .cal-day .cal-event { font-size: 0; height: 5px; padding: 0; margin-top: 3px; border-left-width: 0; border-radius: 3px; }
  .cal-day .cal-more { display: none; }
  .cal-dow { font-size: 10px; }
  .cal-header .flex { width: 100%; }
  .cal-header .flex .btn { flex: 1; }
  .kv { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
  .topbar h2 { font-size: 20px; }
  .log-item { flex-wrap: wrap; }
  .log-item time { flex-basis: 100%; }
}

@media (min-width: 1700px) {
  .main { max-width: 1600px; }
}

.key-blur { display: inline-block; filter: blur(6px); cursor: pointer; user-select: none; -webkit-user-select: none; transition: filter .15s; }
.key-blur.revealed { filter: none; }

.picker { position: relative; margin-bottom: 4px; }
.picker-trigger { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 46px; padding: 6px 12px; background: var(--bg-elev); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); cursor: pointer; outline: none; transition: border-color .15s, box-shadow .15s; }
.picker-trigger:focus, .picker.open .picker-trigger { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.picker-caret { color: var(--text-muted); flex: 0 0 auto; transition: transform .15s; }
.picker.open .picker-caret { transform: rotate(180deg); }
.picker-panel { display: none; position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg-elev); overflow: hidden; box-shadow: 0 16px 40px rgba(0,0,0,.45); }
.picker.open .picker-panel { display: block; }
.picker-search { border: 0; border-bottom: 1px solid var(--border); border-radius: 0; box-shadow: none !important; }
.picker-list { max-height: 200px; overflow-y: auto; overscroll-behavior: contain; }
.picker-item { padding: 8px 12px; cursor: pointer; }
.picker-item:hover, .picker-item.active { background: var(--bg-elev-2); }
.picker-item.disabled { opacity: .5; cursor: not-allowed; }
.picker-empty { padding: 14px 12px; text-align: center; }
.picker-create { display: block; width: 100%; padding: 11px 12px; border: 0; border-top: 1px solid var(--border); background: transparent; color: var(--accent); font: inherit; font-weight: 600; text-align: left; cursor: pointer; }
.picker-create:hover { background: var(--accent-soft); }
.picker .discord-cell { text-align: left; flex-direction: row; }

.modal-header-actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.modal-footer-start { justify-content: flex-start; }
.plugin-accordion details.collapse { margin-top: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; }
.plugin-accordion details.collapse:first-child { margin-top: 0; }
.plugins-outer { border-top: 0; padding-top: 0; }
.modal-header-plain { border-bottom-color: transparent; }

.email-field { position: relative; }
.email-field input { padding-right: 44px; }
.email-status { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); display: inline-flex; }
.email-status.inline { position: static; transform: none; }
.email-status svg { width: 18px; height: 18px; }
.email-status.ok { color: #22c55e; }
.email-status.bad { color: #ef4444; }
.modal-footer-start .btn-danger { margin-left: auto; }

.cselect { position: relative; min-width: 0; }
.cselect-native { display: none !important; }
.cselect-trigger { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; font: inherit; color: var(--text); background: var(--bg-elev); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; text-align: left; outline: none; transition: border-color .15s, box-shadow .15s; }
.cselect-trigger:hover { border-color: var(--text-dim); }
.cselect.open .cselect-trigger, .cselect-trigger:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.cselect.disabled .cselect-trigger { opacity: .55; cursor: not-allowed; }
.cselect-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cselect-caret { display: inline-flex; flex: 0 0 auto; color: var(--text-muted); transition: transform .15s; }
.cselect-caret svg { width: 16px; height: 16px; }
.cselect.open .cselect-caret { transform: rotate(180deg); }
.cselect-menu { display: none; position: absolute; left: 0; top: calc(100% + 6px); min-width: 100%; z-index: 70; max-height: 240px; overflow-y: auto; overscroll-behavior: contain; padding: 6px; background: var(--bg-elev); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: 0 16px 40px rgba(0,0,0,.45); }
.cselect.open .cselect-menu { display: block; }
.cselect.up .cselect-menu { top: auto; bottom: calc(100% + 6px); }
.cselect-option { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.cselect-option.active { background: var(--bg-elev-2); }
.cselect-option.selected { color: var(--accent); font-weight: 600; }
.cselect-option.disabled { opacity: .45; cursor: not-allowed; }
.filter-bar .cselect { width: auto; min-width: 170px; }
@media (max-width: 720px) {
  .filter-bar .cselect { flex: 1 1 calc(50% - 5px); width: auto; min-width: 0; }
}
html, body, body * {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
input, textarea, [contenteditable="true"] {
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}