/* ── Reset & base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --blue:     #2563eb;
    --blue-lt:  #eff6ff;
    --green:    #16a34a;
    --green-lt: #f0fdf4;
    --red:      #dc2626;
    --red-lt:   #fef2f2;
    --gray-1:   #f9fafb;
    --gray-2:   #f3f4f6;
    --gray-3:   #e5e7eb;
    --gray-5:   #6b7280;
    --gray-9:   #111827;
    --radius:   10px;
    --shadow:   0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.06);
    --font:     -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html { font-size: 16px; }
body {
    font-family: var(--font);
    color: var(--gray-9);
    background: var(--gray-1);
    min-height: 100dvh;
    padding: 0;
}

/* ── Layout ─────────────────────────────────────────────────────────── */
.container {
    max-width: 640px;
    margin: 0 auto;
    padding: 24px 16px 64px;
}

.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px 24px;
    margin-bottom: 16px;
}

/* ── Progress bar ───────────────────────────────────────────────────── */
.progress-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
}

.progress-bar .seg {
    height: 4px;
    flex: 1;
    border-radius: 2px;
    background: var(--gray-3);
    transition: background .3s;
}
.progress-bar .seg.done  { background: var(--blue); }
.progress-bar .seg.active { background: var(--blue); opacity: .5; }

.step-label {
    font-size: 13px;
    color: var(--gray-5);
    margin-bottom: 20px;
    font-weight: 500;
    letter-spacing: .02em;
    text-transform: uppercase;
}

/* ── Typography ─────────────────────────────────────────────────────── */
h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; }
h2 { font-size: 1.2rem; font-weight: 600; margin-bottom: 12px; }
p  { font-size: .95rem; color: var(--gray-5); line-height: 1.6; margin-bottom: 12px; }
p:last-child { margin-bottom: 0; }
a  { color: var(--blue); }

/* ── Form ───────────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field label {
    display: block;
    font-size: .85rem;
    font-weight: 600;
    margin-bottom: 6px;
}
.field input, .field select {
    width: 100%;
    border: 1.5px solid var(--gray-3);
    border-radius: 6px;
    padding: 10px 12px;
    font-size: .95rem;
    font-family: var(--font);
    color: var(--gray-9);
    outline: none;
    transition: border-color .2s;
    background: #fff;
}
.field input:focus, .field select:focus {
    border-color: var(--blue);
}

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    border-radius: 8px;
    padding: 12px 20px;
    font-size: .95rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: opacity .15s, transform .1s;
    text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { opacity: .9; }

.btn-secondary {
    background: var(--gray-2);
    color: var(--gray-9);
    border: 1.5px solid var(--gray-3);
}
.btn-secondary:hover:not(:disabled) { background: var(--gray-3); }

.btn-red { background: var(--red); color: #fff; }
.btn-red:hover:not(:disabled) { opacity: .9; }

.btn-full { width: 100%; justify-content: center; }

.btn-row {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

/* ── Recording UI ───────────────────────────────────────────────────── */
.recorder-box {
    border: 2px dashed var(--gray-3);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    transition: border-color .2s;
}
.recorder-box.recording { border-color: var(--red); background: var(--red-lt); }
.recorder-box.done      { border-color: var(--green); background: var(--green-lt); }

.level-meter {
    height: 8px;
    background: var(--gray-2);
    border-radius: 4px;
    overflow: hidden;
    margin: 14px 0;
}
.level-meter-bar {
    height: 100%;
    width: 0%;
    background: var(--green);
    border-radius: 4px;
    transition: width .05s;
}
.level-meter-bar.clipping { background: var(--red); }

.timer {
    font-size: 1.8rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--gray-9);
    margin: 8px 0;
}

.qc-results { margin-top: 14px; text-align: left; }
.qc-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .88rem;
    padding: 4px 0;
}
.qc-item.pass { color: var(--green); }
.qc-item.fail { color: var(--red); }

/* ── Script display ─────────────────────────────────────────────────── */
.script-box {
    background: var(--gray-1);
    border: 1.5px solid var(--gray-3);
    border-radius: 8px;
    padding: 16px 18px;
    font-size: .95rem;
    line-height: 1.7;
    color: var(--gray-9);
    margin-bottom: 16px;
    font-style: italic;
}

/* ── Test sentence progress ─────────────────────────────────────────── */
.sentence-progress {
    font-size: .85rem;
    color: var(--gray-5);
    font-weight: 600;
    margin-bottom: 12px;
}

.sentence-dots {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--gray-3);
}
.dot.done { background: var(--green); }
.dot.active { background: var(--blue); }

/* ── Consent ────────────────────────────────────────────────────────── */
.consent-box {
    background: var(--blue-lt);
    border: 1.5px solid #bfdbfe;
    border-radius: 8px;
    padding: 16px;
    margin: 20px 0;
}
.consent-box label {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    font-size: .88rem;
    line-height: 1.6;
    cursor: pointer;
}
.consent-box input[type=checkbox] {
    margin-top: 3px;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    accent-color: var(--blue);
}

/* ── Status page ────────────────────────────────────────────────────── */
.status-state {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 8px;
}
.state-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: .85rem;
    font-weight: 600;
    background: var(--gray-2);
}
.state-badge.delivered { background: var(--green-lt); color: var(--green); }
.state-badge.failed, .state-badge.needs_rerecord { background: var(--red-lt); color: var(--red); }
.state-badge.training, .state-badge.evaluating, .state-badge.packaging { background: var(--blue-lt); color: var(--blue); }

.pipeline-steps { margin-top: 20px; }
.pipeline-step {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-2);
    font-size: .9rem;
}
.pipeline-step:last-child { border-bottom: none; }
.step-icon { font-size: 1.1rem; width: 24px; text-align: center; }

.wer-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
    margin-top: 12px;
}
.wer-table td { padding: 6px 0; }
.wer-table td:last-child { text-align: right; font-weight: 600; }

/* ── Alert ──────────────────────────────────────────────────────────── */
.alert {
    border-radius: 8px;
    padding: 14px 16px;
    font-size: .9rem;
    margin-bottom: 16px;
    line-height: 1.5;
}
.alert-red   { background: var(--red-lt);   color: var(--red);   border: 1px solid #fecaca; }
.alert-green { background: var(--green-lt); color: var(--green); border: 1px solid #bbf7d0; }
.alert-blue  { background: var(--blue-lt);  color: var(--blue);  border: 1px solid #bfdbfe; }

/* ── Loading spinner ────────────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 18px; height: 18px;
    border: 2.5px solid rgba(255,255,255,.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utility ────────────────────────────────────────────────────────── */
.hidden  { display: none !important; }
.mt-8    { margin-top: 8px; }
.mt-16   { margin-top: 16px; }
.text-sm { font-size: .85rem; color: var(--gray-5); }
