:root {
  --bg: #000; --panel: #111; --panel2: #1a1a1a; --line: #2a2a2a; --text: #f2f2f2; --muted: #8d8d8d;
  --accent: #d9b26a; --green: #2ecc71; --amber: #f5a623; --red: #ff4d4d; --blue: #4ea3ff;
  --r: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { padding-bottom: env(safe-area-inset-bottom); }
a { color: inherit; }
h1, h2, h3, h4 { margin: 0 0 .6em; font-weight: 600; }
h1 { font-size: 1.6rem; letter-spacing: .02em; }
h2 { font-size: 1.05rem; text-transform: uppercase; letter-spacing: .06em; color: #ddd; }
h3 { font-size: .95rem; margin-top: 1.2em; color: #ccc; text-transform: uppercase; letter-spacing: .05em; }
h4 { grid-column: 1 / -1; font-size: .8rem; color: var(--muted); text-transform: uppercase; margin: .4em 0 0; }
.muted { color: var(--muted); }
.accent { color: var(--accent); }
.red { color: var(--red); } .ok-text { color: var(--green); }
.grow { flex: 1; }
.hidden { display: none; }
.center { margin: 20vh auto; max-width: 480px; text-align: center; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: #000; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.brand img { width: 34px; height: 34px; }
.topbar nav { display: flex; gap: 4px; overflow-x: auto; }
.topbar nav a { padding: 8px 12px; border-radius: 8px; text-decoration: none; color: #bbb; white-space: nowrap; }
.topbar nav a.active { background: var(--panel2); color: #fff; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.lang { background: none; color: #fff; border: 1px solid #555; border-radius: 6px; padding: 6px 10px; font-weight: 700; cursor: pointer; }
.sync { font-size: .8rem; color: var(--muted); }
.sync.off { color: var(--red); } .sync.wait { color: var(--amber); }
select.dev { background: #222; color: var(--amber); border: 1px dashed var(--amber); border-radius: 6px; padding: 4px; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 16px; }
.card.error { border-color: var(--red); color: var(--red); }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h1, .card-head h2 { margin: 0; }
.cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } .topbar { flex-wrap: wrap; } .top-right { margin-left: auto; } }
.loading { padding: 40px; text-align: center; color: var(--muted); }

.counts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.count { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; border-left: 6px solid; }
.count b { font-size: 2rem; display: block; line-height: 1; }
.count span { color: var(--muted); text-transform: uppercase; font-size: .75rem; letter-spacing: .06em; }
.count.late { border-left-color: var(--red); } .count.at_risk { border-left-color: var(--amber); } .count.on_track { border-left-color: var(--green); } .count.draft { border-left-color: #555; }
@media (max-width: 600px) { .counts { grid-template-columns: repeat(2, 1fr); } }

.light { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.light i { width: 14px; height: 14px; border-radius: 50%; display: inline-block; box-shadow: 0 0 8px currentColor; background: currentColor; }
.light.on_track { color: var(--green); } .light.at_risk { color: var(--amber); } .light.late { color: var(--red); } .light.draft { color: #777; }
.light.draft i { box-shadow: none; }

.order-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.order-row:last-child { border-bottom: 0; }
.wo-line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.wo-num { font-weight: 700; text-decoration: none; color: var(--accent); font-size: 1.05rem; }
.row-meta { display: flex; gap: 8px; margin: 4px 0; font-size: .85rem; }
.due { font-weight: 600; white-space: nowrap; } .due.red { color: var(--red); } .due.amber { color: var(--amber); }
.due small { color: var(--muted); font-weight: 400; }
.reasons { color: var(--amber); display: block; margin-top: 4px; font-size: .85rem; }
.bar { height: 5px; background: #222; border-radius: 3px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--accent); }
.prio { font-size: .75rem; font-weight: 700; text-transform: uppercase; padding: 2px 8px; border-radius: 4px; border: 1px solid; }
.prio.urgent { color: var(--red); } .prio.high { color: var(--amber); } .prio.low { color: var(--muted); }
.chip { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); color: #ccc; white-space: nowrap; }
.chip.ok, .chip.pr-approved, .chip.pr-received { color: var(--green); border-color: #1d5c37; }
.chip.pr-pending { color: var(--amber); border-color: #6b4c12; } .chip.pr-rejected { color: var(--red); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--panel2); color: #fff; border: 1px solid #3a3a3a; border-radius: 8px; padding: 10px 14px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 42px; }
.btn:hover { border-color: #666; }
.btn.primary { background: var(--accent); color: #000; border-color: var(--accent); }
.btn.ok { background: #14532d; border-color: #1f7a43; }
.btn.danger { background: #5c1515; border-color: var(--red); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: .85rem; }
.icon-btn { background: none; border: 0; color: #fff; font-size: 1.2rem; cursor: pointer; }
.btns { display: flex; gap: 8px; align-items: center; }
.btns.wrap { flex-wrap: wrap; margin-top: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: none; color: #aaa; border: 0; padding: 8px 14px; cursor: pointer; font: inherit; }
.seg button.on { background: var(--panel2); color: #fff; }

input, select, textarea { width: 100%; background: #0a0a0a; color: #fff; border: 1px solid #333; border-radius: 8px; padding: 10px; font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
input[type=search] { max-width: 280px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 12px; margin-bottom: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field.wide { grid-column: span 2; } .field.full { grid-column: 1 / -1; margin-bottom: 10px; }
@media (max-width: 600px) { .field.wide { grid-column: 1 / -1; } }
.totals { display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; color: var(--muted); }
.totals b { color: var(--text); }
.inline { display: flex; gap: 6px; }
.check { display: flex; align-items: center; gap: 10px; padding: 10px 0; font-size: 1rem; }
.check input { width: 24px; height: 24px; }

.admin-box { border: 1px dashed #6b5a32 !important; background: #14110a; border-radius: 8px; padding: 10px; margin-top: 10px; }
.admin-box summary { cursor: pointer; color: var(--accent); }
.admin-line { color: var(--accent); font-size: .9rem; }
.note-box { background: var(--panel2); border-left: 4px solid var(--accent); padding: 8px 12px; border-radius: 4px; }
.note-box.amber { border-left-color: var(--amber); color: #ffd38a; } .note-box.ok { border-left-color: var(--green); }

.item { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px; background: #0c0c0c; }
.item-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.item-head select { width: auto; }
.item .sub { border-top: 1px solid var(--line); padding-top: 6px; }
.sub-details { margin: 6px 0; } .sub-details summary { cursor: pointer; color: #bbb; padding: 6px 0; }
.item-body { display: flex; gap: 12px; align-items: flex-start; }
.specs { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 0; font-size: .9rem; }
.specs dt { color: var(--muted); } .specs dd { margin: 0; }
.start-opts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 700px) { .start-opts { grid-template-columns: 1fr; } }

.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, #000 30%); padding: 20px 0 12px; display: flex; gap: 10px; justify-content: flex-end; }

.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 8px; }
.kv small { display: block; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; }
.tabs a { padding: 10px 16px; border-radius: 8px 8px 0 0; background: var(--panel); border: 1px solid var(--line); text-decoration: none; white-space: nowrap; color: #aaa; position: relative; }
.tabs a.on { color: #fff; border-bottom-color: var(--accent); border-bottom-width: 3px; }
.tabs small { color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-left: 6px; } .dot.red { background: var(--red); }

.stages { list-style: none; padding: 0; margin: 0; }
.stages li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.stages .step { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; border: 2px solid #444; color: #888; font-weight: 700; flex: none; }
.stages li.done .step { background: var(--green); border-color: var(--green); color: #000; }
.stages li.next .step { border-color: var(--accent); color: var(--accent); }
.stages li.todo b { color: #777; }
.stages .thumb img { width: 56px; height: 56px; }

.thumb { display: inline-flex; flex-direction: column; text-decoration: none; gap: 2px; }
.thumb img { width: 84px; height: 84px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: #222; }
.thumb span { font-size: .75rem; } .thumb small { font-size: .7rem; color: var(--muted); }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.photo-grid .thumb img { width: 100%; height: 110px; }
.photo-picker { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.photo-btn { min-height: 56px; font-size: 1.05rem; }
.preview img { max-width: 100%; max-height: 240px; border-radius: 8px; }

.alert { display: flex; gap: 12px; align-items: flex-start; padding: 10px; border-radius: 8px; background: var(--panel2); margin-bottom: 8px; text-decoration: none; }
.alert.blocker { border-left: 4px solid var(--red); } .alert.blocker.resolved { border-left-color: #2b5f3f; opacity: .7; }
.alert.purchase { border-left: 4px solid var(--blue); } .alert.date_change { border-left: 4px solid var(--amber); }
.alert p { margin: 2px 0; }
.alerts { border-color: #5c1515; }
.approval { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.approval p { margin: 2px 0; }
.pr { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stats b { font-size: 1.6rem; display: block; } .stats span { color: var(--muted); font-size: .8rem; }
.task { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); text-decoration: none; flex-wrap: wrap; }
.task .next { color: #ccc; }

.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; color: var(--muted); font-weight: 500; font-size: .75rem; text-transform: uppercase; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 4px; border-bottom: 1px solid #1c1c1c; }
.tbl-wrap { overflow-x: auto; }
.tbl.mats input { padding: 6px; } .tbl.mats input.num { width: 80px; } .tbl.mats input.unit { width: 60px; }
.tbl tr.short td { background: #1f0d0d; }
.labor-form { align-items: end; }

.modal-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.75); display: grid; place-items: center; z-index: 50; padding: 12px; }
.modal { background: var(--panel); border: 1px solid #333; border-radius: 14px; width: min(520px, 100%); max-height: 92vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; text-transform: none; font-size: 1.1rem; color: #fff; }
.modal-body { padding: 16px; }
.modal-actions { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(480px, calc(100% - 32px)); }
.toast { background: #1d1d1d; border: 1px solid #444; border-left: 4px solid var(--green); padding: 12px 14px; border-radius: 8px; opacity: 0; transform: translateY(10px); transition: .25s; }
.toast.show { opacity: 1; transform: none; }
.toast.err { border-left-color: var(--red); } .toast.warn { border-left-color: var(--amber); }
.cols > div { min-width: 0; }
.stages li > div { min-width: 0; overflow-wrap: anywhere; }
main { overflow-x: hidden; }
