:root {
  --bg: #f3e7df;
  --bg-deep: #e6d2c6;
  --surface: #fffcfa;
  --paper: #fffdf9;
  --ink: #2c211c;
  --muted: #6f5e56;
  --line: #e4d3c8;
  --rose: #b76e79;
  --rose-deep: #8e4a55;
  --gold: #b8956c;
  --ok: #3d6b5a;
  --warn: #8a5a28;
  --danger: #9b3b3b;
  --shadow: 0 18px 50px rgba(80, 48, 36, 0.12);
  --radius: 18px;
  --font: "Outfit", "Segoe UI", system-ui, sans-serif;
  --display: "Fraunces", "Palatino Linotype", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #f7d7d0 0%, transparent 55%),
    radial-gradient(900px 400px at 110% 0%, #ead7b8 0%, transparent 50%),
    var(--bg);
  line-height: 1.45;
}
img, svg { display: block; }
button, input, select, textarea {
  font: inherit;
  color: inherit;
}
button { cursor: pointer; }
a { color: var(--rose-deep); }

.hidden { display: none !important; }

.login-body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-wrap { width: min(440px, 100%); }
.login-card,
.card,
.composer,
.receipt {
  background: var(--surface);
  border: 1px solid rgba(142, 74, 85, 0.08);
  box-shadow: var(--shadow);
}
.login-card {
  border-radius: 28px;
  padding: 36px 32px 28px;
  text-align: center;
}
.login-mark { display: flex; justify-content: center; margin-bottom: 12px; }
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: var(--gold);
  margin: 0 0 8px;
}
.login-card h1,
.panel-head h1,
.settings-page h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  margin: 0 0 6px;
  letter-spacing: -0.02em;
}
.lede, .panel-head p, .muted { color: var(--muted); margin: 0; }
.lede { margin-bottom: 22px; }

.stack { display: grid; gap: 14px; text-align: left; }
label span,
.field span {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--muted);
}
input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 16px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(183, 110, 121, 0.28);
  border-color: var(--rose);
}

