/* ============================================================
   Ledger POS — design tokens
   Palette: paper cream / deep teal ledger ink / brass accent
   Type: Space Grotesk (display) + Inter (body) + IBM Plex Mono (figures)
   Arabic: Noto Kufi Arabic (display) + Noto Sans Arabic (body)
   Bangla: Hind Siliguri
   ============================================================ */

:root {
  --paper: #F6F3EA;
  --surface: #FFFFFF;
  --ink: #1F2B27;
  --ink-soft: #566661;
  --primary: #0F5C4F;
  --primary-dark: #0B3F37;
  --primary-tint: #E1EBE6;
  --accent: #C7963A;
  --accent-tint: #F5E9D2;
  --danger: #A8432E;
  --danger-tint: #F3E1DC;
  --line: #DDD6C6;
  --line-strong: #C6BEA9;
  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 22px;
  --shadow-card: 0 1px 2px rgba(31,43,39,0.04), 0 8px 24px -12px rgba(31,43,39,0.18);
  --font-display: 'Space Grotesk', 'Noto Kufi Arabic', 'Hind Siliguri', sans-serif;
  --font-body: 'Inter', 'Noto Sans Arabic', 'Hind Siliguri', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

html[lang="ar"] {
  --font-display: 'Noto Kufi Arabic', 'Space Grotesk', sans-serif;
  --font-body: 'Noto Sans Arabic', 'Inter', sans-serif;
}
html[lang="bn"] {
  --font-display: 'Hind Siliguri', 'Space Grotesk', sans-serif;
  --font-body: 'Hind Siliguri', 'Inter', sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
}
h1, h2, h3, .display {
  font-family: var(--font-display);
  color: var(--primary-dark);
  margin: 0;
  letter-spacing: -0.01em;
}
a { color: inherit; }
button { font-family: inherit; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

::selection { background: var(--accent-tint); }

/* Focus visibility */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

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

/* ---------------- Layout shell ---------------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--primary-dark);
  color: #EFF5F2;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 22px;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(239,245,242,0.14);
}
.sidebar .brand-mark {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--primary-dark);
  flex-shrink: 0;
}
.sidebar .brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar .nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-s);
  color: rgba(239,245,242,0.72);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.sidebar .nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar .nav-link:hover { background: rgba(239,245,242,0.08); color: #fff; }
.sidebar .nav-link.active { background: var(--accent); color: var(--primary-dark); font-weight: 600; }
.sidebar .foot {
  border-top: 1px solid rgba(239,245,242,0.14);
  padding-top: 14px;
  margin-top: 8px;
  font-size: 13px;
  color: rgba(239,245,242,0.65);
}
.sidebar .foot .who { color: #fff; font-weight: 600; margin-bottom: 6px; }
.sidebar .logout-btn {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none; color: inherit;
  cursor: pointer; padding: 0; font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: none; /* shown on mobile */
}
.page {
  padding: 30px 34px 90px;
  max-width: 1180px;
  width: 100%;
}
.page-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 22px;
  gap: 12px; flex-wrap: wrap;
}
.page-head h1 { font-size: 24px; }
.page-sub { color: var(--ink-soft); font-size: 13.5px; margin-top: 4px; }

/* ---------------- Buttons & inputs ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--radius-s);
  border: 1px solid transparent;
  padding: 10px 16px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: var(--primary-dark); }
.btn-accent:hover { filter: brightness(0.95); }
.btn-ghost { background: transparent; color: var(--primary-dark); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--primary-tint); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger-tint); }
.btn-danger:hover { background: var(--danger-tint); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; }
.field input, .field select, .field textarea {
  font-family: inherit;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: var(--radius-s);
  padding: 11px 12px;
  font-size: 14.5px;
  color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 160px; }
.hint { font-size: 12px; color: var(--ink-soft); }
.error-text { font-size: 13px; color: var(--danger); background: var(--danger-tint); border-radius: var(--radius-s); padding: 9px 12px; }

/* ---------------- Cards & stat blocks ---------------- */
.card {
  background: var(--surface);
  border-radius: var(--radius-m);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
}
.card-pad { padding: 20px 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 0; }
.card-head h2 { font-size: 15px; font-weight: 600; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: "";
  position: absolute; left: 20px; right: 20px; bottom: 0;
  height: 3px; background: var(--accent); border-radius: 3px 3px 0 0;
}
.stat-card .label { font-size: 12.5px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.stat-card .value { font-family: var(--font-mono); font-size: 27px; font-weight: 600; margin-top: 8px; color: var(--primary-dark); }
.stat-card .sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 4px; }

/* ---------------- Ledger table ---------------- */
.ledger { width: 100%; border-collapse: collapse; }
.ledger th {
  text-align: start;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-soft); font-weight: 600;
  padding: 10px 10px; border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
