:root {
  color-scheme: light;
  --bg: #f4f1ec;
  --surface: #ffffff;
  --ink: #1c1917;
  --muted: #78716c;
  --line: #ddd8d0;
  --accent: #1d4ed8;
  --accent-dark: #1e40af;
  --warning: #ca8a04;
  --soft: #eff6ff;
  --secondary: #ca8a04;
  --font-ui: "DM Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-data: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
}

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--accent);
  box-shadow: 0 12px 30px rgba(30, 37, 40, 0.14);
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  border-color: #fecaca;
  background: #fff7f7;
  color: #991b1b;
}

.demo-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 18px;
  background: #fef9c3;
  color: var(--secondary);
  border-bottom: 1px solid #e5d7a3;
  font-size: 14px;
}

.demo-notice strong {
  white-space: nowrap;
}

button,
input,
select,
textarea {
  font: inherit;
}

h1,
h2,
.nav-button,
.primary-action,
.secondary-action,
.file-action,
.eyebrow {
  font-family: var(--font-ui);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 32px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}

.app-logo {
  width: 54px;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--soft);
  object-fit: contain;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1;
}

h2 {
  font-size: 24px;
  line-height: 1.2;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.business-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.business-summary strong {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--accent);
}

.cloud-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cloud-actions span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: calc(100vh - 130px);
}

