/* ==========================================================================
   Meldrix — Dashboard (scoped to body.dash)
   Matches the landing design system: #09090b ground, #111114 cards,
   #1f1f23 borders, zinc text, lime reserved for live/active/primary.
   Loaded only on /dashboard; overrides the emerald tokens locally.
   ========================================================================== */
body.dash {
  --bg: #09090b;
  --bg-soft: #0a0a0c;
  --card: #111114;
  --card-hover: #151518;
  --border: #1f1f23;
  --border-soft: #1a1a1e;
  --text: #f7f7f8;
  --muted: #a1a1aa;
  --faint: #71717a;
  --accent: #d9f99d;
  --accent-hover: #bef264;
  --accent-ink: #11150a;
  --accent-soft: rgba(217, 249, 157, 0.12);
  --good: #34d399;
  --radius: 14px;
  --d-max: 1180px;
  --d-gutter: 32px;

  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

body.dash ::selection {
  background: rgba(217, 249, 157, 0.22);
  color: #fff;
}

body.dash .mono,
.d-mono {
  font-family: var(--mono);
}

/* Inherited shared components pick up the new palette via variables. */
body.dash .input,
body.dash .select {
  background: #0b0b0d;
  border-color: var(--border);
}
body.dash .input:focus,
body.dash .select:focus {
  border-color: rgba(217, 249, 157, 0.55);
  box-shadow: 0 0 0 3px rgba(217, 249, 157, 0.1);
}
body.dash .input::placeholder {
  color: #52525b;
}
body.dash .btn-ghost {
  border-color: var(--border);
}
body.dash .btn-ghost:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: #2a2a30;
}
body.dash .toast {
  background: #111114;
  border-color: var(--border);
}
body.dash .modal {
  background: #111114;
  border-color: var(--border);
}
body.dash .secret-box {
  background: #0b0b0d;
  border-color: var(--border);
}
body.dash .secret-box code {
  color: var(--accent);
}
body.dash .modal-backdrop {
  background: rgba(3, 3, 5, 0.72);
}
body.dash .spinner {
  border-top-color: var(--accent);
}
body.dash .auth-gate {
  background: var(--bg);
}

/* ==========================================================================
   Top bar
   ========================================================================== */
.d-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--border);
  background: rgba(9, 9, 11, 0.82);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.d-topbar-inner {
  width: min(var(--d-max), calc(100% - var(--d-gutter)));
  margin-inline: auto;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.d-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.d-mark {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  display: grid;
  place-items: center;
}

.d-wordmark {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  white-space: nowrap;
}

.d-brandsep {
  color: var(--faint);
  font-size: 12px;
}

.d-brandsub {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--faint);
  white-space: nowrap;
}

.d-topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.d-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10.5px;
  white-space: nowrap;
}

.d-live i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(217, 249, 157, 0.5);
  animation: d-pulse 2s ease-in-out infinite;
}

.d-live.is-paused i {
  background: var(--faint);
  box-shadow: none;
  animation: none;
}

@keyframes d-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(217, 249, 157, 0.45); }
  50% { box-shadow: 0 0 0 4px rgba(217, 249, 157, 0); }
}

.d-user {
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.d-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.d-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: #2a2a30;
}

.d-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.d-btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 0 0 4px rgba(217, 249, 157, 0.12);
}

.d-btn-ghost {
  background: transparent;
}

.d-btn-sm {
  padding: 6px 11px;
  font-size: 12.5px;
  border-radius: 7px;
}

.d-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

/* ==========================================================================
   Tab navigation
   ========================================================================== */
.d-tabs {
  border-top: 1px solid var(--border-soft);
  background: rgba(9, 9, 11, 0.82);
}

