/* Niro Admin - one stylesheet, light + dark via tokens. */
:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f1f0ec;
  --border: #e3e2dc;
  --text: #161615;
  --text-2: #52514e;
  --muted: #7a7973;
  --brand: #1bae70;
  --brand-ink: #0d7a4d;
  --accent: #2a78d6;
  --chart: #2a78d6;
  --chart-hover: #1c5cab;
  --grid: #ecebe6;
  --good: #0d7a4d;  --good-bg: #e3f5ec;
  --warning: #8a5a00; --warning-bg: #fdf1d6;
  --serious: #a8461d; --serious-bg: #fde6dc;
  --critical: #b42828; --critical-bg: #fbe3e3;
  --info: #1c5cab; --info-bg: #e2edfb;
  --violet: #4a3aa7; --violet-bg: #ebe8fa;
  --neutral-bg: #efeee9;
  --shadow: 0 1px 2px rgba(20, 20, 18, .05);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2e2e2b;
    --text: #f4f4f1;
    --text-2: #c3c2b7;
    --muted: #8d8c85;
    --brand: #22c07c;
    --brand-ink: #4fd699;
    --accent: #5598e7;
    --chart: #3987e5;
    --chart-hover: #6da7ec;
    --grid: #2a2a27;
    --good: #4fd699;  --good-bg: #173326;
    --warning: #f0b84a; --warning-bg: #3a2e12;
    --serious: #f08a5e; --serious-bg: #3b2218;
    --critical: #f07c7c; --critical-bg: #3d1c1c;
    --info: #86b6ef; --info-bg: #182a40;
    --violet: #a59cf0; --violet-bg: #26223f;
    --neutral-bg: #2a2a27;
    --shadow: none;
  }
}
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 2px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.t-good { color: var(--good); } .t-warning { color: var(--warning); } .t-critical { color: var(--critical); }
.divider { height: 1px; background: var(--border); margin: 12px 0; }
.empty { padding: 8px 0; }

/* Shell */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 228px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px 10px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--text); padding: 4px 8px 16px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 15px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text-2);
  font-weight: 500; width: 100%; background: none; border: 0; font: inherit; cursor: pointer; text-align: left;
}
.nav-item:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.nav-ico { width: 18px; text-align: center; color: var(--muted); }
.nav-item.active .nav-ico { color: var(--brand); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 10px; }
.role-pill { margin-left: auto; font-size: 11px; color: var(--muted); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 28px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 5;
}
.search { flex: 1; max-width: 520px; }
.search input { width: 100%; }
.menu-btn { display: none; background: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; color: var(--text); font-size: 16px; }
.content { padding: 24px 28px 48px; max-width: 1400px; width: 100%; }

/* Forms */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-height: 36px; max-width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 500; color: var(--text-2); }
label.inline, label.radio { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; }
label.radio input, label.inline input[type=checkbox] { min-height: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inline-form { display: inline-block; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600;
  padding: 7px 14px; min-height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); }
.btn-good { background: var(--good-bg); color: var(--good); border-color: transparent; }
.btn-danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn-danger:hover { background: var(--critical); filter: brightness(.92); }
.btn-ghost { background: transparent; }
.btn-danger-text { color: var(--critical); }
.btn-sm { padding: 4px 10px; min-height: 30px; font-size: 12px; }
.btn-block { width: 100%; }

