/* AstroHide admin — dense, neutral, no decoration. */

:root {
  --bg: #0d0e10;
  --bg-panel: #14161a;
  --bg-raised: #1b1e23;
  --bg-hover: #22262c;

  --text: #e9ecef;
  --text-dim: #a2aab6;
  --text-faint: #6e7683;

  --border: #282d35;
  --border-soft: #1e2229;

  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --accent: #e9ecef;

  --radius: 10px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

html[data-theme="light"] {
  --bg: #f7f8fa;
  --bg-panel: #ffffff;
  --bg-raised: #f0f2f5;
  --bg-hover: #e8ebef;
  --text: #111418;
  --text-dim: #4b5563;
  --text-faint: #8a929e;
  --border: #dfe3e8;
  --border-soft: #eceff3;
  --accent: #111418;
  --ok: #15803d;
  --warn: #a16207;
  --bad: #b91c1c;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

svg {
  width: 17px; height: 17px;
  fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  flex: none;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------- Layout ---------------- */

.app { display: grid; grid-template-columns: 218px 1fr; height: 100%; }

/* Until the session is verified nothing may render: the panel used to paint
   behind the login modal, leaking the operator UI to anyone who loaded the
   page. `visibility` (not just opacity) also removes it from the a11y tree. */
.app:not([data-view="ready"]) { visibility: hidden; }
.app[data-view="login"] { display: none; }

.rail {
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 14px 10px 10px;
  min-height: 0;
}

.rail__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.rail__brand svg { width: 19px; height: 19px; }
.rail__brand em {
  font-style: normal;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: auto;
}

.rail__nav { flex: 1; display: flex; flex-direction: column; gap: 2px; min-height: 0; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 13.5px;
  text-align: left;
  width: 100%;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item[aria-current="true"] { background: var(--bg-raised); color: var(--text); font-weight: 500; }
.nav-item svg { width: 16px; height: 16px; opacity: 0.85; }

.rail__foot { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--border-soft); padding-top: 8px; }
.rail__link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text-faint);
  font-size: 12.5px;
  text-decoration: none;
  text-align: left;
  width: 100%;
}
.rail__link:hover { background: var(--bg-hover); color: var(--text); }
.rail__link svg { width: 15px; height: 15px; }

.content { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.content__head {
  padding: 20px 26px 14px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px 16px;
}
.content__head h1 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
.content__head p { margin: 0; font-size: 12.5px; color: var(--text-faint); grid-column: 1; }
.content__actions { grid-column: 2; grid-row: 1 / span 2; display: flex; gap: 8px; align-items: center; }

.content__body { flex: 1; overflow-y: auto; padding: 20px 26px 40px; min-height: 0; }

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; }

.btn--primary { background: var(--accent); color: var(--bg); border-color: transparent; }
.btn--primary:hover:not(:disabled) { background: var(--accent); opacity: 0.88; color: var(--bg); }

.btn--danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.btn--danger:hover:not(:disabled) { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }

.btn--sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }

/* ---------------- Stats ---------------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 22px; }

.stat {
  padding: 14px 15px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-panel);
}
.stat__k { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--text-faint); }
.stat__v { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat__sub { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }

/* ---------------- Panels ---------------- */

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  overflow: hidden;
  margin-bottom: 18px;
}
.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 15px;
  border-bottom: 1px solid var(--border-soft);
}
.panel__head h2 { margin: 0; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-dim); }
.panel__body { padding: 15px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }

/* ---------------- Table ---------------- */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-weight: 600;
  padding: 9px 13px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  white-space: nowrap;
}
td { padding: 10px 13px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--bg-hover); }

.mono { font-family: var(--mono); font-size: 12.5px; letter-spacing: 0.02em; }
.dim { color: var(--text-faint); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------- Badges ---------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 99px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  white-space: nowrap;
}
.badge--ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.badge--warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.badge--bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); background: color-mix(in srgb, var(--bad) 10%, transparent); }
.badge--neutral { color: var(--text-faint); }

/* ---------------- Forms ---------------- */

.form { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); }

input, select, textarea {
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.12s;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--text-faint); }
textarea { resize: vertical; min-height: 100px; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }

.searchbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.searchbar input { max-width: 320px; }
.searchbar select { max-width: 160px; }

/* ---------------- Charts ---------------- */

.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-faint); }
.bar-row__label { width: 52px; font-family: var(--mono); flex: none; }
.bar-row__track { flex: 1; height: 7px; border-radius: 99px; background: var(--bg-raised); overflow: hidden; }
.bar-row__fill { height: 100%; border-radius: 99px; background: var(--text-dim); }
.bar-row__val { width: 62px; text-align: right; font-variant-numeric: tabular-nums; flex: none; }

/* ---------------- Code list ---------------- */

.code-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.code-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-family: var(--mono);
  font-size: 12.5px;
}
.code-chip button { color: var(--text-faint); padding: 2px; border-radius: 4px; }
.code-chip button:hover { color: var(--text); background: var(--bg-hover); }
.code-chip svg { width: 13px; height: 13px; }

