:root {
  --ink: #0e1418;
  --panel: #151d23;
  --panel-2: #1a242b;
  --line: #26343d;
  --line-soft: #1f2a31;
  --text: #e3ebef;
  --muted: #8b9ba6;
  --dim: #64747f;
  --amber: #e2a75a;
  --amber-soft: rgba(226, 167, 90, .14);
  --green: #63b99b;
  --red: #d97b6c;
  --blue: #79a8c9;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "Noto Sans SC", system-ui, -apple-system, "PingFang SC", sans-serif;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font: 14px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4, p { margin: 0; }
[hidden] { display: none !important; }

/* ---------- login ---------- */
.login-screen {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(226, 167, 90, .09), transparent 60%),
    radial-gradient(700px 400px at 0% 110%, rgba(99, 185, 155, .06), transparent 60%),
    var(--ink);
}
.login-panel {
  width: min(400px, 100%);
  padding: 34px 30px 26px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
}
.login-mark {
  font-size: 12px;
  letter-spacing: .22em;
  color: var(--amber);
}
.login-mark span { color: var(--dim); margin-left: 8px; }
.login-panel h1 {
  margin-top: 18px;
  font-size: 27px;
  font-weight: 500;
  letter-spacing: .02em;
}
.login-sub { color: var(--muted); margin: 8px 0 26px; font-size: 13px; }
.login-panel label {
  display: block;
  margin: 14px 0 6px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .06em;
}
.login-panel input {
  width: 100%;
  padding: 11px 12px;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}
.login-panel input:focus { border-color: var(--amber); }
.login-panel .btn { margin-top: 22px; }
.login-hint { margin-top: 18px; font-size: 12px; color: var(--dim); }
.login-hint b { color: var(--muted); font-weight: 500; }
.to-shop { display: inline-block; margin-top: 20px; font-size: 12px; color: var(--dim); }
.to-shop:hover { color: var(--amber); }

/* ---------- shell ---------- */
#admin-app { display: flex; min-height: 100%; }

