/* =====================================================================
   Chello ERP — Design System
   A cold-chain / dairy-operations aesthetic: porcelain canvas, deep
   teal-ink structure, curd-gold and brick accents for status signals.
   ===================================================================== */

:root {
  /* Palette */
  --bg: #F4F6F4;
  --surface: #FFFFFF;
  --surface-sunk: #EEF1EF;
  --ink: #16262A;
  --ink-soft: #52676C;
  --ink-faint: #8B9C9F;
  --border: #E1E7E4;
  --border-strong: #CCD6D2;

  --teal: #285675;
  --teal-dark: #142F49;
  --teal-tint: #E5EEF5;

  --amber: #D89A2E;
  --amber-tint: #FBF1DD;

  --brick: #C1502E;
  --brick-tint: #FBEAE3;

  --green: #2F8F5B;
  --green-tint: #E6F4EC;

  --navy: #1E3A5F;
  --navy-tint: #E7EEF5;

  --sidebar-bg: #101C1F;
  --sidebar-ink: #C7D6D4;
  --sidebar-ink-dim: #6E8583;
  --sidebar-active: #17364F;

  /* Scale */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 18px;
  --shadow-soft: 0 1px 2px rgba(16, 28, 31, 0.06);
  --shadow-pop: 0 12px 32px rgba(16, 28, 31, 0.16);
  --shadow-drawer: -8px 0 32px rgba(16, 28, 31, 0.14);

  --sidebar-w: 264px;
  --topbar-h: 64px;

  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'tnum' 1, 'lnum' 1; /* aligned numerals for money */
}
h1, h2, h3, h4, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
img { max-width: 100%; display: block; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- Typography ---------- */
.h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; }
.h2 { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; }
.h3 { font-size: 1.05rem; font-weight: 600; }
.text-soft { color: var(--ink-soft); }
.text-faint { color: var(--ink-faint); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
.mono-num { font-variant-numeric: tabular-nums; }

/* =====================================================================
   App Shell
   ===================================================================== */
.app-shell { min-height: 100vh; }

/* Covers the first paint until the shared UI is ready. */
.page-loader {
  display: none;
}
.js .page-loader {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.28s ease, visibility 0.28s ease;
}
.js .page-loader.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.page-loader-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: page-loader-spin 0.75s linear infinite;
}
@keyframes page-loader-spin {
  to { transform: rotate(360deg); }
}

/* Let the shared page shell settle into place after the first paint. */
.js .app-shell {
  opacity: 0;
  transition: opacity 0.4s ease;
}
.js .app-shell.is-ready {
  opacity: 1;
}