/* Page */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.back-link { display: inline-block; margin-bottom: 10px; color: var(--muted); font-size: 13px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card.narrow { max-width: 460px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head .muted, .card-head a { font-size: 12px; }
.table-card { padding: 0; overflow-x: auto; }
.table-card > .card-head { padding: 14px 18px 0; }
.table-card > .empty { padding: 8px 18px 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }
section.grid-2, section.grid-3 { margin-bottom: 16px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  color: var(--text); box-shadow: var(--shadow); display: block;
}
a.kpi:hover { text-decoration: none; border-color: var(--muted); }
.kpi-label { font-size: 12px; color: var(--text-2); font-weight: 500; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 2px 0; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.kpis-sm .kpi-value { font-size: 20px; }
.delta.up { color: var(--good); } .delta.down { color: var(--critical); }
.alerts-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.alert-chip {
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px;
  font-size: 13px; color: var(--text-2);
}
.alert-chip strong { color: var(--text); }
.alert-chip.tone-warning { background: var(--warning-bg); border-color: transparent; color: var(--warning); }
.alert-chip.tone-warning strong { color: var(--warning); }
.alert-chip.tone-critical { background: var(--critical-bg); border-color: transparent; color: var(--critical); }
.alert-chip.tone-critical strong { color: var(--critical); }
a.alert-chip:hover { text-decoration: none; filter: brightness(.97); }

/* Badges */
.badge {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  line-height: 1.6; white-space: nowrap; vertical-align: middle;
}
.badge-good { background: var(--good-bg); color: var(--good); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-serious { background: var(--serious-bg); color: var(--serious); }
.badge-critical { background: var(--critical-bg); color: var(--critical); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-violet { background: var(--violet-bg); color: var(--violet); }
.badge-neutral { background: var(--neutral-bg); color: var(--text-2); }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* Flash */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }
.flash-good { background: var(--good-bg); color: var(--good); }
.flash-critical { background: var(--critical-bg); color: var(--critical); }
.flash-warning { background: var(--warning-bg); color: var(--warning); }
.flash-info { background: var(--info-bg); color: var(--info); }
.card .flash { margin: 12px 0 0; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase;
  letter-spacing: .04em; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table.compact td { padding: 8px 0; }
.table.compact td + td { padding-left: 10px; }
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--surface-2); }
.table th.right, .table td.right { text-align: right; }
.meter-cell { min-width: 130px; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.filters input[type=search] { min-width: 240px; flex: 1; max-width: 340px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg-wide { margin-bottom: 14px; }
.seg-item { padding: 5px 12px; border-radius: 7px; color: var(--text-2); font-weight: 500; font-size: 13px; }
.seg-item:hover { text-decoration: none; color: var(--text); }
.seg-item.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 12px 0; }

/* Meter */
.meter-text { font-size: 13px; font-variant-numeric: tabular-nums; }
.meter-track { height: 4px; background: var(--grid); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.meter-fill { height: 100%; background: var(--chart); border-radius: 2px; }
.meter-warning .meter-fill { background: #eda100; }
.meter-critical .meter-fill { background: var(--critical); }

/* Charts */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .mark { fill: var(--chart); }
.chart .hit { fill: transparent; }
.chart .bar:hover .mark, .chart .bar:focus .mark { fill: var(--chart-hover); }
.tooltip {
  position: fixed; pointer-events: none; background: var(--text); color: var(--bg); padding: 6px 10px;
  border-radius: 6px; font-size: 12px; font-weight: 500; opacity: 0; transition: opacity .08s; z-index: 50; max-width: 280px;
}
.tooltip.show { opacity: 1; }
.hbar-row { display: grid; grid-template-columns: 70px 1fr 40px; align-items: center; gap: 10px; padding: 6px 0; color: var(--text); }
.hbar-row:hover { text-decoration: none; }
.hbar-label { font-size: 13px; }
.hbar-track { height: 10px; background: var(--grid); border-radius: 0 4px 4px 0; overflow: hidden; }
.hbar-fill { display: block; height: 100%; background: var(--chart); border-radius: 0 4px 4px 0; min-width: 0; }
.hbar-row:hover .hbar-fill { background: var(--chart-hover); }
.hbar-val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.kv { display: flex; flex-direction: column; gap: 2px; }
.kv > span { font-size: 12px; color: var(--muted); }
.card > .kv { flex-direction: row; justify-content: space-between; padding: 4px 0; }
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px 18px; }
.kv-wide { grid-column: 1 / -1; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.timeline li:last-child { border-bottom: 0; }
.timeline li.done { opacity: .6; }
.tl-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Account */
.account-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.account-id { display: flex; gap: 14px; align-items: flex-start; min-width: 0; }
.avatar {
  width: 48px; height: 48px; border-radius: 12px; background: var(--brand); color: #fff; display: grid;
  place-items: center; font-weight: 700; font-size: 20px; flex-shrink: 0;
}
.icon-link {
  display: inline-grid; place-items: center; min-width: 26px; height: 24px; padding: 0 5px; border-radius: 6px;
  background: var(--surface-2); color: var(--text-2); font-size: 11px; font-weight: 700; margin-left: 4px;
}
.icon-link:hover { text-decoration: none; color: var(--text); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 9px 14px; color: var(--text-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--text); border-bottom-color: var(--brand); font-weight: 600; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
details.action { border-top: 1px solid var(--border); padding: 10px 0; }
details.action:first-of-type { border-top: 0; padding-top: 0; }
details.action > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; }
details.action > summary::after { content: '+'; color: var(--muted); }
details.action[open] > summary::after { content: '−'; }
details.action[open] > summary { margin-bottom: 10px; }
details.action-inline { display: inline-block; border: 0; padding: 0; margin-right: 6px; vertical-align: middle; }
details.action-inline > summary { font-size: 12px; color: var(--accent); }
details.action-inline > summary::after { content: ''; }
details.action-inline[open] .stack { position: absolute; right: 40px; background: var(--surface); border: 1px solid var(--border); padding: 10px; border-radius: 8px; z-index: 3; width: 240px; }
.action-line { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 4px; }
.chips-input { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-radio input { position: absolute; opacity: 0; }
.chip-radio span { display: inline-block; padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px; font-size: 13px; color: var(--text); cursor: pointer; }
.chip-radio input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip-radio input:focus-visible + span { outline: 2px solid var(--accent); }
.stores-field[hidden] { display: none; }

/* Dialog */
.dialog { border: 1px solid var(--border); border-radius: 12px; padding: 20px; max-width: 480px; width: calc(100% - 32px); background: var(--surface); color: var(--text); }
.dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Auth */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.brand-lg { padding: 0 0 4px; font-size: 18px; }
.empty-state { text-align: center; padding: 60px 16px; }

/* Responsive */
@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform .15s; box-shadow: 0 0 40px rgba(0, 0, 0, .2); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-block; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px 16px 40px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value { font-size: 21px; }
  .filters input[type=search] { min-width: 0; max-width: none; width: 100%; }
  .filters select { flex: 1 1 140px; }
  .kv-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .account-quick, .account-quick form, .account-quick .btn { width: 100%; }
}
@media (forced-colors: active) {
  .chart .mark, .hbar-fill, .meter-fill { fill: CanvasText; background: CanvasText; }
}
