@import url('https://fonts.googleapis.com/css2?family=Archivo:wght@400;500;600;700&display=swap');

/* ---------- theme ---------- */

:root,
[data-theme='dark'] {
  --bg: #0d1a24;
  --bg-2: #10222f;
  --surface: #16232e;
  --surface-2: #1b2c3a;
  --sidebar: #0b1620;
  --ink: #e6edf3;
  --ink-soft: #c3d2de;
  --muted: #85a0b3;
  --rule: #23394b;
  --rule-soft: #1a2c3a;

  --accent: #2f7fd4;
  --orange: #e07b28;
  --green: #22a06b;
  --purple: #8b46c9;
  --teal: #1f8fa8;
  --red: #d9534f;
  --amber: #d9a41f;

  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);

  --bar-1: #8d99a3;
  --bar-2: #c9a93f;
  --bar-3: #4e9aa6;
  --bar-4: #4e8f5c;
  --bar-5: #9a6a93;
  --bar-6: #b4655c;
  --bar-7: #4c6392;

  --rail: 226px;
  --r: 6px;
}

[data-theme='light'] {
  --bg: #eef1f4;
  --bg-2: #e6eaee;
  --surface: #ffffff;
  --surface-2: #f4f6f8;
  --sidebar: #ffffff;
  --ink: #16202a;
  --ink-soft: #2c3a47;
  --muted: #5f7183;
  --rule: #d3dae1;
  --rule-soft: #e6eaee;

  --accent: #1f5fa8;
  --orange: #c26414;
  --green: #197f53;
  --purple: #6f34a3;
  --teal: #15707f;
  --red: #b23b37;
  --amber: #9a7314;

  --shadow: 0 1px 2px rgba(20, 30, 40, 0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Archivo', 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.8em; max-width: 70ch; }
a { color: var(--accent); }
[data-theme='dark'] a { color: #6fb3f2; }

button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- signal bar motif ---------- */

.bars { display: flex; height: 5px; overflow: hidden; }
.bars span { flex: 1; }
.bars span:nth-child(1) { background: var(--bar-1); }
.bars span:nth-child(2) { background: var(--bar-2); }
.bars span:nth-child(3) { background: var(--bar-3); }
.bars span:nth-child(4) { background: var(--bar-4); }
.bars span:nth-child(5) { background: var(--bar-5); }
.bars span:nth-child(6) { background: var(--bar-6); }
.bars span:nth-child(7) { background: var(--bar-7); }

/* ---------- login ---------- */

.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.login {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.login .inner { padding: 28px 26px 26px; }
.login h1 { margin-bottom: 4px; }
.login .sub { color: var(--muted); margin-bottom: 22px; font-size: 0.93rem; }
.login .foot {
  border-top: 1px solid var(--rule);
  padding: 14px 26px;
  font-size: 0.86rem;
  color: var(--muted);
  background: var(--surface-2);
}

/* ---------- forms ---------- */

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--muted); margin-bottom: 5px; }
input[type='text'], input[type='email'], input[type='password'],
input[type='number'], select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg-2);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  color: var(--ink);
}
[data-theme='light'] input, [data-theme='light'] select, [data-theme='light'] textarea { background: #fff; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.7; }
textarea { min-height: 110px; resize: vertical; }
.hint { font-size: 0.82rem; color: var(--muted); margin-top: 5px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: var(--r);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.12); }
.btn[disabled] { opacity: 0.5; cursor: default; }
.btn.wide { width: 100%; justify-content: center; }
.btn.quiet { background: var(--surface-2); color: var(--ink); border-color: var(--rule); }
.btn.quiet:hover { background: var(--rule-soft); }
.btn.danger { background: transparent; color: var(--red); border-color: var(--rule); }
.btn.danger:hover { background: var(--red); color: #fff; border-color: var(--red); }
.btn.small { padding: 5px 10px; font-size: 0.85rem; }

.notice {
  padding: 10px 12px;
  border-radius: var(--r);
  border: 1px solid var(--rule);
  background: var(--surface-2);
  margin-bottom: 14px;
  font-size: 0.9rem;
}
.notice.bad { border-color: var(--red); color: var(--red); }
.notice.good { border-color: var(--green); color: var(--green); }

/* ---------- shell ---------- */

.shell { min-height: 100%; display: flex; flex-direction: column; }

.top {
  background: var(--sidebar);
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 0;
  z-index: 20;
}
.top-inner { display: flex; align-items: center; gap: 14px; padding: 12px 20px; }
.brand { font-weight: 700; letter-spacing: -0.02em; margin-right: auto; }
.brand small { display: block; font-weight: 400; font-size: 0.76rem; color: var(--muted); letter-spacing: 0; }

.balance {
  text-align: right;
  line-height: 1.2;
  padding: 4px 14px;
  border-radius: var(--r);
  background: var(--surface-2);
  border: 1px solid var(--rule);
}
.balance .n { font-size: 1.15rem; font-weight: 700; color: var(--amber); }
.balance .l { font-size: 0.74rem; color: var(--muted); }

.who { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; color: var(--muted); }

.theme-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.theme-btn:hover { background: var(--rule-soft); }

.body { display: flex; flex: 1; align-items: stretch; }

.rail {
  width: var(--rail);
  flex: 0 0 var(--rail);
  border-right: 1px solid var(--rule);
  background: var(--sidebar);
  padding: 14px 10px;
}
.rail a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  margin-bottom: 2px;
  border-radius: var(--r);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.93rem;
}
.rail a:hover { background: var(--surface-2); color: var(--ink); }
.rail a.on { background: var(--accent); color: #fff; font-weight: 600; }

.rail .group {
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: 16px 12px 7px;
}
.rail-zone:first-child .group:first-child { padding-top: 4px; }

/* The admin zone is set apart deliberately: a tinted panel with its own accent
   colour and a label spelling out who can see it, so it can never be mistaken
   for another reseller-facing section while scanning the sidebar. */
.rail-zone-admin {
  margin-top: 14px;
  padding: 10px 6px 12px;
  border-radius: var(--r);
  background: var(--surface-2);
  border: 1px solid var(--rule);
}
.rail-zone-admin a { padding-left: 16px; }
.rail-zone-admin a.on { background: var(--purple); }
.zone-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--purple);
  padding: 2px 12px 10px;
}
.zone-label .dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--purple);
  flex-shrink: 0;
}

