:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #eef5f7;
  --ink: #172033;
  --muted: #64748b;
  --line: #d8e0ea;
  --blue: #2563eb;
  --cyan: #0891b2;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --violet: #7c3aed;
  --shadow: 0 12px 28px rgba(15, 23, 42, .08);
  --radius: 8px;
  --font: 'Prompt', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.55;
}

a { color: inherit; text-decoration: none; }

button,
input,
select {
  font: inherit;
}

.hidden { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 60px;
  padding: 10px clamp(16px, 4vw, 36px);
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  font-weight: 800;
  color: #0f766e;
  white-space: nowrap;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topnav a,
.topnav-button,
.toolbar button,
.login-form button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
}

.topnav a:hover,
.topnav-button:hover,
.toolbar button:hover {
  border-color: var(--cyan);
  color: #0f766e;
}

.admin-shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.auth-panel,
.access-panel,
.panel,
.metric-card,
.identity-strip {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-panel,
.access-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, .85fr);
  gap: 28px;
  align-items: start;
  padding: clamp(20px, 4vw, 34px);
}

.eyebrow {
  margin: 0 0 6px;
  color: #0f766e;
  font-size: .78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(1.45rem, 2.7vw, 2.15rem);
  line-height: 1.25;
}

h2 {
  margin-bottom: 2px;
  font-size: 1rem;
  line-height: 1.3;
}

.auth-copy,
.dashboard-subtitle,
.panel-head p,
.state-message {
  color: var(--muted);
  font-size: .92rem;
}

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

.login-form label,
.range-control {
  display: grid;
  gap: 6px;
}

.login-form span,
.range-control span {
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
}

.login-form input,
.range-control select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 9px 11px;
}

.login-form input:focus,
.range-control select:focus {
  outline: 3px solid rgba(8, 145, 178, .15);
  border-color: var(--cyan);
}

.login-form button {
  background: #0f766e;
  border-color: #0f766e;
  color: #fff;
}

.login-form button:disabled,
.toolbar button:disabled {
  opacity: .6;
  cursor: wait;
}

.state-message {
  grid-column: 1 / -1;
  margin: 0;
}

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

.dashboard {
  display: grid;
  gap: 16px;
}

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

.toolbar {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar button:last-child {
  background: #172033;
  border-color: #172033;
  color: #fff;
}

.identity-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  color: var(--muted);
  font-size: .9rem;
}

.identity-strip strong {
  color: var(--ink);
}

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

.metric-card {
  padding: 14px;
  min-height: 118px;
  display: grid;
  gap: 8px;
  align-content: space-between;
}

.metric-card .label {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 700;
}

.metric-card .value {
  font-size: clamp(1.35rem, 2vw, 1.9rem);
  font-weight: 800;
  line-height: 1.1;
}

.metric-card .note {
  color: var(--muted);
  font-size: .78rem;
  overflow-wrap: anywhere;
}

.metric-card[data-tone="blue"] { border-top: 4px solid var(--blue); }
.metric-card[data-tone="green"] { border-top: 4px solid var(--green); }
.metric-card[data-tone="cyan"] { border-top: 4px solid var(--cyan); }
.metric-card[data-tone="amber"] { border-top: 4px solid var(--amber); }
.metric-card[data-tone="red"] { border-top: 4px solid var(--red); }
.metric-card[data-tone="violet"] { border-top: 4px solid var(--violet); }

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

.panel {
  padding: 16px;
  min-width: 0;
}

.panel-wide {
  grid-column: span 2;
}

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

.chart-box {
  min-height: 285px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fff 0%, #f8fbfc 100%);
  overflow: hidden;
}

.trend-svg {
  display: block;
  width: 100%;
  min-height: 285px;
}

.axis-label,
.point-label {
  fill: var(--muted);
  font-size: 10px;
}

.donut-wrap {
  display: grid;
  gap: 14px;
  justify-items: center;
  align-content: start;
  min-height: 285px;
}

.donut {
  width: min(210px, 70vw);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
}

.donut-core {
  width: 58%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #fff;
  display: grid;
  place-items: center;
  text-align: center;
  box-shadow: inset 0 0 0 1px var(--line);
}

.donut-core strong {
  display: block;
  font-size: 1.45rem;
}

.legend,
.bar-list,
.event-list {
  display: grid;
  gap: 10px;
}

.legend-item {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  color: var(--muted);
  font-size: .82rem;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) minmax(120px, 2fr) auto;
  align-items: center;
  gap: 10px;
  font-size: .82rem;
}

.bar-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
  font-weight: 700;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: #e6edf3;
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  min-width: 2px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--green));
}

.bar-value {
  color: var(--muted);
  font-weight: 800;
}

.empty {
  color: var(--muted);
  font-size: .86rem;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
}

.table-panel {
  padding-bottom: 10px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 840px;
  border-collapse: collapse;
  background: #fff;
}

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

th {
  color: var(--muted);
  background: #f8fafc;
  font-size: .78rem;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

td strong,
td small {
  display: block;
}

td small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #e6edf3;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.completed { background: #dcfce7; color: #166534; }
.status-pill.failed { background: #fee2e2; color: #991b1b; }
.status-pill.packaging,
.status-pill.generating_html,
.status-pill.parsing_vtt,
.status-pill.fetching_subtitle,
.status-pill.fetching_metadata,
.status-pill.pending { background: #dbeafe; color: #1d4ed8; }

.job-title {
  max-width: 360px;
}

.event-item {
  display: grid;
  grid-template-columns: minmax(120px, .8fr) minmax(160px, 1fr) minmax(140px, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdff;
  font-size: .82rem;
}

.event-item strong {
  display: block;
}

.event-item span,
.event-item small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

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

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

@media (max-width: 820px) {
  .admin-shell {
    width: min(100vw - 20px, 760px);
    padding-top: 14px;
  }

  .auth-panel,
  .access-panel,
  .dashboard-head,
  .identity-strip {
    display: grid;
    grid-template-columns: 1fr;
  }

  .toolbar {
    justify-content: stretch;
  }

  .toolbar > * {
    flex: 1 1 150px;
  }

  .metric-grid,
  .chart-grid {
    grid-template-columns: 1fr;
  }

  .panel-wide {
    grid-column: auto;
  }

  .event-item {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topnav {
    justify-content: flex-start;
  }

  .bar-row {
    grid-template-columns: 1fr auto;
  }

  .bar-track {
    grid-column: 1 / -1;
  }
}