/* ---------------- Modal ---------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
}
.modal__backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.65); }
.modal__card {
  position: relative;
  width: min(420px, 100%);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 26px 24px 22px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.modal__card--wide { width: min(760px, 100%); }
.modal__card h2 { margin: 0 0 6px; font-size: 18px; font-weight: 600; }
.modal__card > p { margin: 0 0 18px; font-size: 13px; color: var(--text-dim); }
.modal__close {
  position: absolute;
  top: 12px; right: 12px;
  padding: 6px;
  border-radius: 7px;
  color: var(--text-faint);
}
.modal__close:hover { background: var(--bg-hover); color: var(--text); }

.error { margin: 0; font-size: 12.5px; color: var(--bad); }
.hint { margin: 0; font-size: 12px; color: var(--text-faint); }
.hint code { font-family: var(--mono); color: var(--text-dim); }

/* ---------------- Toasts ---------------- */

.toasts {
  position: fixed;
  bottom: 18px; left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: center;
  pointer-events: none;
}
.toast {
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  font-size: 13px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
.toast--err { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }

/* ---------------- Support inbox ---------------- */

/* Two panes, the way every mail client works: the list is the index, the pane
   is the conversation. Height is bounded so the composer never scrolls off. */
.support-split {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  gap: 14px;
  align-items: start;
}
.support-split > .panel { margin-bottom: 0; }

.support-list { max-height: 62vh; overflow-y: auto; }

.support-list__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 11px 13px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
}
.support-list__item:last-child { border-bottom: 0; }
.support-list__item:hover { background: var(--bg-hover); }
.support-list__item[data-active="true"] { background: var(--bg-raised); box-shadow: inset 2px 0 0 var(--accent); }

.support-list__top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.support-list__who { font-size: 13px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.support-list__plan { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.06em; }
.support-list__last {
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.support-pane { display: flex; flex-direction: column; min-height: 400px; }
.support-pane__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 15px;
  border-bottom: 1px solid var(--border-soft);
}
.support-pane__head h2 { margin: 0 0 2px; font-size: 14px; font-weight: 600; }
.support-pane__actions { display: flex; gap: 6px; }

.support-pane__thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 15px;
  max-height: 48vh;
  overflow-y: auto;
}

.support-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 84%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: var(--bg-raised);
}
/* Staff on the right: it is the operator's own voice, and the shape makes
   "did I already answer this?" readable at a glance. */
.support-msg--staff { align-self: flex-end; background: color-mix(in srgb, var(--accent) 8%, var(--bg-raised)); }
.support-msg__meta { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); }
.support-msg__body { margin: 0; font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.support-msg__image {
  /* A screenshot must not stretch to the bubble width: in a flex column it
     would otherwise be sized to the column instead of to its own ratio. */
  align-self: flex-start;
  width: auto;
  max-width: 100%;
  max-height: 240px;
  border-radius: 8px;
  object-fit: contain;
  background: var(--bg);
}

.support-pane__form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 15px;
  border-top: 1px solid var(--border-soft);
  margin-top: auto;
}
.support-pane__form textarea { min-height: 70px; font-family: inherit; font-size: 13px; }
.support-pane__row { display: flex; gap: 8px; align-items: center; }
.support-pane__row .btn:last-child { margin-left: auto; }
.support-pane__attachments { display: flex; flex-wrap: wrap; gap: 7px; }

.support-chip { position: relative; width: 48px; height: 48px; }
.support-chip img { width: 100%; height: 100%; object-fit: cover; border-radius: 7px; border: 1px solid var(--border); }
.support-chip button {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 17px;
  height: 17px;
  display: grid;
  place-items: center;
  border-radius: 99px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1;
}

/* Unread count on the rail. */
.nav-badge {
  margin-left: auto;
  min-width: 17px;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--warn);
  color: var(--bg);
  font-size: 10px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
}

@media (max-width: 880px) {
  .support-split { grid-template-columns: 1fr; }
  .support-list { max-height: 34vh; }
}

/* ---------------- Misc ---------------- */

.empty {
  padding: 34px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}

.kv { display: flex; flex-direction: column; gap: 1px; }
.kv__row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}
.kv__row:last-child { border-bottom: 0; }
.kv__row > span:first-child { color: var(--text-faint); }
.kv__row > span:last-child { text-align: right; word-break: break-word; }

.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 880px) {
  body { overflow-x: hidden; }
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .rail { flex-direction: row; align-items: center; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 8px; min-width: 0; max-width: 100vw; }
  .rail__brand { padding: 0 10px 0 4px; }
  .rail__brand em { display: none; }
  .rail__nav { flex-direction: row; overflow-x: auto; flex: 1; min-width: 0; }
  .nav-item { width: auto; white-space: nowrap; flex: none; }
  .rail__foot { flex-direction: row; border: 0; padding: 0; }
  .rail__link span, .rail__link { font-size: 0; gap: 0; padding: 7px; }
  .content__head { padding: 16px; }
  .content__body { padding: 14px 16px 30px; }
}