/* ---- Sidebar (mobile: off-canvas drawer, desktop: fixed rail) ---- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(280px, 84vw);
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  z-index: 60;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
}
.sidebar.is-open { transform: translateX(0); }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
}
.sidebar-brand .mark {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--teal), #42789B);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 1.1rem;
  flex-shrink: 0;
}
.sidebar-brand .name { font-weight: 700; color: #fff; font-size: 1.05rem; line-height: 1.15; }
.sidebar-brand .tag { font-size: 0.72rem; color: var(--sidebar-ink-dim); }

.sidebar-branch {
  margin: 4px 16px 14px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.05);
  font-size: 0.78rem;
  color: var(--sidebar-ink-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-branch strong { color: var(--sidebar-ink); font-weight: 600; }

.sidebar-nav { flex: 1; padding: 4px 12px 16px; }
.sidebar-section-label {
  font-size: 0.7rem;
  color: var(--sidebar-ink-dim);
  padding: 14px 10px 6px;
  font-weight: 600;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-ink);
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 2px;
  min-height: 48px;
  transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-link svg { width: 19px; height: 19px; flex-shrink: 0; stroke-width: 2; }
.sidebar-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-link.active {
  background: var(--sidebar-active);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--teal);
}
.sidebar-foot {
  padding: 14px 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-user { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sidebar-user .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--teal); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; flex-shrink: 0;
}
.sidebar-user .who { font-size: 0.82rem; color: #fff; font-weight: 600; }
.sidebar-user .role { font-size: 0.72rem; color: var(--sidebar-ink-dim); }
.sidebar-logout {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 10px; border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.06); color: var(--sidebar-ink);
  border: none; font-size: 0.85rem; font-weight: 600; min-height: 44px;
}
.sidebar-logout:hover { background: rgba(255,255,255,0.12); color: #fff; }

.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(10, 18, 20, 0.5);
  z-index: 55; opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease;
}
.sidebar-overlay.is-open { opacity: 1; pointer-events: auto; }

/* ---- Topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  gap: 12px;
  padding: 0 16px;
}
.topbar-menu-btn {
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.72); background: rgba(255,255,255,0.58);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; box-shadow: 0 6px 18px rgba(16,28,31,0.08), inset 0 1px 0 rgba(255,255,255,0.85);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.topbar-menu-btn:hover { background: var(--surface-sunk); }
.topbar-title {
  font-weight: 700; font-size: 1.05rem; flex: 1; min-width: 0;
  display: flex; flex-direction: column; justify-content: center; line-height: 1.15;
}
.topbar-title .crumb {
  color: var(--ink-faint); font-weight: 500; font-size: 0.82rem; display: block;
  margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.branch-switch {
  display: flex; background: var(--surface-sunk); border-radius: 999px;
  padding: 3px; gap: 2px; flex-shrink: 0;
}
.branch-switch button {
  border: none; background: transparent; padding: 7px 12px;
  border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  color: var(--ink-soft); min-height: 34px;
  transition: background 0.15s ease, color 0.15s ease;
}
.branch-switch button.active { background: var(--teal); color: #fff; }

.topbar-avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--teal-tint);
  color: var(--teal-dark); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; flex-shrink: 0; border: 1px solid var(--border);
}

/* ---- Main content ---- */
.main-content { padding: 18px 16px 90px; max-width: 1400px; margin: 0 auto; }
.main-content.is-refreshing { animation: content-refresh 0.2s ease-out both; }
@keyframes content-refresh { from { opacity: 0.72; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .main-content.is-refreshing { animation: none; } }
button[aria-busy="true"] { cursor: wait; opacity: 0.72; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; }

@media (max-width: 767px) {
  .invoice-filter,
  .expense-filter {
    width: 100%;
    max-width: 100%;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }
  .invoice-filter > *,
  .expense-filter > * {
    width: 100%;
    max-width: 100%;
  }
  .invoice-filter .form-input,
  .invoice-filter .form-select,
  .expense-filter .form-input,
  .expense-filter .form-select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 42px;
    padding-left: 10px;
    padding-right: 10px;
  }
  .topbar {
    gap: 8px; padding: 0 12px;
  }
  .topbar-title {
    min-width: 0; font-size: 0.96rem; align-items: flex-start;
  }
  .topbar-title .crumb {
    font-size: 0.7rem; letter-spacing: 0.01em;
  }
  .branch-switch {
    max-width: 100%; overflow-x: auto; scrollbar-width: none;
  }
  .branch-switch button[data-short] {
    font-size: 0; min-width: 48px; padding-inline: 10px;
  }
  .branch-switch button[data-short]::before {
    content: attr(data-short);
    display: block;
    font-size: 0.78rem;
    line-height: 1;
  }
  .branch-switch::-webkit-scrollbar { display: none; }
}

@media (min-width: 1024px) {
  .sidebar { position: fixed; transform: none; width: var(--sidebar-w); }
  .sidebar-overlay { display: none; }
  .topbar-menu-btn { display: none; }
  .main-content { margin-left: var(--sidebar-w); padding: 26px 32px 60px; }
  .topbar { margin-left: var(--sidebar-w); padding: 0 32px; }
}

