:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --bg-radial: #b8f2e6;
  --bg-shape-one: #c9f3e4;
  --bg-shape-two: #b2e0f2;
  --panel: #ffffffcc;
  --topbar-bg: #ffffffcc;
  --surface: #ffffff;
  --surface-soft: #f7f8fb;
  --surface-muted: #fbfcff;
  --ink: #14213d;
  --ink-soft: #41516d;
  --muted-ink: #5b6578;
  --accent: #14746f;
  --accent-soft: #44bba4;
  --danger: #b42318;
  --danger-soft-bg: #fff1f2;
  --danger-soft-border: #fecdca;
  --danger-strong-border: #8f1e16;
  --danger-strong-start: #b42318;
  --danger-strong-end: #d64545;
  --line: #d5d8dd;
  --line-strong: #d6deea;
  --row-border: #e7ebf2;
  --shadow-danger: rgba(180, 35, 24, 0.25);
  --shadow-popover: rgba(20, 33, 61, 0.1);
  --tooltip-bg: #14213d;
  --tooltip-error-bg: #b42318;
  --active-bg: #e8f7f1;
  --active-ink: #0f6a53;
  --active-border: #9fd8c8;
  --inactive-bg: #fff1f2;
  --inactive-ink: #b42318;
  --inactive-border: #fecdca;
  --code-bg: #0f172a;
  --code-ink: #d9f2e6;
  --chart-axis: #5b6578;
  --chart-grid: rgba(65, 81, 109, 0.2);
  --chart-words-line: #1f2937;
  --chart-duration-fill: rgba(20, 116, 111, 0.15);
  --record-danger-start: #b42318;
  --record-danger-end: #dd6b66;
  --record-dot-idle: rgba(255, 255, 255, 0.72);
  --record-dot-border: rgba(255, 255, 255, 0.9);
  --record-pulse: rgba(180, 35, 24, 0.35);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b1427;
    --bg-radial: #1d4f57;
    --bg-shape-one: #1a2f49;
    --bg-shape-two: #233f5d;
    --panel: #111d33d9;
    --topbar-bg: #111d33d9;
    --surface: #15233f;
    --surface-soft: #1a2a49;
    --surface-muted: #13203b;
    --ink: #e7eefb;
    --ink-soft: #b4c3dd;
    --muted-ink: #95a7c6;
    --danger-soft-bg: #3b1f2d;
    --danger-soft-border: #6a3444;
    --danger-strong-border: #a44d57;
    --danger-strong-start: #8f313a;
    --danger-strong-end: #bb4852;
    --line: #2c3a59;
    --line-strong: #324566;
    --row-border: #2a3957;
    --shadow-danger: rgba(0, 0, 0, 0.35);
    --shadow-popover: rgba(0, 0, 0, 0.45);
    --tooltip-bg: #0b1222;
    --tooltip-error-bg: #bb4852;
    --active-bg: #173b37;
    --active-ink: #8ce2c9;
    --active-border: #2f7065;
    --inactive-bg: #3b1f2d;
    --inactive-ink: #ff9aa2;
    --inactive-border: #6a3444;
    --code-bg: #060b17;
    --code-ink: #d9f2e6;
    --chart-axis: #b4c3dd;
    --chart-grid: rgba(149, 167, 198, 0.28);
    --chart-words-line: #d4def0;
    --chart-duration-fill: rgba(68, 187, 164, 0.22);
    --record-danger-start: #8f313a;
    --record-danger-end: #c15d67;
    --record-dot-idle: rgba(231, 238, 251, 0.75);
    --record-dot-border: rgba(231, 238, 251, 0.9);
    --record-pulse: rgba(143, 49, 58, 0.45);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: radial-gradient(circle at 80% 20%, var(--bg-radial) 0, transparent 45%), var(--bg);
  font-family: "Space Grotesk", sans-serif;
}

.bg-shape {
  position: fixed;
  z-index: -1;
  border-radius: 999px;
  filter: blur(20px);
}

.bg-shape.one {
  width: 280px;
  height: 280px;
  left: -40px;
  top: 10vh;
  background: var(--bg-shape-one);
}

.bg-shape.two {
  width: 340px;
  height: 340px;
  right: -80px;
  top: 45vh;
  background: var(--bg-shape-two);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
}

nav {
  display: flex;
  gap: 12px;
  align-items: center;
}

a {
  color: var(--ink);
  text-decoration: none;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 18px;
  animation: rise 0.35s ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-panel {
  max-width: 420px;
  margin: 90px auto;
}

h1, h2, h3 {
  margin: 0 0 12px;
}

input {
  width: 100%;
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 9px 12px;
}

select {
  width: 100%;
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 9px 12px;
  background: var(--surface);
  color: var(--ink);
}

input::placeholder {
  color: var(--muted-ink);
}

button {
  width: auto;
  cursor: pointer;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
  color: white;
  font-weight: 600;
}

button.ghost {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}

button.danger {
  background: var(--danger-soft-bg);
  color: var(--danger);
  border: 1px solid var(--danger-soft-border);
}

.logout-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 140px;
  padding: 10px 14px;
  font-size: 0.95rem;
  font-weight: 700;
  border: 1px solid var(--danger-strong-border);
  background: linear-gradient(135deg, var(--danger-strong-start), var(--danger-strong-end));
  color: var(--surface);
  box-shadow: 0 4px 14px var(--shadow-danger);
}

.logout-btn:hover {
  filter: brightness(1.03);
}

