:root {
  color-scheme: dark;
  --bg: #070604;
  --panel: #12100c;
  --panel-2: #1b1710;
  --line: #40331f;
  --gold: #d8b65c;
  --gold-2: #ffe9a1;
  --text: #fff8e5;
  --muted: #c4b99c;
  --danger: #ff776d;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background: radial-gradient(circle at top left, rgba(216, 182, 92, .12), transparent 36rem), var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button:disabled {
  opacity: .52;
}

.app-shell {
  width: min(100%, 720px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 2px 16px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  color: var(--gold-2);
  font-size: 28px;
  line-height: 1;
}

h2 {
  color: var(--gold-2);
  font-size: 20px;
}

h3 {
  margin: 18px 0 10px;
  color: var(--gold-2);
  font-size: 15px;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(76px, 1fr);
  gap: 6px;
  overflow-x: auto;
  padding: 8px 0 12px;
  background: linear-gradient(180deg, var(--bg), rgba(7, 6, 4, .88));
  backdrop-filter: blur(10px);
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab,
.choice,
.ghost,
.primary {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(18, 16, 12, .92);
  font-size: 12px;
  font-weight: 900;
}

.tab.is-active,
.choice.is-active,
.primary {
  color: #151008;
  border-color: var(--gold);
  background: var(--gold);
}

.choice.is-disabled {
  color: rgba(196, 185, 156, .42);
  background: rgba(18, 16, 12, .5);
}

label.is-disabled {
  opacity: .72;
}

label.is-disabled span:not(.field-caption) {
  background: rgba(18, 16, 12, .5);
}

.panel {
  display: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(27, 23, 16, .94), rgba(11, 9, 6, .96));
  padding: 16px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .24);
}

.panel.is-active {
  display: block;
}

.section-head {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-head strong {
  color: var(--gold-2);
  font-size: 19px;
  white-space: nowrap;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid rgba(216, 182, 92, .32);
  border-radius: 10px;
  background: rgba(216, 182, 92, .07);
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--gold-2);
  font-size: 12px;
  font-weight: 900;
}

label span,
.price-control {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #090704;
  color: var(--muted);
}

label .field-caption {
  display: block;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
}

input[type="number"] {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 800;
}

input[type="text"],
input[type="tel"],
input[type="email"],
input[type="date"],
input[type="file"],
textarea {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 800;
}

textarea {
  min-height: 104px;
  padding: 12px 10px;
  resize: vertical;
}

.textarea-field {
  margin-top: 10px;
}

select {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 900;
}

.currency-symbol,
.price-symbol {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 10px 0;
}

.wide-segmented {
  margin-bottom: 14px;
}

.switches {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}

.switches label {
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(9, 7, 4, .76);
  color: var(--text);
  font-size: 14px;
}

input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--gold);
}

.price-list,
.quote-list,
.summary,
.project-summary,
.saved-list,
.diary-list {
  display: grid;
  gap: 8px;
}

.price-row,
.quote-row,
.summary-card,
.project-summary,
.saved-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 56px;
  padding: 10px;
  border: 1px solid rgba(64, 51, 31, .86);
  border-radius: 8px;
  background: rgba(9, 7, 4, .68);
}

.business-price-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.business-price-row label {
  min-width: 0;
}

.business-price-row label span {
  min-width: 0;
}

.business-price-row input,
.business-price-row select {
  min-width: 0;
}

.price-derived {
  grid-column: 1 / -1;
  padding: 8px 10px;
  border: 1px solid rgba(216, 182, 92, .22);
  border-radius: 8px;
  background: rgba(216, 182, 92, .06);
}

.price-derived small {
  color: var(--muted);
  font-size: 12px;
}

.price-row p,
.quote-row p,
.summary-card p,
.project-summary p,
.saved-row p {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 900;
}

.price-row small,
.quote-row small,
.summary-card small,
.project-summary small,
.saved-row small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.project-summary {
  grid-template-columns: 1fr;
  margin-bottom: 12px;
}

.saved-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.saved-row {
  align-items: stretch;
}

.saved-actions,
.action-row {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.map-actions,
.split-actions {
  flex-wrap: wrap;
  justify-content: stretch;
  margin: 10px 0 14px;
}

.map-actions button,
.split-actions button,
.split-actions .file-button {
  flex: 1 1 150px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin: 8px 0 10px;
}

.inline-form input {
  min-width: 0;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: #090704;
  color: var(--text);
  font-size: 16px;
  font-weight: 800;
}

.compact {
  margin-top: 12px;
}

.task-check {
  display: flex;
  grid-template-columns: none;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 14px;
}

.task-row.is-done .task-check span {
  color: var(--muted);
  text-decoration: line-through;
}

.shopping-row input {
  width: 100%;
  min-height: 36px;
  margin-top: 8px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: #090704;
  color: var(--text);
}

.shopping-row select {
  min-width: 118px;
  min-height: 40px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #090704;
}

.is-overdue {
  border-color: rgba(255, 119, 109, .72);
}

.signature-canvas {
  width: 100%;
  height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #090704;
  touch-action: none;
}

.diary-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
  min-height: 104px;
  padding: 10px;
  border: 1px solid rgba(64, 51, 31, .86);
  border-radius: 8px;
  background: rgba(9, 7, 4, .68);
}

