/* ─── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  color-scheme: light;
  --bg:          #f5f2ec;
  --ink:         #1a1c1e;
  --ink-2:       #3c3f42;
  --muted:       #6b645a;
  --line:        #ddd5c6;
  --panel:       #fffdf8;
  --accent:      #0f7b6c;
  --accent-dark: #09574c;
  --accent-soft: #e6f4f1;
  --warning:     #c0392b;
  --warning-bg:  #fdf0ee;
  --ok:          #1a7a4a;
  --paper:       #ffffff;
  --shadow-sm:   0 2px 8px rgba(20,22,24,.06);
  --shadow-md:   0 8px 32px rgba(20,22,24,.10);
  --shadow-lg:   0 20px 60px rgba(20,22,24,.12);
  --radius:      10px;
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ─── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100svh;
  background:
    radial-gradient(ellipse 80% 40% at 10% 0%, rgba(15,123,108,.12) 0%, transparent 60%),
    radial-gradient(ellipse 60% 30% at 90% 100%, rgba(192,57,43,.07) 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
img { display: block; }

/* ─── Layout ─────────────────────────────────────────────────────────────────── */
.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 28px 28px 60px;
}

.workspace { display: grid; gap: 20px; }

/* ─── Topbar ─────────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-logo {
  width: clamp(60px, 8vw, 96px);
  height: auto;
  flex-shrink: 0;
}

.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

.top-actions button {
  display: flex;
  align-items: center;
  gap: 7px;
}

/* ─── Typography ─────────────────────────────────────────────────────────────── */
.eyebrow {
  margin: 0 0 3px;
  color: var(--accent-dark);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}

h1, h2 { margin: 0; line-height: 1.1; }
h1 { font-size: clamp(1.8rem, 4.5vw, 3.6rem); font-weight: 900; letter-spacing: -.02em; }
h2 { font-size: 1.15rem; font-weight: 800; }

.hint, .muted { margin: 0; color: var(--muted); font-size: 0.88rem; }

.save-status {
  min-height: 18px;
  margin: 3px 0 0;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 700;
}

.rate-info {
  display: block;
  margin-top: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-dark);
  min-height: 16px;
  text-transform: none;
  letter-spacing: 0;
}

.rate-info.rate-error { color: var(--warning); }

/* ─── Controls grid ──────────────────────────────────────────────────────────── */
.controls-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
}

/* ─── Inputs ─────────────────────────────────────────────────────────────────── */
input, select, textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #fffefc;
  color: var(--ink);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input, select { min-height: 42px; padding: 0 12px; }

textarea {
  min-height: 260px;
  padding: 14px;
  resize: vertical;
  line-height: 1.6;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15,123,108,.15);
}

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.primary-btn, .ghost-btn, .icon-btn {
  min-height: 40px;
  border-radius: 8px;
  border: 1.5px solid transparent;
  padding: 0 16px;
  font-weight: 700;
  font-size: 0.88rem;
  letter-spacing: .01em;
  transition: background .14s, border-color .14s, box-shadow .14s, opacity .14s;
  white-space: nowrap;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(15,123,108,.25);
}
.primary-btn:hover  { background: var(--accent-dark); box-shadow: 0 4px 12px rgba(15,123,108,.35); }
.primary-btn:active { opacity: .88; }
.primary-btn:disabled { opacity: .55; cursor: not-allowed; }

.ghost-btn {
  background: var(--paper);
  border-color: var(--line);
  color: var(--ink);
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent-dark); }

.icon-btn {
  width: 34px;
  min-width: 34px;
  padding: 0;
  background: transparent;
  border-color: var(--line);
  color: var(--warning);
  font-size: 0.78rem;
}
.icon-btn:hover { background: var(--warning-bg); border-color: var(--warning); }

/* ─── Main grid ──────────────────────────────────────────────────────────────── */
.main-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: start;
}

/* ─── Panels ─────────────────────────────────────────────────────────────────── */
.panel {
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.input-panel, .catalog-panel { display: grid; gap: 14px; }

.catalog-collapsed { box-shadow: var(--shadow-sm); }
.catalog-collapsed .catalog-edit-control { display: none; }

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

.catalog-search { max-width: 480px; }

/* ─── Tables ─────────────────────────────────────────────────────────────────── */
.catalog-table-wrap,
.invoice-table-wrap,
.missing-table-wrap { overflow: auto; }

table { width: 100%; border-collapse: collapse; }

th {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: .06em;
}

td, th {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  vertical-align: middle;
}

.data-table input { min-width: 110px; }
.data-table .catalog-price { min-width: 90px; }
.catalog-store-cell { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

/* ─── Catalog thumbnail ──────────────────────────────────────────────────────── */
.catalog-img-cell { width: 44px; padding: 6px 4px; }

.catalog-thumb {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg);
}

/* ─── Invoice band ───────────────────────────────────────────────────────────── */
.invoice-band { padding: 4px 0 40px; }

.paper {
  background: var(--paper);
  border: 1.5px solid #e0d8cc;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 32px 36px;
}

/* ─── Invoice header ─────────────────────────────────────────────────────────── */
.invoice-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--ink);
}

.invoice-title-text {
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: -.02em;
  color: var(--accent-dark);
}

.invoice-logo {
  width: clamp(100px, 14vw, 160px);
  height: auto;
  object-fit: contain;
}

/* ─── Invoice details ────────────────────────────────────────────────────────── */
.invoice-details {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 24px 0;
  padding: 16px 18px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #fafaf7;
}

.invoice-details > div { min-width: 0; }
.invoice-details strong { display: block; overflow-wrap: anywhere; font-size: 1rem; }

.label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ─── Invoice table ──────────────────────────────────────────────────────────── */
.invoice-table td, .invoice-table th { padding: 8px 7px; }

