/* ============================================================
   ALIF STUDIO POS — Design tokens
   Palette: ink black, aged bone, brass gold, deep burgundy
   Display: Fraunces (serif, editorial) / Body: Inter / Data: IBM Plex Mono
   Signature: garment hang-tag motif on receipts & invoice numbers
   ============================================================ */

:root {
  --ink: #121110;
  --panel: #1b1916;
  --panel-2: #232019;
  --hairline: #3a362c;
  --bone: #ece6d6;
  --bone-dim: #b7ae98;
  --muted: #8c8474;
  --brass: #c9a15a;
  --brass-dim: #a9854a;
  --burgundy: #7c2d3b;
  --burgundy-bright: #a63b4d;
  --green: #5f8a68;
  --radius: 3px;
  --shadow: 0 12px 30px rgba(0,0,0,.35);
}

[data-theme="light"] {
  --ink: #f4efe2;
  --panel: #ffffff;
  --panel-2: #f0ead9;
  --hairline: #ddd2b5;
  --bone: #221f18;
  --bone-dim: #4d4636;
  --muted: #8c8474;
  --brass: #a9803f;
  --brass-dim: #8c6a34;
  --burgundy: #7c2d3b;
  --burgundy-bright: #a63b4d;
  --green: #3f6b4a;
  --shadow: 0 12px 30px rgba(0,0,0,.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--bone);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  min-height: 100vh;
}

h1, h2, h3, h4, .display {
  font-family: "Fraunces", Georgia, serif;
  font-optical-sizing: auto;
  letter-spacing: 0.01em;
}

.mono, .sku, .invoice-no, .price {
  font-family: "IBM Plex Mono", monospace;
}

a { color: inherit; }

button {
  font-family: inherit;
  cursor: pointer;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--hairline); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

/* ---------------- Login ---------------- */

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(201,161,90,.06), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(124,45,59,.10), transparent 45%),
    var(--ink);
}

.login-card {
  width: 380px;
  max-width: 90vw;
  padding: 44px 38px 36px;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: relative;
}

.login-card::before {
  content: "";
  position: absolute;
  top: -1px; left: 32px;
  width: 14px; height: 14px;
  background: var(--ink);
  border: 1px solid var(--hairline);
  border-top: none;
  border-radius: 0 0 50% 50%;
}

.brand-mark {
  text-align: center;
  margin-bottom: 30px;
}

.brand-mark .brand-logo {
  display: block;
  height: 54px;
  width: auto;
  margin: 0 auto 10px;
}

.brand-mark .word {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--bone);
}

.brand-mark .tag {
  display: block;
  margin-top: 6px;
  font-size: 10px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--brass);
}

.field {
  margin-bottom: 18px;
}

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

.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  background: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  color: var(--bone);
  font-size: 14px;
}

.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brass);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  transition: transform .12s ease, opacity .12s ease;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  width: 100%;
  background: var(--brass);
  color: #1b1610;
}
.btn-primary:hover { background: #d6ac66; }

.btn-outline {
  background: transparent;
  border-color: var(--hairline);
  color: var(--bone);
}
.btn-outline:hover { border-color: var(--brass); color: var(--brass); }

.btn-danger {
  background: var(--burgundy);
  color: var(--bone);
}
.btn-danger:hover { background: var(--burgundy-bright); }

.btn-sm { padding: 7px 12px; font-size: 11px; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 10px;
  border-radius: var(--radius);
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--bone-dim);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 600;
}
.theme-toggle:hover { border-color: var(--brass); color: var(--brass); }

.login-theme-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  width: auto;
  margin-bottom: 0;
  padding: 8px 12px;
}

.error-msg {
  margin-top: 14px;
  padding: 10px 12px;
  background: rgba(124,45,59,.18);
  border: 1px solid var(--burgundy);
  color: #f0c9cf;
  font-size: 13px;
  border-radius: var(--radius);
}

