/* ---------------------------------------------------------------------
   Design tokens — Ubiquiti/UniFi-OS-inspired: dark navy sidebar nav,
   clean light content surface, vivid blue accent, soft-tinted status
   pills instead of solid color blocks.
--------------------------------------------------------------------- */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-alt: #f9fafb;
  --border: #e4e8ee;
  --border-strong: #d3d9e3;

  --text: #101828;
  --text-secondary: #344054;
  --text-muted: #667085;

  --brand-50: #eef4ff;
  --brand-100: #d9e8ff;
  --brand-500: #2f6fed;
  --brand-600: #0b5fff;
  --brand-700: #0847c4;

  --success-text: #067647;
  --success-bg: #ecfdf3;
  --success-border: #abefc6;

  --warn-text: #b54708;
  --warn-bg: #fffaeb;
  --warn-border: #fedf89;

  --danger-text: #b42318;
  --danger-bg: #fef3f2;
  --danger-border: #fecdca;

  --info-text: #175cd3;
  --info-bg: #eff8ff;
  --info-border: #b2ddff;

  --neutral-text: #344054;
  --neutral-bg: #f2f4f7;
  --neutral-border: #eaecf0;

  --sidebar-bg: #0d1526;
  --sidebar-bg-raised: #121b30;
  --sidebar-border: #1c2740;
  --sidebar-text: #8b98ae;
  --sidebar-text-active: #ffffff;
  --sidebar-hover-bg: #16213a;
  --sidebar-active-bg: #1a2745;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.08);

  --sidebar-w: 244px;
}

/* Dark theme. The sidebar stays the same dark navy in both themes (it
   already is one), so only the content-surface tokens change.
   html[data-theme="dark"/"light"] is set server-side from a cookie (no
   flash of the wrong theme on load). The template always renders the
   attribute (possibly as data-theme=""), so "no preference saved yet"
   means neither "dark" nor "light" -- not attribute-absent. */
html[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #131b2e;
  --surface-alt: #182238;
  --border: #232c42;
  --border-strong: #2e3852;

  --text: #e7eaf2;
  --text-secondary: #b9c1d6;
  --text-muted: #8792ab;

  --brand-50: rgba(47, 111, 237, 0.16);
  --brand-100: rgba(47, 111, 237, 0.28);
  --brand-500: #4c86ff;
  --brand-600: #518bff;
  --brand-700: #7ba5ff;

  --success-text: #4ade80;
  --success-bg: rgba(16, 185, 129, 0.14);
  --success-border: rgba(16, 185, 129, 0.35);

  --warn-text: #fbbf24;
  --warn-bg: rgba(245, 158, 11, 0.14);
  --warn-border: rgba(245, 158, 11, 0.35);

  --danger-text: #f87171;
  --danger-bg: rgba(239, 68, 68, 0.14);
  --danger-border: rgba(239, 68, 68, 0.35);

  --info-text: #7dc4fd;
  --info-bg: rgba(59, 130, 246, 0.14);
  --info-border: rgba(59, 130, 246, 0.35);

  --neutral-text: #cbd5e1;
  --neutral-bg: rgba(148, 163, 184, 0.14);
  --neutral-border: rgba(148, 163, 184, 0.32);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
}
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background: var(--surface-alt);
  color: var(--text);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="dark"]):not([data-theme="light"]) {
    --bg: #0b1120;
    --surface: #131b2e;
    --surface-alt: #182238;
    --border: #232c42;
    --border-strong: #2e3852;

    --text: #e7eaf2;
    --text-secondary: #b9c1d6;
    --text-muted: #8792ab;

    --brand-50: rgba(47, 111, 237, 0.16);
    --brand-100: rgba(47, 111, 237, 0.28);
    --brand-500: #4c86ff;
    --brand-600: #518bff;
    --brand-700: #7ba5ff;

    --success-text: #4ade80;
    --success-bg: rgba(16, 185, 129, 0.14);
    --success-border: rgba(16, 185, 129, 0.35);

    --warn-text: #fbbf24;
    --warn-bg: rgba(245, 158, 11, 0.14);
    --warn-border: rgba(245, 158, 11, 0.35);

    --danger-text: #f87171;
    --danger-bg: rgba(239, 68, 68, 0.14);
    --danger-border: rgba(239, 68, 68, 0.35);

    --info-text: #7dc4fd;
    --info-bg: rgba(59, 130, 246, 0.14);
    --info-border: rgba(59, 130, 246, 0.35);

    --neutral-text: #cbd5e1;
    --neutral-bg: rgba(148, 163, 184, 0.14);
    --neutral-border: rgba(148, 163, 184, 0.32);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  }
  html:not([data-theme="dark"]):not([data-theme="light"]) input,
  html:not([data-theme="dark"]):not([data-theme="light"]) select,
  html:not([data-theme="dark"]):not([data-theme="light"]) textarea {
    background: var(--surface-alt);
    color: var(--text);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }

