:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #17202e;
  --muted: #5b6678;
  --border: #d9dfeb;
  --primary: #0b5fff;
  --primary-text: #ffffff;
  --ok: #0a7a43;
  --ok-bg: #dff5e9;
  --warn: #8a5a00;
  --warn-bg: #fff1cc;
  --bad: #b3261e;
  --bad-bg: #fde3e1;
  --shadow: 0 1px 2px rgb(16 24 40 / 8%), 0 4px 16px rgb(16 24 40 / 6%);
  --radius: 10px;
  --sidebar-w: 232px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e131b;
    --surface: #171e29;
    --surface-2: #1f2835;
    --text: #e6ebf3;
    --muted: #96a2b6;
    --border: #2b3647;
    --primary: #5b8dff;
    --primary-text: #07101f;
    --ok: #5fd39a;
    --ok-bg: #123524;
    --warn: #f2c14e;
    --warn-bg: #3a2c0c;
    --bad: #ff8a80;
    --bad-bg: #421a17;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
a {
  color: var(--primary);
}
h1,
h2,
h3,
p {
  margin: 0;
}
code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.9em;
}
:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}
.muted {
  color: var(--muted);
  font-size: 0.9em;
}
.noscript {
  padding: 16px;
}

/* ---------- buttons & forms ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  min-height: 38px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover:not(:disabled) {
  background: var(--surface-2);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text);
}
.btn--primary:hover:not(:disabled) {
  background: var(--primary);
  filter: brightness(1.08);
}
.btn--danger {
  color: var(--bad);
  border-color: var(--bad);
}
.btn--danger:hover:not(:disabled) {
  background: var(--bad-bg);
}
.btn--sm {
  padding: 4px 10px;
  min-height: 30px;
  font-size: 0.9em;
}
.btn--block {
  width: 100%;
}
.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--surface-2);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field label,
.filter label {
  font-size: 0.85em;
  font-weight: 600;
  color: var(--muted);
}
input,
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 38px;
  width: 100%;
}
textarea {
  resize: vertical;
}
[aria-invalid='true'] {
  border-color: var(--bad);
}
.field__error,
.form-error {
  color: var(--bad);
  font-size: 0.9em;
}
.form-error--info {
  color: var(--muted);
}
.field__help {
  color: var(--muted);
  font-size: 0.85em;
}
.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- badges, callouts, states ---------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.78em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge--ok {
  background: var(--ok-bg);
  color: var(--ok);
}
.badge--warn {
  background: var(--warn-bg);
  color: var(--warn);
}
.badge--bad {
  background: var(--bad-bg);
  color: var(--bad);
}
.callout {
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.callout--warn {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: var(--warn);
  margin-bottom: 16px;
}
.callout--warn a {
  color: inherit;
  font-weight: 700;
}
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
}
.state__title {
  font-weight: 600;
  color: var(--text);
}
.state--error .state__title {
  color: var(--bad);
}
.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 3s;
  }
}
.is-refreshing {
  opacity: 0.6;
  transition: opacity 0.15s;
}

/* ---------- login ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login__card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login__title {
  font-size: 1.4rem;
}
.login__form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 6px;
}

/* ---------- shell ---------- */
.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  padding: 4px 8px 16px;
}
.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav__link {
  display: block;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}
.nav__link:hover {
  background: var(--surface-2);
}
.nav__link[aria-current='page'] {
  background: var(--primary);
  color: var(--primary-text);
}
.content-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar__spacer {
  flex: 1;
}
.topbar__user {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40vw;
}
.menu-btn,
.scrim {
  display: none;
}
.main {
  padding: 20px 16px 48px;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}
.main:focus {
  outline: none;
}

@media (max-width: 800px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .menu-btn {
    display: inline-block;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(80vw, 280px);
    z-index: 30;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s, visibility 0.2s;
  }
  .shell--nav-open .sidebar {
    transform: none;
    visibility: visible;
  }
  .shell--nav-open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgb(0 0 0 / 45%);
    z-index: 20;
  }
}

/* ---------- page pieces ---------- */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.page-title {
  font-size: 1.5rem;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  align-items: flex-end;
}
.filter {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
}
.filter--grow {
  flex: 1 1 220px;
}
.section {
  margin-bottom: 24px;
}
.section__title {
  font-size: 1rem;
  margin-bottom: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
}
.card--link:hover {
  border-color: var(--primary);
}
.card--warn {
  border-color: var(--warn);
  background: var(--warn-bg);
}
.card--bad {
  border-color: var(--bad);
  background: var(--bad-bg);
}
.card__label {
  color: var(--muted);
  font-size: 0.85em;
  font-weight: 600;
}
.card__value {
  font-size: 1.5rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.card__sub {
  color: var(--muted);
  font-size: 0.85em;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  gap: 14px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.panel--alert {
  border-color: var(--warn);
  border-width: 2px;
}
.panel__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.panel__title {
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}
.panel__actions,
.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: auto;
}
.kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px 14px;
  margin: 0;
}
.kv dt {
  color: var(--muted);
  font-size: 0.9em;
}
.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}
.load-more {
  display: flex;
  justify-content: center;
  padding: 16px;
}
.timeline {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---------- table ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
.table {
  width: 100%;
  border-collapse: collapse;
}
.table th,
.table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  overflow-wrap: anywhere;
}
.table th {
  font-size: 0.8em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--surface-2);
}
.table tbody tr:last-child td {
  border-bottom: 0;
}
@media (max-width: 700px) {
  .table thead {
    position: absolute;
    left: -9999px;
  }
  .table,
  .table tbody,
  .table tr,
  .table td {
    display: block;
    width: 100%;
  }
  .table tr {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
  }
  .table td {
    border: 0;
    padding: 4px 12px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    text-align: right;
  }
  .table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.8em;
    font-weight: 600;
    text-align: left;
    flex: none;
  }
}

/* ---------- modal ---------- */
.modal {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  box-shadow: var(--shadow);
}
.modal--wide {
  width: min(720px, calc(100vw - 24px));
}
.modal::backdrop {
  background: rgb(0 0 0 / 50%);
}
.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 10px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
}
.modal__title {
  font-size: 1.1rem;
}
.modal__body {
  padding: 16px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal__body h3 {
  margin-top: 8px;
}

/* ---------- toasts ---------- */
.toasts {
  position: fixed;
  right: 12px;
  bottom: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  max-width: 420px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
}
.toast--ok {
  background: var(--ok);
  color: var(--bg);
}
.toast--warn {
  background: var(--warn);
  color: var(--bg);
}
.toast--error {
  background: var(--bad);
  color: var(--bg);
}

/* ---------- support inbox ---------- */
.support-preview {
  margin: 0 0 4px;
  overflow-wrap: anywhere;
}
.support-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.support-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: min(52vh, 440px);
  overflow-y: auto;
  padding: 16px 18px;
  background: var(--surface-2);
}
.support-msg {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.support-msg--agent {
  align-self: flex-end;
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text);
}
.support-msg__body {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.support-msg__meta {
  margin: 4px 0 0;
  font-size: 0.75rem;
  opacity: 0.75;
}
.support-form {
  padding: 14px 18px 16px;
}
.support-form textarea {
  width: 100%;
  resize: vertical;
}
