* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #0f1419;
    color: #e6e6e6;
    height: 100vh;
}
.hidden { display: none !important; }
.muted { color: #888; font-size: 0.85em; }
.error { color: #ff6b6b; margin-top: 8px; min-height: 1em; }

/* Login */
.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}
.login-card {
    background: #1a2028;
    padding: 32px 28px;
    border-radius: 12px;
    width: 360px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card .subtitle { margin: 4px 0 24px; color: #8aa; }
.login-card label {
    display: block;
    margin-bottom: 14px;
    font-size: 13px;
    color: #aab;
}
.login-card input[type="email"],
.login-card input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    margin-top: 4px;
    background: #0f1419;
    border: 1px solid #2a3340;
    color: #e6e6e6;
    border-radius: 6px;
    font-size: 14px;
}
.login-card .remember {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 16px 0;
}
.login-card .remember input { margin: 0; }
.login-card button {
    width: 100%;
    padding: 11px;
    background: #2f7be8;
    border: 0;
    color: white;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}
.login-card button:hover { background: #246fd8; }

/* App */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: #1a2028;
    border-bottom: 1px solid #232c38;
}
.brand { font-weight: 600; }
.brand .muted { margin-left: 8px; }
.topbar-right { display: flex; gap: 8px; }
button.ghost {
    background: transparent;
    color: #aab;
    border: 1px solid #2a3340;
    padding: 7px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
button.ghost:hover { background: #232c38; color: #e6e6e6; }

.tabs {
    display: flex;
    background: #131820;
    border-bottom: 1px solid #232c38;
    padding: 0 20px;
}
.tab {
    background: transparent;
    color: #8a96a8;
    border: none;
    padding: 12px 18px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 2px solid transparent;
}
.tab.active { color: #e6e6e6; border-bottom-color: #2f7be8; }
.tab:hover { color: #cfd6e0; }

.layout {
    display: grid;
    /* Detail pane carries three detector cards side-by-side now, so it needs a much
       wider column. minmax keeps the list pane usable on narrower screens. */
    grid-template-columns: minmax(420px, 1fr) minmax(720px, 55%);
    flex: 1;
    overflow: hidden;
}
.list-pane {
    border-right: 1px solid #232c38;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.list-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 12px 16px;
    border-bottom: 1px solid #232c38;
    font-weight: 600;
}
.list-toolbar {
    padding: 10px 16px;
    border-bottom: 1px solid #232c38;
    background: #131820;
}
.list-toolbar input[type="search"] {
    width: 100%;
    padding: 7px 10px;
    background: #0f1419;
    border: 1px solid #2a3340;
    color: #e6e6e6;
    border-radius: 5px;
    font-size: 13px;
}
.table-wrap { overflow: auto; flex: 1; }
table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
table.data-table thead th {
    position: sticky;
    top: 0;
    background: #1a2028;
    color: #aab;
    text-align: left;
    padding: 9px 12px;
    border-bottom: 1px solid #232c38;
    user-select: none;
    cursor: pointer;
    font-weight: 600;
    white-space: nowrap;
}
table.data-table thead th:hover { color: #e6e6e6; }
table.data-table thead th .arrow {
    display: inline-block;
    margin-left: 4px;
    color: #2f7be8;
    font-size: 10px;
}
table.data-table tbody td {
    padding: 9px 12px;
    border-bottom: 1px solid #1d242e;
    color: #d4d8df;
    white-space: nowrap;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}
table.data-table tbody tr { cursor: pointer; }
table.data-table tbody tr:hover { background: #1a2028; }
table.data-table tbody tr.selected { background: #1f2a3a; }
table.data-table tbody tr.selected td:first-child { border-left: 3px solid #2f7be8; padding-left: 9px; }
.empty-row td {
    text-align: center;
    color: #555;
    padding: 24px;
}
.badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 6px;
}
.badge.ok { background: #1b5e20; color: #c8e6c9; }
.badge.fail { background: #b71c1c; color: #ffcdd2; }
.badge.warn { background: #ef6c00; color: #ffe0b2; }

.status-pills {
    margin: -8px 0 12px;
}
.status-pills .badge:first-child {
    margin-left: 0;
}

.detail-pane { overflow-y: auto; padding: 24px; }
.detail-pane .empty { color: #555; text-align: center; margin-top: 100px; }
.detail-pane h2 { margin-top: 0; font-size: 18px; }
.detail-pane img {
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid #232c38;
    background: #000;
}
.detail-row {
    display: grid;
    grid-template-columns: 160px 1fr;
    padding: 6px 0;
    border-bottom: 1px solid #1d242e;
    font-size: 13px;
}
.detail-row .key { color: #8a96a8; }
.detail-row .val { color: #e6e6e6; word-break: break-word; white-space: pre-wrap; }
pre.raw {
    background: #0a0e13;
    border: 1px solid #232c38;
    padding: 12px;
    border-radius: 6px;
    font-size: 12px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}
.actions { margin: 16px 0; display: flex; gap: 8px; }
.actions button {
    background: #2f7be8;
    color: white;
    border: 0;
    padding: 9px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
.actions button:hover { background: #246fd8; }
.actions button:disabled { background: #444; cursor: not-allowed; }
.resubmit-result {
    background: #0a0e13;
    border: 1px solid #2f7be8;
    padding: 12px;
    border-radius: 6px;
    margin: 12px 0;
}
section.detail-section { margin-bottom: 24px; }
section.detail-section h3 {
    margin: 0 0 8px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #8a96a8;
}

/* Three-up detector comparison grid (Roboflow / BEiT / CarDD-seg). Falls back to a
   single column below 1100 px to stay readable on narrower screens. */
.detector-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 24px;
}
@media (max-width: 1100px) {
    .detector-grid { grid-template-columns: 1fr; }
}
.detector-card {
    background: #0a0e13;
    border: 1px solid #232c38;
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.detector-card h4 {
    margin: 0 0 8px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #8a96a8;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.detector-card .verdict { font-size: 11px; }
.detector-card .body {
    font-size: 12px;
    color: #cfd6e0;
    white-space: pre-wrap;
    word-break: break-word;
    flex: 1;
    overflow-y: auto;
    max-height: 240px;
}
.detector-card .meta {
    margin-top: 8px;
    font-size: 11px;
    color: #6c7785;
}
.detector-card .scores {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: 4px;
}
.detector-card .score-row {
    display: grid;
    grid-template-columns: 90px 1fr 50px;
    align-items: center;
    gap: 6px;
    font-size: 11px;
}
.detector-card .score-bar {
    height: 6px;
    background: #1d242e;
    border-radius: 3px;
    overflow: hidden;
}
.detector-card .score-bar > div {
    height: 100%;
    background: #2f7be8;
}
.vote-summary {
    background: #131b25;
    border: 1px solid #2a3340;
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 24px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}
.vote-summary .vote-final {
    margin-left: auto;
    font-weight: 600;
}
.vote-summary .vote-yes { color: #c8e6c9; }
.vote-summary .vote-no { color: #ffcdd2; }
.vote-summary .vote-unknown { color: #6c7785; }

/* ---- M1c labeling page ---- */
.label-main {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
}
.label-progress { height: 4px; background: #1d242e; }
.label-progress > #progress-bar { height: 100%; width: 0; background: #2f7be8; transition: width 0.2s; }
.label-stage {
    width: 100%;
    max-width: 900px;
    height: 60vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    border: 1px solid #232c38;
    border-radius: 8px;
    overflow: hidden;
}
.label-stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.label-meta { margin: 10px 0 4px; }
.label-actions { display: flex; gap: 12px; margin: 12px 0; flex-wrap: wrap; justify-content: center; }
.lbl-btn {
    min-width: 150px;
    padding: 14px 20px;
    border-radius: 8px;
    border: 1px solid #2a3340;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    color: #e6e6e6;
    background: #1a2028;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.lbl-btn:hover { filter: brightness(1.15); }
.lbl-btn.clean { background: #1b5e20; border-color: #2e7d32; color: #c8e6c9; }
.lbl-btn.damage { background: #b71c1c; border-color: #c62828; color: #ffcdd2; }
.lbl-btn.unsure { background: #37474f; border-color: #455a64; color: #cfd8dc; }
.lbl-btn.ignore { background: #2a2f36; border-color: #3a4250; color: #9aa4b2; }
.lbl-btn.chosen { outline: 3px solid #2f7be8; outline-offset: 2px; }
.lbl-btn kbd, .label-hint kbd {
    background: rgba(0,0,0,0.35);
    border-radius: 4px;
    padding: 1px 7px;
    font-size: 12px;
    font-family: inherit;
    border: 1px solid rgba(255,255,255,0.15);
}
.label-nav { display: flex; gap: 10px; align-items: center; margin: 6px 0; width: 100%; max-width: 900px; justify-content: center; }
.label-nav input {
    flex: 1;
    max-width: 420px;
    padding: 9px 12px;
    background: #0f1419;
    border: 1px solid #2a3340;
    color: #e6e6e6;
    border-radius: 6px;
    font-size: 13px;
}
.label-hint { margin-top: 8px; }
.label-build { text-align: center; margin-top: 80px; }
.label-build button {
    background: #2f7be8;
    color: #fff;
    border: 0;
    padding: 12px 22px;
    border-radius: 8px;
    font-size: 15px;
    cursor: pointer;
}