.col-num {
  width: 28px;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.col-img { width: 56px; padding: 5px 4px; }

.product-thumb {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #f8f8f6;
  display: block;
}

.col-product { min-width: 180px; }

.row-requested {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
}

.row-catalog {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.3;
}

.col-store {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.num-col { text-align: right; white-space: nowrap; }

.match-low { color: var(--warning); }

.missing-invoice-row { color: var(--warning); font-weight: 700; }

/* ─── Invoice footer ─────────────────────────────────────────────────────────── */
.invoice-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.unmatched {
  max-width: 55%;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--warning);
}

.match-all {
  color: var(--ok);
  font-weight: 700;
  font-size: 0.85rem;
}

.totals { min-width: 260px; }

.totals div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 5px 0;
}

.grand-total {
  border-top: 2px solid var(--ink);
  padding-top: 8px !important;
  margin-top: 4px;
  font-size: 1.25rem;
  font-weight: 800;
}

/* ─── Tabs panel ─────────────────────────────────────────────────────────────── */
.tabs-panel { display: grid; gap: 16px; }
.tabs-panel[hidden] { display: none; }

.tab-card {
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--paper);
}

.tab-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  background: var(--accent-soft);
  border-bottom: 1.5px solid var(--line);
}

.tab-card-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }

.tab-guest-name { font-size: 1rem; font-weight: 800; color: var(--ink); }
.tab-villa-name { font-size: 0.82rem; font-weight: 600; color: var(--accent-dark); }
.tab-meta { font-size: 0.75rem; color: var(--muted); }

.tab-card-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

.tab-days { padding: 0 16px; }

.tab-day {
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}
.tab-day:last-child { border-bottom: 0; }

.tab-day-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.tab-day-label { font-weight: 700; font-size: 0.9rem; flex: 1; color: var(--ink); }
.tab-day-subtotal { font-weight: 700; font-size: 0.9rem; color: var(--accent-dark); white-space: nowrap; }

.tab-day-items { display: grid; gap: 3px; }

.tab-day-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--ink-2);
  padding: 2px 0;
}
.tab-item-name { flex: 1; }
.tab-item-qty { color: var(--muted); white-space: nowrap; }
.tab-item-price { white-space: nowrap; font-weight: 600; min-width: 80px; text-align: right; }

.tab-grand-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: #fafaf7;
  border-top: 2px solid var(--ink);
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
}
.tab-grand-total strong { color: var(--accent-dark); }

/* ─── Missing panel ──────────────────────────────────────────────────────────── */
.missing-panel { display: grid; gap: 14px; border-color: var(--warning); }
.missing-panel[hidden] { display: none; }

.missing-table td:first-child { min-width: 180px; }
.missing-table input { min-width: 120px; }

.missing-original, .missing-qty { display: block; }

.missing-qty {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.missing-img-cell { min-width: 160px; }

.missing-img-preview {
  display: flex;
  align-items: center;
  gap: 8px;
}

.missing-img-thumb {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg);
  flex-shrink: 0;
}

/* ─── Inline price input ──────────────────────────────────────────────────── */
.price-inline {
  width: 90px;
  border: 1px solid transparent;
  background: transparent;
  text-align: right;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  padding: 3px 6px;
  border-radius: 5px;
  cursor: text;
  transition: background .12s, border-color .12s;
}

.price-inline:hover {
  background: var(--accent-soft);
  border-color: var(--line);
}

.price-inline:focus {
  outline: none;
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15,123,108,.15);
}

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 980px) {
  .controls-grid { grid-template-columns: 1fr 1fr; }
  .main-grid { grid-template-columns: 1fr 1fr; align-items: stretch; }
}

@media (max-width: 680px) {
  .app-shell { padding: 14px 14px 40px; }

  .topbar, .invoice-header, .invoice-footer { flex-direction: column; align-items: flex-start; }
  .panel-header { flex-direction: column; }

  .controls-grid, .main-grid, .invoice-details { grid-template-columns: 1fr; }

  .top-actions, .top-actions button, .panel-header button { width: 100%; justify-content: center; }

  .unmatched { max-width: 100%; }
  .paper { padding: 20px 16px; }
  .totals { min-width: 0; width: 100%; }
}

/* ─── Login overlay ──────────────────────────────────────────────────────────── */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-overlay[hidden] { display: none; }

.login-card {
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
  width: min(400px, 100%);
}

.login-logo {
  width: 72px;
  height: auto;
  margin: 0 auto 16px;
  display: block;
}

.login-error {
  margin: 10px 0 0;
  color: var(--warning);
  font-size: 0.82rem;
  font-weight: 600;
  min-height: 20px;
  text-align: center;
}

.user-badge {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

/* ─── Print ──────────────────────────────────────────────────────────────────── */
@media print {
  body { background: #fff; }

  .topbar,
  .controls-grid,
  .main-grid,
  .missing-panel { display: none !important; }

  .app-shell, .invoice-band { padding: 0; }

  .paper {
    border: 0;
    box-shadow: none;
    border-radius: 0;
    padding: 0;
  }

  .invoice-logo { width: 130px; }

  .product-thumb { width: 36px; height: 36px; }

  .score-badge { display: none; }

  /* Tabs panel: always starts on a fresh page */
  .tabs-panel {
    break-before: page;
    page-break-before: always;
    border: 0;
    box-shadow: none;
    padding: 0;
  }

  /* Hide interactive buttons inside tabs when printing */
  .tab-card-actions,
  .tab-order-delete,
  .tab-delete-btn { display: none !important; }

  .tab-card {
    box-shadow: none;
    border: 1px solid #ddd5c6;
    break-inside: avoid;
  }
}