.logout-btn .logout-icon {
  font-size: 1.05rem;
  line-height: 1;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th, td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.table-wrap table {
  border-collapse: separate;
  border-spacing: 0;
}

.table-wrap thead th {
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}

.table-wrap tbody td,
.table-wrap tbody th {
  background: var(--surface);
  border-bottom: 1px solid var(--row-border);
}

.table-wrap tbody tr:nth-child(even) td,
.table-wrap tbody tr:nth-child(even) th {
  background: var(--surface-muted);
}

.table-wrap tbody tr:last-child td,
.table-wrap tbody tr:last-child th {
  border-bottom: 0;
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.row > * {
  flex: 1 1 220px;
}

.row.spread {
  justify-content: space-between;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-title {
  margin-top: 6px;
  margin-bottom: 4px;
  font-size: 1.05rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}

.muted {
  color: var(--muted-ink);
  font-size: 0.9rem;
}

.help-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 700;
  cursor: help;
  margin-left: 6px;
  vertical-align: middle;
}

.duration-input {
  max-width: 180px;
}

.metric-sub {
  display: block;
  color: var(--muted-ink);
  font-size: 0.82rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
}

.checkbox-row input[type="checkbox"] {
  width: auto;
}

.record-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}

.record-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 190px;
  padding: 12px 18px;
  font-size: 1.02rem;
}

.record-btn.is-recording {
  background: linear-gradient(135deg, var(--record-danger-start), var(--record-danger-end));
}

.record-btn-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--record-dot-idle);
  flex: 0 0 auto;
}

.record-btn-dot.is-recording {
  background: var(--record-danger-start);
  border: 1px solid var(--record-dot-border);
  animation: record-pulse 1s ease-in-out infinite;
}

@keyframes record-pulse {
  0% { box-shadow: 0 0 0 0 var(--record-pulse); }
  70% { box-shadow: 0 0 0 8px rgba(0, 0, 0, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0); }
}

.record-tools-popover {
  position: relative;
}

.record-tools-popover > summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink-soft);
  font-weight: 600;
  padding: 10px 12px;
}

.record-tools-popover > summary::-webkit-details-marker {
  display: none;
}

.record-tools-popover[open] > summary {
  border-style: solid;
}

.record-tools-grid {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 20;
  min-width: 240px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 22px var(--shadow-popover);
  padding: 10px 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.record-tools-grid .checkbox-row {
  width: 100%;
}

.upload-audio-btn {
  min-width: 130px;
}

.record-inline-status {
  white-space: nowrap;
}

.recording-preview-widget {
  margin-left: auto;
  min-width: 270px;
  width: clamp(270px, 32vw, 420px);
}

@media (max-width: 720px) {
  .record-row {
    flex-wrap: wrap;
  }

  .recording-preview-widget {
    margin-left: 0;
    width: 100%;
    min-width: 220px;
  }

  .record-tools-grid {
    position: static;
    margin-top: 8px;
    box-shadow: none;
  }
}

.status-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 12px;
}

.status-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.status-card h3 {
  margin-bottom: 4px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
}

.status-card p {
  margin: 0;
  font-weight: 700;
  font-size: 1.05rem;
}

.nav-button {
  display: inline-block;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.users-table {
  table-layout: auto;
}

.users-table th,
.users-table td {
  vertical-align: middle;
}

.users-table .key-cell {
  min-width: 220px;
}

.users-table .actions-col {
  min-width: 72px;
}

.users-table .number-col {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.summary-table-wrap {
  margin-top: 8px;
}

.summary-table {
  min-width: 760px;
}

.summary-table thead th {
  text-align: right;
}

.summary-table thead th:first-child {
  text-align: left;
}

.summary-table tbody td {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.summary-table .summary-metric {
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
}

.key-inline {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: nowrap;
}

.key-inline-expanded {
  flex-direction: column;
  align-items: flex-start;
}

.key-tools {
  position: relative;
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
}

.copy-key-tooltip {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 8;
  background: var(--tooltip-bg);
  color: var(--surface);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.74rem;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.copy-key-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.copy-key-tooltip.is-error {
  background: var(--tooltip-error-bg);
}

.key-display {
  display: inline-block;
  min-width: 0;
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.key-inline-expanded .key-display {
  max-width: 360px;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
  line-height: 1.2;
}

.key-cell .mono {
  font-size: 0.9rem;
  white-space: nowrap;
  display: inline-block;
  vertical-align: middle;
}

.tiny-btn {
  padding: 4px 8px;
  font-size: 0.8rem;
}

.icon-btn {
  min-width: 34px;
  text-align: center;
  padding: 4px 6px;
}

.icon-link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.actions-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.link-btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--surface);
  white-space: nowrap;
}

.active-toggle {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.86rem;
  white-space: nowrap;
}

.active-toggle.is-active {
  background: var(--active-bg);
  color: var(--active-ink);
  border-color: var(--active-border);
}

.active-toggle.is-inactive {
  background: var(--inactive-bg);
  color: var(--inactive-ink);
  border-color: var(--inactive-border);
}

.error {
  color: var(--danger);
}

.mono {
  font-family: "IBM Plex Mono", monospace;
}

pre {
  background: var(--code-bg);
  color: var(--code-ink);
  border-radius: 12px;
  padding: 12px;
  overflow: auto;
}

@media (max-width: 720px) {
  .container {
    padding: 14px;
  }
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .record-row {
    flex-wrap: wrap;
  }
}
