:root {
  color-scheme: light;
  --page: #f3f0e9;
  --surface: #fffdf8;
  --surface-soft: #f8f5ee;
  --surface-warm: #fbf7ee;
  --rail: #1d241f;
  --rail-soft: #28332b;
  --ink: #171917;
  --muted: #706f69;
  --faint: #9a978d;
  --line: #ded8ca;
  --line-soft: rgba(222, 216, 202, 0.68);
  --field: #fffefa;
  --accent: #426451;
  --accent-soft: rgba(66, 100, 81, 0.1);
  --blue: #355d70;
  --amber: #a8732a;
  --red: #9a3b33;
  --shadow: rgba(35, 31, 23, 0.12);
  --mono: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--page);
}

body {
  min-height: 100svh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.7), transparent 260px),
    radial-gradient(circle at 12% 0%, rgba(66, 100, 81, 0.08), transparent 320px),
    var(--page);
  color: var(--ink);
  font-family: var(--sans);
  letter-spacing: 0;
}

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

button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--rail);
  color: #fffdf8;
  font-weight: 720;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

button.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

button.danger {
  background: var(--red);
}

button.subtle {
  border-color: rgba(154, 59, 51, 0.24);
  background: rgba(154, 59, 51, 0.08);
  color: var(--red);
}

.secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--field);
  color: var(--ink);
  outline: none;
}

input,
select {
  min-height: 38px;
  padding: 0 11px;
}

textarea {
  min-height: 132px;
  padding: 12px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.58;
  white-space: pre-wrap;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(66, 100, 81, 0.14);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

.shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.hidden {
  display: none !important;
}

.login-view {
  width: min(100%, 460px);
  margin: min(12svh, 88px) auto 0;
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 28px 80px var(--shadow);
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-soft);
}

.brand-mark.compact {
  width: 36px;
  height: 36px;
  margin: 0;
  border-color: rgba(255, 253, 248, 0.2);
  background: rgba(255, 253, 248, 0.08);
}

.brand-mark svg {
  width: 24px;
  height: 24px;
  stroke-width: 1.8;
}

.brand-mark.compact svg {
  width: 18px;
  height: 18px;
}

.login-view h1 {
  margin-bottom: 28px;
  font-size: 42px;
  font-weight: 740;
  line-height: 1;
}

.login-form,
.stack-form {
  display: grid;
  gap: 14px;
}

.login-error {
  min-height: 20px;
  color: var(--red);
  font-size: 13px;
}

.admin-console {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: calc(100svh - 48px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 30px 90px var(--shadow);
}

.admin-rail {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: 100%;
  padding: 22px 18px;
  background: var(--rail);
  color: #f4efe4;
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.rail-brand strong {
  display: block;
  font-size: 16px;
  line-height: 1.1;
}

.rail-brand span,
.rail-status span {
  color: rgba(244, 239, 228, 0.58);
  font-family: var(--mono);
  font-size: 11px;
}

.rail-nav {
  display: grid;
  gap: 5px;
}

.rail-nav a {
  display: block;
  border-radius: 7px;
  padding: 10px 11px;
  color: rgba(244, 239, 228, 0.74);
  font-size: 13px;
  font-weight: 720;
  text-decoration: none;
}

.rail-nav a:hover,
.rail-nav a:focus-visible,
.rail-nav a.is-active {
  background: rgba(255, 253, 248, 0.08);
  color: #fffdf8;
  outline: none;
}

.rail-nav a.is-active {
  background: #fffdf8;
  color: var(--rail);
}

.rail-status {
  display: grid;
  gap: 4px;
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 253, 248, 0.12);
}

.rail-status strong {
  color: #fffdf8;
  font-family: var(--mono);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.admin-main {
  min-width: 0;
  padding: 22px;
  background:
    linear-gradient(180deg, rgba(248, 245, 238, 0.9), rgba(248, 245, 238, 0.4) 240px, transparent),
    var(--surface);
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 16px;
}

.eyebrow {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar h1 {
  margin-top: 4px;
  font-size: clamp(34px, 4.5vw, 56px);
  font-weight: 760;
  line-height: 0.98;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.status {
  min-height: 20px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.status.error {
  color: var(--red);
}

.status.ok {
  color: var(--accent);
}

.view-stack {
  min-height: 560px;
}

.view-panel {
  display: none;
  animation: view-in 180ms ease both;
}

.view-panel.is-active {
  display: block;
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.overview-panel {
  display: none;
}

.overview-panel.is-active {
  display: grid;
  gap: 14px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metrics div {
  display: grid;
  min-height: 72px;
  align-content: center;
  gap: 6px;
  padding: 14px 16px;
  border-right: 1px solid var(--line-soft);
}

.metrics div:last-child {
  border-right: 0;
}

.metrics span {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.metrics strong {
  font-size: 24px;
  line-height: 1;
}

.overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.44fr);
  gap: 14px;
}

.overview-block {
  min-height: 220px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.78);
}

.overview-block h2 {
  max-width: 520px;
  margin-top: 10px;
  font-size: clamp(26px, 3.4vw, 44px);
  line-height: 1.02;
}

.overview-block p:not(.eyebrow) {
  max-width: 560px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 0.88fr) minmax(390px, 1.12fr);
  gap: 14px;
}

.view-panel:not(.is-active) {
  display: none;
}

.view-panel.workspace.is-active {
  display: grid;
}

.panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.78);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 15px 12px;
}

.panel-head.compact {
  padding: 0 0 10px;
}

h2,
h3 {
  font-size: 15px;
  font-weight: 760;
}

.row-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px 84px;
  gap: 8px;
  padding: 0 15px 15px;
}

.key-panel .stack-form {
  padding: 0 15px 15px;
}

.user-detail {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin: 0 15px 15px;
  padding: 13px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-warm);
}