.ledger td {
  padding: 13px 10px; border-bottom: 1px solid var(--line);
  font-size: 14px; vertical-align: middle;
}
.ledger tbody tr:hover { background: var(--primary-tint); }
.ledger .num { font-family: var(--font-mono); text-align: end; font-variant-numeric: tabular-nums; }
.ledger-wrap { overflow-x: auto; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 100px; font-size: 12px; font-weight: 600; }
.badge-paid { background: var(--primary-tint); color: var(--primary-dark); }
.badge-void { background: var(--danger-tint); color: var(--danger); }
.badge-cash { background: var(--accent-tint); color: #7A5A1E; }
.badge-card { background: #E4E9F5; color: #364785; }
.badge-transfer { background: #E4E9F5; color: #364785; }

.empty-state { text-align: center; padding: 46px 20px; color: var(--ink-soft); }
.empty-state .icon { font-size: 30px; margin-bottom: 10px; }

/* ---------------- Login page ---------------- */
.login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
}
.login-art {
  background: var(--primary-dark);
  color: #EFF5F2;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 48px;
  position: relative;
  overflow: hidden;
}
.login-art .brand-mark { width: 44px; height: 44px; border-radius: 12px; background: var(--accent); display:flex; align-items:center; justify-content:center; font-family: var(--font-display); font-weight:700; color: var(--primary-dark); font-size: 18px; }
.login-art h1 { color: #fff; font-size: 34px; max-width: 420px; margin-top: 26px; }
.login-art p { color: rgba(239,245,242,0.75); max-width: 380px; margin-top: 14px; font-size: 14.5px; }
.login-receipt { align-self: flex-start; }
.login-form-side { display: flex; align-items: center; justify-content: center; padding: 40px; }
.login-box { width: 100%; max-width: 360px; }
.login-box .brand-mobile { display: none; }
.login-box h1 { font-size: 24px; margin-bottom: 6px; }
.login-box .sub { color: var(--ink-soft); font-size: 13.5px; margin-bottom: 26px; }

.whatsapp-link {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 18px; padding: 10px 14px;
  border-radius: var(--radius-s);
  background: #E7F5EE; color: #1E7A4C;
  font-size: 13.5px; font-weight: 600;
  text-decoration: none;
  transition: background 0.15s;
}
.whatsapp-link:hover { background: #D6EEE1; }

/* ---------------- Receipt slip (signature element) ---------------- */
.receipt-slip {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  position: relative;
  padding: 22px 22px 16px;
  font-family: var(--font-mono);
  font-size: 13px;
}
.receipt-slip::before, .receipt-slip::after {
  content: "";
  position: absolute; left: 0; right: 0; height: 9px;
  background:
    linear-gradient(135deg, var(--paper) 50%, transparent 50%) 0 0/12px 12px repeat-x,
    linear-gradient(-135deg, var(--paper) 50%, transparent 50%) 0 0/12px 12px repeat-x;
}
.receipt-slip::before { top: -1px; }
.receipt-slip::after { bottom: -1px; transform: rotate(180deg); }
.receipt-slip .r-title { font-family: var(--font-display); font-size: 16px; text-align: center; color: var(--primary-dark); margin-bottom: 2px; }
.receipt-slip .r-sub { text-align: center; color: var(--ink-soft); font-size: 11.5px; margin-bottom: 14px; }
.receipt-slip .r-meta { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink-soft); margin-bottom: 10px; }
.receipt-slip .r-divider { border-top: 1px dashed var(--line-strong); margin: 10px 0; }
.receipt-slip .r-row { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; font-size: 12.5px; }
.receipt-slip .r-row .name { flex: 1; color: var(--ink); }
.receipt-slip .r-row .qty { color: var(--ink-soft); width: 46px; text-align: center; flex-shrink: 0; }
.receipt-slip .r-row .amt { width: 70px; text-align: end; flex-shrink: 0; }
.receipt-slip .r-total-row { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; }
.receipt-slip .r-total-row.grand { font-size: 16px; font-weight: 700; color: var(--primary-dark); padding-top: 8px; }
.receipt-slip .r-footer { text-align: center; margin-top: 14px; font-size: 11px; color: var(--ink-soft); }

/* ---------------- Sale page layout ---------------- */
.sale-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 20px; align-items: flex-start; }
.item-row { display: grid; grid-template-columns: 1fr 74px 100px 96px 34px; gap: 8px; align-items: end; margin-bottom: 10px; }
.item-row .field { margin-bottom: 0; }
.item-row .line-total { font-family: var(--font-mono); text-align: end; padding: 11px 4px; font-size: 14px; align-self: center; }
.remove-item { background: none; border: none; color: var(--ink-soft); cursor: pointer; font-size: 17px; align-self: center; padding: 6px; border-radius: 8px; }
.remove-item:hover { background: var(--danger-tint); color: var(--danger); }
.totals-box { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 14px; }
.totals-box .row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 14px; }
.totals-box .row.grand { font-size: 18px; font-weight: 700; font-family: var(--font-mono); color: var(--primary-dark); border-top: 1px solid var(--line-strong); margin-top: 6px; padding-top: 10px; }
.sale-sticky { position: sticky; top: 20px; }

/* ---------------- Sparkline / small bar chart ---------------- */
.trend-bars { display: flex; align-items: flex-end; gap: 8px; height: 96px; padding: 4px 2px; }
.trend-bars .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; }
.trend-bars .bar { width: 100%; max-width: 26px; background: var(--primary); border-radius: 4px 4px 0 0; }
.trend-bars .bar.today { background: var(--accent); }
.trend-bars .lbl { font-size: 10.5px; color: var(--ink-soft); }

