/* ============================================================
   Buku Hantu — styles.css
   Dark ghost theme, mobile-first (360px baseline), print styles
   ============================================================ */

/* ── Custom properties ────────────────────────────────────── */
:root {
  /* Palette */
  --bg:        #0d0a1a;
  --bg-card:   #1a1530;
  --bg-input:  #231d3a;
  --border:    #2e2850;
  --amber:     #f5b942;
  --amber-dim: #c9942e;
  --violet:    #8b7ff0;
  --violet-dim:#6457c4;
  --text:      #e8e4f7;
  --text-muted:#8d84b4;
  --danger:    #e05c5c;
  --success:   #4fc38a;
  --ghost:     #d0ccf7;

  /* Spacing */
  --gap:    12px;
  --gap-lg: 20px;
  --radius: 10px;

  /* Typography */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "Courier New", monospace;

  /* Nav */
  --nav-h: 60px;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  min-height: 100dvh;
  /* Reserve space for bottom nav */
  padding-bottom: var(--nav-h);
}

img, svg { display: block; max-width: 100%; }

a { color: var(--amber); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* ── Typography ───────────────────────────────────────────── */
h1 { font-size: 1.4rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }

.text-amber   { color: var(--amber); }
.text-violet  { color: var(--violet); }
.text-muted   { color: var(--text-muted); }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-ghost   { color: var(--ghost); }

.text-right  { text-align: right; }
.text-center { text-align: center; }

/* ── Layout helpers ───────────────────────────────────────── */
.row   { display: flex; align-items: center; gap: var(--gap); }
.col   { display: flex; flex-direction: column; gap: var(--gap); }
.wrap  { flex-wrap: wrap; }
.grow  { flex: 1; }
.ml-auto { margin-left: auto; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
}

.card-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.card-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--amber);
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s;
  min-height: 44px; /* touch target */
  user-select: none;
  white-space: nowrap;
}

.btn:active { filter: brightness(0.85); }
.btn:disabled { opacity: 0.45; pointer-events: none; }