.sidebar {
  padding: 24px 16px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.nav-button {
  width: 100%;
  min-height: 42px;
  margin-bottom: 8px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
}

.nav-button.active,
.nav-button:hover {
  border-color: var(--accent);
  background: var(--soft);
  color: var(--accent);
}

.content {
  padding: 32px;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.section-heading {
  margin-bottom: 24px;
}

.compact-heading {
  margin: 0 0 14px;
}

.test-guide {
  display: grid;
  grid-template-columns: minmax(240px, 340px) 1fr;
  gap: 18px;
  align-items: start;
  margin-bottom: 24px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.test-guide p {
  color: var(--muted);
  line-height: 1.45;
}

.test-guide ol {
  margin: 0;
  padding-left: 22px;
  color: var(--ink);
  line-height: 1.55;
}

.test-guide li + li {
  margin-top: 6px;
}

.assist-panel,
.calculation-explanation,
.starter-help {
  margin-bottom: 20px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.assist-panel strong,
.calculation-explanation strong,
.starter-help strong {
  display: block;
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
}

.assist-panel p,
.calculation-explanation p,
.starter-help p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.starter-help {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr);
  gap: 14px;
  background: var(--surface);
}

.starter-help ol {
  margin: 0;
  padding-left: 22px;
  color: var(--ink);
  line-height: 1.5;
}

.starter-help li + li {
  margin-top: 5px;
}

.calculation-explanation:empty {
  display: none;
}

.explanation-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.explanation-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.explanation-item span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.explanation-item b {
  display: block;
  margin-top: 6px;
  color: var(--ink);
  font-size: 14px;
}

.form-grid,
.budget-controls,
.quote-data,
.manual-line {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 16px;
  align-items: end;
  margin-bottom: 20px;
}

.manual-line {
  grid-template-columns: 2fr 1fr 1fr 1fr auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.backup-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  margin-top: 24px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.panel-note,
.legal-note {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.legal-note {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
}

.file-action {
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid var(--secondary);
  border-radius: 8px;
  background: var(--secondary);
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.file-action input {
  display: none;
}

.history-filters {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 14px;
  margin-bottom: 16px;
}

.commercial-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.summary-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.summary-item strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
  color: var(--accent);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status-draft {
  background: #eef2f7;
  color: #475569;
}

.status-sent {
  background: #e0f2fe;
  color: #0369a1;
}

.status-accepted {
  background: #dcfce7;
  color: #166534;
}

.status-rejected {
  background: #fee2e2;
  color: #991b1b;
}

.split {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  gap: 24px;
  align-items: start;
}

.entry-form {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

label small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

textarea {
  min-height: 112px;
  resize: vertical;
}

.primary-action {
  min-height: 42px;
  padding: 10px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.primary-action:hover {
  background: var(--accent-dark);
}

.secondary-action {
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid var(--secondary);
  border-radius: 8px;
  background: var(--secondary);
  color: #ffffff;
  font-weight: 800;
  cursor: pointer;
}

.danger-action {
  border-color: var(--secondary);
  background: var(--secondary);
  color: #ffffff;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
  font-family: var(--font-data);
}

th,
td {
  padding: 13px 14px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td input {
  min-height: 36px;
  padding: 8px;
}

.template-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 16px;
}

.wide-split {
  grid-template-columns: minmax(300px, 420px) 1fr;
}

.line-builder {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.hidden {
  display: none;
}

.mini-list {
  display: grid;
  gap: 8px;
}

.mini-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.mini-item strong {
  color: var(--ink);
}

.mini-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mini-actions select {
  width: auto;
  min-height: 38px;
}

.template-meta {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.template-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.template-card h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.template-card p {
  color: var(--muted);
  line-height: 1.45;
}

.template-actions,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.form-actions {
  margin-top: 0;
}

.template-actions button,
.action-row button {
  flex: 1;
}

.budget-footer {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 360px);
  gap: 24px;
  margin-top: 24px;
  align-items: start;
}

.totals {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.totals p {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  color: var(--accent);
}

.totals strong {
  color: var(--accent);
  font-family: var(--font-data);
  font-weight: 500;
}

.grand-total {
  margin-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 20px;
  color: var(--accent);
}

.print-button {
  width: 100%;
  margin-top: 14px;
}

.remove-line {
  min-width: 34px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff7ed;
  color: var(--warning);
  cursor: pointer;
}

.line-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.line-action {
  min-width: 30px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.line-action:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.saved-quotes {
  margin-top: 28px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.print-sheet {
  display: none;
}

@media (max-width: 900px) {
  .demo-notice {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .demo-notice strong {
    white-space: normal;
  }

  .topbar,
  .business-summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .layout,
  .split,
  .backup-panel,
  .test-guide,
  .starter-help,
  .explanation-grid,
  .budget-footer {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-button {
    min-width: 150px;
  }

  .form-grid,
  .budget-controls,
  .quote-data,
  .manual-line,
  .history-filters,
  .commercial-summary,
  .template-list {
    grid-template-columns: 1fr;
  }

  .content {
    padding: 20px;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 18px;
  }

  h1 {
    font-size: 30px;
  }

  h2 {
    font-size: 21px;
  }

  .content {
    padding: 16px;
  }

  .sidebar {
    padding: 12px;
  }

  .nav-button {
    min-width: 132px;
    min-height: 40px;
    padding: 9px 10px;
  }

  .entry-form,
  .backup-panel,
  .test-guide,
  .saved-quotes,
  .totals,
  .manual-line {
    padding: 14px;
  }

  .template-actions button,
  .action-row button,
  .file-action {
    width: 100%;
    flex: auto;
    text-align: center;
  }

  .mini-item,
  .mini-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .mini-actions select,
  .mini-actions button {
    width: 100%;
  }

  .toast {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
  }
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .layout {
    display: none;
  }

  .print-sheet {
    display: block;
    padding: 28px;
    color: #111;
    font-family: Arial, sans-serif;
  }

  .print-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    margin-bottom: 28px;
    border-bottom: 2px solid #111;
    padding-bottom: 16px;
  }

  .print-brand {
    display: flex;
    align-items: center;
    gap: 14px;
  }

  .print-logo {
    max-height: 56px;
    max-width: 140px;
    object-fit: contain;
    flex-shrink: 0;
  }

  .print-header h1 {
    font-size: 22px;
    margin: 0 0 4px 0;
  }

  .print-contact {
    font-size: 11px;
    color: #555;
    margin: 0;
    line-height: 1.5;
  }

  .print-meta {
    text-align: right;
    color: #555;
    font-size: 13px;
  }

  .print-meta p {
    margin: 2px 0;
  }

  .print-meta strong {
    font-size: 15px;
    color: #111;
  }

  .print-sheet table {
    min-width: 0;
    margin-top: 18px;
  }

  .print-client {
    display: grid;
    gap: 5px;
    margin-bottom: 18px;
    padding: 12px;
    border: 1px solid #ddd;
  }

  .print-sheet th,
  .print-sheet td {
    border-bottom: 1px solid #ddd;
  }

  .print-totals {
    width: 320px;
    margin-top: 22px;
    margin-left: auto;
  }

  .print-totals p {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
  }

  .print-total {
    border-top: 2px solid #111;
    font-size: 20px;
    font-weight: 700;
  }

  .print-notes,
  .print-terms {
    margin-top: 28px;
    color: #444;
    line-height: 1.5;
  }

  .print-terms {
    margin-top: 18px;
    padding-top: 12px;
    border-top: 1px solid #ddd;
  }
}
