* {
  box-sizing: border-box;
}

:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #111827;
  --muted: #64748b;
  --line: #d7dee9;
  --primary: #1458d4;
  --primary-dark: #0f43a5;
  --ink: #172033;
  --good: #16734a;
  --good-bg: #e8f6ef;
  --warn: #9a5b00;
  --warn-bg: #fff4db;
  --bad: #b42318;
  --bad-bg: #fdecec;
  --neutral-bg: #eef2f7;
  --shadow: 0 12px 34px rgba(16, 24, 40, 0.08);
  --radius: 8px;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  padding: 18px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 11px;
  background: #fff;
  color: var(--text);
}

textarea {
  min-height: 180px;
  resize: vertical;
}

.hidden {
  display: none !important;
}

.shell {
  max-width: 1520px;
  margin: 0 auto;
}

.login-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 24px;
  align-items: stretch;
  margin: 64px auto 0;
  max-width: 980px;
}

.login-copy,
.login-form,
.ops-panel,
.metric,
.modal,
.table-shell,
.empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-copy,
.login-form {
  padding: 28px;
}

.turnstile-slot {
  min-height: 0;
}

.login-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-copy h1,
.topbar h1 {
  margin: 0 0 10px;
  font-size: 30px;
  letter-spacing: 0;
}

.login-copy p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.app-shell {
  display: block;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 14px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.muted {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.topbar-actions,
.modal-actions,
.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.compact-btn {
  padding: 10px 13px;
  font-weight: 700;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
}

.primary-btn:hover {
  background: var(--primary-dark);
}

.secondary-btn {
  background: var(--ink);
  color: #fff;
}

.ghost-btn {
  background: var(--neutral-bg);
  color: var(--ink);
  border: 1px solid var(--line);
}

.compact-btn {
  padding: 7px 10px;
  font-size: 12px;
}

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.tab {
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
}

.tab.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.message {
  min-height: 22px;
  margin: 10px 0;
  color: var(--muted);
}

.message.error,
.error-state {
  color: var(--bad);
}

.view-section {
  display: grid;
  gap: 14px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  padding: 14px 0 4px;
}

.section-heading h2,
.ops-panel h2 {
  margin: 0 0 4px;
  font-size: 20px;
}

.inline-filter {
  min-width: min(360px, 100%);
}

.field {
  display: block;
  margin: 14px 0;
}

.field span,
.inline-filter span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.metrics-grid,
.metrics-strip {
  display: grid;
  gap: 10px;
}

.metrics-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.metrics-strip {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 12px;
}

.metric {
  padding: 13px;
  min-height: 112px;
}

.metric.good {
  border-color: #9ed8bb;
}

.metric.warn {
  border-color: #e5be71;
}

.metric.bad {
  border-color: #ee9c96;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric-value {
  margin-top: 7px;
  font-size: 30px;
  font-weight: 800;
}

.metric-note {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.ops-panel {
  padding: 14px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  margin-bottom: 10px;
}

.link-btn,
.table-sort-btn {
  padding: 0;
  background: transparent;
  color: var(--primary);
  font-weight: 700;
}

.attention-list,
.breakdown,
.guardrail-list {
  display: grid;
  gap: 8px;
}

.support-ticket-list,
.support-thread {
  display: grid;
  gap: 12px;
}

.support-ticket-card {
  display: grid;
  gap: 14px;
}

.support-message {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.support-message.is-admin {
  border-color: #9ed8bb;
  background: #f0fbf5;
}

.support-message-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.support-message p {
  margin: 8px 0 0;
  white-space: pre-wrap;
}

.support-reply-form textarea {
  min-height: 96px;
}

.attention-row,
.breakdown-row,
.guardrail-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.attention-row {
  flex-direction: column;
}

.attention-row span,
.guardrail-list div {
  color: var(--muted);
  font-size: 13px;
}

.chip {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  margin: 0 4px 4px 0;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  background: var(--neutral-bg);
  color: var(--ink);
  overflow-wrap: anywhere;
}

.chip.good {
  background: var(--good-bg);
  color: var(--good);
}

.chip.warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.chip.bad {
  background: var(--bad-bg);
  color: var(--bad);
}

.queue-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.queue-summary span {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 7px 9px;
  font-size: 13px;
}

.table-shell {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--line);
  padding: 11px;
  text-align: left;
  vertical-align: top;
}

.admin-table th {
  background: #f1f5f9;
  color: var(--ink);
  font-size: 12px;
  text-transform: uppercase;
}

.admin-table td span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.admin-table td strong {
  display: block;
  overflow-wrap: anywhere;
}

.row-warn {
  background: #fffaf0;
}

.row-bad {
  background: #fff5f5;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.58);
}

.modal {
  width: 100%;
  max-width: 780px;
  max-height: 92vh;
  padding: 18px;
  overflow: auto;
}

.detail-modal {
  max-width: 1040px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-header h2 {
  margin: 0;
  font-size: 22px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--ink);
  color: #fff;
  font-size: 18px;
  font-weight: 800;
}

.modal-body {
  margin-bottom: 14px;
}

.meta-row {
  margin-bottom: 12px;
}

.meta-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

.meta-value {
  display: block;
  overflow-wrap: anywhere;
}

.link {
  color: var(--primary);
  text-decoration: none;
}

.link:hover {
  text-decoration: underline;
}

.stack {
  display: grid;
  gap: 12px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.checkbox-row input {
  width: auto;
}

.short-textarea {
  min-height: 92px;
}

.compact-details {
  margin: 14px 0;
}

.detail-body {
  display: grid;
  gap: 14px;
}

.detail-section {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.detail-section h3 {
  margin: 0 0 10px;
  font-size: 17px;
}

.detail-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.detail-field {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--panel-soft);
}

.detail-key {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
  overflow-wrap: anywhere;
}

.detail-value {
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.detail-json {
  margin: 0;
  max-height: 340px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #101827;
  color: #e5edf9;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.pagination-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

@media (max-width: 1180px) {
  .metrics-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metrics-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  body {
    padding: 12px;
  }

  .login-panel,
  .overview-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .section-heading {
    flex-direction: column;
    align-items: stretch;
  }

  .metrics-grid,
  .metrics-strip {
    grid-template-columns: 1fr;
  }

  .tab {
    flex: 1 1 auto;
  }
}