.view { flex: 1; padding: 22px 24px 60px; min-width: 0; }
.view header { margin-bottom: 18px; }
.view header p { color: var(--muted); margin: 4px 0 0; }

/* ---------- panels ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.panel > h2 { margin-bottom: 10px; }
.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.toolbar .field { margin: 0; }
.toolbar .grow { flex: 1; min-width: 180px; }

/* ---------- dashboard tiles ---------- */

.dash { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-bottom: 16px; }
.dash.wide { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 15px;
  color: #fff;
  font-weight: 600;
}
.card-head .count {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 0 9px;
  font-size: 0.82rem;
}
.card-head.orange { background: var(--orange); }
.card-head.green { background: var(--green); }
.card-head.purple { background: var(--purple); }
.card-head.teal { background: var(--teal); }
.card-head.red { background: var(--red); }
.card-body { padding: 15px; flex: 1; }
.card-body p:last-child { margin-bottom: 0; }
.card-foot { padding: 11px 15px; border-top: 1px solid var(--rule-soft); background: var(--surface-2); }

.stat-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--rule-soft);
}
.stat-row:last-child { border-bottom: 0; }
.stat-row .k { color: var(--muted); font-size: 0.9rem; }
.stat-row .v { font-weight: 600; }

.meter { height: 6px; border-radius: 3px; background: var(--rule-soft); overflow: hidden; margin-top: 5px; }
.meter span { display: block; height: 100%; }

.expiry {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  flex-wrap: wrap;
  padding: 9px 0;
  border-bottom: 1px solid var(--rule-soft);
}
.expiry:last-child { border-bottom: 0; }
.expiry-who { min-width: 40%; }
.expiry-actions { flex-shrink: 0; }
.expiry .u { font-weight: 600; }
.expiry .t { font-size: 0.84rem; color: var(--muted); }
.expiry .urgent { color: var(--red); font-weight: 600; }

/* ---------- tables ---------- */

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th {
  text-align: left; font-weight: 600; font-size: 0.8rem; color: var(--muted);
  padding: 0 10px 8px; border-bottom: 1px solid var(--rule);
}
td { padding: 10px; border-bottom: 1px solid var(--rule-soft); vertical-align: top; }
tr:hover td { background: var(--surface-2); }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 0.85em; }
.wrap-scroll { overflow-x: auto; }

