:root {
  --bg: #141612;
  --bg2: #1c1f18;
  --card: #22261e;
  --ink: #e8e4d8;
  --muted: #9a9484;
  --line: #3a3f32;
  --accent: #c4a574;
  --accent-ink: #1a160e;
  --danger: #d36b5a;
  --ok: #7fa36b;
  --warn: #d4a017;
  --sidebar: #10120e;
  --sidebar-ink: #d7d2c4;
  --focus: #e0c48a;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --wallpaper: none;
  --login-wallpaper: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; height: 100%; background-color: var(--bg); background-image: var(--wallpaper); background-size: cover; background-position: center; background-attachment: fixed; color: var(--ink); font: 15px/1.45 var(--sans); -webkit-text-size-adjust: 100%; }
html { font-size: clamp(15px, 0.25vw + 14.5px, 16.5px); }
a { color: var(--accent); }
button, input, select, textarea {
  font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 6px; padding: 0.45rem 0.65rem;
}
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]),
select, textarea { min-width: 0; max-width: 100%; }
button { cursor: pointer; background: var(--line); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.link { background: none; border: 0; color: var(--accent); padding: 0; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
label { display: block; font-size: 0.82rem; color: var(--muted); margin: 0.35rem 0 0.15rem; }
.layout { display: grid; grid-template-columns: minmax(13rem, 16.5rem) 1fr; min-height: 100dvh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-ink); padding: 1rem 0.75rem; display: flex; flex-direction: column; gap: 0.25rem; border-right: 1px solid var(--line); min-height: 100dvh; }
.brand { font-weight: 700; letter-spacing: 0.02em; color: var(--accent); padding: 0.4rem 0.6rem 1rem; line-height: 1.2; display: flex; flex-direction: column; gap: 0.35rem; }
.brand-logo { max-width: 100%; max-height: 3rem; object-fit: contain; align-self: flex-start; }
.brand small { display: block; color: var(--muted); font-weight: 400; font-size: 0.72rem; margin-top: 0.25rem; }
.nav-btn { display: block; width: 100%; text-align: left; background: transparent; border: 0; color: var(--sidebar-ink); padding: 0.45rem 0.65rem; border-radius: 6px; }
.nav-btn:hover, .nav-btn.active { background: color-mix(in srgb, var(--accent) 16%, var(--sidebar)); color: var(--ink); }
.main { padding: 1.1rem 1.4rem 3rem; min-width: 0; overflow-x: hidden; }
html.has-wallpaper .layout { background: transparent; }
html.has-wallpaper .main { background: color-mix(in srgb, var(--bg) 82%, transparent); }
h1 { font-size: 1.35rem; font-weight: 650; margin: 0 0 0.75rem; }
h2 { font-size: 1.05rem; margin: 1.2rem 0 0.5rem; }
.banner { background: color-mix(in srgb, var(--warn) 14%, var(--card)); border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--line)); padding: 0.7rem 0.85rem; border-radius: 8px; color: var(--ink); font-size: 0.88rem; margin-bottom: 1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.75rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 0.85rem 1rem; }
.card .k { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.card .v { font-size: 1.45rem; font-weight: 650; margin-top: 0.2rem; }
.toolbar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: end; margin: 0.6rem 0 0.8rem; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: 0.45rem 0.75rem; align-items: end; margin: 0 0 0.75rem; }
.filters .search { width: 100%; }
.filter-count { align-self: end; padding-bottom: 0.55rem; }
.table-wrap { overflow: auto; max-height: calc(100dvh - 14rem); border: 1px solid var(--line); border-radius: 8px; }
.table-wrap table { border: 0; }
.load-table { min-width: 78rem; }
.load-table th, .load-table td { white-space: nowrap; }
.load-table td:nth-child(2) { white-space: normal; min-width: 10rem; }
.load-table thead th { position: sticky; background: var(--bg2); z-index: 2; }
.load-table thead tr.groups th { top: 0; }
.load-table thead tr.cols th { top: 2.15rem; }
.load-table th.group.start { text-align: center; color: var(--ink); }
.load-table th.group.max { text-align: center; color: var(--ink); }
.load-table th.sortable { cursor: pointer; user-select: none; }
.load-table th.sortable:hover { color: var(--ink); }
.load-table th.sorted { color: var(--accent); }
.load-table .num { font-family: var(--mono); font-size: 0.86rem; }
table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
th, td { padding: 0.45rem 0.65rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
tr:hover td { background: color-mix(in srgb, var(--accent) 12%, var(--card)); color: var(--ink); }
.badge { display: inline-block; font-size: 0.72rem; padding: 0.1rem 0.4rem; border-radius: 999px; border: 1px solid var(--line); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.danger { color: var(--danger); border-color: var(--danger); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.4rem 0.75rem; }
.form-grid .wide { grid-column: 1 / -1; }
.muted { color: var(--muted); }
.auth {
  min-height: 100dvh;
  margin: 0;
  max-width: none;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  background-color: var(--bg);
  background-image: radial-gradient(1200px 500px at 20% -10%, color-mix(in srgb, var(--accent) 28%, transparent), var(--bg));
  background-size: cover;
  background-position: center;
  border: 0;
  border-radius: 0;
}
.auth-center { flex: 1; display: grid; place-items: center; width: 100%; }
.auth-card {
  width: min(26rem, 100%);
  background: var(--card);
  padding: 1.5rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.auth-card h2 { text-align: center; width: 100%; }
.auth-card > p { text-align: center; width: 100%; }
.auth-card label {
  width: 100%;
  max-width: 16rem;
  text-align: left;
}
.auth-card label input:not([type=checkbox]):not([type=radio]):not([type=file]) {
  display: block;
  width: 100%;
}
.auth-card button.primary { min-width: 8rem; margin-top: 0.25rem; }
.auth-head { text-align: center; margin-bottom: 0.85rem; width: 100%; }
.auth-head h1 { margin: 0 0 0.2rem; font-size: 1.35rem; }
.auth-head h2 { margin: 0.6rem 0 0.25rem; }
.auth-logo { display: block; margin: 0 auto 0.75rem; max-width: 11rem; max-height: 4.5rem; object-fit: contain; }
.auth-foot { text-align: center; font-size: 0.78rem; color: var(--muted); max-width: 36rem; margin: 0 auto; padding-top: 1rem; line-height: 1.5; }
html.has-login-wallpaper .auth { background-image: var(--login-wallpaper); }
html.has-login-wallpaper .auth-foot { color: #fff; mix-blend-mode: difference; }
.wallpaper-preview { max-width: 100%; max-height: 8rem; object-fit: cover; border-radius: 8px; display: block; margin: 0.4rem 0; border: 1px solid var(--line); }
.row-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.menu-fab { display: none; }
.chart { width: 100%; height: 220px; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; }
.empty { padding: 1.5rem; color: var(--muted); }
.status-bar { margin-top: auto; padding: 0.75rem 0.65rem 0; font-size: 0.75rem; color: var(--muted); }
.search { width: min(16rem, 100%); }
.sidebar-backdrop { display: none; }
.settings-nav { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 1rem; }
.theme-swatches { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.theme-swatch { min-width: 6.5rem; text-align: left; }
.theme-swatch.active { outline: 2px solid var(--accent); }
.user-card { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 0.5rem 0.75rem; align-items: end; margin-bottom: 0.75rem; }
.check { display: flex; align-items: center; gap: 0.4rem; margin: 0.6rem 0 0.2rem; color: var(--ink); }
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(18rem, 86vw); transform: translateX(-105%); z-index: 30; transition: transform 0.2s ease; padding-top: max(1rem, env(safe-area-inset-top)); }
  .sidebar.open { transform: none; }
  .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgb(0 0 0 / 0.45); z-index: 25; }
  .menu-fab { display: inline-flex; align-items: center; justify-content: center; min-height: 2.75rem; min-width: 2.75rem; position: fixed; top: max(0.6rem, env(safe-area-inset-top)); left: max(0.6rem, env(safe-area-inset-left)); z-index: 35; }
  .main { padding: 3.4rem max(0.85rem, env(safe-area-inset-right)) max(2rem, env(safe-area-inset-bottom)) max(0.85rem, env(safe-area-inset-left)); }
  input, select, textarea, button { font-size: 16px; }
  .filters { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr 1fr; }
  .load-table { min-width: 52rem; }
  .table-wrap { max-height: none; }
  .auth { margin: 0; padding: 1rem max(0.75rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left)); }
}
@media (max-width: 520px) {
  .cards { grid-template-columns: 1fr; }
}
@media (min-width: 1100px) {
  .main { padding: 1.25rem 1.75rem 3rem; }
}
html[data-theme="slate"] {
  --bg: #12151c; --bg2: #181c25; --card: #1e2430; --ink: #e6eaf2; --muted: #8b93a3;
  --line: #323a4a; --accent: #7aa2f7; --accent-ink: #0d1220; --sidebar: #0e1118; --sidebar-ink: #cdd3df; --focus: #9bb6f8;
}
html[data-theme="sand"] {
  --bg: #1c1812; --bg2: #241f18; --card: #2b241c; --ink: #f3ead9; --muted: #b3a48c;
  --line: #433b2e; --accent: #e0a45a; --accent-ink: #1a130a; --sidebar: #15110c; --sidebar-ink: #e8dcc8; --focus: #f0c07a;
}
html[data-theme="night"] {
  --bg: #09090b; --bg2: #111113; --card: #18181b; --ink: #f4f4f5; --muted: #a1a1aa;
  --line: #27272a; --accent: #22c55e; --accent-ink: #052e16; --sidebar: #000; --sidebar-ink: #e4e4e7; --focus: #4ade80;
}
html[data-theme="light"] {
  --bg: #f4f1ea; --bg2: #fffdf8; --card: #ffffff; --ink: #1c1914; --muted: #6b6458;
  --line: #d9d2c5; --accent: #8a5a1b; --accent-ink: #fff8ee; --sidebar: #ece6d8; --sidebar-ink: #2a251c; --focus: #b07a32;
  --danger: #b42318; --ok: #3f7d2c; --warn: #a16207;
}
