/* ============================================================
   Nexus Billing — design tokens
   Display/UI: Space Grotesk · Body: Inter · Receipt: JetBrains Mono
   ============================================================ */
:root {
  --ink: #1b1b1b;
  --paper: #fbf7ee;
  --paper-line: rgba(27, 27, 27, 0.14);
  --charcoal: #14181b;
  --charcoal-2: #1d2226;
  --charcoal-3: #262c31;
  --hairline: rgba(251, 247, 238, 0.09);
  --paprika: #c1481f;
  --paprika-dark: #8f2f16;
  --mustard: #d9a02b;
  --curry: #4c7a3f;
  --whatsapp: #25d366;
  --muted: #9aa3a8;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--charcoal);
  color: #f2efe8;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}
button:focus-visible,
select:focus-visible,
textarea:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--mustard);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------------- App shell ---------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: var(--charcoal);
  border-bottom: 1px solid var(--hairline);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.brand-logo {
  flex: none;
  display: block;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.brand-text strong {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.brand-text span {
  font-size: 11px;
  color: var(--muted);
}

.app-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 13px;
  color: var(--muted);
  display: none;
}

@media (min-width: 720px) {
  .app-title { display: block; }
}

/* ---------------- Layout ---------------- */
.layout {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 16px 90px;
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 380px;
    align-items: start;
  }
  .preview-col { position: sticky; top: 78px; }
}

.panel {
  background: var(--charcoal-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 18px;
}

.panel + .panel { margin-top: 18px; }

.panel-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mustard);
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-title .step {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--paprika);
  color: var(--paper);
  font-size: 11px;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0;
}

/* ---------------- Order fields ---------------- */
.meta-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  background: var(--charcoal-3);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
  color: #f2efe8;
  font-size: 14px;
  font-family: inherit;
}

textarea#orderInput {
  min-height: 150px;
  resize: vertical;
  line-height: 1.5;
  font-family: 'JetBrains Mono', 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 13.5px;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 0;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.btn {
  padding: 11px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13.5px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--paprika); color: var(--paper); }
.btn-primary:hover { filter: brightness(1.08); }

.btn-ghost {
  background: transparent;
  color: #f2efe8;
  border: 1px solid var(--hairline);
}
.btn-ghost:hover { border-color: var(--muted); }

.btn-whatsapp { background: var(--whatsapp); color: #06210f; }
.btn-whatsapp:hover { filter: brightness(1.06); }

.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------------- Parsed items table ---------------- */
.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.items-table th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0 6px 8px;
  font-weight: 600;
}

.items-table td {
  padding: 8px 6px;
  border-top: 1px solid var(--hairline);
  vertical-align: middle;
}

.items-table tr.unmatched-row td { border-top-color: rgba(217, 160, 43, 0.3); }

.item-name { font-weight: 500; }
.item-category { display: block; font-size: 11px; color: var(--muted); }

.qty-input {
  width: 52px;
  text-align: center;
  background: var(--charcoal-3);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  color: #f2efe8;
  padding: 5px 4px;
  font-family: inherit;
}

.row-remove {
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
}
.row-remove:hover { color: var(--paprika); background: rgba(193, 72, 31, 0.12); }

.empty-state {
  color: var(--muted);
  font-size: 13.5px;
  padding: 14px 4px;
  text-align: center;
  border: 1px dashed var(--hairline);
  border-radius: var(--radius-sm);
}

/* Unmatched-line review */
.review-list { display: flex; flex-direction: column; gap: 10px; }

.review-card {
  background: var(--charcoal-3);
  border: 1px solid rgba(217, 160, 43, 0.35);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.review-card .raw-line {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  color: var(--mustard);
  margin-bottom: 8px;
  word-break: break-word;
}

.review-card .review-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.review-card select { flex: 1 1 180px; }

.badge-warn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--mustard);
  margin-bottom: 10px;
}

.add-item-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.add-item-row select { flex: 1 1 220px; }
.add-item-row button { flex: none; }

/* ---------------- Receipt / ticket (also used as PDF source) ---------------- */
.ticket-wrap {
  background: var(--charcoal-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 18px;
}

.ticket {
  background: #fbf7ee;
  color: #1b1b1b;
  font-family: 'JetBrains Mono', 'IBM Plex Mono', ui-monospace, monospace;
  padding: 22px 20px 4px;
  border-radius: 4px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);

.ticket-scallop {
  height: 12px;
  background:
    radial-gradient(circle at 8px 0, transparent 8px, #fbf7ee 8.5px) 0 -6px / 16px 12px repeat-x;
  margin-top: 6px;
}

.ticket-head {
  text-align: center;
  margin-bottom: 14px;
}

.ticket-brand {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.04em;
}

.ticket-sub {
  font-size: 11px;
  color: #5a5650;
  margin-top: 2px;
}

.ticket-divider {
  border: none;
  border-top: 1px dashed rgba(27, 27, 27, 0.14);
  margin: 12px 0;
}

.ticket-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  margin-bottom: 3px;
}

.ticket-items { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 4px; }
.ticket-items th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-bottom: 6px;
  border-bottom: 1px dashed rgba(27, 27, 27, 0.14);
}
.ticket-items th.num, .ticket-items td.num { text-align: right; }
.ticket-items td { padding: 4px 0; vertical-align: top; }
.ticket-items tr.item-row td { border-bottom: 1px dotted rgba(27,27,27,0.08); }

.ticket-totals { margin-top: 10px; font-size: 12.5px; }
.ticket-totals .row { display: flex; justify-content: space-between; padding: 2px 0; }
.ticket-totals .grand {
  font-weight: 700;
  font-size: 15px;
  border-top: 1px dashed rgba(27, 27, 27, 0.14);
  margin-top: 6px;
  padding-top: 8px;
}

.ticket-footer {
  text-align: center;
  margin-top: 16px;
  padding-top: 10px;
  border-top: 1px dashed rgba(27, 27, 27, 0.14);
  font-size: 10.5px;
  color: #5a5650;
}

.ticket-footer a {
  color: #8f2f16;
  font-weight: 600;
  text-decoration: none;
}
.ticket-footer a:hover { text-decoration: underline; }

.ticket-barcode {
  height: 26px;
  margin: 10px auto 2px;
  width: 70%;
  background: repeating-linear-gradient(
    90deg, #1b1b1b 0 2px, transparent 2px 4px, #1b1b1b 4px 5px,
    transparent 5px 8px, #1b1b1b 8px 9px, transparent 9px 13px
  );
  opacity: 0.85;
}

.preview-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }

/* ---------------- Global footer ---------------- */
.app-footer {
  text-align: center;
  padding: 22px 16px 30px;
  font-size: 12px;
  color: var(--muted);
}
.app-footer a { color: var(--mustard); font-weight: 600; text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(120%);
  background: var(--charcoal-3);
  border: 1px solid var(--hairline);
  color: #f2efe8;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 50;
  transition: transform 0.25s ease;
  box-shadow: var(--shadow);
}
.toast.show { transform: translateX(-50%) translateY(0); }

.offline-pill {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(76, 122, 63, 0.18);
  color: var(--curry);
  border: 1px solid rgba(76, 122, 63, 0.35);
  display: none;
  align-items: center;
  gap: 5px;
}
.offline-pill.show { display: inline-flex; }
.offline-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--curry);
}

/* Print / PDF export tuning — only the ticket is captured */
@media print {
  body * { visibility: hidden; }
  .ticket, .ticket * { visibility: visible; }
  .ticket { position: absolute; top: 0; left: 0; box-shadow: none; }
}