.d-tabs-inner {
  width: min(var(--d-max), calc(100% - var(--d-gutter)));
  margin-inline: auto;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 44px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.d-tabs-inner::-webkit-scrollbar {
  display: none;
}

.d-tab {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.d-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.d-tab.is-active {
  color: var(--text);
  background: #18181b;
  border-color: var(--border);
}

.d-tab-link {
  color: var(--faint);
}

/* ==========================================================================
   Layout
   ========================================================================== */
.d-main {
  width: min(var(--d-max), calc(100% - var(--d-gutter)));
  margin-inline: auto;
  padding: 26px 0 64px;
}

.d-view {
  display: none;
}

.d-view.is-active {
  display: block;
  animation: d-view-in 0.18s ease;
}

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

.d-view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.d-view-head h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.d-view-head p {
  margin-top: 3px;
  font-size: 13px;
}

.d-muted {
  color: var(--muted);
}

.d-small {
  font-size: 11px;
}

.d-head-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.d-updated {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10.5px;
  white-space: nowrap;
}

.d-ta-r {
  text-align: right;
}

.d-trunc {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

/* ==========================================================================
   2-column stat grid — always 2 cols, even at 360px
   ========================================================================== */
.d-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.d-stat {
  min-width: 0;
  padding: 16px 16px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  overflow: hidden;
}

.d-stat-label {
  display: block;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.d-stat-value {
  display: block;
  margin-top: 10px;
  font-size: 28px;
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.d-stat-sub {
  display: block;
  margin-top: 7px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   Cards
   ========================================================================== */
.d-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  overflow: hidden;
}

.d-card + .d-card {
  margin-top: 16px;
}

.d-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 14px;
  flex-wrap: wrap;
}

.d-card-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.d-card-sub {
  margin-top: 2px;
  color: var(--faint);
  font-size: 11.5px;
}

.d-card-meta {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
}

.d-two-col {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  margin-top: 16px;
}

.d-two-col > .d-card {
  margin-top: 0;
}

.d-two-col-play {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
}

.d-stack {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.d-stack > .d-card {
  margin-top: 0;
}

/* ==========================================================================
   Chart
   ========================================================================== */
.d-chart {
  padding: 0 18px 16px;
}

.d-chart-bars {
  height: 108px;
  display: flex;
  align-items: flex-end;
  gap: 3px;
}

.d-chart-bars .bar {
  flex: 1;
  min-width: 0;
  min-height: 2px;
  border-radius: 2px 2px 0 0;
  background: rgba(217, 249, 157, 0.16);
  border-top: 1px solid rgba(217, 249, 157, 0.4);
  transition: background 0.15s ease;
}

.d-chart-bars .bar:hover {
  background: rgba(217, 249, 157, 0.42);
}

.d-chart-bars .bar.is-zero {
  background: rgba(255, 255, 255, 0.05);
  border-top-color: transparent;
}

.d-chart-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 9.5px;
}

/* ==========================================================================
   Tables
   ========================================================================== */
.d-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.d-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.d-table th {
  padding: 8px 18px;
  border-top: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.012);
  color: var(--faint);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
}

.d-table td {
  padding: 11px 18px;
  border-bottom: 1px solid var(--border-soft);
  color: #d4d4d8;
  vertical-align: middle;
  white-space: nowrap;
}

.d-table tbody tr:last-child td {
  border-bottom: 0;
}

.d-table tbody tr[data-log-id] {
  cursor: pointer;
}

.d-table tbody tr[data-log-id]:hover {
  background: rgba(255, 255, 255, 0.025);
}

.d-table .d-cell-time {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.d-table .d-cell-video {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 11.5px;
}

.d-table .d-cell-mono {
  font-family: var(--mono);
  font-size: 11.5px;
}

.d-dim {
  color: var(--faint);
}

.d-key-name {
  color: var(--text);
  font-weight: 500;
}

.d-latency {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Pills / badges
   ========================================================================== */
.d-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 21px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

.d-pill-ok {
  color: #6ee7b7;
  border-color: rgba(52, 211, 153, 0.4);
  background: rgba(52, 211, 153, 0.1);
}

.d-pill-warn {
  color: #fcd34d;
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.1);
}

.d-pill-err {
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.1);
}

.d-pill-muted {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
}

.d-pill-lime {
  color: var(--accent);
  border-color: rgba(217, 249, 157, 0.35);
  background: rgba(217, 249, 157, 0.1);
}

.d-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex: 0 0 6px;
}

.d-dot.is-idle {
  background: var(--faint);
}

/* ==========================================================================
   Key list (overview) + status list
   ========================================================================== */
.d-keylist {
  list-style: none;
  margin: 0;
  padding: 0 18px 8px;
}

.d-keylist li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--border-soft);
  min-width: 0;
}

