/* Twin Axis Engineering brand palette: teal #00B7C3 + copper #C47A4A on charcoal.
   Data colours come from the validated reference palette (see dataviz skill):
   categorical slots for group identity, fixed status palette for condition. */
:root {
    --bg: #0f1419;
    --surface: #141b21;
    --surface-2: #1c252d;
    --border: #2a323a;
    --text: #f2f5f7;
    --muted: #8b96a1;
    --accent: #00b7c3;
    --accent-2: #c47a4a;
    --ok: #0ca30c;
    --warn: #fab219;
    --serious: #ec835a;
    --crit: #d03b3b;
    --group-structure: #3987e5;
    --group-conveyor: #d95926;
    --group-access: #199e70;
    --group-envelope: #9085e9;
    --group-equipment: #c98500;
    --group-services: #d55181;
    --group-other: #008300;
    --radius: 12px;
}
:root[data-theme="light"] {
    --bg: #f7f9fa;
    --surface: #ffffff;
    --surface-2: #eef2f4;
    --border: #d8dde2;
    --text: #0f1419;
    --muted: #58616b;
    --accent: #0090a0;
    --accent-2: #b06a3d;
    --group-structure: #2a78d6;
    --group-conveyor: #eb6834;
    --group-access: #1baf7a;
    --group-envelope: #4a3aa7;
    --group-equipment: #eda100;
    --group-services: #e87ba4;
    --group-other: #008300;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
h1 { font-size: 1.15rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 .35rem; }
h3 { font-size: .92rem; margin: 0 0 .3rem; }
.muted { color: var(--muted); margin: 0 0 .6rem; font-size: .86rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .82rem; }

.topbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: .7rem 1.2rem; border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.brand { display: flex; align-items: center; gap: .8rem; }
.brand-logo { height: 34px; }
.brand-divider { width: 1px; height: 30px; background: var(--border); }
.topbar-actions { display: flex; gap: .6rem; align-items: center; }
.pill {
    border: 1px solid var(--border); border-radius: 999px;
    padding: .18rem .7rem; font-size: .8rem; color: var(--muted);
}
.pill.ok { color: var(--ok); border-color: var(--ok); }
.pill.bad { color: var(--crit); border-color: var(--crit); }

.tabs { display: flex; gap: .3rem; padding: .55rem 1.2rem 0; border-bottom: 1px solid var(--border); }
.tab {
    background: none; border: none; border-bottom: 2px solid transparent;
    color: var(--muted); padding: .45rem .8rem; cursor: pointer; font-size: .92rem;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 1.1rem 1.2rem 2rem; display: grid; gap: 1rem; }
.view { display: none; gap: 1rem; }
.view.active { display: grid; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.panel {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem 1.1rem;
}
.panel-head {
    display: flex; justify-content: space-between; align-items: baseline;
    gap: 1rem; flex-wrap: wrap; margin-bottom: .4rem;
}

.btn {
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
    border-radius: 8px; padding: .35rem .75rem; cursor: pointer; font-size: .85rem;
    text-decoration: none; display: inline-block;
}
.btn:hover { border-color: var(--accent); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #05262a; font-weight: 600; }
.icon-btn {
    background: none; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer;
}
.icon-btn:hover { color: var(--text); }

/* KPI stat tiles */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.kpi {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: .85rem 1rem;
}
.kpi .kpi-label { color: var(--muted); font-size: .8rem; }
.kpi .kpi-value { font-size: 1.7rem; font-weight: 650; letter-spacing: -.02em; }
.kpi .kpi-note { color: var(--muted); font-size: .78rem; }
.kpi.alert .kpi-value { color: var(--crit); }

/* Bar lists (single-hue magnitude bars with direct labels) */
.bar-list { display: grid; gap: .45rem; }
.bar-row { display: grid; grid-template-columns: 9.5rem 1fr 2.5rem; gap: .6rem; align-items: center; }
.bar-row .bar-label { font-size: .85rem; display: flex; align-items: center; gap: .45rem; }
.bar-track { background: var(--surface-2); border-radius: 4px; height: 14px; position: relative; }
.bar-fill { display: block; height: 100%; border-radius: 4px; background: var(--accent); min-width: 2px; }
.bar-row .bar-value { text-align: right; font-size: .85rem; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

/* Status */
.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: .4rem; flex: none; }
.cond-good .status-dot { background: var(--ok); }
.cond-fair .status-dot { background: var(--warn); }
.cond-poor .status-dot { background: var(--serious); }
.cond-defective .status-dot { background: var(--crit); }
.cond-unverified .status-dot { background: var(--muted); }
.crit-high { color: var(--accent-2); font-weight: 600; }

/* Register table */
.register-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
@media (max-width: 1100px) { .register-layout { grid-template-columns: 1fr; } }
.register-tools { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
input[type="search"], select, input[type="text"], textarea {
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
    border-radius: 8px; padding: .35rem .6rem; font-size: .85rem; font-family: inherit;
}
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .85rem; }
th, td { text-align: left; padding: .42rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.selected { background: var(--surface-2); box-shadow: inset 2px 0 0 var(--accent); }
td.overdue { color: var(--crit); font-weight: 600; }

/* Asset drawer */
.asset-drawer { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; }
.drawer-tag { color: var(--muted); }
.fact-grid, .asset-drawer dl {
    display: grid; grid-template-columns: max-content 1fr; gap: .25rem .9rem; margin: .5rem 0;
}
.fact-grid dt, .asset-drawer dt, #popover-specs dt { color: var(--muted); font-size: .82rem; }
.fact-grid dd, .asset-drawer dd, #popover-specs dd { margin: 0; font-size: .85rem; }
.record {
    border-left: 2px solid var(--border); padding: .3rem 0 .3rem .7rem; margin: .45rem 0;
}
.record .record-head { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.record .record-type {
    font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--accent); font-weight: 600;
}
.record .record-when { color: var(--muted); font-size: .78rem; }
.record p { margin: .15rem 0; font-size: .85rem; }
.record .record-details { color: var(--muted); }
.record-form { display: grid; gap: .45rem; margin-top: .6rem; }
.record-form .form-row { display: flex; gap: .45rem; }
.record-form select, .record-form input, .record-form textarea { width: 100%; }
.form-error { color: var(--crit); font-size: .8rem; }

/* 3D scene */
.model-tools { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.layer-controls { display: flex; gap: .9rem; flex-wrap: wrap; margin: .4rem 0 .6rem; }
.layer-toggle { display: flex; align-items: center; gap: .4rem; font-size: .85rem; cursor: pointer; }
.scene-wrap { position: relative; }
#scene { height: 62vh; min-height: 380px; border-radius: 8px; overflow: hidden; background: #0b0f13; }
:root[data-theme="light"] #scene { background: #dde5ea; }
.scene-status { position: absolute; top: .7rem; left: .9rem; }
.asset-popover {
    position: absolute; top: .7rem; right: .7rem; width: 300px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: .8rem .9rem; box-shadow: 0 8px 28px rgba(0,0,0,.35);
}
/* !important: .hidden is applied alongside elements (like .login-screen)
   that set their own display; it must win regardless of source order. */
.asset-popover.hidden, .hidden { display: none !important; }
.popover-head { display: flex; justify-content: space-between; gap: .5rem; }
.popover-title { font-weight: 650; }
.popover-tag { color: var(--muted); }
#popover-specs { display: grid; grid-template-columns: max-content 1fr; gap: .2rem .8rem; margin: .55rem 0; }

/* Training */
.training-layout { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 1100px) { .training-layout { grid-template-columns: 1fr; } }
.training-sidebar { display: grid; gap: 1rem; }
.wt-card {
    border: 1px solid var(--border); border-radius: 8px; padding: .6rem .75rem;
    margin-bottom: .55rem; background: var(--surface-2);
}
.wt-card h3 { margin-bottom: .1rem; }
.wt-card .wt-meta { color: var(--muted); font-size: .78rem; margin-bottom: .4rem; }
.training-main { display: grid; gap: .8rem; }
#training-scene-holder { min-height: 380px; }
#training-scene-holder #scene { height: 52vh; }
.training-panel { border-top: 1px solid var(--border); padding-top: .8rem; }
.kicker {
    font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
    color: var(--accent); font-weight: 600;
}
.safety-note {
    border-left: 3px solid var(--warn); background: var(--surface-2);
    border-radius: 0 8px 8px 0; padding: .5rem .7rem; margin: .6rem 0;
    font-size: .85rem;
}
.safety-note::before { content: "⚠ "; color: var(--warn); }
.training-controls { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .7rem; }
.training-controls .spacer { flex: 1; }
.quiz-progress { font-size: .85rem; color: var(--muted); }
.quiz-feedback { font-weight: 600; }
.quiz-feedback.good { color: var(--ok); }
.quiz-feedback.bad { color: var(--crit); }
.training-result-row {
    display: flex; justify-content: space-between; gap: .6rem;
    font-size: .82rem; padding: .28rem 0; border-bottom: 1px solid var(--border);
}
.training-result-row:last-child { border-bottom: none; }
.training-result-row .muted { margin: 0; }

/* Renders gallery */
.render-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .8rem; }
.render-card { cursor: zoom-in; }
.render-card img {
    width: 100%; border-radius: 8px; border: 1px solid var(--border); display: block;
    background: #fff;
}
.render-card figcaption { font-size: .78rem; color: var(--muted); margin-top: .25rem; }
.lightbox {
    position: fixed; inset: 0; background: rgba(5, 8, 11, .88); z-index: 40;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: .6rem; cursor: zoom-out; padding: 2rem;
}
.lightbox.hidden { display: none; }
.lightbox img { max-width: 92vw; max-height: 84vh; border-radius: 8px; background: #fff; }
.lightbox-caption { color: #cfd8de; }

footer { padding: 1rem 1.2rem 1.4rem; font-size: .8rem; }


/* ---------------- Login ---------------- */
.login-screen {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--bg);
}
.login-card {
    display: grid; gap: .6rem; width: min(340px, 90vw);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.6rem 1.5rem; text-align: center;
}
.login-card .brand-logo { height: 40px; justify-self: center; margin-bottom: .3rem; }
.login-card input { width: 100%; padding: .5rem .65rem; text-align: left; }
.login-card .btn { margin-top: .2rem; }
.form-error { color: var(--crit); font-size: .85rem; min-height: 1.1em; }
#user-badge { display: none; }
#user-badge.visible { display: inline-flex; align-items: center; }