/* =====================================================================
   Buttons
   ===================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 0.88rem; border: 1px solid rgba(255,255,255,0.58);
  white-space: nowrap;
}
button, .btn {
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 6px 18px rgba(16,28,31,0.08), inset 0 1px 0 rgba(255,255,255,0.58);
  backdrop-filter: blur(14px) saturate(130%);
  -webkit-backdrop-filter: blur(14px) saturate(130%);
  transition: transform 0.22s cubic-bezier(.2,.8,.2,1), background 0.22s ease,
    border-color 0.22s ease, box-shadow 0.22s ease, color 0.22s ease;
}
button:not(:disabled):hover, .btn:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(16,28,31,0.14), inset 0 1px 0 rgba(255,255,255,0.72);
}
button:not(:disabled):active, .btn:not(:disabled):active { transform: translateY(0) scale(0.97); }
button:disabled, .btn:disabled { cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; stroke-width: 2.2; }
.btn-primary { background: linear-gradient(145deg, rgba(15,110,102,0.94), rgba(10,78,72,0.88)); color: #fff; border-color: rgba(255,255,255,0.2); }
.btn-primary:hover { background: var(--teal-dark); }
.btn-outline { background: rgba(255,255,255,0.54); color: var(--ink); border-color: rgba(204,214,210,0.9); }
.btn-outline:hover { background: var(--surface-sunk); }
.btn-danger { background: linear-gradient(145deg, rgba(193,80,46,0.94), rgba(165,64,31,0.9)); color: #fff; }
.btn-danger:hover { background: #A5401F; }
.btn-ghost { background: rgba(255,255,255,0.28); color: var(--ink-soft); }
.btn-ghost:hover { background: var(--surface-sunk); color: var(--ink); }
.btn-sm { min-height: 38px; padding: 0 13px; font-size: 0.8rem; border-radius: var(--radius-sm); }
.btn-icon { min-width: 44px; padding: 0; }
.btn-block { width: 100%; }

/* =====================================================================
   Forms
   ===================================================================== */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.invoice-filter,
.expense-filter { min-width: 0; }
.invoice-filter > *,
.expense-filter > * { min-width: 0; }
label.form-label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.form-input, .form-select, .form-textarea {
  width: 100%; min-height: 48px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid rgba(204,214,210,0.86); background: rgba(255,255,255,0.58); color: var(--ink);
  box-shadow: inset 0 1px 2px rgba(16,28,31,0.04), 0 4px 14px rgba(16,28,31,0.03);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.form-textarea { padding: 12px 14px; min-height: 90px; resize: vertical; }
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-tint); outline: none;
}
.form-hint { font-size: 0.76rem; color: var(--ink-faint); margin-top: 5px; }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2352676C' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
.form-check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.form-check input { width: 20px; height: 20px; accent-color: var(--teal); }

/* =====================================================================
   Cards, KPI tiles
   ===================================================================== */