.d-keylist li:first-child {
  border-top: 0;
}

.d-keylist .d-key-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.d-keylist .d-key-meta {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.d-status {
  list-style: none;
  margin: 0;
  padding: 0 18px 8px;
}

.d-status li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border-soft);
  min-width: 0;
}

.d-status li:first-child {
  border-top: 0;
}

.d-status-k {
  color: var(--muted);
  font-size: 12px;
  flex: 0 0 auto;
  white-space: nowrap;
}

.d-status-v {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  font-size: 11.5px;
  color: var(--text-2, #c9c9cf);
}

.d-status-v.d-mono {
  font-size: 10.5px;
}

.d-status-v .d-trunc {
  min-width: 0;
  flex: 0 1 auto;
}

/* ==========================================================================
   Controls (filters)
   ========================================================================== */
.d-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-soft);
}

.d-input {
  width: 100%;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #0b0b0d;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.d-input::placeholder {
  color: #52525b;
}

.d-input:focus {
  border-color: rgba(217, 249, 157, 0.55);
  box-shadow: 0 0 0 3px rgba(217, 249, 157, 0.1);
}

.d-input-sm {
  height: 32px;
  font-size: 12.5px;
  width: 210px;
  max-width: 100%;
}

.d-select-wrap {
  position: relative;
  display: inline-flex;
}

.d-select-wrap::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 11px;
  width: 9px;
  height: 9px;
  margin-top: -6px;
  border-right: 1.5px solid var(--faint);
  border-bottom: 1.5px solid var(--faint);
  transform: rotate(45deg);
  pointer-events: none;
}

.d-select {
  height: 32px;
  padding: 0 30px 0 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #0b0b0d;
  color: var(--text);
  font-size: 12.5px;
  outline: none;
  appearance: none;
  cursor: pointer;
  max-width: 100%;
}

.d-select:focus {
  border-color: rgba(217, 249, 157, 0.55);
}

.d-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.d-toggle input {
  accent-color: var(--accent);
  width: 13px;
  height: 13px;
}

/* ==========================================================================
   Pagination + empty
   ========================================================================== */
.d-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-top: 1px solid var(--border-soft);
}

.d-pager-btns {
  display: flex;
  gap: 8px;
}

.d-empty {
  padding: 34px 18px;
  text-align: center;
  color: var(--faint);
  font-size: 12.5px;
}

.d-empty strong {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-weight: 500;
}

.d-empty-sm {
  padding: 20px 18px;
}

/* ==========================================================================
   Switch (key toggle)
   ========================================================================== */
.d-switch {
  position: relative;
  width: 34px;
  height: 19px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #1c1c20;
  transition: background 0.16s ease, border-color 0.16s ease;
  vertical-align: middle;
}

.d-switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #a1a1aa;
  transition: transform 0.16s ease, background 0.16s ease;
}

.d-switch.on {
  background: rgba(217, 249, 157, 0.22);
  border-color: rgba(217, 249, 157, 0.5);
}

.d-switch.on .d-switch-knob {
  transform: translateX(15px);
  background: var(--accent);
}

.d-row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
}

.d-status-text {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
}

.d-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--faint);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.d-icon-btn:hover {
  color: #fca5a5;
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.2);
}

/* ==========================================================================
   Playground
   ========================================================================== */
.d-form {
  display: grid;
  gap: 12px;
  padding: 0 18px 18px;
}

.d-form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.d-field {
  display: block;
  min-width: 0;
}