.pay-list { display: flex; flex-direction: column; gap: 10px; }
.pay-list .p-row { display: flex; align-items: center; gap: 10px; }
.pay-list .p-name { width: 78px; font-size: 13px; font-weight: 600; }
.pay-list .p-bar-track { flex: 1; background: var(--primary-tint); border-radius: 100px; height: 8px; overflow: hidden; }
.pay-list .p-bar-fill { height: 100%; background: var(--accent); border-radius: 100px; }
.pay-list .p-amt { font-family: var(--font-mono); font-size: 13px; width: 82px; text-align: end; }

/* ---------------- Modal ---------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,29,25,0.45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  z-index: 50;
}
.modal-box { background: var(--surface); border-radius: var(--radius-l); max-width: 560px; width: 100%; max-height: 88vh; overflow-y: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 22px 24px; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--ink-soft); padding: 4px 8px; border-radius: 8px; }
.modal-close:hover { background: var(--paper); }
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; padding: 4px 24px 22px; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--primary-dark); color: #fff; padding: 12px 20px;
  border-radius: 100px; font-size: 13.5px; font-weight: 500;
  box-shadow: 0 10px 30px -8px rgba(0,0,0,0.35);
  z-index: 80; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }
.toast.error { background: var(--danger); }

/* ---------------- Tabs (settings) ---------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.tab-btn { background: none; border: none; padding: 12px 4px; margin-inline-end: 22px; font-size: 14px; font-weight: 600; color: var(--ink-soft); cursor: pointer; border-bottom: 2px solid transparent; }
.tab-btn.active { color: var(--primary-dark); border-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------------- Language switcher ---------------- */
.lang-switch { display: flex; gap: 2px; background: rgba(239,245,242,0.08); padding: 3px; border-radius: 100px; }
.lang-switch button { background: none; border: none; color: rgba(239,245,242,0.7); font-size: 12px; font-weight: 700; padding: 6px 10px; border-radius: 100px; cursor: pointer; }
.lang-switch button.active { background: var(--accent); color: var(--primary-dark); }
.lang-switch.on-paper button { color: var(--ink-soft); }
.lang-switch.on-paper { background: var(--primary-tint); }
.lang-switch.on-paper button.active { background: var(--accent); color: var(--primary-dark); }

/* ---------------- Responsive ---------------- */
@media (max-width: 980px) {
  .sale-grid { grid-template-columns: 1fr; }
  .sale-sticky { position: static; }
  .login-screen { grid-template-columns: 1fr; }
  .login-art { display: none; }
}

@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar { display: none; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; background: var(--primary-dark); color: #fff;
    position: sticky; top: 0; z-index: 30;
  }
  .topbar .brand { display: flex; align-items: center; gap: 9px; font-family: var(--font-display); font-weight: 600; font-size: 14.5px; }
  .topbar .brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-weight: 700; color: var(--primary-dark); font-size: 13px; }
  .page { padding: 18px 16px 100px; }
  .stat-row { grid-template-columns: 1fr; }
  .item-row { grid-template-columns: 1fr; gap: 6px; padding-bottom: 12px; border-bottom: 1px dashed var(--line); margin-bottom: 12px; }
  .item-row .line-total { text-align: start; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    z-index: 30;
  }
  .bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 6px 2px; text-decoration: none; color: var(--ink-soft); font-size: 10.5px; font-weight: 600;
  }
  .bottom-nav a svg { width: 20px; height: 20px; }
  .bottom-nav a.active { color: var(--primary); }
  .page-head { flex-direction: column; align-items: flex-start; }
}
@media (min-width: 721px) { .bottom-nav { display: none; } }