.card {
  background: rgba(255,255,255,0.68); border: 1px solid rgba(255,255,255,0.78);
  border-radius: var(--radius-lg); padding: 20px;
  box-shadow: 0 12px 30px rgba(16,28,31,0.06), inset 0 1px 0 rgba(255,255,255,0.8);
  backdrop-filter: blur(16px) saturate(120%); -webkit-backdrop-filter: blur(16px) saturate(120%);
}
.card-title { font-weight: 700; font-size: 0.98rem; margin-bottom: 14px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px 20px; position: relative; overflow: hidden;
  opacity: 0; transform: translateY(8px);
  animation: kpi-in 0.5s cubic-bezier(.2,.8,.2,1) forwards;
}
.kpi-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px; background: var(--accent, var(--teal)); }
.kpi-card .kpi-label { font-size: 0.8rem; color: var(--ink-soft); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.kpi-card .kpi-label svg { width: 16px; height: 16px; stroke-width: 2.3; color: var(--accent, var(--teal)); }
.kpi-card .kpi-value { font-size: 1.65rem; font-weight: 800; margin-top: 8px; letter-spacing: -0.02em; }
.kpi-card .kpi-sub { font-size: 0.76rem; color: var(--ink-faint); margin-top: 4px; }
@keyframes kpi-in { to { opacity: 1; transform: translateY(0); } }

/* Reports keep wide tables inside their own scroll area instead of moving the page. */
.reports-page { width: 100%; max-width: 100%; min-width: 0; overflow: hidden; }
.reports-page > .grid-2 > *,
.reports-page > .table-card,
.reports-page .kpi-card { min-width: 0; }
.reports-page .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.reports-page .table-wrap { max-width: 100%; overflow-x: auto; }

@media (max-width: 1100px) {
  .reports-page .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 767px) {
  .reports-page .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .reports-page .kpi-card { padding: 16px; }
  .reports-page .kpi-card .kpi-value { font-size: 1.35rem; }
  .reports-page .card { padding: 16px; }
}

/* =====================================================================
   Badges / status pills
   ===================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px;
  border-radius: 999px; font-size: 0.72rem; font-weight: 700;
}
.badge-teal   { background: var(--teal-tint); color: var(--teal-dark); }
.badge-amber  { background: var(--amber-tint); color: #8A5D12; }
.badge-brick  { background: var(--brick-tint); color: var(--brick); }
.badge-green  { background: var(--green-tint); color: var(--green); }
.badge-navy   { background: var(--navy-tint); color: var(--navy); }
.badge-gray   { background: var(--surface-sunk); color: var(--ink-soft); }

/* =====================================================================
   Tables
   ===================================================================== */
.table-card { background: rgba(255,255,255,0.7); border: 1px solid rgba(255,255,255,0.78); border-radius: var(--radius-lg); overflow: hidden; box-shadow: 0 12px 30px rgba(16,28,31,0.06), inset 0 1px 0 rgba(255,255,255,0.8); backdrop-filter: blur(16px) saturate(120%); -webkit-backdrop-filter: blur(16px) saturate(120%); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 18px 0 4px; }
.pagination-link { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; height: 42px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: rgba(255,255,255,0.52); color: var(--ink-soft); font-size: 0.86rem; }
.pagination-link:hover { background: var(--surface-sunk); color: var(--ink); }
.pagination-link-active { background: var(--amber); border-color: var(--amber); color: #1f180d; font-weight: 700; }
.pagination-ellipsis { min-width: 18px; text-align: center; color: var(--ink-soft); }
.pagination-arrow { font-size: 1.35rem; line-height: 1; }
.pagination-next { min-width: 96px; color: var(--ink); }
table.data-table { width: 100%; border-collapse: collapse; min-width: 640px; }
table.data-table thead th {
  position: sticky; top: 0; background: var(--surface-sunk); z-index: 5;
  text-align: left; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-soft); font-weight: 700; padding: 12px 16px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data-table tbody td {
  padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 0.87rem; vertical-align: middle;
}
table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover { background: var(--surface-sunk); }
table.data-table td.num, table.data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-empty { padding: 40px 20px; text-align: center; color: var(--ink-faint); }
.table-empty svg { width: 40px; height: 40px; margin: 0 auto 10px; stroke-width: 1.5; opacity: 0.5; }

/* =====================================================================
   Modal / Drawer (used for forms + calendar day detail)
   ===================================================================== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 18, 20, 0.55);
  display: none; place-items: center; overflow-y: auto; z-index: 80; padding: 16px;
}
.modal-backdrop.is-open {
  display: grid; place-items: center; animation: fade-in 0.16s ease-out both;
}
.modal-backdrop.is-open.is-section-centered { display: block; }
.modal-backdrop.is-closing { animation: modal-backdrop-out 0.2s ease-in both; pointer-events: none; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); width: min(calc(100vw - 32px), 560px);
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-pop); margin: auto;
  animation: modal-in 0.3s cubic-bezier(.2,.85,.25,1) both;
}
.modal-backdrop.is-open.is-section-centered .modal { position: fixed; margin: 0; }
.modal-backdrop.is-closing .modal { animation: modal-out 0.2s cubic-bezier(.4,0,1,1) both; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; position: sticky; bottom: 0; background: var(--surface); }
.modal-close { width: 36px; height: 36px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.72); background: rgba(238,241,239,0.72); display: flex; align-items: center; justify-content: center; box-shadow: inset 0 1px 0 rgba(255,255,255,0.75); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  0% { opacity: 0; transform: translateY(16px) scale(0.95); filter: blur(3px); }
  72% { opacity: 1; transform: translateY(-2px) scale(1.008); filter: blur(0); }
  100% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}
@keyframes modal-out {
  from { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
  to { opacity: 0; transform: translateY(8px) scale(0.97); filter: blur(2px); }
}
@keyframes modal-backdrop-out { from { opacity: 1; } to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .modal-backdrop.is-open, .modal-backdrop.is-closing, .modal, .modal-backdrop.is-closing .modal {
    animation-duration: 0.01ms !important;
  }
}

/* Right-side slide drawer (calendar day detail) */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(10,18,20,0.5); z-index: 80; display: none;
}
.drawer-backdrop.is-open { display: block; animation: fade-in 0.2s ease; }
.drawer-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 100vw;
  background: var(--surface); z-index: 85; box-shadow: var(--shadow-drawer);
  transform: translateX(100%); transition: transform 0.3s cubic-bezier(.2,.8,.2,1);
  display: flex; flex-direction: column;
}
.drawer-backdrop.is-open .drawer-panel { transform: translateX(0); }
.drawer-header { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.drawer-body { padding: 20px; overflow-y: auto; flex: 1; }

/* =====================================================================
   Flash messages / toasts
   ===================================================================== */
.flash-stack { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 32px)); }
.flash {
  padding: 13px 16px; border-radius: var(--radius); background: var(--ink); color: #fff;
  font-size: 0.85rem; box-shadow: var(--shadow-pop); display: flex; align-items: center; gap: 10px;
  animation: toast-in 0.25s cubic-bezier(.2,.8,.2,1);
}
.flash svg { width: 18px; height: 18px; flex-shrink: 0; }
.flash-success { background: var(--teal-dark); }
.flash-error { background: var(--brick); }
.flash-info { background: var(--navy); }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }

/* =====================================================================
   Skeletons
   ===================================================================== */
.skeleton { background: linear-gradient(90deg, var(--surface-sunk) 25%, #E4E9E6 37%, var(--surface-sunk) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* =====================================================================
   Login page
   ===================================================================== */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: #F1F4F8;
  padding: 20px;
}
.login-card {
  position: relative; isolation: isolate; overflow: hidden;
  background: linear-gradient(145deg, rgba(255,255,255,0.78), rgba(255,255,255,0.48));
  border: 1px solid rgba(255,255,255,0.64); border-radius: 24px; width: 100%; max-width: 400px;
  padding: 34px 28px; box-shadow: 0 24px 60px rgba(2, 18, 20, 0.28), inset 0 1px 0 rgba(255,255,255,0.85);
  backdrop-filter: blur(22px) saturate(135%); -webkit-backdrop-filter: blur(22px) saturate(135%);
  animation: modal-in 0.35s cubic-bezier(.2,.8,.2,1);
}
.login-card::before {
  content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(120deg, rgba(255,255,255,0.48), transparent 42%, rgba(134,223,211,0.14));
}
.login-brand { display: flex; align-items: center; justify-content: center; margin-bottom: 26px; }
.text-only-brand { margin-bottom: 20px; }
.text-only-brand h1 {
  margin: 0; color: #1a3d6b; font-size: clamp(1.6rem, 3vw, 2.2rem); line-height: 1.1; letter-spacing: -0.04em; text-align: center;
  animation: brand-fade-in 0.8s cubic-bezier(.2,.7,.2,1) both;
}
@keyframes brand-fade-in {
  0% { opacity: 0; transform: translateY(-10px) scale(0.98); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
.login-brand-logo {
  display: block; width: min(100%, 300px); max-height: 190px; object-fit: contain;
  image-rendering: auto; filter: none; -webkit-filter: none;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; }
.sidebar-brand-logo {
  width: 56px; height: 56px; object-fit: contain; border-radius: 14px; display: block; flex-shrink: 0;
}
.login-welcome { position: relative; overflow: hidden; padding: 23px; margin-bottom: 32px; border: 1px solid #CFE0FF; border-radius: 22px; background: linear-gradient(135deg, rgba(255,255,255,0.82), rgba(235,244,255,0.72)); box-shadow: inset 0 1px 0 #fff, 0 12px 24px rgba(67,137,245,0.08); transform-origin: center top; animation: login-welcome-pop 0.65s 0.18s cubic-bezier(.2,.85,.25,1.15) both; }
@keyframes login-welcome-pop {
  0% { opacity: 0; transform: translateY(18px) scale(0.88); }
  65% { opacity: 1; transform: translateY(-3px) scale(1.015); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
.login-3d-orbit { position: absolute; top: 22px; right: 28px; width: 64px; height: 64px; perspective: 260px; pointer-events: none; }
.login-3d-cube { position: relative; width: 34px; height: 34px; margin: 13px auto; transform-style: preserve-3d; animation: login-cube-float 5s ease-in-out infinite, login-cube-spin 9s linear infinite; }
.cube-face { position: absolute; display: block; width: 34px; height: 34px; border: 1px solid rgba(67,137,245,0.55); background: linear-gradient(135deg, rgba(255,255,255,0.72), rgba(119,178,255,0.25)); box-shadow: inset 0 0 12px rgba(255,255,255,0.6); }
.cube-front { transform: translateZ(17px); }
.cube-side { transform: rotateY(90deg) translateZ(17px); background: linear-gradient(135deg, rgba(110,180,255,0.32), rgba(67,137,245,0.08)); }
.cube-top { transform: rotateX(90deg) translateZ(17px); background: rgba(255,255,255,0.66); }
@keyframes login-cube-spin { from { transform: rotateX(-18deg) rotateY(0deg) rotateZ(8deg); } to { transform: rotateX(-18deg) rotateY(360deg) rotateZ(8deg); } }
@keyframes login-cube-float { 0%, 100% { translate: 0 0; } 50% { translate: 0 -8px; } }
.login-welcome-label { display: inline-block; padding: 8px 13px; border: 1px solid #D4E2FC; border-radius: 999px; color: #556273; font-size: 0.66rem; letter-spacing: 0.16em; font-weight: 700; }
.login-welcome strong { display: block; margin-top: 13px; color: #142B4B; font-size: 2.35rem; line-height: 0.98; letter-spacing: -0.06em; }
.login-welcome p { margin-top: 15px; color: #61758F; font-size: 0.88rem; }
.login-card .form-label { color: #354052; letter-spacing: 0.04em; text-transform: uppercase; }
.login-card .form-input { background: #EAF2FF; border-color: #A9C8FF; border-radius: 12px; }
.login-card .btn-primary { min-height: 56px; border-radius: 12px; background: linear-gradient(135deg, #4389F5, #2863DF); box-shadow: 0 12px 22px rgba(52,111,231,0.22); }
.login-demo { margin-top: 20px; padding: 12px 14px; background: var(--surface-sunk); border-radius: var(--radius-sm); font-size: 0.76rem; color: var(--ink-soft); line-height: 1.6; }
@media (max-width: 440px) {
  .login-card { padding: 30px 20px 24px; }
  .login-brand { gap: 11px; }
  .login-brand h1 { font-size: 1.55rem; }
  .login-brand-sub { font-size: 0.55rem; letter-spacing: 0.12em; }
  .login-welcome strong { font-size: 2rem; }
}

/* =====================================================================
   POS / Invoice builder
   ===================================================================== */
.pos-layout {
  display: grid; grid-template-columns: 1fr; gap: 16px;
  min-height: calc(100vh - 170px);
}
@media (min-width: 900px) {
  .pos-layout { grid-template-columns: 1.5fr 1fr; align-items: start; }
  .pos-layout > .card { min-height: 0; }
}

.pos-layout > .card {
  display: flex; flex-direction: column; min-height: 0;
}

.pos-summary-card {
  position: sticky; top: 88px; max-height: calc(100vh - 120px); overflow: auto;
  width: 100%; max-width: 100%; box-sizing: border-box;
}

.pos-search { position: relative; margin-bottom: 12px; }
.pos-search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--ink-faint); }
.pos-search input { padding-left: 42px; }

.shop-list-scroll {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 240px; overflow-y: auto; min-height: 160px;
  padding-right: 4px;
}

.pos-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px;
  max-height: calc(100vh - 420px); min-height: 220px; overflow-y: auto; padding-right: 4px;
}
.pos-item {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  padding: 14px 12px; text-align: left; min-height: 92px; display: flex; flex-direction: column; justify-content: space-between;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.pos-item:hover { border-color: var(--teal); }
.pos-item.in-cart { border-color: var(--teal); background: var(--teal-tint); }
.pos-item .pname { font-weight: 700; font-size: 0.85rem; line-height: 1.25; }
.pos-item .pprice { font-size: 0.8rem; color: var(--ink-soft); margin-top: 6px; }
.pos-item .pstock { display: block; margin-top: 3px; }
.pos-item:disabled,
.pos-item.out-of-stock { opacity: 0.52; cursor: not-allowed; }
.pos-item .pqty-badge {
  align-self: flex-end; background: var(--teal); color: #fff; font-size: 0.72rem; font-weight: 800;
  border-radius: 999px; padding: 2px 9px; margin-top: 6px;
}

.cart-line { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.cart-line:last-child { border-bottom: none; }
.cart-line .cname { flex: 1 1 140px; min-width: 0; }
.cart-line .cname .nm { font-weight: 600; font-size: 0.86rem; }
.cart-line .cname .pr { font-size: 0.75rem; color: var(--ink-faint); }
.cart-line .cname label { display: flex; align-items: center; gap: 5px; margin-top: 4px; flex-wrap: wrap; }
.cart-line .cname label .form-input { width: 82px; min-height: 28px; padding: 4px 6px; font-size: 0.75rem; max-width: 100%; }

.qty-stepper { display: flex; align-items: center; border: 1px solid var(--border-strong); border-radius: 999px; overflow: hidden; flex-shrink: 0; }
.qty-stepper button { width: 32px; height: 32px; background: var(--surface-sunk); border: none; font-weight: 700; font-size: 1rem; display: flex; align-items: center; justify-content: center; }
.qty-stepper input { width: 38px; text-align: center; border: none; min-height: 32px; padding: 0; font-weight: 700; }
.cart-line-total { width: 76px; text-align: right; font-weight: 700; font-size: 0.85rem; flex-shrink: 0; margin-left: auto; }
.cart-line-remove { width: 32px; height: 32px; flex-shrink: 0; border-radius: 50%; border: none; background: transparent; color: var(--brick); display: flex; align-items: center; justify-content: center; }
.cart-line-remove:hover { background: var(--brick-tint); }

.pos-summary-row { display: flex; justify-content: space-between; padding: 7px 0; font-size: 0.88rem; }
.pos-summary-row.total { font-size: 1.15rem; font-weight: 800; border-top: 1px dashed var(--border-strong); margin-top: 8px; padding-top: 12px; }
.pos-summary-row .credit-amt { color: var(--brick); font-weight: 700; }

/* Lorry stock stays inside the page width; wide data scrolls within its own area. */
.lorry-stock-page {
  width: 100%;
  min-width: 0;
  overflow: hidden;
}
.lorry-stock-page > .card,
.lorry-stock-page > .grid-2,
.lorry-stock-page .table-card {
  min-width: 0;
}
.lorry-stock-page .form-row {
  min-width: 0;
}
.lorry-stock-page .lorry-table-wrap {
  width: 100%;
  min-width: 0;
}
.lorry-stock-page .lorry-table-wrap .data-table {
  min-width: 0;
}

@media (max-width: 767px) {
  .lorry-stock-page .grid-2 {
    gap: 12px;
  }
  .lorry-stock-page .card {
    padding: 16px;
    overflow: hidden;
  }
  .lorry-stock-page .form-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(92px, 0.42fr) auto;
    gap: 8px;
    align-items: end;
  }
  .lorry-stock-page .form-row .form-group {
    min-width: 0 !important;
    width: auto !important;
    flex: none !important;
  }
  .lorry-stock-page .form-row .btn-icon {
    flex-shrink: 0;
  }
  .lorry-stock-page .lorry-table-wrap {
    overflow-x: auto;
    overscroll-behavior-x: contain;
  }
  .lorry-stock-page .lorry-table-wrap .data-table {
    width: 100%;
    table-layout: fixed;
  }
  .lorry-stock-page .lorry-table-wrap th,
  .lorry-stock-page .lorry-table-wrap td {
    padding: 10px 8px;
    font-size: 0.78rem;
    overflow-wrap: anywhere;
  }
  .lorry-stock-page .lorry-table-wrap th:first-child,
  .lorry-stock-page .lorry-table-wrap td:first-child {
    width: 58%;
  }
  .lorry-stock-page .table-card .table-wrap {
    overflow-x: auto;
    overscroll-behavior-x: contain;
  }
}

/* =====================================================================
   Calendar (warehouse purchase log)
   ===================================================================== */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { text-align: center; font-size: 0.72rem; font-weight: 700; color: var(--ink-faint); padding-bottom: 4px; }
.cal-cell {
  aspect-ratio: 1 / 1; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 0.8rem; font-weight: 600; position: relative; min-height: 44px;
}
.cal-cell.has-data { border-color: var(--teal); background: var(--teal-tint); cursor: pointer; padding: 0; appearance: none; font-family: inherit; }
.cal-cell.has-data:hover { background: #D5EBE7; }
.cal-cell.empty { visibility: hidden; }
.cal-cell .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--teal); }
.cal-cell.is-today { box-shadow: inset 0 0 0 2px var(--amber); }
.purchase-detail-card { overflow: hidden; }
.purchase-items-table { margin-left: -20px; margin-right: -20px; width: calc(100% + 40px); }
.purchase-items-table table.data-table { min-width: 640px; }

/* =====================================================================
   Utility
   ===================================================================== */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.gap-8 { gap: 8px; } .gap-10 { gap: 10px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 780px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.grid-2.warehouse-purchase-overview { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 767px) {
  .grid-2.warehouse-purchase-overview { grid-template-columns: minmax(0, 1fr); }
}
.grid-3 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 780px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.chip-row {
  display: flex; flex-wrap: wrap; gap: 8px; row-gap: 8px; overflow-x: auto; overflow-y: hidden;
  padding-bottom: 4px; -webkit-overflow-scrolling: touch;
}
.chip {
  flex-shrink: 0; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: rgba(255,255,255,0.5); font-size: 0.8rem; font-weight: 600; color: var(--ink-soft); min-height: 40px; display: flex; align-items: center;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.72), 0 4px 12px rgba(16,28,31,0.04);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}

.page-branch-switch .branch-switch button {
  touch-action: manipulation;
  user-select: none;
}

@media (max-width: 767px) {
  .page-branch-switch {
    overflow-x: auto; padding-bottom: 4px; scrollbar-width: none;
  }
  .page-branch-switch .branch-switch {
    min-width: max-content;
  }
  .page-branch-switch .branch-switch button { padding: 8px 12px; }
}
.chip.active { background: var(--teal); color: #fff; border-color: var(--teal); }
.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-faint); }
.empty-state svg { width: 46px; height: 46px; margin: 0 auto 12px; stroke-width: 1.5; opacity: 0.5; }
.divider { height: 1px; background: var(--border); margin: 16px 0; border: none; }