.diary-row img {
  width: 96px;
  height: 96px;
  border-radius: 8px;
  object-fit: cover;
  background: #090704;
}

.diary-row p {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 900;
}

.diary-row small {
  display: block;
  margin: 4px 0;
  color: var(--muted);
  font-size: 12px;
}

.file-button {
  display: grid;
  place-items: center;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #151008;
  background: var(--gold);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.file-button input {
  display: none;
}

.status-box {
  min-height: 42px;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid rgba(64, 51, 31, .86);
  border-radius: 8px;
  background: rgba(9, 7, 4, .68);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.status-box:empty {
  display: none;
}

.status-box p,
.status-box ul {
  margin: 0;
}

.status-box ul {
  padding-left: 18px;
}

.status-box.is-ok {
  border-color: rgba(99, 190, 123, .58);
  color: #d8f5df;
}

.status-box.is-warning {
  border-color: rgba(216, 182, 92, .58);
  color: var(--gold-2);
}

.ocr-row {
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
}

.ocr-row label {
  min-width: 0;
}

.ocr-row small {
  overflow-wrap: anywhere;
}

.mini-button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--gold-2);
  background: rgba(18, 16, 12, .92);
  font-size: 12px;
  font-weight: 900;
}

.mini-button.danger {
  color: var(--danger);
}

.price-control {
  width: 126px;
}

.price-control input {
  text-align: right;
}

.ghost {
  min-width: 92px;
  padding: 0 12px;
}

.primary {
  padding: 0 14px;
}

.summary {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.summary-card {
  grid-template-columns: 1fr;
}

.summary-card strong {
  color: var(--gold-2);
  font-size: 20px;
}

.document-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: rgba(7, 6, 4, .98);
}

.document-modal[hidden] {
  display: none;
}

.document-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 14px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 16, 12, .98);
}

.document-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.document-actions button {
  min-width: 86px;
}

.document-scroll {
  overflow: auto;
  padding: 14px;
  background: #f4f0e6;
}

.document-paper {
  width: min(100%, 780px);
  margin: 0 auto;
  padding: 22px;
  border-radius: 8px;
  background: #fff;
  color: #17130b;
  font-family: Arial, sans-serif;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.document-paper *,
.document-paper h1,
.document-paper h2,
.document-paper h3 {
  color: #17130b;
}

.document-paper .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.document-paper .brand img {
  width: 54px;
  height: 54px;
  object-fit: contain;
}

.document-paper .eyebrow {
  color: #8a6a1f;
}

.document-paper .section-head,
.document-paper .action-row,
.document-paper .internal-only {
  display: none !important;
}

.document-paper .project-summary,
.document-paper .summary,
.document-paper .quote-list,
.document-paper .saved-list,
.document-paper .diary-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.document-paper .summary {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.document-paper .project-summary p,
.document-paper .summary-card,
.document-paper .quote-row,
.document-paper .saved-row,
.document-paper .diary-row {
  margin: 0;
  padding: 10px;
  border: 1px solid #d8c797;
  border-radius: 6px;
  background: #fffdf8;
  color: #17130b;
  min-height: 0;
  box-shadow: none;
}

.document-paper .quote-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 18px;
}

.document-paper p,
.document-paper strong {
  margin: 0;
  color: #17130b;
  font-weight: 700;
}

.document-paper small {
  display: block;
  margin-top: 4px;
  color: #665c45;
  font-size: 12px;
  font-weight: 400;
}

.document-paper .summary-card strong {
  display: block;
  margin-top: 2px;
  color: #17130b;
  font-size: 18px;
}

.document-paper img {
  max-width: 180px;
  border-radius: 6px;
}

@media (max-width: 380px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .grid,
  .settings-grid,
  .summary {
    grid-template-columns: 1fr;
  }

  .tabs {
    gap: 4px;
  }

  .tab {
    font-size: 11px;
  }

  .saved-row {
    grid-template-columns: 1fr;
  }

  .inline-form,
  .diary-row,
  .business-price-row {
    grid-template-columns: 1fr;
  }

  .diary-row img {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 10;
  }

  .saved-actions,
  .action-row {
    justify-content: stretch;
  }

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

  .document-toolbar {
    display: grid;
  }

  .document-paper {
    padding: 14px;
  }

  .document-paper .summary,
  .document-paper .quote-row {
    grid-template-columns: 1fr;
  }
}

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

  .topbar,
  .tabs,
  .document-toolbar,
  .view:not([data-view="quote"]) {
    display: none !important;
  }

  .document-modal {
    position: static;
    display: block;
    background: #fff;
  }

  .document-scroll {
    overflow: visible;
    padding: 0;
    background: #fff;
  }

  .document-paper {
    width: 100%;
    padding: 0;
    border-radius: 0;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .panel {
    display: block;
    border: 0;
    box-shadow: none;
    background: #fff;
    color: #111;
  }

  .internal-only {
    display: none !important;
  }
}