.rail {
  width: 214px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 16px 18px;
  border-right: 1px solid var(--line-soft);
  background: #11181d;
}
.rail-logo { font-size: 19px; font-weight: 500; letter-spacing: .04em; padding: 2px 8px 0; }
.rail-logo small {
  display: block;
  font-size: 9px;
  letter-spacing: .3em;
  color: var(--amber);
  margin-top: 3px;
  font-weight: 400;
}
#admin-nav { display: flex; flex-direction: column; gap: 2px; }
#admin-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13.5px;
}
#admin-nav a span { width: 16px; text-align: center; color: var(--dim); font-size: 12px; }
#admin-nav a:hover { background: var(--panel); color: var(--text); }
#admin-nav a.on { background: var(--amber-soft); color: var(--amber); }
#admin-nav a.on span { color: var(--amber); }
.rail-foot { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.who { font-size: 12px; color: var(--muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who b { display: block; color: var(--text); font-weight: 500; }
.link { background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 12px; padding: 4px; }
.link:hover { color: var(--red); }

.stage { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.stage-head {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 62px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line-soft);
}
.stage-head h2 { font-size: 16px; font-weight: 500; letter-spacing: .03em; }
.spacer { flex: 1; }
.clock { font: 12px var(--mono); color: var(--dim); }
.view { padding: 24px 28px 60px; }

/* ---------- primitives ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
.btn:hover { border-color: var(--dim); }
.btn.primary { background: var(--amber); border-color: var(--amber); color: #1b1308; font-weight: 500; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { color: var(--muted); }
.btn.danger { color: var(--red); border-color: rgba(217, 123, 108, .35); }
.btn.small { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

input.field, select.field, textarea.field {
  width: 100%;
  padding: 9px 11px;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: none;
  font-size: 13px;
}
input.field:focus, select.field:focus, textarea.field:focus { border-color: var(--amber); }
textarea.field { resize: vertical; min-height: 66px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}
.card-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 15px 18px 11px;
}
.card-head h3 { font-size: 13.5px; font-weight: 500; letter-spacing: .02em; }
.card-head .sub { font-size: 11.5px; color: var(--dim); }
.card-body { padding: 0 18px 16px; }

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.kpi {
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}
.kpi .k { font-size: 11.5px; color: var(--muted); letter-spacing: .06em; }
.kpi .v { font: 500 23px var(--mono); margin-top: 8px; font-variant-numeric: tabular-nums; }
.kpi .n { font-size: 11.5px; color: var(--dim); margin-top: 5px; }
.kpi .v.warn { color: var(--amber); }
.kpi .v.bad { color: var(--red); }
.kpi .v.good { color: var(--green); }

.grid-2 { display: grid; grid-template-columns: 1.5fr 1fr; gap: 14px; margin-bottom: 14px; }
.grid-2.even { grid-template-columns: 1fr 1fr; }
.stack { display: flex; flex-direction: column; gap: 14px; }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: .08em;
  color: var(--dim);
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td {
  padding: 10px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
  vertical-align: top;
}
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions { text-align: right; white-space: nowrap; }
tbody tr:hover { background: rgba(255, 255, 255, .015); }
.table-wrap { overflow-x: auto; }
.nowrap { white-space: nowrap; }
.invoice-table td.note { white-space: normal; min-width: 96px; }
.tiny { font-size: 11.5px; color: var(--dim); }
.mono { font-family: var(--mono); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.badge.ok { color: var(--green); border-color: rgba(99, 185, 155, .3); background: rgba(99, 185, 155, .08); }
.badge.warn { color: var(--amber); border-color: rgba(226, 167, 90, .35); background: var(--amber-soft); }
.badge.bad { color: var(--red); border-color: rgba(217, 123, 108, .3); background: rgba(217, 123, 108, .08); }
.badge.mute { color: var(--dim); }

.positive { color: var(--green); }
.negative { color: var(--red); }

.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--dim);
  font-size: 13px;
}

/* bar chart */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 132px; padding: 8px 2px 0; overflow-x: auto; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 24px; }
.bar-track { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.bar-fill {
  width: 100%;
  min-height: 2px;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(180deg, var(--amber), rgba(226, 167, 90, .35));
}
.bar-label { font: 9.5px var(--mono); color: var(--dim); white-space: nowrap; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filters .f { display: flex; flex-direction: column; gap: 5px; }
.filters label { font-size: 11px; color: var(--dim); letter-spacing: .05em; }
.filters .field { min-width: 130px; }

.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.form-row label { font-size: 11.5px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.hint { font-size: 11.5px; color: var(--dim); margin-top: 6px; line-height: 1.5; }

.section-title { font-size: 12px; letter-spacing: .1em; color: var(--dim); margin: 22px 0 10px; }

/* modal */
.layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 8, 10, .68);
  backdrop-filter: blur(3px);
}
.modal {
  width: min(520px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}
.modal.wide { width: min(880px, 100%); }
.modal-head { display: flex; align-items: center; padding: 17px 20px 0; }
.modal-head h3 { font-size: 15px; font-weight: 500; }
.modal-body { padding: 16px 20px 4px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px 20px; }
.x { margin-left: auto; background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 18px; line-height: 1; }
.x:hover { color: var(--text); }

/* toast */
#admin-toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 60;
  pointer-events: none;
}
#admin-toast .t {
  margin-top: 8px;
  padding: 10px 16px;
  border-radius: 8px;
  background: #223039;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
  animation: rise .18s ease-out;
}
#admin-toast .t.bad { border-color: rgba(217, 123, 108, .45); color: #f2b3a7; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-2.even { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  #admin-app { flex-direction: column; }
  .rail {
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
    overflow-x: auto;
  }
  .rail-logo { padding: 0; font-size: 15px; flex: none; }
  .rail-logo small { display: none; }
  #admin-nav { flex-direction: row; gap: 4px; flex: 1; }
  #admin-nav a { white-space: nowrap; padding: 6px 9px; font-size: 12.5px; }
  #admin-nav a span { display: none; }
  .rail-foot { margin: 0; padding: 0; flex: none; }
  .who { display: none; }
  .stage-head { height: 52px; padding: 0 16px; }
  .view { padding: 16px 14px 48px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 9px; }
  .kpi { padding: 12px 13px; }
  .kpi .v { font-size: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .clock { display: none; }
}

/* ---------- plans & subscriptions ---------- */
.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}
.plan-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.plan-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.plan-head b { font-size: 15px; font-weight: 500; }
.plan-price { font-family: var(--mono); font-size: 26px; line-height: 1.2; letter-spacing: -.02em; }
.plan-price span { margin-left: 5px; font-family: var(--sans); font-size: 12px; color: var(--dim); }
.plan-feats {
  display: flex; flex-direction: column; gap: 5px;
  margin: 2px 0 4px; padding: 0; list-style: none;
  font-size: 12.5px; color: var(--muted);
}
.plan-feats li::before { content: "·"; color: var(--amber); margin-right: 6px; }
.plan-limits { padding-top: 6px; border-top: 1px solid var(--line-soft); font-size: 12px; color: var(--muted); }
.plan-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: auto; padding-top: 4px;
}