.demo-creds {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px dashed var(--hairline);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.7;
}
.demo-creds b { color: var(--bone-dim); }

/* ---------------- App shell ---------------- */

.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  padding: 26px 0;
}

.sidebar .brand-mark {
  margin-bottom: 30px;
  padding: 0 22px;
  text-align: left;
}
.sidebar .brand-mark .word { font-size: 20px; }
.sidebar .brand-mark .brand-logo {
  height: 34px;
  margin: 0 0 8px;
}

.nav-group {
  padding: 0 12px;
  margin-bottom: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--bone-dim);
  font-size: 13px;
  letter-spacing: 0.03em;
  text-decoration: none;
  margin-bottom: 2px;
}

.nav-link:hover { background: var(--panel-2); color: var(--bone); }
.nav-link.active {
  background: var(--panel-2);
  color: var(--brass);
  box-shadow: inset 2px 0 0 var(--brass);
}

.nav-link .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .6; }

.sidebar-footer {
  margin-top: auto;
  padding: 16px 22px 0;
  border-top: 1px solid var(--hairline);
}

.user-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
}
.user-chip .name { font-size: 13px; color: var(--bone); }
.user-chip .role {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--brass);
}

.main {
  padding: 30px 36px 60px;
  overflow-y: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 26px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--hairline);
}

.topbar h1 { font-size: 26px; margin: 0; }
.topbar .eyebrow {
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--brass);
  margin: 0 0 6px;
}
.topbar .clock { font-size: 12px; color: var(--muted); }

/* ---------------- Cards / grid ---------------- */

.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

.card {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-card .label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}
.stat-card .value {
  font-family: "Fraunces", serif;
  font-size: 30px;
  color: var(--bone);
}
.stat-card .value.brass { color: var(--brass); }
.stat-card .value.burgundy { color: var(--burgundy-bright); }

/* ---------------- Tables ---------------- */

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--hairline);
}
tbody td {
  padding: 12px;
  border-bottom: 1px solid rgba(58,54,44,.5);
  color: var(--bone-dim);
}
tbody tr:hover { background: rgba(255,255,255,.02); }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.badge-low { background: rgba(124,45,59,.2); color: #ef9fac; }
.badge-ok { background: rgba(95,138,104,.2); color: #9fd4ab; }
.badge-role { background: rgba(201,161,90,.15); color: var(--brass); }

/* ---------------- POS / Billing ---------------- */

.pos-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 22px;
  align-items: start;
}

.category-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.tab {
  padding: 8px 14px;
  border: 1px solid var(--hairline);
  border-radius: 20px;
  font-size: 12px;
  color: var(--bone-dim);
  background: transparent;
}
.tab.active { border-color: var(--brass); color: var(--brass); }

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}

.product-tile {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 14px;
  text-align: left;
}
.product-tile:hover { border-color: var(--brass); }
.product-tile .name { font-size: 13px; color: var(--bone); margin-bottom: 4px; }
.product-tile .meta { font-size: 11px; color: var(--muted); margin-bottom: 10px; }
.product-tile .price { font-size: 15px; color: var(--brass); }
.tile-thumb {
  width: 100%;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 8px;
  border: 1px solid var(--hairline);
}
.table-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--hairline);
  flex-shrink: 0;
}
.table-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 11px;
  background: var(--panel);
}
.product-tile .stock-warn { color: var(--burgundy-bright); font-size: 10px; margin-top: 6px; }

.cart-panel {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 20px;
  position: sticky;
  top: 30px;
}

.cart-panel h3 { margin-top: 0; font-size: 17px; }

.cart-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px dashed var(--hairline);
  font-size: 12.5px;
}
.cart-item .qty-controls { display: flex; align-items: center; gap: 8px; }
.qty-btn {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--bone);
  display: grid; place-items: center;
  font-size: 13px;
  line-height: 1;
}

.cart-totals { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--hairline); }
.cart-totals .row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 8px; color: var(--bone-dim); }
.cart-totals .row.total { font-size: 19px; color: var(--brass); font-family: "Fraunces", serif; margin-top: 10px; }