code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em; }

/* ---------------------------------------------------------------------
   App shell: dark sidebar + light content column
--------------------------------------------------------------------- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
  transition: transform 0.2s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.1rem 1.1rem 0.9rem;
  color: #fff;
  font-weight: 700;
  font-size: 0.98rem;
  letter-spacing: -0.01em;
}
.sidebar-brand .mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar-brand .mark svg { width: 17px; height: 17px; color: #fff; }
.sidebar-brand .store-name { font-weight: 400; font-size: 0.72rem; color: var(--sidebar-text); display: block; margin-top: 0.1rem; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 0.4rem 0.7rem; }
.nav-group { margin-bottom: 1.1rem; }
.nav-group-label {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em;
  color: #4c5872; padding: 0.5rem 0.6rem 0.35rem;
}

.nav-item {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 0.87rem; font-weight: 500;
  margin-bottom: 0.1rem;
  position: relative;
}
.nav-item:hover { background: var(--sidebar-hover-bg); color: #fff; text-decoration: none; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; stroke: currentColor; }
.nav-item.active {
  background: var(--sidebar-active-bg, #1a2745);
  color: #fff;
}
.nav-item.active::before {
  content: "";
  position: absolute; left: -0.7rem; top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%;
  background: var(--brand-500);
  border-radius: 0 3px 3px 0;
}
.nav-item.active svg { stroke: var(--brand-500); }

.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding: 0.8rem 0.9rem;
}
.user-chip { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.6rem; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-600); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 700; flex-shrink: 0;
}
.user-meta { min-width: 0; }
.user-name { color: #fff; font-size: 0.82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: var(--sidebar-text); font-size: 0.72rem; text-transform: capitalize; }

.signout-btn {
  display: flex; align-items: center; gap: 0.5rem;
  width: 100%; background: transparent; border: 1px solid var(--sidebar-border);
  color: var(--sidebar-text); font-size: 0.8rem; font-weight: 600;
  padding: 0.4rem 0.6rem; border-radius: var(--radius-sm); cursor: pointer;
  font-family: inherit;
}
.signout-btn:hover { background: var(--sidebar-hover-bg); color: #fff; }
.signout-btn svg { width: 15px; height: 15px; }

.theme-toggle {
  margin-left: auto; flex-shrink: 0;
  width: 30px; height: 30px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  padding: 0;
}
.theme-toggle:hover { background: var(--sidebar-hover-bg); color: #fff; }
.theme-toggle svg { width: 15px; height: 15px; }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

.main-area { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 56px; flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0 1.25rem;
  position: sticky; top: 0; z-index: 30;
}
.sidebar-toggle {
  display: none;
  background: none; border: none; cursor: pointer; padding: 0.3rem;
  color: var(--text-secondary);
}
.sidebar-toggle svg { width: 22px; height: 22px; }

.topbar-search { flex: 1; max-width: 360px; }
.topbar-search form { display: flex; align-items: center; gap: 0.5rem; background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 0.35rem 0.85rem; }
.topbar-search svg { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }
.topbar-search input { border: none; background: transparent; padding: 0; font-size: 0.85rem; }
.topbar-search input:focus { outline: none; box-shadow: none; }

.topbar-spacer { flex: 1; }
.topbar-date { color: var(--text-muted); font-size: 0.82rem; }

.sidebar-backdrop { display: none; }

main.content { max-width: 1240px; width: 100%; margin: 0 auto; padding: 1.6rem 1.75rem 3rem; }

@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-md); }
  .main-area { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; }
  .sidebar-backdrop.open {
    display: block; position: fixed; inset: 0; background: rgba(16, 24, 40, 0.45); z-index: 39;
  }
}

/* ---------------------------------------------------------------------
   Typography
--------------------------------------------------------------------- */