.sub-card {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  margin-bottom: 16px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel-2); flex-wrap: wrap;
}
.sub-main { display: flex; flex-direction: column; gap: 5px; }
.sub-title { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.sub-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sub-actions select { width: auto; min-width: 190px; }
.amount-line { padding: 5px 0; font-family: var(--mono); font-size: 20px; color: var(--amber); }

/* ---------- theme toggle ---------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.theme-toggle:hover { color: var(--text); border-color: var(--dim); }
.theme-toggle:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.theme-toggle .ti { font-size: 13px; line-height: 1; }

/* ---------- light theme ---------- */
html[data-theme="light"] {
  color-scheme: light;
  --ink: #f2efe8;
  --panel: #fbfaf6;
  --panel-2: #ffffff;
  --line: #d9d2c5;
  --line-soft: #e7e1d5;
  --text: #1f2a2f;
  --muted: #55646c;
  --dim: #6c797f;
  --amber: #9a651d;
  --amber-soft: rgba(154, 101, 29, .12);
  --green: #2f7a5e;
  --red: #a94a3b;
  --blue: #3b6d8c;
}

html[data-theme="light"] body { background: var(--ink); }

html[data-theme="light"] .login-screen {
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(185, 124, 42, .11), transparent 60%),
    radial-gradient(700px 400px at 0% 110%, rgba(47, 122, 94, .07), transparent 60%),
    var(--ink);
}

html[data-theme="light"] .rail { background: #eae5d9; }
html[data-theme="light"] .login-panel { box-shadow: 0 24px 60px rgba(61, 52, 35, .12); }
html[data-theme="light"] .modal { box-shadow: 0 24px 60px rgba(61, 52, 35, .18); }

html[data-theme="light"] .login-panel input,
html[data-theme="light"] input.field,
html[data-theme="light"] select.field,
html[data-theme="light"] textarea.field { background: #fff; }

html[data-theme="light"] .btn.primary { color: #fff; }
html[data-theme="light"] .btn.primary:hover { filter: brightness(1.05); }
html[data-theme="light"] .layer { background: rgba(26, 30, 26, .38); }
html[data-theme="light"] tbody tr:hover { background: rgba(30, 40, 30, .035); }
html[data-theme="light"] .bar-fill {
  background: linear-gradient(180deg, var(--amber), rgba(154, 101, 29, .32));
}

html[data-theme="light"] #admin-toast .t {
  background: #fff;
  box-shadow: 0 10px 30px rgba(40, 35, 25, .16);
}
html[data-theme="light"] #admin-toast .t.bad { color: #8d3527; }
html[data-theme="light"] .badge.ok { background: rgba(47, 122, 94, .09); }
html[data-theme="light"] .badge.bad { background: rgba(169, 74, 59, .09); }

@media (max-width: 520px) {
  .theme-toggle .tl { display: none; }
  .theme-toggle { padding: 5px 8px; }
}

html[data-theme="light"] .btn.danger { border-color: rgba(169, 74, 59, .32); }
html[data-theme="light"] .badge.ok { border-color: rgba(47, 122, 94, .28); }
html[data-theme="light"] .badge.warn { border-color: rgba(154, 101, 29, .3); }
html[data-theme="light"] .badge.bad { border-color: rgba(169, 74, 59, .28); }
html[data-theme="light"] #admin-toast .t.bad { border-color: rgba(169, 74, 59, .4); }
