:root {
  --bg: #0f1720; --panel: #16212d; --panel2: #1b2836; --line: #26364a; --text: #e6edf3; --muted: #8aa0b6;
  --accent: #2f9bff; --ok: #3fb950; --warn: #d29922; --bad: #f85149; --crit: #ff6b9a;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
h2 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 13px; }
.mt { margin-top: 22px; }
[hidden] { display: none !important; }

/* header */
.top { display: flex; align-items: center; gap: 14px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
       position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); letter-spacing: .3px; }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; }
.top nav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; }
.top nav a.active, .top nav a:hover { color: var(--text); background: var(--panel2); }
.spacer { flex: 1; }
.top select { width: auto; min-width: 160px; padding: 6px 8px; }
.who { color: var(--muted); font-size: 13px; white-space: nowrap; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.badge.admin { color: var(--accent); border-color: var(--accent); }

/* tabs */
.tabs { display: flex; gap: 2px; padding: 0 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { color: var(--muted); padding: 11px 14px; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 16px; max-width: 1280px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; min-width: 0; }
.card.flush { padding: 0; overflow-x: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

/* forms */
input, select, textarea, button, .button {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { min-height: 70px; resize: vertical; }
button, .button { background: var(--accent); border-color: var(--accent); cursor: pointer; width: auto; font-weight: 600; display: inline-block; text-align: center; }
button.ghost, .button.ghost { background: transparent; color: var(--text); border-color: var(--line); font-weight: 500; }
button.danger { background: transparent; color: var(--bad); border-color: var(--line); font-weight: 500; }
button.small, .button.small { padding: 4px 9px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
.form label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.form label input, .form label select, .form label textarea { margin-top: 4px; }
.f3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.f2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.f4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 620px) { .f4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .f3 { grid-template-columns: 1fr 1fr; } }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1; min-width: 80px; }
.filebtn input { display: none; }
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 200px; }
.toolbar select { width: auto; }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; background: var(--panel2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* status chips */
.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); white-space: nowrap; }
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, transparent); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.chip.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
.chip.crit { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 50%, transparent); }
.chip.info { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.tile b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 13px; }

.list-item { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.flash { padding: 10px 12px; border-radius: 8px; background: var(--panel2); border: 1px solid var(--line); }
.flash.bad { border-color: var(--bad); color: var(--bad); }
.flash.ok { border-color: var(--ok); color: var(--ok); }
.bar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 18px; width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .55); }

.check { display: flex !important; gap: 8px; align-items: center; color: var(--text) !important; font-size: 14px !important; margin: 6px 0 !important; }
.check input { width: auto; margin: 0 !important; }
.check small { color: var(--muted); }
td select.inline { width: auto; padding: 3px 6px; font-size: 13px; }
.spacer { flex: 1; }

/* history */
dialog.wide { width: min(860px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
.tiles.small { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 12px 0 16px; }
.tiles.small .tile { padding: 10px; }
.tiles.small .tile b { font-size: 20px; }
.timeline { list-style: none; margin: 8px 0 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.timeline li { position: relative; display: flex; justify-content: space-between; gap: 12px; padding: 8px 0 8px 10px; font-size: 14px; }
.timeline li::before { content: ""; position: absolute; left: -21px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.timeline li > .muted { white-space: nowrap; flex-shrink: 0; }
.timeline li.ev-completed::before { background: var(--ok); }
.timeline li.ev-created::before, .timeline li.ev-pinned::before { background: var(--accent); }
.timeline li.ev-archived::before { background: var(--bad); }
tr.archived td { opacity: .6; }
@media (max-width: 640px) { .timeline li { flex-direction: column; gap: 2px; } .timeline li > .muted { white-space: normal; } }

/* repair estimates */
ol.steps { margin: 0; padding-left: 20px; font-size: 14px; }
ol.steps li { margin: 3px 0; }
ul.notes { padding-left: 18px; margin: 14px 0 0; }
.estimate-box { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; background: var(--panel2); }

/* AI corrosion findings */
.finding-view { position: relative; margin: 10px 0; line-height: 0; }
.finding-view img { width: 100%; border-radius: 8px; }
.finding-box { position: absolute; border: 2px solid var(--warn); border-radius: 3px; line-height: 1.2; }
.finding-box.g4, .finding-box.g5 { border-color: var(--bad); }
.finding-box span { position: absolute; top: -20px; left: -2px; font-size: 11px; padding: 1px 5px; background: rgba(0,0,0,.7); color: #fff; border-radius: 3px; white-space: nowrap; }

.coat-list{margin:6px 0 0;padding-left:0;list-style:none}
.coat-list li{margin:2px 0}
.roller-warning{margin:8px 0;padding:6px 10px;border-left:3px solid var(--warn,#e0a030);background:rgba(224,160,48,.12);font-weight:600}