.tag {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-size: 0.77rem;
  color: var(--muted);
}
.tag.live { color: #4ecb8f; border-color: #2c6a51; }
.tag.off { color: #f08a86; border-color: #7a3835; }
.tag.soon { color: #e8bd4d; border-color: #7a6421; }
[data-theme='light'] .tag.live { color: var(--green); border-color: #a9d4c0; }
[data-theme='light'] .tag.off { color: var(--red); border-color: #e0b3b1; }
[data-theme='light'] .tag.soon { color: var(--amber); border-color: #ddc890; }

.badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  margin-left: auto;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 0.74rem;
  font-weight: 600;
  text-align: center;
  line-height: 18px;
}

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.meta { color: var(--muted); font-size: 0.86rem; }
.empty {
  padding: 26px 18px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--rule);
  border-radius: var(--r);
}
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; }
.pager { display: flex; align-items: center; gap: 12px; margin-top: 14px; }

/* ---------- credits ---------- */

.packs { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.pack { border: 1px solid var(--rule); border-radius: var(--r); padding: 14px; background: var(--surface-2); }
.pack .c { font-size: 1.4rem; font-weight: 700; }
.pack .p { color: var(--amber); font-weight: 600; }
.pack .n { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

/* ---------- announcements ---------- */

.announce {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.announce-mark { flex: 0 0 7px; display: flex; flex-direction: column; }
.announce-mark span { flex: 1; }
.announce-mark span:nth-child(1) { background: var(--bar-1); }
.announce-mark span:nth-child(2) { background: var(--bar-2); }
.announce-mark span:nth-child(3) { background: var(--bar-3); }
.announce-mark span:nth-child(4) { background: var(--bar-4); }
.announce-mark span:nth-child(5) { background: var(--bar-5); }
.announce-mark span:nth-child(6) { background: var(--bar-6); }
.announce-mark span:nth-child(7) { background: var(--bar-7); }
.announce-body { padding: 16px 18px; }
.announce-meta { font-size: 0.82rem; color: var(--muted); margin-bottom: 5px; }
.announce-body h2 { margin-bottom: 5px; }
.announce-body p { margin: 0; }

.post { border-bottom: 1px solid var(--rule-soft); padding: 15px 0; }
.post:last-child { border-bottom: 0; padding-bottom: 0; }
.post h3 { margin-bottom: 2px; }
.post .when { color: var(--muted); font-size: 0.83rem; margin-bottom: 8px; }

/* ---------- apps ---------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
}
.tile.off { background: var(--surface-2); }
.tile.off .tile-logo { filter: grayscale(1); opacity: 0.4; }
.tile.off .tile-name { color: var(--muted); }
.tile-logo {
  width: 64px; height: 64px;
  border-radius: var(--r);
  overflow: hidden;
  margin-bottom: 4px;
  background: var(--surface-2);
}
.tile-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.logo-fallback {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 1.4rem;
  color: hsl(var(--h) 50% 80%);
  background: hsl(var(--h) 40% 26%);
}
[data-theme='light'] .logo-fallback { color: hsl(var(--h) 45% 30%); background: hsl(var(--h) 45% 88%); }
.logo-fallback.small { font-size: 0.8rem; width: 34px; height: 34px; border-radius: 3px; }
.tile-name { font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tile-note { font-size: 0.88rem; color: var(--muted); margin: 2px 0 6px; }
.tile-url {
  font-size: 0.78rem;
  padding: 6px 8px;
  background: var(--bg-2);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  overflow-wrap: anywhere;
  margin-bottom: 8px;
}
.tile-price { font-weight: 600; color: var(--amber); min-height: 1.4em; }
.tile .row-actions { margin-top: auto; }

.access-row {
  display: grid;
  grid-template-columns: 1fr 2fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule-soft);
}
.access-name { font-weight: 500; }
.switch { display: flex; align-items: center; gap: 6px; font-size: 0.88rem; color: var(--muted); }

/* ---------- forced acknowledgment ---------- */

.ack-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(3, 8, 12, 0.78);
  display: grid;
  place-items: center;
  padding: 20px;
}
.ack-card {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.ack-card-body { padding: 22px 24px 24px; }
.ack-step {
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--purple);
  margin-bottom: 10px;
}
.ack-card-body h2 { margin: 4px 0 8px; }
.ack-card-body p { margin-bottom: 16px; }

/* ---------- kb, tickets, dialogs ---------- */

details.kb { border-bottom: 1px solid var(--rule-soft); padding: 12px 0; }
details.kb summary { cursor: pointer; font-weight: 500; }
details.kb[open] summary { margin-bottom: 8px; }
details.kb p { color: var(--muted); }

.thread { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.msg { padding: 10px 12px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--rule); }
.msg.staff { border-color: var(--accent); }
.msg .who-line { font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }

dialog {
  border: 1px solid var(--rule);
  border-radius: var(--r);
  padding: 0;
  width: min(470px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--ink);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog .dlg-body { padding: 20px; }
dialog .dlg-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--rule);
  background: var(--surface-2);
}

.spin { color: var(--muted); padding: 18px 0; }

@media (max-width: 860px) {
  .body { flex-direction: column; }
  .rail {
    width: auto; flex: none;
    border-right: 0; border-bottom: 1px solid var(--rule);
    display: flex; gap: 4px; overflow-x: auto; padding: 8px;
  }
  .rail .group, .zone-label { display: none; }
  .rail-zone, .rail-zone-admin { display: contents; }
  .rail-zone-admin a {
    border: 1px solid var(--purple);
    background: color-mix(in srgb, var(--purple) 12%, transparent);
  }
  .rail-zone-admin a.on { background: var(--purple); border-color: var(--purple); }
  .rail a { white-space: nowrap; margin-bottom: 0; }
  .view { padding: 16px 13px 48px; }
  .top-inner { padding: 10px 13px; gap: 10px; }
  .who span.name { display: none; }
  .access-row { grid-template-columns: 1fr; }
  table { font-size: 0.86rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