h1 { font-size: 1.5rem; font-weight: 700; margin: 0 0 1.1rem; letter-spacing: -0.015em; color: var(--text); }
h2 { font-size: 1.05rem; font-weight: 700; margin: 1.8rem 0 0.7rem; letter-spacing: -0.01em; }
h3 { font-size: 0.92rem; font-weight: 700; margin: 1rem 0 0.5rem; color: var(--text-secondary); }

/* ---------------------------------------------------------------------
   Cards / panels / grid
--------------------------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.4rem;
}

.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------------
   Tables
--------------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; font-size: 0.865rem; }
table th, table td { text-align: left; padding: 0.65rem 0.7rem; vertical-align: top; }
table th {
  color: var(--text-muted); font-weight: 600; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-strong);
}
table td { border-bottom: 1px solid var(--border); color: var(--text-secondary); }
table tr:last-child td { border-bottom: none; }
table tr:hover td { background: var(--surface-alt); }
.table-wrap { overflow-x: auto; margin: -0.2rem 0; }

/* plain key/value tables used inside detail panels */
.panel table th { text-transform: none; letter-spacing: 0; font-size: 0.78rem; width: 190px; font-weight: 600; color: var(--text-muted); border-bottom-color: var(--border); }

/* ---------------------------------------------------------------------
   Badges (status pills)
--------------------------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
  line-height: 1.4;
}
.badge-ok { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }
.badge-warn { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
.badge-danger { background: var(--danger-bg); color: var(--danger-text); border-color: var(--danger-border); }
.badge-info { background: var(--info-bg); color: var(--info-text); border-color: var(--info-border); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral-text); border-color: var(--neutral-border); }

/* ---------------------------------------------------------------------
   Stat tiles
--------------------------------------------------------------------- */

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.05rem 1.15rem;
  display: flex; align-items: flex-start; gap: 0.8rem;
}
.stat .icon-badge {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--neutral-bg); color: var(--text-secondary);
}
.stat .icon-badge svg { width: 19px; height: 19px; }
.stat.warn .icon-badge { background: var(--warn-bg); color: var(--warn-text); }
.stat.danger .icon-badge { background: var(--danger-bg); color: var(--danger-text); }
.stat.ok .icon-badge { background: var(--success-bg); color: var(--success-text); }
.stat .value { font-size: 1.55rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.stat .label { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.1rem; }
.stat.warn { border-color: var(--warn-border); }
.stat.danger { border-color: var(--danger-border); }
a.stat-link { display: block; }
a.stat-link:hover { text-decoration: none; }
a.stat-link:hover .stat { border-color: var(--brand-500); box-shadow: 0 0 0 3px var(--brand-50); }

/* ---------------------------------------------------------------------
   Forms
--------------------------------------------------------------------- */

form.inline { display: inline; }

.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: 0.32rem; font-size: 0.82rem; color: var(--text-secondary); }
.field .hint { color: var(--text-muted); font-size: 0.76rem; margin-top: 0.3rem; line-height: 1.4; }

input, select, textarea {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.87rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-50);
}
textarea { min-height: 5.2rem; resize: vertical; }
.checkbox-row { display: flex; align-items: center; gap: 0.55rem; }
.checkbox-row input { width: auto; accent-color: var(--brand-600); }
.checkbox-row label { margin-bottom: 0; } /* labels next to a checkbox shouldn't carry the standalone .field label gap */

fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 1.1rem; padding: 0.9rem 1rem 0.2rem; }
legend { font-weight: 700; font-size: 0.82rem; padding: 0 0.4rem; color: var(--text-secondary); }

/* Toggled by app.js's [data-toggle-target] handler instead of an inline
   style="display:none" -- the CSP (style-src 'self') silently drops inline
   style attributes, so the hidden state has to come from a class. */
.hidden-field { display: none; }

/* A clear, separated footer for form submit/cancel actions, instead of a
   button sitting flush against the last field. */
.form-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.4rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
}

/* Standard widths for a form living inside a .panel, so forms don't stretch
   to the full content width. */
.panel-narrow { max-width: 460px; }
.panel-form { max-width: 700px; }

.login-shell { max-width: 380px; margin: 4rem auto 0; }

.stat-callout { max-width: 240px; margin-bottom: 1rem; }

.inline-form-row { display: flex; align-items: center; gap: 0.4rem; }
.input-compact { flex: 1; min-width: 140px; }

.mt-sm { margin-top: 0.5rem; }
.mt-md { margin-top: 0.8rem; }
.mt-lg { margin-top: 1.2rem; }

/* ---------------------------------------------------------------------
   Buttons
--------------------------------------------------------------------- */

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  background: var(--brand-600);
  color: #fff;
  border: 1px solid var(--brand-600);
  padding: 0.52rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s, border-color 0.12s;
  line-height: 1.2;
}
button:hover, .btn:hover { background: var(--brand-700); border-color: var(--brand-700); text-decoration: none; color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text-secondary); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-alt); border-color: var(--border-strong); color: var(--text); }
.btn-danger { background: var(--danger-text); border-color: var(--danger-text); }
.btn-danger:hover { background: #8f1c13; border-color: #8f1c13; }
.btn-sm { padding: 0.32rem 0.65rem; font-size: 0.78rem; }
button:disabled, .btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------------------------------------------------------------------
   Alerts / flash
--------------------------------------------------------------------- */

.error-banner, .flash-success {
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1.1rem;
  font-size: 0.86rem;
  border: 1px solid;
}
.error-banner { background: var(--danger-bg); color: var(--danger-text); border-color: var(--danger-border); }
.flash-success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }

/* ---------------------------------------------------------------------
   Misc
--------------------------------------------------------------------- */

.muted { color: var(--text-muted); }
.subtle-note { color: var(--text-muted); font-weight: 400; font-size: 0.85rem; } /* a de-emphasized aside next to a bold heading */
.section-empty { color: var(--text-muted); font-style: italic; padding: 0.4rem 0; font-size: 0.87rem; }

.breadcrumb { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--brand-600); }

.chip-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.pill-tabs { display: flex; gap: 0.3rem; margin-bottom: 1.2rem; flex-wrap: wrap; background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 0.25rem; width: fit-content; }
.pill-tabs a { padding: 0.35rem 0.85rem; border-radius: var(--radius-pill); color: var(--text-secondary); font-size: 0.82rem; font-weight: 600; }
.pill-tabs a:hover { text-decoration: none; color: var(--text); }
.pill-tabs a.active { background: var(--surface); color: var(--brand-600); box-shadow: var(--shadow-sm); }

.search-combo { position: relative; }
.search-results {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 10; margin-top: 0.25rem;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md);
  border-radius: var(--radius); max-height: 220px; overflow-y: auto;
}
.search-result-item { padding: 0.5rem 0.7rem; cursor: pointer; font-size: 0.85rem; }
.search-result-item:hover { background: var(--brand-50); }

.page-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.page-header h1 { margin-bottom: 0.2rem; }
.page-subtitle { color: var(--text-muted); font-size: 0.85rem; margin: -0.6rem 0 1.1rem; }

.detail-block { border-bottom: 1px solid var(--border); padding: 1rem 0; }
.detail-block:last-child { border-bottom: none; }
.detail-block-header { display: flex; justify-content: space-between; align-items: center; }

.mailing-address {
  font-style: normal;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92rem;
  line-height: 1.7;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 1rem;
  display: inline-block;
}
.mailing-address span { display: block; }
