/* Theme on top of Pico. Same specificity as Pico's theme selectors. */
:root:not([data-theme="dark"]) {
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f1f3f6;
  --border: #e4e7ec;
  --text: #1d2433;
  --text-muted: #667085;
  --accent: #2f5d50;
  --accent-soft: #e6efeb;
  --accent-strong: #2f5d50;
  --positive: #1f7a4d;
  --negative: #b42318;
  --sidebar-bg: #141a21;
  --sidebar-text: #aab3c0;
  --sidebar-text-active: #ffffff;
  --sidebar-hover: #1f2731;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);

  --pico-font-family: var(--font-sans);
  --pico-font-size: 15px;
  --pico-line-height: 1.5;
  --pico-background-color: var(--bg);
  --pico-color: var(--text);
  --pico-muted-color: var(--text-muted);
  --pico-muted-border-color: var(--border);
  --pico-primary: var(--accent);
  --pico-primary-background: var(--accent);
  --pico-primary-border: var(--accent);
  --pico-primary-hover: #244a40;
  --pico-primary-hover-background: #244a40;
  --pico-primary-hover-border: #244a40;
  --pico-primary-focus: rgba(47, 93, 80, 0.25);
  --pico-primary-inverse: #fff;
  --pico-border-radius: 8px;
  --pico-form-element-background-color: var(--surface);
  --pico-form-element-border-color: var(--border);
  --pico-form-element-spacing-vertical: 0.55rem;
  --pico-form-element-spacing-horizontal: 0.75rem;
  --pico-card-background-color: var(--surface);
  --pico-card-sectioning-background-color: var(--surface);
  --pico-card-box-shadow: var(--shadow);
  --pico-table-border-color: var(--border);
  --pico-spacing: 1rem;
  --pico-typography-spacing-vertical: 1rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419;
    --surface: #171d24;
    --surface-muted: #1d242c;
    --border: #2a323c;
    --text: #e6e9ee;
    --text-muted: #8f99a8;
    --accent: #6fb39c;
    --accent-soft: #1c2d28;
    --accent-strong: #1f3f36;
    --positive: #5cc28f;
    --negative: #f0766b;
    --sidebar-bg: #0b0f13;
    --sidebar-hover: #161c23;
    --shadow: none;
    --pico-primary-hover: #86c4ae;
    --pico-primary-hover-background: #86c4ae;
    --pico-primary-hover-border: #86c4ae;
    --pico-primary-inverse: #0f1419;
  }
}

body {
  background: var(--bg);
  color: var(--text);
  font-feature-settings: "cv11", "ss01";
}

h1, h2, h3 {
  color: var(--text);
  font-weight: 600;
  letter-spacing: -0.01em;
}
h1 { font-size: 1.6rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }

