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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f172a;
    color: #e2e8f0;
    min-height: 100vh;
}

header {
    background: #1e293b;
    border-bottom: 1px solid #334155;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 { font-size: 20px; font-weight: 600; color: #f8fafc; }
header .device-name { font-weight: 400; color: #94a3b8; margin-left: 8px; }

.header-center {
    display: flex; align-items: center; gap: 12px;
    flex: 1; justify-content: center;
}
.hdr-label { font-size: 12px; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.5px; }
.header-center select {
    padding: 6px 10px; border: 1px solid #475569; border-radius: 6px;
    background: #0f172a; color: #f8fafc; font-size: 13px; min-width: 140px;
}
.hdr-nav { display: flex; gap: 4px; margin-left: 16px; }
.nav-btn {
    padding: 6px 14px; border: 1px solid #475569; border-radius: 6px;
    background: transparent; color: #94a3b8; font-size: 12px; cursor: pointer;
}
.nav-btn.active { background: #3b82f6; border-color: #3b82f6; color: #fff; }
.nav-btn:hover:not(.active) { background: #334155; }

.header-right { display: flex; align-items: center; gap: 16px; }

.user-chip {
    display: flex; align-items: center; gap: 10px;
    background: #0f172a; border: 1px solid #334155;
    padding: 6px 12px; border-radius: 8px; font-size: 13px;
}
.user-role {
    background: #334155; color: #cbd5e1; font-size: 11px;
    text-transform: uppercase; padding: 2px 8px; border-radius: 10px;
    letter-spacing: 0.5px;
}
.btn-link {
    background: none; border: none; color: #60a5fa;
    font-size: 13px; cursor: pointer; padding: 0;
}
.btn-link:hover { text-decoration: underline; }
.user-name-edit {
    background: #1e293b; border: 1px solid #475569; color: #e2e8f0;
    border-radius: 6px; padding: 4px 8px; font-size: 13px; width: 140px;
}

.status-badge {
    padding: 4px 12px; border-radius: 12px; font-size: 13px; font-weight: 500;
}
.status-badge.loading { background: #1e3a5f; color: #60a5fa; }
.status-badge.ready { background: #14532d; color: #4ade80; }
.status-badge.error { background: #7f1d1d; color: #fca5a5; }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }

.login-gate {
    min-height: calc(100vh - 60px);
    display: flex; align-items: center; justify-content: center;
}
.login-card {
    background: #1e293b; border: 1px solid #334155; border-radius: 12px;
    padding: 40px 48px; text-align: center; max-width: 360px;
}
.login-card h2 { font-size: 22px; margin-bottom: 8px; color: #f8fafc; }
.login-card p { color: #94a3b8; margin-bottom: 24px; font-size: 14px; }

/* Data / Control folder-style sub-tabs */
.subtab-nav {
    display: flex; gap: 6px; margin: 0 0 0 4px;
    position: relative; z-index: 1;
}
.subtab-btn {
    padding: 12px 30px;
    border: 1px solid transparent; border-bottom: none;
    border-radius: 12px 12px 0 0;
    background: transparent; color: #94a3b8;
    font-size: 18px; font-weight: 700; letter-spacing: 0.3px;
    cursor: pointer; transition: all 0.15s;
    margin-bottom: -1px; /* overlap the box's top border for a connected tab */
}
.subtab-btn:hover:not(.active) { color: #e2e8f0; background: #1e293b; }
.subtab-btn.active {
    background: #131c2e; color: #f8fafc;
    border-color: #334155;
}

/* Box framing all the pane content; folder tabs sit on its top edge */
.pane-box {
    background: #131c2e; border: 1px solid #334155;
    border-radius: 0 12px 12px 12px;
    padding: 20px 20px 4px; margin-bottom: 24px;
}
.pane-box > div > *:last-child { margin-bottom: 16px; }

.job-panel {
    background: #1e293b; border: 1px solid #334155; border-radius: 12px;
    padding: 20px 24px; margin-bottom: 24px;
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.job-panel label { font-size: 14px; color: #94a3b8; }
.job-panel input[type="number"] {
    width: 80px; padding: 8px 12px; border: 1px solid #475569; border-radius: 8px;
    background: #0f172a; color: #f8fafc; font-size: 16px; text-align: center;
}
.job-panel input[type="number"]:focus { outline: none; border-color: #3b82f6; }

.btn {
    padding: 8px 20px; border: none; border-radius: 8px;
    font-size: 14px; font-weight: 600; cursor: pointer; transition: background 0.15s;
}
.btn-primary { background: #3b82f6; color: #fff; }
.btn-primary:hover { background: #2563eb; }
.btn-primary:disabled { background: #475569; cursor: not-allowed; }
.btn-secondary { background: #334155; color: #e2e8f0; }
.btn-secondary:hover { background: #475569; }

.job-status { font-size: 13px; color: #94a3b8; margin-left: auto; }
.job-status.sent { color: #4ade80; }
.job-status.error { color: #fca5a5; }

/* Run-log ("Pull Log") viewer */
.log-meta { font-size: 12px; color: #94a3b8; margin: 8px 2px; }
.runlog-view {
    background: #0b1220; border: 1px solid #334155; border-radius: 10px;
    color: #cbd5e1; font-family: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
    font-size: 12px; line-height: 1.5; padding: 14px;
    max-height: 65vh; overflow: auto; white-space: pre-wrap; word-break: break-word;
}

.filter-panel {
    background: #1e293b; border: 1px solid #334155; border-radius: 12px;
    padding: 16px 20px; margin-bottom: 24px;
    display: flex; flex-direction: column; gap: 12px;
}
.filter-row { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label {
    font-size: 11px; color: #64748b;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.filter-group select,
.filter-group input[type="number"],
.filter-group input[type="date"] {
    padding: 7px 10px; border: 1px solid #475569; border-radius: 6px;
    background: #0f172a; color: #f8fafc; font-size: 13px;
}
.filter-group input[type="number"] { width: 80px; text-align: center; }
.filter-group input[type="date"] { width: 140px; }
.filter-group select:focus, .filter-group input:focus { outline: none; border-color: #3b82f6; }
.range-inputs { display: flex; align-items: center; gap: 6px; }
.range-sep { color: #64748b; font-size: 14px; }
.filter-actions { justify-content: flex-end; margin-left: auto; }
.btn-sm { padding: 7px 14px; font-size: 12px; }

/* Overview / Detailed / Raw — folder tabs inside the Data pane, mirroring the
   Data / Control tabs above but a shade lighter so the nested box reads. */
.data-subtab-nav {
    display: flex; gap: 6px; margin: 0 0 0 4px;
    position: relative; z-index: 1;
}
.data-subtab-btn {
    padding: 9px 24px;
    border: 1px solid transparent; border-bottom: none;
    border-radius: 10px 10px 0 0;
    background: transparent; color: #94a3b8;
    font-size: 15px; font-weight: 600; letter-spacing: 0.3px;
    cursor: pointer; transition: all 0.15s;
    margin-bottom: -1px; /* overlap the box's top border for a connected tab */
}
.data-subtab-btn:hover:not(.active) { color: #e2e8f0; background: #1b2740; }
.data-subtab-btn.active {
    background: #0f1726; color: #f8fafc;
    border-color: #334155;
}
/* Box framing the sub-pane content; folder tabs sit on its top edge. Kept a
   shade darker than the panels inside (#1e293b) so cards/charts still pop. */
.data-subpane-box {
    background: #0f1726; border: 1px solid #334155;
    border-radius: 0 10px 10px 10px;
    padding: 20px 20px 4px; margin-bottom: 24px;
}
.data-subpane-box > div > *:last-child { margin-bottom: 16px; }

.cards {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px; margin-bottom: 24px;
}
/* Overview metric groups: a labeled band of cards (Machine Data above,
   Performance Data below). The inner .cards drops its own bottom margin so the
   group's spacing controls the gap. */
.metric-group { margin-bottom: 24px; }
.metric-group-title {
    font-size: 13px; font-weight: 600; color: #94a3b8;
    text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 12px;
}
.metric-group .cards { margin-bottom: 0; }
.card {
    background: #1e293b; border: 1px solid #334155; border-radius: 12px;
    padding: 16px 20px;
}
.card .label {
    font-size: 12px; color: #64748b;
    text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px;
}
.card .value { font-size: 28px; font-weight: 700; color: #f8fafc; }
.card .value.success { color: #4ade80; }
.card .value.warning { color: #fbbf24; }

.charts {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(520px, 1fr));
    gap: 20px; margin-bottom: 24px;
}
.chart-box {
    background: #1e293b; border: 1px solid #334155; border-radius: 12px; padding: 20px;
}
.chart-box h3 { font-size: 14px; font-weight: 600; color: #cbd5e1; margin-bottom: 12px; }
.chart-box canvas { width: 100% !important; max-height: 280px; }

.empty-state { text-align: center; padding: 48px; color: #64748b; }
.empty-state p { font-size: 15px; margin-top: 8px; }

.raw-data-panel {
    background: #1e293b; border: 1px solid #334155; border-radius: 12px;
    margin-bottom: 24px; overflow: hidden;
}
.raw-data-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid #334155;
}
.raw-data-header h3 { font-size: 14px; font-weight: 600; color: #cbd5e1; }
.raw-data-tabs { display: flex; gap: 4px; }
.tab-btn {
    padding: 5px 14px; border: 1px solid #475569; border-radius: 6px;
    background: transparent; color: #94a3b8; font-size: 12px;
    cursor: pointer; transition: all 0.15s;
}
.tab-btn.active { background: #3b82f6; border-color: #3b82f6; color: #fff; }
.tab-btn:hover:not(.active) { background: #334155; }

.raw-data-body { max-height: 500px; overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead { position: sticky; top: 0; z-index: 1; }
.data-table th {
    background: #0f172a; color: #64748b;
    text-transform: uppercase; letter-spacing: 0.5px;
    font-size: 11px; font-weight: 600;
    padding: 10px 12px; text-align: left; border-bottom: 1px solid #334155;
}
.data-table td {
    padding: 8px 12px; border-bottom: 1px solid #1e293b;
    color: #e2e8f0; white-space: nowrap;
}
.data-table tr.data-row { cursor: pointer; }
.data-table tr.data-row:hover td { background: #334155; }
.data-table tr.data-row.cup-highlight td { background: #3b3416; }
.data-table tr.data-row.cup-highlight:hover td { background: #4a4220; }
.data-table td.success-yes { color: #4ade80; }
.data-table td.success-no { color: #f87171; }
.data-table span.success-yes { color: #4ade80; }
.data-table span.success-no { color: #f87171; }
.reclassify-cell { display: flex; align-items: center; gap: 6px; }
.reclassify-select {
    background: #1e293b; color: #cbd5e1; border: 1px solid #334155;
    border-radius: 4px; font-size: 11px; padding: 2px 4px; cursor: pointer;
}
.reclassify-select.overridden { border-color: #f97316; color: #fbbf24; }
.data-table tr.json-row td { padding: 0; border-bottom: 1px solid #334155; }
.json-preview { background: #0f172a; padding: 12px 16px; max-height: 300px; overflow: auto; }
.json-preview pre {
    font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    font-size: 12px; color: #94a3b8;
    white-space: pre-wrap; word-break: break-all; margin: 0;
}

/* Batch config drill-down */
.batch-config-panel {
    background: #1e293b; border: 1px solid #334155; border-radius: 12px;
    padding: 20px 24px; margin-bottom: 24px;
}
.batch-config-header { display: flex; align-items: baseline; gap: 12px; margin-bottom: 16px; }
.batch-config-header h3 { font-size: 14px; font-weight: 600; color: #cbd5e1; }
.batch-config-header span { color: #64748b; font-size: 13px; }
.batch-config-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}
.config-cell {
    background: #0f172a; border: 1px solid #334155; border-radius: 8px;
    padding: 10px 14px;
}
.config-cell .k {
    font-size: 11px; color: #64748b; text-transform: uppercase;
    letter-spacing: 0.5px; margin-bottom: 4px;
}
.config-cell .v { font-size: 16px; font-weight: 600; color: #f8fafc; }

/* OTA panel */
.ota-panel {
    background: #1e293b; border: 1px solid #334155; border-radius: 12px;
    padding: 20px 24px; margin-bottom: 24px;
}
.ota-header { display: flex; align-items: baseline; gap: 16px; margin-bottom: 16px; }
.ota-header h3 { font-size: 14px; font-weight: 600; color: #cbd5e1; }
.ota-hint { color: #64748b; font-size: 12px; }
.ota-form {
    display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end;
    padding-bottom: 16px; border-bottom: 1px solid #334155;
}
.ota-form .filter-group input[type="text"] {
    padding: 7px 10px; border: 1px solid #475569; border-radius: 6px;
    background: #0f172a; color: #f8fafc; font-size: 13px; width: 180px;
}
.ota-form input[type="file"] {
    color: #cbd5e1; font-size: 12px;
}
.ota-status { padding: 12px 0; font-size: 13px; color: #94a3b8; }
.ota-status.sent { color: #4ade80; }
.ota-status.error { color: #fca5a5; }
.ota-jobs-header {
    display: flex; justify-content: space-between; align-items: center;
    margin: 12px 0 8px 0;
}
.ota-jobs-header h4 { font-size: 13px; font-weight: 600; color: #cbd5e1; }
.ota-jobs .data-table { font-size: 12px; }
.ota-jobs .status-chip {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    font-size: 11px; font-weight: 600;
}
.status-chip.in_progress { background: #1e3a5f; color: #60a5fa; }
.status-chip.queued { background: #422006; color: #fbbf24; }
.status-chip.completed,
.status-chip.succeeded { background: #14532d; color: #4ade80; }
.status-chip.failed,
.status-chip.canceled,
.status-chip.cancelled { background: #7f1d1d; color: #fca5a5; }

/* Fleet view */
.fleet-overview, .fleet-users {
    background: #1e293b; border: 1px solid #334155; border-radius: 12px;
    padding: 20px 24px; margin-bottom: 24px;
}
.fleet-header {
    display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.fleet-header h3 { font-size: 14px; font-weight: 600; color: #cbd5e1; flex: 1; }

.fleet-status-chip {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    font-size: 11px; font-weight: 600;
}
.fleet-status-chip.online { background: #14532d; color: #4ade80; }
.fleet-status-chip.running { background: #1e3a5f; color: #93c5fd; font-weight: 600; }
.fleet-status-chip.offline { background: #450a0a; color: #f87171; }
.fleet-status-chip.active { background: #14532d; color: #4ade80; }
.fleet-status-chip.idle { background: #1e3a5f; color: #60a5fa; }
.fleet-status-chip.stale { background: #422006; color: #fbbf24; }
.fleet-status-chip.silent { background: #334155; color: #94a3b8; }

.user-things-input {
    width: 100%; padding: 4px 8px; border: 1px solid #475569; border-radius: 4px;
    background: #0f172a; color: #f8fafc; font-size: 12px;
}
.user-machines-cell { white-space: normal; }
.machine-checklist {
    display: flex; flex-wrap: wrap; gap: 4px 14px; max-width: 360px;
}
.machine-item {
    display: flex; align-items: center; gap: 5px;
    font-size: 12px; color: #e2e8f0; cursor: pointer;
}
.machine-item input[type="checkbox"] { accent-color: #3b82f6; cursor: pointer; }
.machine-note { font-size: 12px; color: #64748b; font-style: italic; }
.user-role-select {
    padding: 4px 8px; border: 1px solid #475569; border-radius: 4px;
    background: #0f172a; color: #f8fafc; font-size: 12px;
}

/* Modal */
.modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-card {
    background: #1e293b; border: 1px solid #334155; border-radius: 12px;
    padding: 28px 32px; min-width: 420px; max-width: 90vw;
    display: flex; flex-direction: column; gap: 16px;
}
.modal-card h3 { font-size: 16px; color: #f8fafc; margin-bottom: 8px; }
.modal-intro { color: #94a3b8; font-size: 13px; margin: -2px 0 14px; }
.modal-card input[type="text"] {
    padding: 8px 12px; border: 1px solid #475569; border-radius: 6px;
    background: #0f172a; color: #f8fafc; font-size: 13px; width: 100%;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; }
.modal-status { font-size: 12px; color: #94a3b8; min-height: 18px; }
.modal-status.error { color: #fca5a5; }
.modal-status.success { color: #4ade80; }

/* Provision result panel — shown after successful provisioning */
.cert-bundle {
    background: #0f172a; border: 1px solid #422006; border-radius: 8px;
    padding: 16px; margin-top: 12px;
}
.cert-bundle .warn {
    color: #fbbf24; font-size: 12px; margin-bottom: 8px; font-weight: 600;
}

/* Tuning feature dump: many small numeric cards, so pack them tighter than the
   big overview metric cards. */
#tuning-features-cards, #tof-metric-cards { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
#tuning-features-cards .card, #tof-metric-cards .card { padding: 10px 12px; }
#tuning-features-cards .card .value, #tof-metric-cards .card .value { font-size: 16px; }

/* Misaligned ToF capture rows read red in the capture list. */
.data-table tr.data-row.tof-row-bad td { color: #f87171; }

@media (max-width: 600px) {
    .charts { grid-template-columns: 1fr; }
    .cards { grid-template-columns: repeat(2, 1fr); }
    .job-panel { flex-direction: column; align-items: stretch; }
    .job-status { margin-left: 0; }
}
