:root {
  --navy: #0b2339;
  --blue: #1378c9;
  --blue-dark: #0d5fa3;
  --ink: #15293a;
  --muted: #637786;
  --line: #dce6ec;
  --surface: #ffffff;
  --page: #eef3f6;
  --success-bg: #eaf7f0;
  --warning-bg: #fff7df;
  --warning-border: #efd587;
  --error-bg: #fff0f0;
  --error: #a83434;
  --shadow: 0 14px 40px rgba(11, 35, 57, .09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { background: var(--page); }
body { margin: 0; background: var(--page); color: var(--ink); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.only-print { display: none; }

.app-shell { width: min(1120px, 100%); min-height: 100vh; margin: 0 auto; background: var(--surface); box-shadow: var(--shadow); }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding: 28px 28px 34px; padding-top: max(28px, env(safe-area-inset-top)); background: var(--navy); color: #fff; border-radius: 0 0 28px 28px; }
.eyebrow, .kicker { margin: 0 0 6px; font-size: 11px; letter-spacing: .1em; font-weight: 800; opacity: .72; }
.hero h1 { margin: 0; font-size: clamp(27px, 5vw, 38px); line-height: 1.1; }
.hero-copy { max-width: 620px; margin: 8px 0 0; font-size: 14px; opacity: .82; }
.hero-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.status-pill, .unit-chip, .badge { display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; font-weight: 800; }
.status-pill { padding: 7px 10px; font-size: 12px; background: rgba(255,255,255,.13); }
.status-pill.offline { background: #7a3d23; }
.unit-chip { padding: 7px 10px; background: #eef6fc; color: var(--blue-dark); font-size: 12px; white-space: nowrap; }
.badge { min-width: 20px; height: 20px; padding: 0 5px; margin-left: 5px; background: rgba(255,255,255,.18); font-size: 11px; }
.tab:not(.active) .badge { background: #e8eef2; color: var(--muted); }

main { padding: 22px 28px 36px; }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 0 0 14px; margin-bottom: 4px; scrollbar-width: thin; }
.tab { flex: 0 0 auto; border: 1px solid var(--line); border-radius: 999px; background: #fff; padding: 10px 14px; color: var(--muted); font-weight: 750; }
.tab.active { color: #fff; border-color: var(--blue); background: var(--blue); }
.view { animation: appear .14s ease-out; }
@keyframes appear { from { opacity: .35; transform: translateY(3px); } }

.card { border: 1px solid var(--line); border-radius: 18px; padding: 20px; margin: 14px 0 18px; background: #fff; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.section-heading h2 { margin: 0; font-size: 22px; }
h3 { margin: 28px 0 12px; font-size: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.field { min-width: 0; }
.field.grow { flex: 1 1 360px; }
label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.field small { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
input, select { width: 100%; min-height: 44px; border: 1px solid #c8d5dd; border-radius: 10px; background: #fff; padding: 10px 11px; color: var(--ink); outline: none; }
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(19,120,201,.12); }
input:invalid { border-color: #c75050; }

.result-panel { margin-top: 18px; border-radius: 14px; background: var(--success-bg); padding: 14px; min-height: 74px; }
.result-title { margin: 0 0 8px; color: #2e6650; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.result-line, .total-line { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid rgba(21,41,58,.09); }
.result-line:last-child, .total-line:last-child { border-bottom: 0; }
.result-line strong, .total-line strong { color: var(--blue-dark); text-align: right; }
.result-cost { margin-top: 6px; padding-top: 12px; border-top: 1px solid rgba(21,41,58,.13); font-size: 17px; }

.warning-note, .info-note, .formula-box { margin: 14px 0 0; padding: 11px 12px; border-radius: 10px; font-size: 12px; line-height: 1.5; }
.warning-note { background: var(--warning-bg); border: 1px solid var(--warning-border); color: #6e571f; }
.info-note { background: #f3f7f9; color: var(--muted); }
.formula-box { background: #eef6fc; color: #315a79; font-weight: 650; }
.error-box { margin: 0 0 14px; padding: 11px 12px; border: 1px solid #efc3c3; border-radius: 10px; background: var(--error-bg); color: var(--error); font-size: 13px; }

.btn { min-height: 42px; border-radius: 10px; border: 1px solid transparent; padding: 10px 14px; font-weight: 800; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { border-color: var(--line); background: #fff; color: var(--ink); }
.btn-light { background: #fff; color: var(--navy); }
.btn-danger-outline { border-color: #e2b8b8; background: #fff; color: #9c3636; }
.add-to-quote { width: 100%; margin-top: 14px; }
.button-row, .project-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-top: 16px; }

.toast { position: sticky; top: 8px; z-index: 20; width: fit-content; max-width: 100%; margin: 0 auto 10px; padding: 10px 13px; border-radius: 999px; background: var(--navy); color: #fff; box-shadow: 0 8px 26px rgba(0,0,0,.18); font-size: 13px; }
.empty-state { margin: 14px 0; padding: 18px; border: 1px dashed #cbd7de; border-radius: 12px; color: var(--muted); text-align: center; }
.quote-items { margin-top: 16px; }
.quote-item { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.quote-item:last-child { border-bottom: 0; }
.quote-item h4 { margin: 0 0 4px; font-size: 14px; }
.quote-item p { margin: 0; color: var(--muted); font-size: 12px; }
.quote-item .amount { color: var(--blue-dark); font-weight: 800; }
.icon-btn { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: #9c3636; font-weight: 900; }
.quote-settings { display: grid; grid-template-columns: repeat(2, minmax(0, 180px)); gap: 12px; justify-content: end; margin: 18px 0 8px; }
.totals { margin-top: 8px; padding: 14px; border-radius: 12px; background: #f5f8fa; }
.total-line.grand { margin-top: 3px; padding-top: 13px; font-size: 19px; font-weight: 900; border-top: 2px solid #d4e0e7; }

.projects-list { display: grid; gap: 10px; }
.project-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.project-row h4 { margin: 0 0 4px; }
.project-row p { margin: 0; color: var(--muted); font-size: 12px; }
.project-actions { display: flex; gap: 7px; }
.project-actions .btn { min-height: 36px; padding: 7px 10px; font-size: 12px; }

.table-wrap { overflow-x: auto; }
.settings-table { width: 100%; border-collapse: collapse; min-width: 570px; }
.settings-table th, .settings-table td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; }
.settings-table th { color: var(--muted); font-size: 12px; }
.settings-table input { min-width: 110px; }
.footer { padding: 0 28px calc(28px + env(safe-area-inset-bottom)); color: var(--muted); font-size: 11px; text-align: center; }
.footer p { margin: 4px; }

@media (max-width: 780px) {
  .app-shell { box-shadow: none; }
  .hero { align-items: flex-start; padding-left: 18px; padding-right: 18px; }
  main { padding: 16px 14px 30px; }
  .card { padding: 16px; border-radius: 15px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .quote-item { grid-template-columns: 1fr auto; }
  .quote-item .amount { grid-column: 1; }
  .quote-item .icon-btn { grid-column: 2; grid-row: 1 / span 2; }
}

@media (max-width: 480px) {
  .hero { display: block; }
  .hero-actions { justify-content: flex-start; margin-top: 14px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .field { grid-column: span 1; }
  .project-toolbar .field, .project-toolbar .btn { width: 100%; }
  .quote-settings { grid-template-columns: 1fr 1fr; }
  .project-row { grid-template-columns: 1fr; }
  .project-actions { width: 100%; }
  .project-actions .btn { flex: 1; }
  .section-heading h2 { font-size: 19px; }
}

@media print {
  @page { margin: 14mm; }
  body, html, .app-shell { background: #fff !important; box-shadow: none !important; }
  .no-print, .hero, .tabs, .footer, .toast { display: none !important; }
  .view { display: none !important; }
  #quote.view { display: block !important; }
  #quote .card { border: 0; padding: 0; margin: 0; }
  #quote .card + .card { display: none !important; }
  .only-print { display: block !important; }
  .print-title { padding-bottom: 12px; border-bottom: 2px solid #222; margin-bottom: 18px; }
  .print-title h1 { margin: 0 0 4px; font-size: 22px; }
  .quote-item { break-inside: avoid; }
  .totals { background: #fff; border: 1px solid #ccc; }
  .warning-note { background: #fff; color: #444; border-color: #ccc; }
}
