/* ==========================================================================
   Tesla Contractor Portal — red & white engineering UI
   ========================================================================== */
:root {
  --red: #D7141A;
  --red-dark: #A80F14;
  --red-soft: #FDECEC;
  --red-line: #F4C6C7;
  --ink: #1F2328;
  --ink-2: #4A4F57;
  --ink-3: #7A7F87;
  --line: #E2E3E6;
  --line-2: #EDEEF0;
  --card: #F6F6F7;
  --white: #FFFFFF;
  --ok: #1E7B45;
  --ok-soft: #E7F4EC;
  --warn: #9A5B00;
  --warn-soft: #FFF4E0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--white);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--red); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 10px 28px;
  background: var(--red);
  color: #fff;
  position: sticky; top: 0; z-index: 20;
  box-shadow: 0 1px 0 var(--red-dark);
}
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; min-width: 0; }
.brand img { width: 40px; height: 40px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px #fff; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 16px; letter-spacing: .06em; }
.brand-text small { font-size: 12px; opacity: .88; }
.mainnav { display: flex; gap: 4px; margin-left: auto; }
.mainnav a {
  color: #fff; text-decoration: none; padding: 8px 14px; border-radius: 6px;
  font-weight: 600; font-size: 14px; opacity: .92;
}
.mainnav a:hover { background: rgba(255, 255, 255, .14); opacity: 1; }
.mainnav a.active { background: #fff; color: var(--red); opacity: 1; }

.storage-banner { background: var(--warn-soft); color: var(--warn); padding: 10px 28px; border-bottom: 1px solid #F1D9A8; font-weight: 600; }

main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 28px 28px 48px; outline: none; }
.loading { padding: 80px; text-align: center; color: var(--ink-3); }

.appfoot {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 12px 28px; border-top: 1px solid var(--line); color: var(--ink-3); font-size: 12.5px;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font-weight: 600; font-size: 14px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { border-color: #C9CBD0; background: #FAFAFA; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
.btn.outline { border-color: var(--red); color: var(--red); }
.btn.outline:hover { background: var(--red-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--card); }
.btn.danger { background: #fff; border-color: #E5A3A5; color: var(--red-dark); }
.btn.danger:hover { background: var(--red-soft); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 6px; }
.btn.large { padding: 13px 22px; font-size: 16px; }
.btn.outline-light { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .7); }
.btn.outline-light:hover { background: #fff; color: var(--red); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--ink-3); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--card); color: var(--ink); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- generic ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: 26px; margin: 0; letter-spacing: .01em; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .12em; color: var(--red); text-transform: uppercase; margin-bottom: 6px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); }
.card.grey { background: var(--card); box-shadow: none; }
.card + .card { margin-top: 18px; }
.card h2 { font-size: 18px; }
.card h3 { font-size: 16px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--card); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap;
}
.badge.scheme { background: #FDECEC; color: #A80F14; border-color: #F4C6C7; }
.badge.completion { background: #EEF2F7; color: #2A4A73; border-color: #D5DFEA; }
.badge.direct { background: #FFF4E0; color: #8A5200; border-color: #F1D9A8; }
.badge.status-draft { background: #fff; color: var(--ink-2); }
.badge.status-generated { background: var(--ok-soft); color: var(--ok); border-color: #C5E3D0; }
.badge.status-archived { background: var(--card); color: var(--ink-3); }
.notice {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: 8px;
  background: var(--warn-soft); border: 1px solid #F1D9A8; color: #5E3A00; margin-bottom: 18px;
}
.notice.info { background: #F4F6F9; border-color: var(--line); color: var(--ink-2); }
.notice.red { background: var(--red-soft); border-color: var(--red-line); color: var(--red-dark); }
.notice.ok { background: var(--ok-soft); border-color: #C5E3D0; color: #11502B; }
.notice strong { display: block; }
.notice .grow { flex: 1; }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-3); }

/* ---------- home ---------- */
.hero { text-align: center; padding: 18px 0 8px; }
.hero h1 { font-size: 30px; letter-spacing: .04em; margin-bottom: 6px; }
.hero p { color: var(--ink-2); margin: 0 0 26px; }
.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; max-width: 860px; margin: 0 auto; }
.choice {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  padding: 28px 28px 26px; border-radius: 14px; border: 2px solid var(--line); background: #fff;
  text-align: left; cursor: pointer; text-decoration: none; color: var(--ink);
  transition: border-color .15s, box-shadow .15s, transform .15s;
  box-shadow: var(--shadow);
}
.choice:hover { border-color: var(--red); box-shadow: 0 8px 24px rgba(215, 20, 26, .14); transform: translateY(-2px); }
.choice .choice-icon { width: 48px; height: 48px; border-radius: 12px; background: var(--red); color: #fff; display: grid; place-items: center; }
.choice .choice-icon svg { width: 26px; height: 26px; }
.choice h2 { font-size: 22px; letter-spacing: .05em; margin: 4px 0 0; }
.choice p { margin: 0; color: var(--ink-2); font-size: 14px; }
.choice ul { margin: 4px 0 0; padding-left: 18px; color: var(--ink-2); font-size: 13.5px; }
.choice .go { margin-top: 8px; font-weight: 700; color: var(--red); }
.choice.alt .choice-icon { background: #fff; color: var(--red); border: 2px solid var(--red); }

.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin: 34px 0 22px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--line-2); }
.stat b { display: block; font-size: 26px; line-height: 1.1; color: var(--ink); }
.stat span { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.stat.red { background: var(--red); border-color: var(--red); }
.stat.red b, .stat.red span { color: #fff; }

.home-cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; }
.home-cols .card + .card { margin-top: 0; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2);
  background: var(--card); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr:hover td { background: #FCFCFD; }
table.data .proj-name { font-weight: 700; color: var(--ink); text-decoration: none; }
table.data .proj-name:hover { color: var(--red); }
table.data .sub { display: block; font-size: 12.5px; color: var(--ink-3); max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { display: flex; gap: 4px; flex-wrap: wrap; }
.actions .btn { padding: 4px 9px; font-size: 12.5px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { flex: 1; min-width: 200px; max-width: 360px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 7px 12px; font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--red); color: #fff; }

.recent-list { list-style: none; margin: 0; padding: 0; }
.recent-list li { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line-2); }
.recent-list li:last-child { border-bottom: 0; }
.recent-list .grow { flex: 1; min-width: 0; }
.recent-list a.name { font-weight: 700; color: var(--ink); text-decoration: none; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-list a.name:hover { color: var(--red); }

/* ---------- forms ---------- */
input[type=text], input[type=tel], input[type=search], input[type=date], input[type=number], input[type=email], input[type=password], input:not([type]), select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #CFD2D7; border-radius: 7px; background: #fff;
  transition: border-color .12s, box-shadow .12s;
}
textarea { resize: vertical; min-height: 42px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(215, 20, 26, .12); }
.field { display: block; margin-bottom: 16px; }
.field .lbl { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; font-weight: 600; font-size: 14px; margin-bottom: 5px; color: var(--ink); }
.field .lbl .req { color: var(--red); font-style: normal; margin-left: 2px; }
.field .lbl .docs { font-weight: 500; font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.field .help { display: block; font-size: 12.5px; color: var(--ink-3); margin-top: 4px; }
.field.err input, .field.err textarea, .field.err select { border-color: var(--red); background: #FFFBFB; }
.field .errmsg { display: none; color: var(--red-dark); font-size: 12.5px; font-weight: 600; margin-top: 4px; }
.field.err .errmsg { display: block; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.grid-2 .full { grid-column: 1 / -1; }

.yesno { display: inline-flex; border: 1px solid #CFD2D7; border-radius: 8px; overflow: hidden; }
.yesno button { border: 0; background: #fff; padding: 8px 18px; font-weight: 700; font-size: 13.5px; cursor: pointer; color: var(--ink-2); min-width: 64px; }
.yesno button + button { border-left: 1px solid #CFD2D7; }
.yesno button.on { background: var(--red); color: #fff; }
.yesno button.on.no { background: var(--ink-2); }
.field.inline { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line-2); margin: 0; }
.field.inline .lbl { margin: 0; font-weight: 500; }

.group { border: 1px solid var(--line); border-radius: var(--radius); padding: 0; margin: 0 0 18px; background: #fff; overflow: hidden; }
.group > legend { display: none; }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 18px; background: var(--card); border-bottom: 1px solid var(--line); }
.group-head h3 { margin: 0; font-size: 15px; letter-spacing: .02em; }
.group-q { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 18px; }
.group-q .q { font-weight: 600; }
.group-body { padding: 16px 18px 2px; border-top: 1px solid var(--line-2); }
.group.off .group-body { display: none; }
.group.off .group-head { border-bottom: 0; }
.subhead { grid-column: 1 / -1; font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--red); margin: 6px 0 10px; padding-top: 6px; border-top: 1px dashed var(--line); }
.note { grid-column: 1 / -1; font-size: 13px; color: var(--ink-2); font-style: italic; margin: 0 0 10px; }
.section-heading { font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--red); margin: 10px 0 12px; }

.derived { border: 1px dashed #D5D7DC; border-radius: 8px; padding: 10px 12px; background: #FBFBFC; }
.derived .auto-text { font-size: 14px; color: var(--ink); }
.derived .auto-text.empty-auto { color: var(--ink-3); font-style: italic; }
.derived .derived-foot { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--ink-3); }
.derived .linkbtn { border: 0; background: none; color: var(--red); font-weight: 700; cursor: pointer; padding: 0; font-size: 12.5px; }

/* ---------- wizard ---------- */
.wiz-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.wiz-head h1 { font-size: 22px; margin: 0; }
.wiz-head .meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.saved-ind { font-size: 13px; color: var(--ok); font-weight: 600; opacity: 0; transition: opacity .3s; }
.saved-ind.show { opacity: 1; }
.wiz-body { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 24px; align-items: start; }
.steps { list-style: none; margin: 0; padding: 0; position: sticky; top: 84px; }
.steps li { margin: 0 0 4px; }
.steps button {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  border: 1px solid transparent; background: transparent; padding: 9px 10px; border-radius: 8px; cursor: pointer; color: var(--ink-2); font-weight: 600; font-size: 14px;
}
.steps button:hover { background: var(--card); }
.steps .num { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12.5px; font-weight: 800; background: var(--card); border: 1px solid var(--line); color: var(--ink-2); flex: none; }
.steps li.done .num { background: #fff; border-color: var(--ok); color: var(--ok); }
.steps li.warn .num { background: #fff; border-color: #E8A33C; color: var(--warn); }
.steps li.current button { background: var(--red-soft); color: var(--red-dark); border-color: var(--red-line); }
.steps li.current .num { background: var(--red); color: #fff; border-color: var(--red); }
.step-card { min-height: 380px; }
.step-card > h2 { font-size: 20px; letter-spacing: .02em; margin-bottom: 2px; }
.step-card > .intro { color: var(--ink-2); margin: 0 0 20px; }
.wiz-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.errbar { margin-bottom: 16px; }

.doc-checklist { list-style: none; padding: 0; margin: 0; }
.doc-checklist li { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: #fff; }
.doc-checklist li .grow { flex: 1; }
.doc-checklist input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--red); }
.tick { width: 22px; height: 22px; border-radius: 50%; background: var(--ok); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 800; flex: none; }
.tick.off { background: var(--line); }

.encl-row { display: grid; grid-template-columns: 30px minmax(0, 1fr) 130px 40px; gap: 8px; align-items: center; margin-bottom: 8px; }
.encl-row .n { color: var(--ink-3); font-weight: 700; text-align: right; }

/* review */
.review-sec { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; }
.review-sec header { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.review-sec header h3 { margin: 0; font-size: 15px; }
.review-sec dl { margin: 0; padding: 6px 16px 10px; display: grid; grid-template-columns: minmax(180px, 40%) 1fr; gap: 0 16px; }
.review-sec dt { color: var(--ink-2); font-size: 13.5px; padding: 6px 0; border-bottom: 1px solid var(--line-2); }
.review-sec dd { margin: 0; font-size: 14px; font-weight: 600; padding: 6px 0; border-bottom: 1px solid var(--line-2); white-space: pre-wrap; word-break: break-word; }
.review-sec dd.missing { color: var(--red); font-weight: 700; }
.review-sec dd.na { color: var(--ink-3); font-weight: 500; }
.generate-bar { display: flex; justify-content: center; margin: 26px 0 6px; }

/* documents ready */
.ready-head { text-align: center; margin: 6px 0 22px; }
.ready-head h1 { font-size: 28px; letter-spacing: .06em; margin-bottom: 4px; }
.ready-list { max-width: 900px; margin: 0 auto; }
.ready-item { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; background: #fff; box-shadow: var(--shadow); flex-wrap: wrap; }
.ready-item .grow { flex: 1; min-width: 200px; }
.ready-item .name { font-weight: 700; font-size: 15.5px; }
.ready-all { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 22px 0 10px; }

/* settings */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 20px; flex-wrap: wrap; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--ink-2); font-weight: 700; font-size: 14px; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tabs a.on { color: var(--red); border-bottom-color: var(--red); }
.logo-box { display: flex; gap: 16px; align-items: center; }
.logo-box img { width: 72px; height: 72px; border-radius: 50%; border: 1px solid var(--line); object-fit: contain; background: #fff; }
.kbd { font-family: Consolas, monospace; background: var(--card); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 12.5px; }
.ph-list { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 22, 26, .45); display: grid; place-items: center; z-index: 100; padding: 20px; opacity: 0; transition: opacity .18s; }
.modal-back.show { opacity: 1; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; box-shadow: var(--shadow-lg); }
.modal.wide { max-width: 980px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px; overflow: auto; }
.modal-body p:first-child { margin-top: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal.preview .modal-body { background: #E9EAED; padding: 20px; }
.preview-pages { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.preview-pages svg.doc-page { width: 100%; max-width: 794px; height: auto; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, .18); }

/* ---------- toast ---------- */
#toast-host { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 600; transform: translateY(10px); opacity: 0; transition: all .2s; max-width: 380px; }
.toast.show { transform: none; opacity: 1; }
.toast.ok { background: var(--ok); }
.toast.error { background: var(--red-dark); }

.noscript { padding: 20px; background: var(--red); color: #fff; font-weight: 700; }

/* ---------- print (documents only, no UI) ---------- */
#print-root { display: none; }
@media print {
  @page { size: A4 portrait; margin: 0; }
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing #print-root { display: block; }
  body.printing { background: #fff; }
  .print-page { width: 210mm; height: 297mm; page-break-after: always; break-after: page; overflow: hidden; }
  .print-page:last-child { page-break-after: auto; break-after: auto; }
  .print-page svg { width: 210mm; height: 297mm; display: block; }
  body:not(.printing) .topbar, body:not(.printing) .appfoot, body:not(.printing) .wiz-foot, body:not(.printing) .steps { display: none; }
}

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .home-cols { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .topbar { padding: 10px 16px; gap: 12px; flex-wrap: wrap; }
  .brand-text small { display: none; }
  .mainnav { order: 3; width: 100%; margin: 0; overflow-x: auto; }
  .mainnav a { padding: 6px 10px; }
  #top-backup { margin-left: auto; }
  main { padding: 18px 16px 40px; }
  .choice-grid { grid-template-columns: 1fr; }
  .wiz-body { grid-template-columns: 1fr; }
  .steps { position: static; display: flex; gap: 4px; overflow-x: auto; padding-bottom: 6px; }
  .steps li { flex: none; }
  .steps button .t { display: none; }
  .steps li.current button .t { display: inline; }
  .grid-2 { grid-template-columns: 1fr; }
  .review-sec dl { grid-template-columns: 1fr; }
  .review-sec dt { border-bottom: 0; padding-bottom: 0; }
  .group-q, .field.inline { flex-direction: column; align-items: flex-start; }
  .encl-row { grid-template-columns: 22px minmax(0, 1fr) 90px 34px; }
  .appfoot { padding: 12px 16px; }
}
@media (max-width: 520px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero h1 { font-size: 24px; }
  .choice { padding: 22px; }
}

/* ---------- contractor details ---------- */
.cp-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.cp-form .card + .card { margin-top: 16px; }
.cp-aside { position: sticky; top: 84px; }
.cp-actions { position: sticky; bottom: 0; background: #fff; z-index: 5; padding-bottom: 12px; }
.cp-preview { border: 1px solid var(--line); border-radius: 10px; background: #fff; overflow: hidden; box-shadow: var(--shadow); font-size: 12.5px; }
.cp-band { height: 6px; background: var(--red); }
.cp-head { display: flex; gap: 12px; align-items: center; padding: 14px 16px 10px; }
.cp-head img { max-width: 90px; max-height: 60px; object-fit: contain; }
.cp-name { color: var(--red); font-weight: 800; font-size: 15px; letter-spacing: .02em; line-height: 1.2; }
.cp-desc { color: var(--ink); }
.cp-tag { color: var(--ink-3); font-style: italic; }
.cp-rule { height: 2px; background: var(--red); margin: 0 16px; }
.cp-body { padding: 10px 16px; line-height: 1.55; }
.cp-lic { color: var(--ink-2); font-weight: 600; }
.cp-sign { border-top: 1px dashed var(--line); margin: 0 16px; padding: 10px 0 14px; line-height: 1.7; }
.cp-sign span { display: inline-block; width: 78px; color: var(--ink-3); }
.cp-sign-t { font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--red); }
.cp-nologo { width: 56px; height: 56px; border: 1px dashed var(--line); border-radius: 8px; display: grid; place-items: center; font-size: 11px; color: var(--ink-3); text-align: center; }
.cp-nologo.big { width: 90px; height: 72px; }
@media (max-width: 1000px) { .cp-layout { grid-template-columns: 1fr; } .cp-aside { position: static; order: -1; } }

/* ---------- drawings (A3 / A4 landscape) ---------- */
.preview-pages svg.doc-page.landscape { max-width: 100%; }
@media print {
  @page a4l { size: A4 landscape; margin: 0; }
  @page a3l { size: A3 landscape; margin: 0; }
  .print-page.a4l { page: a4l; width: 297mm; height: 210mm; }
  .print-page.a3l { page: a3l; width: 420mm; height: 297mm; }
  .print-page.a4l svg { width: 297mm; height: 210mm; }
  .print-page.a3l svg { width: 420mm; height: 297mm; }
}
.feeder-row, .feeder-head { display: grid; grid-template-columns: 30px minmax(0, 2fr) 86px 110px 70px minmax(0, 2fr) 34px; gap: 6px; align-items: center; margin-bottom: 6px; }
.feeder-head { font-size: 12px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.feeder-row .n { font-weight: 800; color: var(--red); font-size: 13px; }
.feeder-row.fpanel-row, .feeder-head.fpanel-row { grid-template-columns: 30px minmax(0, 2fr) 56px 56px 96px 84px 84px 34px; }
@media (max-width: 820px) {
  .feeder-head { display: none; }
  .feeder-row { grid-template-columns: 30px 1fr 1fr 34px; padding: 8px 0; border-bottom: 1px solid var(--line-2); }
  .feeder-row input[data-k=name], .feeder-row input[data-k=cable] { grid-column: 2 / 4; }
  .feeder-row.fpanel-row { grid-template-columns: 30px 1fr 1fr 34px; }
  .feeder-row.fpanel-row input[data-k=label] { grid-column: 2 / 4; }
}

/* ---------- projects & stages (v1.3) ---------- */
.badge.compliance { background: #EEF7F1; color: #1E6B3E; border-color: #C9E6D3; }
.stage-flow { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr auto 1fr; gap: 10px; align-items: stretch; max-width: 1060px; margin: 0 auto; }
.stage-flow-item { display: flex; flex-direction: column; gap: 6px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: var(--shadow); }
.stage-flow-item .choice-icon { width: 38px; height: 38px; border-radius: 10px; background: var(--red); color: #fff; display: grid; place-items: center; }
.stage-flow-item .choice-icon svg { width: 21px; height: 21px; }
.stage-flow-item b { font-size: 14.5px; line-height: 1.3; }
.stage-flow-arrow { align-self: center; color: var(--red); font-size: 22px; font-weight: 800; }
.hero-cta { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 26px 0 0; text-align: center; }
.recent-badges { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; max-width: 50%; }
.stage-cell .badge { margin: 1px 0; }

.stages-box { margin-bottom: 8px; }
.stage-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stage-card { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border: 2px solid var(--line); border-radius: 10px; cursor: pointer; background: #fff; transition: border-color .12s, background .12s; }
.stage-card:hover { border-color: #C9CBD0; }
.stage-card.on { border-color: var(--red); background: var(--red-soft); }
.stage-card input { width: 20px; height: 20px; accent-color: var(--red); margin-top: 2px; flex: none; }
.stage-card .grow { display: flex; flex-direction: column; gap: 3px; }
.stage-n { width: 24px; height: 24px; border-radius: 50%; background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; font-size: 12px; font-weight: 800; flex: none; }
.stage-card.on .stage-n { background: var(--red); color: #fff; border-color: var(--red); }
.stage-done { color: var(--ok); font-weight: 700; }
.stages-box.err .stage-grid { outline: 2px solid var(--red); outline-offset: 4px; border-radius: 10px; }
.completion-mode { margin-top: 12px; }
.steps li.stage-step .num { border-style: dashed; }

.comp-head, .comp-row { display: grid; grid-template-columns: 26px minmax(0, 1fr) minmax(0, 1fr) 170px 60px; gap: 8px; align-items: start; }
.comp-head { font-size: 12px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.comp-row { padding: 8px 0; border-bottom: 1px solid var(--line-2); }
.comp-row .n { font-weight: 800; color: var(--red); padding-top: 9px; text-align: right; }
.comp-row textarea { min-height: 62px; }
.comp-side { display: flex; flex-direction: column; gap: 6px; }
.comp-tools { display: flex; gap: 2px; padding-top: 4px; }
.comp-field.err .comp-head { color: var(--red); }
.comp-review { margin: 4px 0; padding-left: 20px; font-weight: 500; }
.comp-review li { margin-bottom: 6px; }

.stage-reviews { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.stage-review { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border: 1px solid var(--line); border-left: 5px solid var(--ok); border-radius: 10px; background: #fff; box-shadow: var(--shadow); }
.stage-review.has-errs { border-left-color: #E8A33C; }
.stage-review-title { font-weight: 800; font-size: 15.5px; }
.stage-missing { color: var(--warn); font-weight: 600; margin-top: 3px; }
.stage-ok { color: var(--ok); font-weight: 600; margin-top: 3px; }
.next-stages { max-width: 900px; margin: 16px auto 0; }
@media (max-width: 1000px) {
  .stage-flow { grid-template-columns: 1fr 1fr; }
  .stage-flow-arrow { display: none; }
}
@media (max-width: 820px) {
  .stage-grid { grid-template-columns: 1fr; }
  .comp-head { display: none; }
  .comp-row { grid-template-columns: 22px 1fr 34px; }
  .comp-row textarea, .comp-side { grid-column: 2 / 3; }
  .comp-tools { grid-column: 3; grid-row: 1; flex-direction: column; }
  .stage-review { flex-direction: column; align-items: stretch; }
  .recent-badges { max-width: none; }
}
.stage-review .grow { flex: 1; min-width: 0; }

/* ---------- online portal: sign-in & user box ---------- */
.user-box { display: flex; align-items: center; gap: 8px; }
.user-chip { color: #fff; font-size: 13px; font-weight: 600; text-decoration: none; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip:hover { text-decoration: underline; }
body.auth-mode .mainnav, body.auth-mode #top-backup, body.auth-mode .user-box { display: none; }
.auth-wrap { min-height: 60vh; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card h1 { margin: 6px 0 4px; font-size: 24px; }
.auth-card form { display: grid; gap: 12px; margin-top: 16px; }
.auth-logo { display: block; margin: 0 auto 6px; }
.btn.block { width: 100%; justify-content: center; }
.auth-links { text-align: center; font-size: 14px; margin: 16px 0 0; }

/* ---------- verticals ---------- */
.vbar { display: flex; gap: 4px; padding: 0 28px; background: #fff; border-bottom: 1px solid var(--line); overflow-x: auto; }
.vbar a { display: inline-flex; align-items: center; gap: 8px; padding: 11px 14px 10px; color: var(--ink-2); font-weight: 600; font-size: 14px; text-decoration: none; border-bottom: 3px solid transparent; white-space: nowrap; }
.vbar a:hover { color: var(--red); }
.vbar a.on { color: var(--red); border-bottom-color: var(--red); }
.vb-ico { font-size: 15px; }
body[data-vertical="safety"] .mainnav[data-for="inspectorate"],
body:not([data-vertical="safety"]) .mainnav[data-for="safety"] { display: none; }
body.auth-mode .vbar { display: none; }
#safety-host { flex: 1; display: flex; }
#safety-host[hidden] { display: none; }
#safety-frame { flex: 1; width: 100%; border: 0; min-height: calc(100vh - 170px); background: #F6F7F9; }
@media (max-width: 760px) { .vbar { padding: 0 12px; } .vbar a { padding: 10px 10px 9px; font-size: 13px; } }