.d-field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.d-form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.d-pg-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.d-pg-status.is-ok .d-dot { background: var(--good); }
.d-pg-status.is-err .d-dot { background: #f87171; }
.d-pg-status.is-busy .d-dot { background: var(--accent); animation: d-pulse 1.2s ease-in-out infinite; }

.d-code {
  margin: 0;
  padding: 16px 18px;
  border-top: 1px solid var(--border-soft);
  background: #0b0b0d;
  color: #d4d4d8;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.65;
  overflow: auto;
  max-height: 440px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ==========================================================================
   Key/value grid (settings + drawer)
   ========================================================================== */
.d-kv {
  padding: 0 18px 16px;
}

.d-kv-row {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border-soft);
  min-width: 0;
}

.d-kv-row:first-child {
  border-top: 0;
}

.d-kv-label {
  color: var(--faint);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding-top: 1px;
}

.d-kv-value {
  min-width: 0;
  color: var(--text);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

.d-kv-value.d-mono {
  font-size: 11.5px;
}

.d-kv.d-kv-inline {
  padding: 4px 0 0;
}

/* ==========================================================================
   Inline banners / save status
   ========================================================================== */
.d-banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 16px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #131316;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.d-banner[hidden] {
  display: none;
}

.d-banner-err {
  border-color: rgba(248, 113, 113, 0.32);
  background: rgba(248, 113, 113, 0.08);
  color: #fca5a5;
}

.d-banner-warn {
  border-color: rgba(250, 204, 21, 0.28);
  background: rgba(250, 204, 21, 0.07);
  color: #fcd34d;
}

.d-card > .d-banner {
  margin: 14px 16px;
}

.d-save-status {
  align-self: flex-start;
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.4;
  color: var(--faint);
  text-align: right;
}

.d-save-status.is-ok {
  color: var(--good);
}

.d-save-status.is-error {
  color: #f87171;
}

.d-link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.d-link-btn:hover {
  color: var(--accent-hover);
}

/* ==========================================================================
   Segmented control + toggle sizing
   ========================================================================== */
.d-seg {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #0b0b0d;
}

.d-seg-btn {
  padding: 5px 11px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}

.d-seg-btn:hover {
  color: var(--text);
}

.d-seg-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.d-seg .d-copy-btn {
  margin-left: 2px;
}

.d-toggle-lg {
  font-family: inherit;
  font-size: 12px;
  color: var(--muted);
  white-space: normal;
  line-height: 1.45;
  align-items: flex-start;
}

.d-toggle-lg input {
  margin-top: 1px;
  flex: 0 0 auto;
}

/* ==========================================================================
   Playground output
   ========================================================================== */
.d-pg-out {
  padding: 16px 18px;
  border-top: 1px solid var(--border-soft);
}

.d-pg-placeholder {
  margin: 0;
  color: var(--faint);
  font-size: 12px;
}

.d-pg-error {
  padding: 13px 14px;
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: 10px;
  background: rgba(248, 113, 113, 0.07);
}

.d-pg-error strong {
  display: block;
  color: #fca5a5;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}

.d-pg-error p {
  margin: 0;
}

.d-pg-tr-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.d-pg-text {
  margin: 0 0 14px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.d-pg-snips {
  display: grid;
  gap: 2px;
  max-height: 320px;
  overflow: auto;
  padding: 8px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  background: #0b0b0d;
}

.d-pg-snip {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  padding: 5px 4px;
  border-radius: 5px;
  font-size: 12px;
  line-height: 1.5;
}

.d-pg-snip:nth-child(odd) {
  background: rgba(255, 255, 255, 0.015);
}

.d-pg-ts {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10.5px;
  padding-top: 1px;
  opacity: 0.85;
}

.d-pg-snip-text {
  min-width: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* Shared visibility helper */
.d-hidden {
  display: none !important;
}

/* ==========================================================================
   Footer
   ========================================================================== */
.d-footer {
  margin-top: 34px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--faint);
  font-size: 10px;
}

/* ==========================================================================
   Request detail drawer
   ========================================================================== */
.d-drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 280;
  background: rgba(3, 3, 5, 0.6);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.d-drawer-backdrop.is-open {
  opacity: 1;
}

.d-drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(460px, 100%);
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: #0d0d0f;
  box-shadow: -30px 0 80px -30px rgba(0, 0, 0, 0.9);
  transform: translateX(16px);
  transition: transform 0.2s ease;
  overflow: hidden;
}

.d-drawer-backdrop.is-open .d-drawer {
  transform: translateX(0);
}

.d-drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.d-eyebrow {
  display: block;
  color: var(--faint);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.d-drawer-title {
  margin-top: 4px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.d-drawer-body {
  padding: 18px 20px 28px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.d-drawer-note {
  margin-bottom: 16px;
  color: var(--faint);
  font-size: 11.5px;
}

.d-detail-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
}

.d-detail-id {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1 1 160px;
}

.d-detail-k {
  color: var(--faint);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.d-detail-v {
  color: var(--text);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

.d-detail-v.d-mono {
  font-family: var(--mono);
  font-size: 11.5px;
}

.d-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 11px;
  font-family: var(--mono);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.d-copy-btn:hover {
  color: var(--text);
  border-color: #2a2a30;
  background: rgba(255, 255, 255, 0.06);
}

.d-copy-btn.is-copied {
  color: var(--accent);
  border-color: rgba(217, 249, 157, 0.4);
}

.d-detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px 18px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-soft);
}

.d-detail-grid > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.d-detail-grid .d-detail-v {
  margin-top: 3px;
}

.d-detail-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 18px 0 8px;
}

.d-detail-section-head h3 {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.d-detail-actions {
  display: flex;
  gap: 6px;
}

.d-pre {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #0b0b0d;
  color: #d4d4d8;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  overflow: auto;
  max-height: 300px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 900px) {
  .d-two-col,
  .d-two-col-play {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  body.dash {
    --d-gutter: 24px;
  }

  .d-topbar-inner,
  .d-tabs-inner,
  .d-main {
    width: calc(100% - var(--d-gutter));
  }

  .d-brandsub,
  .d-brandsep {
    display: none;
  }

  .d-topbar-inner {
    gap: 10px;
  }

  .d-user {
    max-width: 92px;
    font-size: 10.5px;
  }

  /* On phones, drop the API-key column so status + latency stay in view */
  .d-table-logs th:nth-child(2),
  .d-table-logs td:nth-child(2) {
    display: none;
  }

  /* Keys: keep label, prefix, status + actions on-screen without h-scroll */
  .d-view[data-view="api-keys"] .d-table th:nth-child(3),
  .d-view[data-view="api-keys"] .d-table td:nth-child(3),
  .d-view[data-view="api-keys"] .d-table th:nth-child(4),
  .d-view[data-view="api-keys"] .d-table td:nth-child(4) {
    display: none;
  }

  .d-view[data-view="api-keys"] .d-table th,
  .d-view[data-view="api-keys"] .d-table td {
    padding-inline: 4px;
  }

  .d-view[data-view="api-keys"] .d-table td .d-cell-mono {
    font-size: 10px;
    letter-spacing: -0.02em;
  }

  .d-view[data-view="api-keys"] .d-key-name {
    font-size: 12px;
  }

  /* Toggle already conveys status on phones — drop the redundant label */
  .d-view[data-view="api-keys"] .d-row-actions .d-status-text {
    display: none;
  }

  .d-stats {
    gap: 8px;
  }

  .d-stat {
    padding: 13px 12px 12px;
  }

  .d-stat-value {
    font-size: 24px;
  }

  .d-stat-label {
    font-size: 9.5px;
    letter-spacing: 0.06em;
  }

  .d-stat-sub {
    font-size: 9.5px;
  }

  .d-card-head {
    padding: 14px 14px 12px;
  }

  .d-controls {
    padding: 12px 14px;
  }

  .d-input-sm {
    width: 100%;
    flex: 1 1 150px;
  }

  .d-table th,
  .d-table td {
    padding-inline: 11px;
  }

  .d-chart {
    padding: 0 14px 14px;
  }

  .d-form {
    padding: 0 14px 16px;
  }

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

  .d-kv {
    padding: 0 14px 14px;
  }

  .d-kv-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 3px;
  }

  .d-keylist,
  .d-status {
    padding-inline: 14px;
  }

  .d-pager {
    padding: 12px 14px;
  }

  .d-drawer {
    width: 100%;
  }

  .d-detail-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }
}

@media (max-width: 400px) {
  body.dash {
    --d-gutter: 20px;
  }

  .d-user {
    max-width: 68px;
  }

  /* Keep status + latency on-screen; full detail lives in the drawer */
  .d-table-logs th:nth-child(3),
  .d-table-logs td:nth-child(3),
  .d-view[data-view="overview"] .d-table th:nth-child(3),
  .d-view[data-view="overview"] .d-table td:nth-child(3) {
    display: none;
  }

  .d-stat-value {
    font-size: 22px;
  }

  .d-btn {
    padding: 8px 12px;
  }

  .d-tab {
    padding: 0 10px;
    font-size: 12.5px;
  }
}
