:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --sidebar-width: 220px;
}

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

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.portal-layout {
    display: flex;
    min-height: 100vh;
}

.portal-sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1rem 0;
    flex-shrink: 0;
}

.portal-content {
    flex: 1;
    padding: 2rem;
    max-width: 1200px;
}

.portal-nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.portal-brand {
    font-weight: 700;
    font-size: 1.1rem;
    padding: 0.5rem 1.25rem 1rem;
    color: var(--primary);
}

.portal-nav a, .portal-nav a:visited {
    display: block;
    padding: 0.5rem 1.25rem;
    color: var(--text);
    text-decoration: none;
    border-left: 3px solid transparent;
}

.portal-nav a:hover {
    background: var(--bg);
}

.portal-nav a.active {
    border-left-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
    background: #eff6ff;
}

.portal-signout {
    margin-top: auto;
    padding: 0.5rem 1.25rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    text-align: left;
    font-size: 0.9rem;
}

.portal-signout:hover { color: var(--text); }

/* Codes management */
.codes-summary { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1rem; }
.codes-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 900px) { .codes-layout { grid-template-columns: 1fr; } }
.codes-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 1rem; }
.codes-panel h2 { font-size: 1rem; margin-bottom: 0.75rem; }
.codes-search { width: 100%; padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.85rem; margin-bottom: 0.75rem; }
.codes-group { margin-bottom: 0.5rem; }
.codes-group summary { cursor: pointer; font-weight: 600; font-size: 0.85rem; padding: 0.25rem 0; }
.codes-group-list { display: flex; flex-direction: column; gap: 0.25rem; padding: 0.5rem 0; }
.codes-item { display: flex; justify-content: space-between; align-items: center; padding: 0.25rem 0.5rem; font-size: 0.8rem; border-radius: 4px; }
.codes-item:hover { background: #f1f5f9; }
.codes-item--active { opacity: 0.5; }
.codes-active-badge { font-size: 0.7rem; color: var(--text-muted); }

/* Workbench */
.workbench-filters { display: flex; gap: 0.25rem; margin-bottom: 1rem; }
.filter-tab { padding: 0.4rem 0.8rem; background: none; border: 1px solid var(--border); border-radius: 4px; font-size: 0.8rem; cursor: pointer; }
.filter-tab--active { background: var(--primary); color: white; border-color: var(--primary); }
.workbench-summary { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.workbench-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.workbench-table th { font-size: 0.75rem; text-transform: uppercase; color: var(--text-muted); font-weight: 600; }
.workbench-table td, .workbench-table th { padding: 0.5rem 0.5rem; border-bottom: 1px solid var(--border); text-align: left; }
.workbench-table tr:hover { background: #f8fafc; }
.actions-cell { white-space: nowrap; display: flex; gap: 0.25rem; }
.verification-num { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; }

/* Status badges (shared with user app) */
.status { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 1rem; font-size: 0.7rem; font-weight: 600; text-transform: capitalize; }
.status.pending { background: #fef3c7; color: #92400e; }
.status.processing { background: #dbeafe; color: #1e40af; }
.status.completed { background: #d1fae5; color: #065f46; }
.status.failed { background: #fee2e2; color: #991b1b; }
.status.rejected { background: #fecaca; color: #7f1d1d; }
.status.approved { background: #d1fae5; color: #065f46; font-weight: 700; }
.status.retakerequested { background: #fef3c7; color: #92400e; }

.confidence-badge { display: inline-block; padding: 0.05rem 0.35rem; border-radius: 1rem; font-size: 0.65rem; font-weight: 600; }
.confidence-high { background: #d1fae5; color: #065f46; }
.confidence-medium { background: #fef3c7; color: #92400e; }
.confidence-low { background: #fee2e2; color: #991b1b; }

/* Buttons */
.btn-small { font-size: 0.7rem; padding: 0.2rem 0.5rem; border-radius: 4px; cursor: pointer; border: none; }
.btn-primary { background: var(--primary); color: white; border: none; border-radius: 6px; cursor: pointer; padding: 0.5rem 1rem; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; padding: 0.5rem 1rem; }
.btn-danger { background: #fee2e2; color: #991b1b; }
.btn-danger:hover { background: #fecaca; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-box { background: var(--surface); border-radius: 8px; padding: 1.5rem; width: min(400px, 90vw); box-shadow: 0 10px 25px rgba(0,0,0,0.15); }
.modal-box h3 { margin-bottom: 0.75rem; }
.modal-box textarea { width: 100%; padding: 0.5rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.85rem; resize: vertical; }
.modal-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; }

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

/* Detail page */
.detail-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.5rem; }
.detail-header h1 { font-size: 1.2rem; margin: 0; }
.verification-badge { background: #d1fae5; color: #065f46; padding: 0.15rem 0.5rem; border-radius: 1rem; font-size: 0.75rem; font-weight: 700; }

.detail-layout { display: grid; grid-template-columns: 300px 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 800px) { .detail-layout { grid-template-columns: 1fr; } }
.detail-image img { width: 100%; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; }
.detail-data { display: flex; flex-direction: column; gap: 1rem; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.detail-field { display: flex; flex-direction: column; gap: 0.15rem; }
.detail-field label { font-size: 0.7rem; text-transform: uppercase; color: var(--text-muted); font-weight: 600; }
.detail-field span { font-size: 0.9rem; }

.detail-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

.banner { padding: 0.5rem 0.75rem; border-radius: 6px; font-size: 0.85rem; margin-bottom: 0.5rem; }
.banner--warning { background: #fef3c7; color: #92400e; border-left: 3px solid #f59e0b; }

.conflicts-section { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 0.75rem; }
.conflicts-section h3 { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.conflict-row { display: flex; gap: 0.5rem; align-items: center; font-size: 0.8rem; padding: 0.2rem 0; }
.conflict-field { font-weight: 600; min-width: 80px; }
.conflict-canonical { color: var(--text); }
.conflict-arrow { color: var(--text-muted); font-size: 0.7rem; }
.conflict-llm { color: var(--primary); }

.reject-inline { margin-top: 0.5rem; }
.reject-inline textarea { width: 100%; padding: 0.4rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.85rem; resize: vertical; }

.audit-section { margin-top: 1rem; }
.audit-section summary { cursor: pointer; }
.audit-section h3 { font-size: 0.85rem; display: inline; }
.audit-table { width: 100%; border-collapse: collapse; font-size: 0.75rem; margin-top: 0.5rem; }
.audit-table th, .audit-table td { padding: 0.3rem 0.4rem; border-bottom: 1px solid var(--border); text-align: left; }
.audit-table th { color: var(--text-muted); text-transform: uppercase; font-size: 0.65rem; }
.audit-details { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: monospace; font-size: 0.65rem; }

.clickable { cursor: pointer; }
.clickable:hover { background: #f1f5f9; }

/* Login */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    gap: 1.5rem;
}

.login-container h1 {
    color: var(--primary);
    font-size: 1.5rem;
}

.login-container form {
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field label { font-size: 0.85rem; font-weight: 500; color: var(--text-muted); }
.field input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
}

button[type="submit"] {
    padding: 0.6rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
}

button[type="submit"]:hover { background: var(--primary-hover); }
button[type="submit"]:disabled { opacity: 0.6; cursor: not-allowed; }

.error { color: #dc2626; font-size: 0.9rem; }

/* Tables */
table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
th, td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 600; font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; }
code { font-size: 0.8rem; color: var(--text-muted); }

/* ── Mobile responsive ── */
.portal-nav-checkbox { display: none; }
.portal-nav-overlay { display: none; }
.portal-topbar { display: none; }

@media (max-width: 768px) {
    .portal-sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        bottom: 0;
        width: 260px;
        z-index: 200;
        transition: left 0.2s ease;
        box-shadow: none;
    }
    .portal-nav-checkbox:checked ~ .portal-layout .portal-sidebar {
        left: 0;
        box-shadow: 4px 0 15px rgba(0,0,0,0.15);
    }
    .portal-nav-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.3);
        z-index: 199;
    }
    .portal-nav-checkbox:checked ~ .portal-layout .portal-nav-overlay {
        display: block;
    }
    .portal-topbar {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }
    .portal-hamburger {
        cursor: pointer;
        display: flex;
        align-items: center;
        padding: 0.25rem;
        color: var(--text);
    }
    .portal-topbar-title {
        font-weight: 700;
        font-size: 1.1rem;
        color: var(--primary);
    }
    .portal-content {
        padding: 1rem;
        max-width: 100%;
    }
    .portal-brand { display: none; }

    /* Tables scroll horizontally */
    .workbench-table, .audit-table, table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Touch-friendly buttons */
    .btn-primary, .btn-secondary, .btn-danger, button[type="submit"] {
        min-height: 44px;
        font-size: 0.9rem;
    }
    .btn-small { min-height: 36px; font-size: 0.8rem; padding: 0.3rem 0.6rem; }

    /* Filter tabs wrap */
    .workbench-filters { flex-wrap: wrap; }
    .filter-tab { min-height: 36px; }

    /* Detail page single column */
    .detail-layout { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .detail-header { flex-wrap: wrap; }

    /* Login form */
    .login-container form { width: min(320px, 90vw); }

    /* Codes layout */
    .codes-layout { grid-template-columns: 1fr; }

    /* Actions stack */
    .detail-actions { flex-wrap: wrap; }
    .actions-cell { flex-wrap: wrap; }
}
