:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface2: #f8fafc; --line: #e3e8ef;
  --text: #0f172a; --text2: #475569; --muted: #64748b;
  --brand: #15803d; --brand-ink: #ffffff; --brand-soft: #dcfce7;
  --bar: #16a34a; --bar-hot: #15803d; --grid: #e8edf3;
  --good: #15803d; --good-bg: #dcfce7; --warn: #b45309; --warn-bg: #fef3c7;
  --bad: #b91c1c; --bad-bg: #fee2e2; --info-bg: #dbeafe; --info: #1d4ed8;
  --side: #0f172a; --side-text: #cbd5e1;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --surface: #111a2e; --surface2: #0f172a; --line: #22304a;
    --text: #e5ecf6; --text2: #b6c2d6; --muted: #8394ad;
    --brand: #22c55e; --brand-ink: #052e12; --brand-soft: #052e16;
    --bar: #22c55e; --bar-hot: #4ade80; --grid: #1c2840;
    --good: #86efac; --good-bg: #052e16; --warn: #fcd34d; --warn-bg: #3b2506;
    --bad: #fca5a5; --bad-bg: #3b1219; --info-bg: #172554; --info: #93c5fd;
    --side: #070b16; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body, #root { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; }
h1 { font-size: 22px; margin: 0; display: flex; align-items: center; gap: 10px; }
h3 { margin: 0 0 12px; font-size: 15px; }
a { color: var(--brand); text-decoration: none; }
.muted { color: var(--muted); }
.sm { font-size: 12px; }
.mono, code { font-family: ui-monospace, Consolas, monospace; }
code { background: var(--surface2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; }
code.big { font-size: 15px; letter-spacing: .08em; font-weight: 700; }
.spacer { flex: 1; }
.warn { color: var(--warn); }

.btn { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--surface2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.file { cursor: pointer; }
.danger-text { color: var(--bad) !important; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }

input, select, textarea { font: inherit; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text2); font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
label.check input { width: auto; }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }

.error { background: var(--bad-bg); color: var(--bad); padding: 10px 12px; border-radius: 8px; }
.toast { background: var(--info-bg); color: var(--info); padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.logo { font-size: 18px; font-weight: 600; }
.logo b { color: var(--brand); }

.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: 20px 14px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; }
.side .logo { color: #fff; padding: 0 10px; }
.side .logo b { color: #4ade80; }
.org { padding: 0 10px 14px; font-size: 12px; color: #8394ad; border-bottom: 1px solid #1e293b; margin-bottom: 8px; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: var(--side-text); padding: 9px 10px; border-radius: 8px; }
.side nav a:hover { background: #1e293b; }
.side nav a.active { background: #14532d; color: #fff; }
.me { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px; border-top: 1px solid #1e293b; }
.me span { display: block; font-size: 11px; color: #8394ad; text-transform: capitalize; }
.me .btn { color: var(--side-text); border-color: #334155; }

.content { padding: 24px 28px; max-width: 1280px; width: 100%; display: flex; flex-direction: column; gap: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 16px; overflow-x: auto; }
.panel.success { border-color: var(--brand); background: var(--brand-soft); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; align-items: end; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .row { justify-content: flex-end; }
.rule-row { display: grid; grid-template-columns: 100px 180px 100px auto; gap: 10px; align-items: end; }
.toolbar { display: flex; gap: 12px; margin-bottom: 14px; align-items: center; flex-wrap: wrap; }
.toolbar input { max-width: 360px; }
.toolbar select { width: auto; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.tile span { color: var(--muted); font-size: 12px; }
.tile b { font-size: 22px; font-variant-numeric: tabular-nums; }
.tile b.sm { font-size: 16px; }
.tile em { font-style: normal; color: var(--muted); font-size: 12px; }
.tile.hero b { font-size: 28px; }
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }
.grid-2 > .panel { margin-bottom: 16px; }

.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--surface2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 28px !important; }
.pager { justify-content: center; margin-top: 12px; }

.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; margin-left: 6px; text-transform: capitalize; }
.tag.active, .tag.verified { background: var(--good-bg); color: var(--good); }
.tag.suspended, .tag.rejected, .tag.revoked { background: var(--bad-bg); color: var(--bad); }
.tag.pending { background: var(--warn-bg); color: var(--warn); }
.tag.info { background: var(--info-bg); color: var(--info); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot.on { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.2); }
.dot.off { background: #f59e0b; }

.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--good); font-weight: 600; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.chart-wrap { position: relative; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .bar { fill: var(--bar); }
.chart .bar.hot { fill: var(--bar-hot); }
.tip { position: absolute; top: 0; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.12); pointer-events: none; white-space: nowrap; }
.table-view { margin-top: 10px; font-size: 12px; }
.table-view summary { cursor: pointer; color: var(--muted); }

.reg-list, .feed, .alerts { list-style: none; margin: 0; padding: 0; }
.reg-list li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.feed li { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.mini-stats { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.mini-stats a { color: var(--text2); }
.mini-stats b { color: var(--text); margin-right: 4px; }
.alerts li { display: flex; gap: 12px; padding: 12px 6px; border-bottom: 1px solid var(--line); align-items: center; }
.alerts li.unread { background: var(--warn-bg); }
.alerts .icon { font-size: 20px; }
.codes { display: flex; gap: 12px; flex-wrap: wrap; margin: 10px 0; }
.codes div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; display: flex; flex-direction: column; gap: 4px; }
.codes code { font-size: 20px; font-weight: 700; letter-spacing: .1em; border: 0; padding: 0; background: none; }
.qr-prev { display: flex; align-items: end; gap: 10px; margin: 8px 0; }
.qr-prev img { width: 120px; height: 120px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 8px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: column; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .me { flex-direction: row; align-items: center; justify-content: space-between; }
  .content { padding: 16px; }
  .grid-2, .rule-row { grid-template-columns: 1fr; }
}

/* PHP panel additions */
form.inline { display: inline; margin: 0; }
.toast.ok { background: var(--good-bg); color: var(--good); }
.toast.error { background: var(--bad-bg); color: var(--bad); }
.toast.warn { background: var(--warn-bg); color: var(--warn); }
.side nav a[target] { color: #86efac; }
.me form { margin: 0; }
textarea { resize: vertical; }
[hidden] { display: none !important; }
.chart .hit { fill: transparent; }