.btn-primary  { background: var(--amber);  color: #0d0a1a; }
.btn-secondary{ background: var(--violet); color: #fff; }
.btn-ghost    { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-sm       { padding: 6px 12px; font-size: 0.85rem; min-height: 36px; }
.btn-block    { width: 100%; }

/* ── Form controls ────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 4px; }
.label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 1rem;
  transition: border-color 0.15s;
  min-height: 44px;
}

.input:focus {
  outline: none;
  border-color: var(--amber);
}

.input::placeholder { color: var(--text-muted); }

.input-money {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  text-align: right;
}

.input-error { border-color: var(--danger) !important; }

/* ── Inline error / info banners ──────────────────────────── */
.banner {
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.9rem;
}
.banner-error   { background: #3a1a1a; border: 1px solid var(--danger);  color: var(--danger); }
.banner-success { background: #0f2b1e; border: 1px solid var(--success); color: var(--success); }
.banner-info    { background: #1a1636; border: 1px solid var(--violet);  color: var(--ghost); }

/* ── Bottom navigation ────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 4px;
  transition: color 0.15s;
  min-width: 0;
  /* Touch target */
  min-height: var(--nav-h);
}

.nav-item:active { background: var(--bg-input); }

.nav-item.active {
  color: var(--amber);
}

.nav-icon {
  font-size: 1.3rem;
  line-height: 1;
}

/* ── View sections ────────────────────────────────────────── */
.view {
  display: none;
  padding: var(--gap);
  max-width: 600px;
  margin: 0 auto;
}

.view.active { display: block; }

.view-header {
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: var(--gap) 0 var(--gap-lg);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.view-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ghost);
}

/* ── Product grid (Kasir) ─────────────────────────────────── */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: var(--gap);
}

.product-tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 8px;
  text-align: center;
  cursor: pointer;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: border-color 0.15s, background 0.15s;
  font-size: 0.85rem;
  font-weight: 600;
  word-break: break-word;
  -webkit-tap-highlight-color: transparent;
}

.product-tile:active,
.product-tile:focus-visible {
  border-color: var(--amber);
  background: #1f1b34;
}

.product-tile .tile-price { font-size: 0.75rem; color: var(--amber); font-weight: 700; }
.product-tile .tile-stock { font-size: 0.7rem; color: var(--text-muted); }
.product-tile.low-stock   { border-color: var(--danger); }
.product-tile.out-of-stock { opacity: 0.4; pointer-events: none; }

/* ── Cart ─────────────────────────────────────────────────── */
.cart-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
}

.cart-item {
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.cart-item:last-child { border-bottom: none; }

.cart-item-name { flex: 1; font-size: 0.9rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-item-qty  { display: flex; align-items: center; gap: 6px; }
.qty-btn        { background: var(--bg-input); border: none; border-radius: 6px; width: 30px; height: 30px; cursor: pointer; font-size: 1rem; color: var(--text); display: flex; align-items: center; justify-content: center; }
.cart-item-price{ font-size: 0.9rem; font-weight: 600; font-family: var(--font-mono); min-width: 70px; text-align: right; }

.cart-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.cart-total .total-label { color: var(--text-muted); }
.cart-total .total-value { color: var(--amber); font-family: var(--font-mono); }

/* ── Receipt modal ────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding: var(--gap);
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: var(--gap-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: var(--gap);
  color: var(--ghost);
}

/* ── Customer / Bon list ──────────────────────────────────── */
.customer-list { display: flex; flex-direction: column; gap: 8px; }

.customer-row {
  display: flex;
  align-items: center;
  gap: var(--gap);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px var(--gap);
  cursor: pointer;
}

.customer-row:active { background: var(--bg-input); }

.customer-name  { font-weight: 600; flex: 1; }
.customer-debt  { font-family: var(--font-mono); font-weight: 700; color: var(--amber); }
.customer-lunas { font-size: 0.75rem; color: var(--success); font-weight: 600; }
.hantu-badge    { font-size: 0.75rem; color: var(--danger); font-weight: 700; }

/* ── Stock table ──────────────────────────────────────────── */
.stock-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.stock-table th {
  text-align: left;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

.stock-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.stock-table tr:last-child td { border-bottom: none; }

.low-badge {
  display: inline-block;
  background: #3a1a1a;
  color: var(--danger);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 20px;
  text-transform: uppercase;
}

/* ── KPI chips (Laporan) ──────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

.date-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: var(--gap) 0;
}

.chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
}

.chip.active,
.chip:active {
  background: var(--amber);
  border-color: var(--amber);
  color: #0d0a1a;
}

/* ── Top products list ────────────────────────────────────── */
.top-list { display: flex; flex-direction: column; gap: 6px; }

.top-item {
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.top-item:last-child { border-bottom: none; }
.top-rank { color: var(--text-muted); font-size: 0.8rem; min-width: 20px; text-align: center; }
.top-name { flex: 1; }
.top-val  { font-family: var(--font-mono); font-weight: 600; color: var(--amber); }

/* ── Timeline (Bon detail) ────────────────────────────────── */
.timeline { display: flex; flex-direction: column; gap: 0; }

.timeline-entry {
  display: flex;
  gap: var(--gap);
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.timeline-entry:last-child { border-bottom: none; }

.timeline-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}

.timeline-dot.sale    { background: var(--violet); }
.timeline-dot.payment { background: var(--success); }

.timeline-info { flex: 1; }
.timeline-date { font-size: 0.75rem; color: var(--text-muted); }
.timeline-amt  { font-family: var(--font-mono); font-weight: 600; }

/* ── Empty state ──────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--gap);
  padding: 48px var(--gap);
  text-align: center;
  color: var(--text-muted);
}

.empty-mascot { font-size: 4rem; line-height: 1; }
.empty-label  { font-size: 0.95rem; }

/* Ghost SVG mascot — inline, no external images */
.ghost-svg {
  width: 80px;
  height: 96px;
  display: block;
  /* gentle float animation */
  animation: ghost-float 3s ease-in-out infinite;
}

@keyframes ghost-float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}

/* ── Divider ──────────────────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--gap) 0;
}

/* ── Utility ──────────────────────────────────────────────── */
.hidden      { display: none !important; }
.mt-sm       { margin-top: 8px; }
.mt-md       { margin-top: var(--gap); }
.mt-lg       { margin-top: var(--gap-lg); }
.mb-sm       { margin-bottom: 8px; }
.mb-md       { margin-bottom: var(--gap); }
.font-mono   { font-family: var(--font-mono); }
.fw-700      { font-weight: 700; }
.fs-sm       { font-size: 0.85rem; }
.fs-xs       { font-size: 0.75rem; }

/* ── Scrollbar (webkit) ───────────────────────────────────── */
::-webkit-scrollbar       { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Focus visible ────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

/* ============================================================
   PRINT STYLES — thermal 80mm receipt
   ============================================================ */
@media print {
  /* Hide everything except receipt */
  body > *:not(#receipt-print-area) { display: none !important; }

  #receipt-print-area {
    display: block !important;
  }

  /* 80mm thermal paper; browsers will paginate automatically */
  @page {
    size: 80mm auto;
    margin: 4mm;
  }

  .receipt {
    width: 72mm;
    font-family: var(--font-mono), monospace;
    font-size: 11pt;
    color: #000;
    background: #fff;
  }

  .receipt-header {
    text-align: center;
    margin-bottom: 6pt;
  }

  .receipt-title {
    font-size: 14pt;
    font-weight: bold;
  }

  .receipt-shop {
    font-size: 10pt;
  }

  .receipt-divider {
    border: none;
    border-top: 1px dashed #000;
    margin: 4pt 0;
  }

  .receipt-items { width: 100%; border-collapse: collapse; }

  .receipt-items td {
    padding: 1pt 0;
    font-size: 10pt;
    vertical-align: top;
  }

  .receipt-items .col-qty   { width: 6mm; text-align: right; padding-right: 2mm; }
  .receipt-items .col-name  { }
  .receipt-items .col-price { width: 22mm; text-align: right; }

  .receipt-total-row {
    display: flex;
    justify-content: space-between;
    font-weight: bold;
    font-size: 12pt;
    margin-top: 4pt;
  }

  .receipt-change-row {
    display: flex;
    justify-content: space-between;
    font-size: 10pt;
  }

  .receipt-bon-label {
    text-align: center;
    font-size: 13pt;
    font-weight: bold;
    border: 2px solid #000;
    padding: 2pt;
    margin-top: 4pt;
  }

  .receipt-footer {
    text-align: center;
    font-size: 9pt;
    margin-top: 8pt;
    color: #555;
  }
}
