:root {
    --primary: #1a4f72;
    --primary-dark: #123450;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #1e293b;
    --muted: #64748b;
    --safe: #15803d;
    --safe-bg: #dcfce7;
    --warn: #b45309;
    --warn-bg: #fef3c7;
    --danger: #b91c1c;
    --danger-bg: #fee2e2;
    --accent: #ea580c;
    --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Poppins', sans-serif;
    background: var(--bg);
    color: var(--text);
    padding: 12px;
    display: flex;
    justify-content: center;
}

.app-container {
    width: 100%;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.app-header {
    text-align: center;
    padding: 8px 0;
}

.app-header h1 {
    font-size: 1.7rem;
    font-weight: 800;
    color: var(--primary);
}

.lab-badge {
    font-size: 0.72rem;
    background: #7c3aed;
    color: #fff;
    padding: 3px 8px;
    border-radius: 6px;
    vertical-align: middle;
    margin-left: 6px;
}

.subtitle {
    font-size: 0.78rem;
    color: var(--muted);
    font-weight: 600;
    margin-top: 2px;
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.05);
}

.card-header h2 {
    font-size: 1rem;
    color: var(--primary);
    margin-bottom: 12px;
}

.row-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.row-between h2 { margin-bottom: 0; }

.viewport {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 12px;
    border: 2px solid var(--primary);
}

#reader, #reader video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

#reader__dashboard, #reader__header_message { display: none !important; }

.controls-row {
    display: flex;
    gap: 8px;
}

.controls-row .btn-primary { flex: 1; }

.btn {
    font-family: inherit;
    font-weight: 700;
    font-size: 0.88rem;
    padding: 11px 16px;
    border: none;
    border-radius: 25px;
    cursor: pointer;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary.is-stopping { background: var(--danger); }
.btn-secondary { background: #334155; color: #fff; }
.btn-secondary.is-on { background: #d97706; }

.search-area { margin-top: 14px; }

.input-group {
    display: flex;
    gap: 8px;
}

.input-group input {
    flex: 1;
    padding: 11px 14px;
    border-radius: 25px;
    border: 2px solid #cbd5e1;
    font-family: inherit;
    font-size: 0.86rem;
    outline: none;
}

.input-group input:focus { border-color: var(--primary); }

.chips-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.chip {
    background: #e2e8f0;
    border: none;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
}

.chip:hover { background: #cbd5e1; }

.hidden { display: none !important; }

.badges-line {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.pill {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 999px;
}

.pill-source { background: #e0f2fe; color: #0369a1; }
.pill-full { background: #dcfce7; color: #15803d; }
.pill-partial { background: #fef3c7; color: #b45309; }
.pill-custom { background: #ede9fe; color: #6d28d9; }

.banner {
    padding: 12px;
    border-radius: 10px;
    font-weight: 800;
    font-size: 0.92rem;
    text-align: center;
    margin-bottom: 12px;
}

.banner-safe { background: var(--safe-bg); color: var(--safe); }
.banner-warn { background: var(--warn-bg); color: var(--warn); }
.banner-danger { background: var(--danger-bg); color: var(--danger); }

.product-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
}

.product-sub {
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 12px;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.metric-card {
    background: #fff7ed;
    border: 1.5px solid #fdba74;
    border-radius: 12px;
    padding: 10px 8px;
    text-align: center;
}

.metric-label {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
}

.metric-value {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--accent);
    margin-top: 2px;
}

.metric-sub {
    font-size: 0.68rem;
    color: var(--muted);
}

.portion-box {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #f8fafc;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    margin-bottom: 12px;
}

.portion-box input,
.portion-box select {
    padding: 6px 10px;
    border-radius: 14px;
    border: 2px solid #cbd5e1;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.9rem;
    background: #fff;
}

.portion-box input { width: 84px; text-align: center; }

.detail-block {
    border-top: 1px dashed #cbd5e1;
    padding-top: 10px;
    margin-top: 10px;
    font-size: 0.8rem;
    line-height: 1.45;
}

.detail-block h4 {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--primary);
    margin-bottom: 4px;
}

.raw-text {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 0.78rem;
    color: #334155;
    word-break: break-word;
}

.custom-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
    background: #f8fafc;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid #cbd5e1;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-align: left;
}

.form-field label {
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--primary);
}

.form-field input,
.form-field textarea {
    padding: 8px 10px;
    border-radius: 10px;
    border: 1.5px solid #cbd5e1;
    font-family: inherit;
    font-size: 0.84rem;
    background: #fff;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 9px 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    cursor: pointer;
}

.history-item:hover { border-color: var(--primary); }

.history-name {
    font-size: 0.84rem;
    font-weight: 700;
    color: var(--primary);
}

.history-meta {
    font-size: 0.7rem;
    color: var(--muted);
}

.history-parts {
    font-weight: 800;
    color: var(--accent);
    font-size: 0.92rem;
    white-space: nowrap;
}

.btn-link-danger {
    background: none;
    border: none;
    color: var(--danger);
    font-weight: 700;
    font-size: 0.78rem;
    cursor: pointer;
    text-decoration: underline;
}

.app-footer {
    text-align: center;
    font-size: 0.74rem;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.app-footer .small { font-size: 0.68rem; }

@media (max-width: 480px) {
    .metrics-grid { grid-template-columns: 1fr; }
    .input-group { flex-direction: column; }
}