.btn {
  min-height: 48px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 0 16px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: inherit;
}
.btn-primary {
  background: var(--rose-deep);
  border-color: var(--rose-deep);
  color: #fff;
}
a.btn-primary { color: #fff; }
.btn-ghost { background: transparent; color: inherit; }
a.btn-ghost { color: inherit; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn:hover { filter: brightness(0.98); }

.hint {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.hint code {
  background: #f6eee8;
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--ink);
}
.banner {
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0 0 16px;
}
.banner-error { background: #fdecec; color: var(--danger); }
.banner-warn { background: #f8ecd9; color: var(--warn); }
.banner-ok { background: #e7f3ec; color: var(--ok); }

.app-body { min-height: 100dvh; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(243, 231, 223, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(142, 74, 85, 0.08);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}
.brand strong {
  display: block;
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 600;
}
.brand em {
  display: block;
  font-style: normal;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.top-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.top-nav a, .text-btn, .who {
  text-decoration: none;
  color: var(--ink);
  padding: 8px 10px;
  border-radius: 10px;
  font-weight: 500;
}
.top-nav a.is-active { background: rgba(142, 74, 85, 0.1); }
.who { color: var(--muted); }

.workspace {
  width: min(1180px, calc(100% - 24px));
  margin: 18px auto 110px;
}
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 80mm;
  gap: 20px;
  align-items: start;
}
.composer, .card {
  border-radius: var(--radius);
  padding: 22px;
}
.panel-head { margin-bottom: 18px; }
.panel-head h2, .card h2 {
  font-family: var(--display);
  margin: 0 0 4px;
}
.card h3 { margin: 10px 0 4px; font-size: 1rem; }

.field { display: block; margin-bottom: 14px; }
.field.compact { margin: 0; }
.lines-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 10px;
}
.lines-head h2 { font-size: 1rem; margin: 0; }

.lines { display: grid; gap: 10px; }
.line-row {
  display: grid;
  grid-template-columns: 0.9fr 1.4fr 0.9fr 0.7fr auto;
  grid-template-areas:
    "service variant tech price remove"
    "note note note note note";
  gap: 8px;
  align-items: end;
  background: #fbf6f2;
  border-radius: 14px;
  padding: 10px;
}
.line-service { grid-area: service; }
.line-variant { grid-area: variant; }
.line-tech { grid-area: tech; }
.line-price { grid-area: price; }
.line-remove { grid-area: remove; }
.line-note {
  grid-area: note;
  padding-left: 18px;
  border-left: 2px solid var(--line);
  margin-left: 4px;
}
.line-amt {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  padding-right: 4px;
}
.icon-btn {
  width: 48px;
  height: 48px;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 12px;
}
.icon-btn:hover { background: #f3e1dc; color: var(--danger); }

.extras, .tip-row {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
  margin: 16px 0;
}
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  font-weight: 600;
}
.check input { width: 20px; height: 20px; }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  min-height: 42px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 0 14px;
  font-weight: 600;
}
.chip.is-on {
  background: var(--rose-deep);
  border-color: var(--rose-deep);
  color: #fff;
}

.running-total, .receipt-totals, .receipt-meta {
  display: grid;
  gap: 6px;
}
.running-total {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.running-total > div,
.receipt-totals > div,
.receipt-meta > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.running-total dt, .receipt-totals dt, .receipt-meta dt {
  color: var(--muted);
  font-weight: 500;
}
.running-total dd, .receipt-totals dd, .receipt-meta dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.grand dt, .grand dd {
  color: var(--rose-deep);
  font-size: 1.15rem;
}

.preview-wrap {
  position: sticky;
  top: 84px;
  width: 80mm;
  justify-self: center;
}
.receipt {
  width: 80mm;
  max-width: 80mm;
  box-sizing: border-box;
  background: var(--paper);
  border-radius: 2px;
  padding: 5mm 4mm 8mm;
  min-height: 0;
  font-size: 12px;
  line-height: 1.3;
}
.receipt-head { text-align: center; margin-bottom: 8px; }
.receipt-mark { display: flex; justify-content: center; margin: 0 0 4px; }
.receipt-mark svg { width: 22px; height: 22px; }
.receipt-head h2 {
  font-family: var(--display);
  font-size: 1.15rem;
  margin: 0 0 4px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.receipt-address, .receipt-phone {
  margin: 0;
  color: var(--muted);
  white-space: pre-line;
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}
.receipt-meta {
  border-top: 1px dashed #222;
  border-bottom: 1px dashed #222;
  padding: 8px 0;
  margin: 8px 0;
  gap: 3px;
  font-size: 0.82rem;
}
.receipt-items {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  margin-bottom: 8px;
  font-size: 0.82rem;
}
.receipt-items th {
  text-align: left;
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
  padding-bottom: 4px;
}
.receipt-items th:last-child,
.receipt-items td:last-child {
  text-align: right;
  width: 22mm;
  white-space: nowrap;
  vertical-align: top;
}
.receipt-items td {
  padding: 4px 0 6px;
  border-bottom: 1px dotted var(--line);
  vertical-align: top;
  overflow-wrap: anywhere;
}
.item-title { font-weight: 600; display: block; }
.item-note {
  display: block;
  margin-left: 3mm;
  padding-left: 2mm;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
}
.receipt-totals { gap: 3px; font-size: 0.85rem; }
.receipt-totals .grand {
  border-top: 1px dashed #222;
  padding-top: 6px;
  margin-top: 4px;
}
.grand dt, .grand dd { font-size: 1rem; }
.receipt-thanks {
  text-align: center;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}
.receipt-thanks-name {
  text-align: center;
  margin: 2px 0 0;
  font-family: var(--display);
  color: var(--rose-deep);
  font-size: 0.92rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 252, 250, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.action-btns { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.form-error {
  color: var(--danger);
  margin: 0;
  min-height: 0;
  font-weight: 600;
}
.form-error:empty { display: none; }
.action-bar .form-error:not(:empty) {
  background: #fdecec;
  padding: 8px 12px;
  border-radius: 10px;
}

.subtabs {
  display: flex;
  gap: 8px;
  margin: 0 0 16px;
}
.subtabs a {
  flex: 1;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border-radius: 12px;
  text-decoration: none;
  font-weight: 600;
  color: inherit;
  background: #fff;
  border: 1px solid var(--line);
  text-align: center;
}
.subtabs a.is-active {
  background: var(--rose-deep);
  border-color: var(--rose-deep);
  color: #fff;
}
.history-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
}
.history-filters-compact {
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
}
.filter-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.history-results .muted { margin: 0 0 12px; }
.table-wrap { overflow-x: auto; }
.history-table {
  width: 100%;
  border-collapse: collapse;
}
.history-table th {
  text-align: left;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0 8px 10px 0;
}
.history-table td {
  padding: 12px 8px 12px 0;
  border-top: 1px solid var(--line);
  vertical-align: middle;
}
.history-table td:last-child,
.history-table th:last-child { text-align: right; padding-right: 0; }
.history-table code {
  background: #f6eee8;
  padding: 2px 6px;
  border-radius: 6px;
}
.history-table .btn { min-height: 48px; }
.history-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.inline-form { display: inline; margin: 0; }
.empty { margin: 0; color: var(--muted); }
.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
}
.pager-page {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  text-decoration: none;
  color: inherit;
  font-weight: 600;
}
.pager-page.is-active {
  background: var(--rose-deep);
  border-color: var(--rose-deep);
  color: #fff;
}
.pager-gap { color: var(--muted); padding: 0 4px; }
.pager [aria-disabled="true"] { opacity: 0.45; pointer-events: none; }

.production-card { padding: 16px; overflow: hidden; }
.prod-board {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.prod-scroll {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.prod-grid {
  display: grid;
  grid-template-columns: 4.5rem;
  width: max-content;
  min-width: 100%;
  font-variant-numeric: tabular-nums;
}
.prod-grid:not(.is-empty) {
  grid-template-columns: 4.5rem repeat(var(--tech-count), 7.75rem);
}
.prod-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 52px;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  text-align: center;
  background: var(--surface);
}
.prod-head, .prod-corner {
  background: #fbf6f2;
  font-weight: 600;
}
.prod-corner {
  position: sticky;
  left: 0;
  z-index: 2;
  color: var(--muted);
}
.prod-head.prod-corner { z-index: 3; }
.prod-tech {
  display: block;
  width: 100%;
  text-align: center;
  overflow-wrap: anywhere;
  line-height: 1.2;
}
.prod-price {
  width: 100%;
  text-align: center;
  font-weight: 600;
}
.prod-blank { color: transparent; }
.prod-foot { border-bottom: 0; }
.prod-add {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  margin-top: 4px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  font-size: 1.3rem;
  line-height: 1;
}
.prod-remove {
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  font-size: 1.2rem;
  line-height: 1;
}
.prod-hint { margin: 12px 0 0; }
.prod-shop {
  margin: 0;
  text-align: right;
  font-size: 1.05rem;
}
.prod-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.tech-summary { display: none; }
.picker {
  position: fixed;
  inset: 0;
  background: rgba(44, 33, 28, 0.35);
  display: grid;
  place-items: end center;
  z-index: 40;
  padding: 16px;
}
.picker-card {
  width: min(480px, 100%);
  background: var(--surface);
  border-radius: 20px 20px 12px 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.picker-card h2 { margin: 0 0 8px; font-family: var(--display); }
.picker-list { display: grid; gap: 8px; margin: 12px 0 16px; }
.picker-choice { min-height: 48px; text-align: left; }

.settings-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 20px;
  align-items: start;
}
.settings-side { display: grid; gap: 20px; }
.tech-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.tech-list li {
  display: flex;
  gap: 8px;
  align-items: center;
}
.tech-list li span {
  flex: 1;
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: #fbf6f2;
  border-radius: 12px;
  font-weight: 600;
}
.tech-add {
  display: flex;
  gap: 8px;
}
.tech-add input { flex: 1; }
.price-group {
  margin: 14px 0 18px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.price-group h4 {
  margin: 0 0 10px;
  font-family: var(--display);
  font-size: 1.05rem;
}
.price-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}

@media (max-width: 980px) {
  .layout, .settings-grid { grid-template-columns: 1fr; }
  .preview-wrap { position: static; margin: 0 auto; }
  .history-filters { grid-template-columns: 1fr 1fr; }
  .preview-wrap { position: static; }
  .topbar { align-items: flex-start; }
}

@media (max-width: 720px) {
  .line-row {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "service remove"
      "variant variant"
      "tech tech"
      "price price"
      "note note";
  }
  .line-note { margin-left: 0; }
  .workspace { width: calc(100% - 16px); margin-bottom: 128px; }
  .action-bar { flex-direction: column; align-items: stretch; }
  .action-btns .btn { flex: 1; }
  .brand em { display: none; }
  .history-filters { grid-template-columns: 1fr; }
  .history-table thead { display: none; }
  .history-table tr {
    display: grid;
    gap: 6px;
    padding: 12px 0;
    border-top: 1px solid var(--line);
  }
  .history-table td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border: 0;
    padding: 0;
    text-align: right;
  }
  .history-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
  }
  .history-table td:last-child { display: block; }
  .history-table td:last-child .btn { width: 100%; }
}

@media print {
  @page {
    size: 80mm auto;
    margin: 2mm 3mm;
  }
  html, body {
    width: 80mm;
    margin: 0;
    padding: 0;
    background: #fff;
  }
  .no-print, .topbar, .action-bar, .composer, .banner, .picker, .production-page { display: none !important; }
  .tech-summary {
    display: block !important;
    width: 74mm;
    max-width: 74mm;
    margin: 0 auto;
    color: #000;
    font-size: 12px;
    line-height: 1.35;
  }
  .summary-head { text-align: center; margin-bottom: 8px; }
  .summary-head h1 { font-size: 15px; margin: 0 0 4px; }
  .summary-head p { margin: 0; font-size: 10px; }
  .summary-label, .summary-date, .summary-tech { text-align: center; margin: 2px 0; }
  .summary-tech { font-weight: 700; margin: 8px 0; }
  .summary-table { width: 100%; margin: 8px 0; }
  .summary-row {
    display: grid;
    grid-template-columns: 10mm 1fr;
    align-items: baseline;
    padding: 3px 0;
    border-bottom: 1px dotted #000;
    font-variant-numeric: tabular-nums;
  }
  .summary-cols { font-size: 10px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
  .summary-num { text-align: center; }
  .summary-amt { text-align: right; }
  .summary-empty { grid-column: 1 / -1; text-align: center; }
  .summary-total {
    font-weight: 700;
    font-size: 14px;
    margin: 4px 0 0;
    display: grid;
    grid-template-columns: 10mm 1fr;
  }
  .summary-total span:last-child { text-align: right; }
  .workspace, .layout, .preview-wrap {
    width: 80mm;
    max-width: 80mm;
    margin: 0;
    padding: 0;
    display: block;
    position: static;
    box-shadow: none;
    background: #fff;
  }
  .receipt {
    width: 74mm;
    max-width: 74mm;
    margin: 0 auto;
    padding: 1mm 0 8mm;
    min-height: 0;
    box-shadow: none;
    border: 0;
    background: #fff;
    color: #000;
    font-size: 11px;
  }
  .receipt, .receipt * {
    color: #000 !important;
    background: #fff !important;
    box-shadow: none !important;
  }
  .receipt-head h2 { font-size: 14px; }
  .grand dt, .grand dd { font-size: 13px; }
}