.pay-methods { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
.pay-methods .tab { flex: 1; text-align: center; }

/* ---------------- Receipt (garment tag motif) ---------------- */

.receipt {
  width: 300px;
  margin: 0 auto;
  background: #f7f2e2;
  color: #1b1916;
  padding: 26px 22px;
  border-radius: 2px;
  position: relative;
  font-family: "IBM Plex Mono", monospace;
  page-break-inside: avoid;
  break-inside: avoid;
}
.receipt-thanks {
  text-align: center;
  font-size: 12px;
  font-style: italic;
  margin-top: 10px;
  page-break-inside: avoid;
  break-inside: avoid;
}
.receipt-policy {
  text-align: center;
  font-size: 10px;
  color: #6b6455;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
  page-break-inside: avoid;
  break-inside: avoid;
}
.receipt::before {
  content: "";
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  width: 16px; height: 16px;
  background: #2b2925;
  border-radius: 50%;
}
.receipt-logo { display: block; height: 40px; width: auto; margin: 18px auto 0; }
.receipt-brand { text-align: center; font-family: "Fraunces", serif; font-size: 20px; margin: 8px 0 2px; }
.receipt-sub { text-align: center; font-size: 10px; letter-spacing: 0.15em; text-transform: uppercase; color: #6b6455; margin-bottom: 14px; }
.receipt hr { border: none; border-top: 1px dashed #6b6455; margin: 12px 0; }
.receipt .r-row { display: flex; justify-content: space-between; font-size: 11.5px; margin-bottom: 6px; gap: 10px; }
.receipt .r-row.r-item span:first-child { display: flex; flex-direction: column; }
.receipt .r-row.r-item em { font-style: normal; font-size: 10px; color: #6b6455; }
.receipt .r-total { font-size: 15px; font-weight: 700; }

@media print {
  body * { visibility: hidden; }
  .receipt, .receipt * { visibility: visible; }
  .receipt {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    margin: 0;
    box-shadow: none;
    page: receipt-page;
  }
  .receipt-actions, .modal-backdrop { display: none !important; }
}

@page receipt-page { margin: 0; size: 80mm auto; }

/* ---------------- Sales Reports (downloaded via browser "Save as PDF") ---------------- */

.print-report {
  width: 100%;
  max-width: 700px;
  margin: 0 auto;
  background: #ffffff;
  color: #1b1916;
  font-family: "IBM Plex Mono", monospace;
  padding: 10mm;
  page: report-page;
}
.print-report-header { text-align: center; margin-bottom: 6px; }
.print-report-brand { font-family: "Fraunces", serif; font-size: 22px; font-weight: 600; }
.print-report-sub { font-size: 11px; letter-spacing: 0.15em; text-transform: uppercase; color: #6b6455; }
.print-report h2 { text-align: center; font-size: 16px; margin: 18px 0 2px; }
.print-report-meta { text-align: center; font-size: 11px; color: #6b6455; margin: 0 0 20px; }
.print-report h3 { font-size: 13px; margin: 22px 0 8px; border-bottom: 1px solid #ddd2b5; padding-bottom: 4px; }
.print-report-stats { display: flex; justify-content: space-between; gap: 10px; margin: 14px 0; flex-wrap: wrap; }
.print-report-stats > div { flex: 1; min-width: 120px; border: 1px solid #ddd2b5; border-radius: 3px; padding: 10px; text-align: center; }
.print-report-stats span { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: #6b6455; margin-bottom: 4px; }
.print-report-stats strong { font-size: 15px; }
.print-report table { width: 100%; border-collapse: collapse; font-size: 11px; margin-bottom: 10px; }
.print-report th { text-align: left; font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; color: #6b6455; border-bottom: 1px solid #ddd2b5; padding: 6px 4px; }
.print-report td { padding: 6px 4px; border-bottom: 1px solid #efe9d8; }

/* A4 page for the full report — separate from the small receipt/label
   named pages so a report print job never gets squeezed onto an 80mm or
   50mm strip. */
@page report-page { size: A4; margin: 12mm; }

@media print {
  #print-area .print-report {
    width: 100% !important;
    max-width: none !important;
    background: #ffffff !important;
    color: #1b1916 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* ---------------- Product barcodes ---------------- */

.barcode-modal-list { max-height: 50vh; overflow-y: auto; margin: 14px 0; display: flex; flex-direction: column; gap: 10px; }
.barcode-modal-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px; border: 1px solid var(--hairline); border-radius: var(--radius);
}
.barcode-modal-preview { width: 110px; height: 40px; flex-shrink: 0; }
.barcode-modal-preview svg { width: 100%; height: 100%; }
.barcode-modal-info { flex: 1; font-size: 13px; }

.barcode-label {
  width: 190px;
  margin: 0 auto;
  background: #ffffff;
  color: #1b1916;
  padding: 4px 6px 6px;
  text-align: center;
  font-family: "IBM Plex Mono", monospace;
  page-break-after: always;
  page-break-inside: avoid;
  break-inside: avoid;
  page: label-page;
}
.barcode-label-brand { font-family: "Fraunces", serif; font-size: 11px; font-weight: 600; line-height: 1.2; }
.barcode-label-name { font-size: 8px; margin-top: 1px; line-height: 1.2; }
.barcode-label-variant { font-size: 7px; color: #6b6455; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 2px; line-height: 1.2; }
.barcode-label-code { width: 100%; margin: 2px auto; line-height: 0; }
.barcode-label-code svg { width: 100%; height: auto; display: block; }
.barcode-label-price { font-size: 11px; font-weight: 700; margin-top: 2px; page-break-before: avoid; break-before: avoid; }

/* Most handheld/desktop thermal barcode printers (e.g. "4BARCODE 2B-220B")
   use a fixed 50mm-wide label roll with their own driver-defined label
   height — they ignore custom @page sizes that don't match a size they
   already know. Keeping the label small (well under a typical 25-30mm
   label height) means it fits on one physical label regardless of which
   preset the printer driver ends up using.
   Named page "label-page" (set via the `page:` property on .barcode-label
   above) keeps this sizing isolated from the receipt's 80mm @page rule,
   so the two print jobs never fight over the paper size. */
@page label-page { size: 50mm auto; margin: 0; }

@media print {
  #print-area .barcode-label {
    width: 100% !important;
    background: #ffffff !important;
    color: #1b1916 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  #print-area .barcode-label:last-child { page-break-after: auto; }
}

/* ---------------- Forms / modals ---------------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: grid; place-items: center;
  z-index: 50;
}
.modal {
  width: 480px;
  max-width: 92vw;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 26px;
}
.modal h3 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.search-input {
  max-width: 260px;
  width: 100%;
  padding: 11px 12px;
  background: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  color: var(--bone);
  font-size: 14px;
}
.search-input:focus {
  border-color: var(--brass);
  outline: none;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state .display { font-size: 20px; color: var(--bone-dim); margin-bottom: 8px; }

.section-title {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
  margin: 30px 0 12px;
}

.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--panel-2);
  border: 1px solid var(--brass);
  color: var(--bone);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 100;
}
.toast.error { border-color: var(--burgundy-bright); }

.hidden { display: none !important; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .pos-layout { grid-template-columns: 1fr; }
}

#print-area { display: none; }

@media print {
  body > *:not(#print-area) { display: none !important; }

  #print-area {
    display: block !important;
    position: static !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  #print-area .receipt {
    width: 100% !important;
    margin: 0 !important;
    box-shadow: none !important;
    background: #f7f2e2 !important;
    color: #1b1916 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    page: receipt-page;
  }
  #print-area .receipt::before { background: #2b2925 !important; }
}

@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
  }
}
