:root {
  --ink: #102434; --muted: #708590; --line: #dbe8ea; --paper: #f7fbfb; --panel: #ffffff;
  --cyan: #42c4c9; --cyan-deep: #168d9b; --navy: #0b1e30; --blue: #5678ee; --violet: #9b80f4;
  --amber: #e9a946; --danger: #dc6f74; --ok: #2fa37a; --shadow: 0 20px 50px rgba(25,75,83,.08);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Manrope, system-ui, sans-serif; color: var(--ink); background: var(--paper); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
button, .btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 7px 12px; cursor: pointer; font-weight: 600; font-size: 13px; }
button:hover, .btn:hover { border-color: var(--cyan); }
button.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
button.small { padding: 4px 8px; font-size: 12px; }
button.danger { color: var(--danger); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 24px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; gap: 12px; align-items: center; }
.logo { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, var(--cyan), var(--blue)); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 20px; }
.brand-name { font-weight: 800; font-size: 17px; }
.brand-name b { color: var(--cyan-deep); }
.brand-sub { color: var(--muted); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.steps { display: flex; gap: 8px; padding: 12px 24px; overflow-x: auto; }
.steps button { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: 12px; white-space: nowrap; }
.steps button span { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 2px 6px; font-size: 11px; color: var(--muted); }
.steps button.active { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(66,196,201,.15); }
.steps button.active span { background: var(--cyan); color: #fff; border-color: var(--cyan); }

.layout { display: grid; grid-template-columns: minmax(330px, 420px) 1fr; gap: 16px; padding: 0 24px 16px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); max-height: calc(100vh - 150px); overflow: auto; position: sticky; top: 12px; }
.panel h2 { margin: 0 0 4px; font-size: 18px; }
.panel h3 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--cyan-deep); }
.panel p.hint { color: var(--muted); margin: 0 0 12px; font-size: 12.5px; line-height: 1.45; }
.field { display: grid; grid-template-columns: 1fr 140px; align-items: center; gap: 8px; margin-bottom: 8px; }
.field label { font-size: 13px; color: var(--ink); }
.field input, .field select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fff; }
.field input[type=checkbox] { width: auto; justify-self: start; }
textarea { min-height: 60px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; background: #fff; }
.chip.on { background: var(--cyan); color: #fff; border-color: var(--cyan); }

.viewer-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; position: relative; }
.viewer-toolbar { display: flex; justify-content: space-between; gap: 8px; padding: 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.seg { display: flex; gap: 4px; flex-wrap: wrap; }
.seg button { padding: 5px 10px; font-size: 12px; }
.seg button.active { background: var(--navy); color: #fff; border-color: var(--navy); }
#layers button.active { background: #e6f7f8; color: var(--cyan-deep); border-color: var(--cyan); }
.viewer { position: relative; height: min(68vh, 680px); min-height: 380px; }
.viewer canvas { display: block; }
.labels-layer { position: absolute; inset: 0; pointer-events: none; }
.lbl { font-size: 10.5px; font-weight: 700; padding: 2px 6px; border-radius: 6px; background: rgba(255,255,255,.9); border: 1px solid var(--line); white-space: nowrap; }
.lbl-lt { background: var(--navy); color: #fff; border-color: var(--navy); }
.lbl-eq { color: var(--cyan-deep); }
.lbl-muted { color: var(--muted); }
.legend { position: absolute; left: 10px; bottom: 10px; background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; font-size: 11.5px; display: grid; gap: 3px; }
.legend i { display: inline-block; width: 18px; height: 5px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.selection { position: absolute; right: 10px; top: 60px; width: 260px; background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 12.5px; box-shadow: var(--shadow); }
.selection h4 { margin: 0 0 6px; font-size: 13px; }

.results { padding: 0 24px 40px; display: grid; gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.kpi { border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.kpi .k { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
.kpi .v { font-size: 20px; font-weight: 800; margin-top: 4px; }
.kpi .s { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.sel td { background: #e6f7f8; }
tbody tr { cursor: default; }
.table-wrap { overflow-x: auto; }
.tag { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.tag.v { background: #e3f5ee; color: var(--ok); }
.tag.h { background: #fdf3e2; color: #a7701a; }
.tag.c { background: #fde9ea; color: var(--danger); }
.alerts { display: grid; gap: 6px; }
.alert { border-radius: 10px; padding: 8px 12px; font-size: 13px; border: 1px solid; }
.alert.err { background: #fdeeef; border-color: #f2c3c6; }
.alert.warn { background: #fdf6e8; border-color: #f1dcb0; }
.alert.info { background: #eef6fb; border-color: #cfe3ef; }
.disclaimer { font-size: 12px; color: var(--muted); line-height: 1.5; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 18px; min-width: 340px; max-width: 92vw; }
dialog::backdrop { background: rgba(11,30,48,.35); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 10; }
.pieces-table input { width: 64px; border: 1px solid var(--line); border-radius: 6px; padding: 3px 5px; }
.pieces-table select { border: 1px solid var(--line); border-radius: 6px; padding: 3px; max-width: 120px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 0 16px 16px; }
  .panel { position: static; max-height: none; }
  .results, .steps { padding-left: 16px; padding-right: 16px; }
  .topbar { padding: 12px 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .viewer { height: 56vh; }
}
@media print { .topbar, .steps, .layout { display: none; } }