.user-detail h3 {
  margin-top: 4px;
  font-size: 22px;
}

.user-detail .muted {
  overflow-wrap: anywhere;
}

.contacts-section,
.keys-list-section {
  padding: 0 15px 15px;
}

.contact-form {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1fr) 72px;
  gap: 8px;
  margin-bottom: 10px;
}

.keys-table,
.contacts-table {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface);
}

.key-row,
.contact-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line-soft);
}

.contact-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.key-row:last-child,
.contact-row:last-child {
  border-bottom: 0;
}

.key-row strong,
.contact-row strong {
  display: block;
  font-size: 13px;
}

.key-row > div,
.contact-row > div {
  min-width: 0;
}

.key-row span,
.contact-row span,
.muted {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.key-row.is-revoked {
  opacity: 0.62;
}

.status-pill {
  min-width: 66px;
  margin-top: 0 !important;
  padding: 5px 9px;
  border-radius: 999px;
  text-align: center;
  font-family: var(--mono);
  font-size: 10px !important;
  font-weight: 760;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.status-pill.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.status-pill.is-revoked {
  background: rgba(112, 111, 105, 0.12);
  color: var(--muted);
}

.section-divider {
  height: 1px;
  margin: 0 15px 15px;
  background: var(--line-soft);
}

.mint-head {
  padding: 0 15px 12px;
}

.list {
  display: grid;
  border-top: 1px solid var(--line-soft);
}

.user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  width: 100%;
  min-height: 58px;
  padding: 12px 15px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  border-left: 3px solid transparent;
  border-radius: 0;
  text-align: left;
}

.user-row:last-child {
  border-bottom: 0;
}

.user-row:hover,
.user-row:focus-visible {
  background: var(--surface-soft);
  outline: none;
}

.user-row.is-selected {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.user-row strong {
  display: block;
  font-size: 14px;
}

.quota {
  align-self: center;
  color: var(--blue);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 760;
}

.key-result {
  margin: 0 15px 15px;
  padding: 12px;
  border: 1px solid rgba(168, 115, 42, 0.34);
  border-radius: 8px;
  background: #fff7df;
}

.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.result-head h3 {
  margin-bottom: 4px;
}

.result-actions {
  display: flex;
  gap: 8px;
}

.key-result textarea {
  min-height: 120px;
  margin-top: 12px;
}

.key-result.is-collapsed textarea {
  display: none;
}

.calls-panel select {
  max-width: 240px;
}

.calls-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 0.58fr);
  border-top: 1px solid var(--line-soft);
}

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

.calls-layout .table-wrap {
  border-right: 1px solid var(--line-soft);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 15px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: top;
  font-size: 12px;
}

tbody tr {
  cursor: pointer;
  transition: background 140ms ease;
}

tbody tr:hover,
tbody tr:focus-visible {
  background: var(--surface-soft);
  outline: none;
}

tbody tr.is-selected {
  background: var(--accent-soft);
}

tbody tr.is-selected td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}

th {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 760;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

td code {
  color: var(--blue);
  font-family: var(--mono);
}

.empty {
  padding: 18px 15px;
  color: var(--muted);
  font-size: 13px;
}

.call-detail {
  min-height: 420px;
  max-height: 720px;
  overflow: auto;
  padding: 16px;
  background: #fbf8f0;
}

.call-detail h3 {
  margin: 4px 0 14px;
  overflow-wrap: anywhere;
  font-size: 22px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 16px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--line-soft);
}

.detail-grid div {
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: 10px;
  background: var(--surface);
}

.detail-grid span,
.detail-block h4 {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 760;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.detail-grid strong {
  overflow-wrap: anywhere;
  font-size: 12px;
}

.detail-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}

.detail-block h4 {
  margin: 0 0 8px;
}

.detail-block pre {
  overflow-x: auto;
  margin: 0;
  color: var(--ink);
  font: 12px/1.55 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.error-text pre {
  color: var(--red);
}

.transcript-block {
  display: grid;
  gap: 10px;
}

.transcript-line {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface);
}

.transcript-line strong {
  color: var(--blue);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.transcript-line p {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.55;
}

@media (max-width: 1020px) {
  .admin-console {
    grid-template-columns: 1fr;
  }

  .admin-rail {
    min-height: auto;
    flex-direction: row;
    align-items: center;
  }

  .rail-nav {
    grid-auto-flow: column;
    margin-left: auto;
  }

  .rail-status {
    display: none;
  }

  .workspace,
  .calls-layout,
  .overview-grid {
    grid-template-columns: 1fr;
  }

  .calls-layout .table-wrap {
    border-right: 0;
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100% - 18px, 1440px);
    padding: 9px 0;
  }

  .admin-main,
  .login-view {
    padding: 18px;
  }

  .admin-rail,
  .topbar,
  .result-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .rail-nav,
  .metrics,
  .detail-grid,
  .row-form,
  .contact-form,
  .user-detail,
  .contact-row,
  .key-row {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .result-actions {
    width: 100%;
  }

  .topbar-actions button,
  .result-actions button {
    flex: 1;
  }

  .metrics div {
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
  }

  .metrics div:last-child {
    border-bottom: 0;
  }

  .call-detail {
    max-height: none;
    border-top: 1px solid var(--line-soft);
  }
}
