:root {
  color-scheme: dark;
  --bg: #07111f;
  --bg-soft: #0f172a;
  --card: rgba(15, 23, 42, 0.96);
  --line: #263244;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --brand: #38bdf8;
  --brand-strong: #0ea5e9;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, rgba(56, 189, 248, 0.18), transparent 36%), linear-gradient(135deg, #07111f, #0b1220 55%, #111827);
  color: var(--text);
}

button, input, select, textarea { font: inherit; }
button {
  border: 0;
  border-radius: 14px;
  padding: 11px 14px;
  color: #06111f;
  background: var(--brand);
  font-weight: 800;
  cursor: pointer;
}
button:disabled { cursor: not-allowed; opacity: 0.48; }
button.secondary { background: #1f2937; color: var(--text); border: 1px solid var(--line); }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.danger, .danger { color: #fecaca; border-color: rgba(239, 68, 68, 0.45); }

.app-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: start;
  max-width: 1440px;
  margin: 0 auto;
  padding: 22px 16px 10px;
}
.eyebrow { margin: 0 0 6px; color: var(--brand); font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.75rem; }
h1 { margin: 0; font-size: clamp(2rem, 6vw, 4rem); line-height: 0.95; letter-spacing: -0.06em; }
.subtitle { max-width: 760px; margin: 12px 0 0; color: var(--muted); line-height: 1.5; }
.status-card {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 20px;
  padding: 14px 16px;
  min-width: 170px;
  box-shadow: var(--shadow);
}
.status-card span { display: block; color: var(--muted); font-size: 0.8rem; }
.status-card strong { display: block; margin-top: 4px; color: var(--ok); }

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.9fr);
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 10px 16px 40px;
}
.card {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--card);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}
.card h2 { margin: 0 0 14px; font-size: 1.08rem; }
.hint { color: var(--muted); margin: -4px 0 14px; line-height: 1.45; }
.stepper {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0 12px;
  background: linear-gradient(180deg, #07111f 65%, rgba(7, 17, 31, 0));
}
.stepper a {
  white-space: nowrap;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(15, 23, 42, 0.9);
}

.fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.fields.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label, .full-label {
  display: grid;
  gap: 7px;
  color: #dbeafe;
  font-weight: 700;
  font-size: 0.88rem;
}
input, select, textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #0b1220;
  color: var(--text);
  padding: 10px 11px;
}
textarea { resize: vertical; line-height: 1.4; }
.checks { display: grid; gap: 10px; margin-top: 14px; }
.checks label { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.checks input { width: auto; min-height: auto; }

.form-panel { min-width: 0; }
.summary-panel { min-width: 0; }
.sticky-card { position: sticky; top: 8px; z-index: 4; }
.total-main {
  border-radius: 18px;
  padding: 16px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.18), rgba(34, 197, 94, 0.1));
  border: 1px solid rgba(56, 189, 248, 0.28);
}
.total-main span { display: block; color: var(--muted); }
.total-main strong { display: block; margin-top: 5px; font-size: 2rem; }
.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin: 14px 0;
}
.metrics div { border: 1px solid var(--line); border-radius: 14px; padding: 10px; }
.metrics dt { color: var(--muted); font-size: 0.75rem; }
.metrics dd { margin: 3px 0 0; font-weight: 800; }
.actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }

.material-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.materials-list { display: grid; gap: 10px; }
.material-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr 0.8fr 0.7fr 1fr auto;
  gap: 9px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: rgba(11, 18, 32, 0.66);
}

.workflow { padding-left: 20px; color: var(--muted); }
.workflow li { margin: 6px 0; }
.workflow .active { color: var(--brand); font-weight: 900; }
.workflow .done { color: var(--ok); }
.guard-message {
  border: 1px solid rgba(245, 158, 11, 0.42);
  background: rgba(245, 158, 11, 0.1);
  color: #fde68a;
  border-radius: 14px;
  padding: 12px;
  line-height: 1.4;
}
.guard-message.ok { border-color: rgba(34, 197, 94, 0.42); background: rgba(34, 197, 94, 0.1); color: #bbf7d0; }
.guard-message.error { border-color: rgba(239, 68, 68, 0.42); background: rgba(239, 68, 68, 0.1); color: #fecaca; }

.tabs { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 12px; }
.tab { background: transparent; color: var(--text); border: 1px solid var(--line); }
.tab.active { background: var(--brand); color: #06111f; }
.document { display: none; color: #e2e8f0; line-height: 1.55; }
.document.active { display: block; }
.document h3 { margin: 14px 0 8px; }
.document table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.document th, .document td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; vertical-align: top; }
.document .num { text-align: right; white-space: nowrap; }
.document .warning { color: #fde68a; font-weight: 800; }
pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #020617;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  max-height: 540px;
  overflow: auto;
}

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 1fr; }
  .sticky-card { position: static; }
}
@media (max-width: 720px) {
  .app-header { grid-template-columns: 1fr; }
  .fields, .fields.compact, .metrics, .actions-grid { grid-template-columns: 1fr; }
  .card { padding: 15px; border-radius: 18px; }
  .material-row { grid-template-columns: 1fr; }
  .document table { font-size: 0.82rem; }
}

@media print {
  body { background: white; color: #111827; }
  .app-header, .form-panel, .totals, .workflow-card, .tabs { display: none !important; }
  .app-shell { display: block; padding: 0; }
  .summary-panel { display: block; }
  .tabs-card { box-shadow: none; border: 0; background: white; color: #111827; }
  .document { display: none !important; color: #111827; }
  body.print-client #clientPreview, body.print-internal #internalReport { display: block !important; }
  .document th, .document td { border-color: #d1d5db; }
}