.num, td.num, th.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.muted { color: var(--text-muted); }
.positive { color: var(--positive); }
.negative { color: var(--negative); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 1.25rem 0.75rem;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0 0.75rem 1.5rem;
  color: var(--sidebar-text-active);
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.sidebar .brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
}
.sidebar nav { display: block; }
.sidebar nav ul,
.sidebar nav ul:first-of-type,
.sidebar nav ul:last-of-type {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  margin: 0;
  padding: 0;
}
.sidebar nav li { list-style: none; padding: 0; margin: 0; }
.sidebar .nav-label {
  padding: 1rem 0.75rem 0.35rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6b7686;
}
.sidebar nav li a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0;
  padding: 0.5rem 0.75rem;
  border-radius: 7px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.92rem;
}
.sidebar nav li a:hover { background: var(--sidebar-hover); color: var(--sidebar-text-active); }
.sidebar nav li a[aria-current="page"] {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-active);
  box-shadow: inset 2px 0 0 var(--accent);
}
.sidebar svg { width: 18px; height: 18px; flex: none; }
/* Main menu takes the free space: admin links and user stay at the bottom. */
.sidebar > nav:first-of-type { flex: 1 1 auto; }
.sidebar-admin { padding-bottom: 0.5rem; }
.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid #222a34;
  font-size: 0.85rem;
}
.sidebar-footer .user { color: var(--sidebar-text-active); overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .email { color: #6b7686; font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer form { margin: 0.6rem 0 0; }
.sidebar-footer button {
  width: auto;
  margin: 0;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  background: transparent;
  border: 1px solid #2c3540;
  color: var(--sidebar-text);
}
.sidebar-footer button:hover { color: #fff; border-color: #48525f; background: transparent; }

.content {
  min-width: 0;
  padding: 2rem 2.5rem 3rem;
  max-width: 1200px;
  width: 100%;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    padding: 0.75rem;
  }
  .sidebar .brand { padding-bottom: 0.75rem; }
  .sidebar nav ul { flex-direction: row; flex-wrap: wrap; }
  .sidebar .nav-label { display: none; }
  .sidebar > nav:first-of-type { flex: none; }
  .sidebar-footer { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
  .sidebar-footer form { margin: 0; }
  .content { padding: 1.25rem 1rem 2rem; }
}

/* Page header */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.75rem;
}
.page-header .subtitle { margin: 0.25rem 0 0; color: var(--text-muted); font-size: 0.92rem; }
.page-header .actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.breadcrumb { font-size: 0.85rem; margin-bottom: 0.35rem; }
.breadcrumb a { color: var(--text-muted); text-decoration: none; }

/* Buttons */
.button, a[role="button"], button {
  font-size: 0.88rem;
  font-weight: 500;
  padding: 0.5rem 0.9rem;
}
a[role="button"].secondary, button.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
a[role="button"].secondary:hover, button.secondary:hover {
  background: var(--surface-muted);
  border-color: var(--border);
  color: var(--text);
}
button.link {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  width: auto;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-decoration: underline;
  text-underline-offset: 2px;
}
button.link:hover { color: var(--negative); background: none; }
button.danger { background: var(--negative); border-color: var(--negative); color: #fff; }
.inline-form { display: inline; margin: 0; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.25rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}
.card-header h2 { margin: 0; }
.card-header a { font-size: 0.85rem; }
.card.flush { padding: 0; }
.card.flush .card-header { padding: 1rem 1.4rem 0; }
.card.flush table { margin: 0; }

.grid-2, .grid-3 { display: grid; gap: 1.25rem; margin-bottom: 1.25rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.stat { margin-bottom: 0; }
.stat .label { color: var(--text-muted); font-size: 0.82rem; font-weight: 500; }
.stat .value {
  margin-top: 0.35rem;
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat .hint { margin-top: 0.2rem; font-size: 0.82rem; color: var(--text-muted); }
.stat.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.stat.primary .label, .stat.primary .hint { color: rgba(255, 255, 255, 0.75); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { font-size: 0.9rem; margin-bottom: 0; }
table th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: transparent;
}
table td, table th { padding: 0.65rem 1rem; background: transparent; }
.card.flush table td:first-child, .card.flush table th:first-child { padding-left: 1.4rem; }
.card.flush table td:last-child, .card.flush table th:last-child { padding-right: 1.4rem; }
table tbody tr:last-child td { border-bottom: none; }
table tbody tr:hover td { background: var(--surface-muted); }
table td a { text-decoration: none; font-weight: 500; }
table .empty td { color: var(--text-muted); text-align: center; padding: 1.5rem; }
tr.inactive td { opacity: 0.55; }

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--surface-muted);
  color: var(--text-muted);
  white-space: nowrap;
}
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* Bars (allocation) */
.bar-list { list-style: none; padding: 0; margin: 0; }
.bar-list li { list-style: none; margin-bottom: 0.8rem; }
.bar-list .row { display: flex; justify-content: space-between; font-size: 0.88rem; margin-bottom: 0.3rem; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-muted); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* Messages */
.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

/* Forms */
.form-card { max-width: 560px; }
.form-card form > div { margin-bottom: 0.25rem; }
.form-card label { font-size: 0.88rem; font-weight: 500; }
.helptext, .form-card .helptext { display: block; font-size: 0.8rem; color: var(--text-muted); margin-top: -0.6rem; margin-bottom: 0.75rem; }
.errorlist { list-style: none; padding: 0; margin: 0 0 0.5rem; color: var(--negative); font-size: 0.85rem; }
.errorlist li { list-style: none; }
.form-actions { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.5rem; }
.form-actions button, .form-actions a[role="button"] { width: auto; margin: 0; }

.filters {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.filters select, .filters input { width: auto; min-width: 220px; margin: 0; }
.filters button { width: auto; margin: 0; }

/* Auth pages */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}
.auth .panel { width: 100%; max-width: 400px; }
.auth .brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
  font-weight: 600;
  font-size: 1.15rem;
}
.auth .brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
}
.auth .card { padding: 1.75rem; }
.auth h1 { font-size: 1.25rem; margin-bottom: 0.35rem; }
.auth .lead { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.25rem; }
.auth button[type="submit"] { width: 100%; }
.qr {
  width: 200px;
  margin: 0 auto 1rem;
  padding: 10px;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.qr svg { display: block; width: 100%; height: auto; }
.secret { display: block; text-align: center; font-size: 0.8rem; word-break: break-all; margin-bottom: 1.25rem; }

details.log summary { font-size: 0.88rem; color: var(--text-muted); }
.danger-zone { border-color: color-mix(in srgb, var(--negative) 35%, var(--border)); }

/* Actions menu (Pico dropdown); selectors match Pico's specificity. */
.actions-menu { margin: 0; }
details.dropdown.actions-menu > summary[role="button"] {
  width: auto;
  padding: 0.5rem 0.9rem;
  font-size: 0.88rem;
}
details.dropdown.actions-menu > summary + ul {
  left: auto;
  right: 0;
  min-width: 250px;
  padding: 0.35rem 0;
}
details.dropdown.actions-menu > summary + ul li { padding: 0; }
details.dropdown.actions-menu > summary + ul li a,
details.dropdown.actions-menu > summary + ul li button {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 0;
  background: none;
  text-align: left;
  white-space: nowrap;
  overflow: visible;
  font: inherit;
  font-size: 0.88rem;
  line-height: inherit;
  color: var(--text);
  cursor: pointer;
}
details.dropdown.actions-menu > summary + ul li a:hover,
details.dropdown.actions-menu > summary + ul li button:hover { background: var(--surface-muted); }
details.dropdown.actions-menu > summary + ul li form { margin: 0; }
details.dropdown.actions-menu > summary + ul li button.menu-danger { color: var(--negative); }

.pagination { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.pagination a[role="button"] { margin: 0; }
