:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --success: #16a34a;
  --danger: #be123c;
  --warning: #d97706;
  --info: #0369a1;
  --purple: #9333ea;
  --dark: #111827;
  --bg: #f4f5fb;
  --card-radius: 14px;
  --shadow: 0 4px 20px rgba(17,24,39,0.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', 'Noto Sans Bengali', system-ui, sans-serif;
  background: var(--bg);
  color: var(--dark);
}
a { text-decoration: none; color: inherit; }

/* ===== Layout ===== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: linear-gradient(180deg, #1e1b4b 0%, #111827 100%);
  color: #e5e7eb;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 100;
  transition: transform 0.25s ease;
}
.sidebar-close-btn { display: none; }
.sidebar-brand {
  padding: 20px; font-size: 20px; font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.sidebar nav { padding: 12px 0; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 20px; font-size: 14.5px; color: #cbd5e1;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover, .sidebar nav a.active {
  background: rgba(255,255,255,0.06); color: #fff;
  border-left-color: var(--primary);
}
.sidebar nav .icon { width: 18px; text-align: center; }

.main {
  margin-left: 240px;
  flex: 1;
  min-width: 0;
}

.topbar {
  background: #fff; padding: 14px 26px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  box-shadow: var(--shadow); position: sticky; top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.hamburger-btn {
  display: none; background: none; border: none; font-size: 22px; cursor: pointer;
  padding: 4px 8px; border-radius: 8px; color: var(--dark); flex-shrink: 0;
}
.hamburger-btn:hover { background: #f1f2f8; }
.search-box {
  display: flex; align-items: center; background: #f1f2f8; border-radius: 10px;
  padding: 8px 14px; width: 320px; max-width: 100%; gap: 8px;
}
.search-box input { border: none; background: transparent; outline: none; width: 100%; font-size: 14px; min-width: 0; }

.topbar-actions { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; justify-content: flex-end; }
.topbar-actions a.topbar-action-link { display: flex; flex-direction: column; align-items: center; font-size: 12px; gap: 4px; font-weight: 600; }
.topbar-actions a.topbar-action-link em { font-style: normal; }
.user-chip {
  display: flex; align-items: center; gap: 8px; background: #f1f2f8;
  padding: 6px 12px; border-radius: 30px; font-size: 13px; font-weight: 600;
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}

.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 99;
}
.sidebar-overlay.show { display: block; }

.content { padding: 22px 26px; }

/* ===== Stat Cards ===== */
.stat-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 24px;
}
@media (max-width: 1200px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

.stat-card {
  border-radius: var(--card-radius); padding: 18px; color: #fff;
  display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow);
}
.stat-card .icon-box {
  width: 44px; height: 44px; border-radius: 12px; background: rgba(255,255,255,0.22);
  display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0;
}
.stat-card .label { font-size: 12.5px; opacity: 0.9; margin: 0 0 4px; }
.stat-card .value { font-size: 20px; font-weight: 700; margin: 0; }

.bg-green   { background: linear-gradient(135deg,#16a34a,#15803d); }
.bg-gray    { background: linear-gradient(135deg,#6b7280,#4b5563); }
.bg-crimson { background: linear-gradient(135deg,#be123c,#9f1239); }
.bg-amber   { background: linear-gradient(135deg,#f59e0b,#d97706); }
.bg-purple  { background: linear-gradient(135deg,#9333ea,#7e22ce); }
.bg-sky     { background: linear-gradient(135deg,#0284c7,#075985); }
.bg-slate   { background: linear-gradient(135deg,#334155,#1e293b); }
.bg-teal    { background: linear-gradient(135deg,#0f766e,#115e59); }
.bg-blue    { background: linear-gradient(135deg,#2563eb,#1d4ed8); }
.bg-lime    { background: linear-gradient(135deg,#84cc16,#65a30d); }

/* ===== Panels / Cards ===== */
.panel {
  background: #fff; border-radius: var(--card-radius); padding: 20px;
  box-shadow: var(--shadow); margin-bottom: 20px;
  overflow-x: auto;
}
.panel-title { font-size: 15.5px; font-weight: 700; color: var(--primary-dark); margin: 0 0 16px; }
.grid-2 { display: grid; grid-template-columns: 1.2fr 1fr; gap: 20px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* ===== Forms ===== */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #374151; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #e2e4ee; border-radius: 8px;
  font-size: 14px; outline: none; transition: border 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--primary); }

.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px;
  border-radius: 9px; font-size: 14px; font-weight: 600; border: none; cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: #fff; border: 1px solid #d1d5db; color: #374151; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }

/* ===== Table ===== */
table.data-table { width: 100%; min-width: 480px; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left; padding: 11px 12px; background: #f8f9fd; color: #4b5563;
  font-weight: 700; border-bottom: 1px solid #eceef5; white-space: nowrap;
}
.data-table td { padding: 11px 12px; border-bottom: 1px solid #f1f2f8; }
.data-table tr:hover td { background: #fafbff; }

.badge { padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-danger  { background: #fee2e2; color: #b91c1c; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-info    { background: #e0f2fe; color: #0369a1; }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; }
.alert-success { background: #dcfce7; color: #15803d; }
.alert-danger { background: #fee2e2; color: #b91c1c; }

.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg,#1e1b4b,#4f46e5 60%,#9333ea);
}
.login-card {
  background: #fff; width: 380px; max-width: 92vw; padding: 36px 32px; border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-card h1 { font-size: 22px; margin: 0 0 4px; color: var(--primary-dark); }
.login-card p.sub { color: #6b7280; font-size: 13.5px; margin: 0 0 24px; }
.login-card .btn { width: 100%; justify-content: center; padding: 12px; }

.text-muted { color: #6b7280; font-size: 12.5px; }
.mt-0 { margin-top: 0; }

/* ===== Invoice ===== */
.invoice-box {
  background: #fff; border-radius: var(--card-radius); box-shadow: var(--shadow);
  padding: 36px 40px; max-width: 900px; margin: 0 auto;
  overflow-x: auto;
}
.invoice-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  border-bottom: 2px solid #1e1b4b; padding-bottom: 20px; margin-bottom: 24px;
}
.invoice-brand { display: flex; align-items: center; gap: 12px; }
.invoice-brand .logo-box {
  width: 52px; height: 52px; border-radius: 12px; background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 700;
}
.invoice-brand h2 { margin: 0; font-size: 20px; color: var(--primary-dark); }
.invoice-brand p { margin: 2px 0 0; font-size: 12.5px; color: #6b7280; }
.invoice-meta { text-align: right; }
.invoice-meta h1 { margin: 0; font-size: 24px; letter-spacing: 1px; color: #1e1b4b; }
.invoice-meta p { margin: 3px 0; font-size: 13px; color: #4b5563; }

.invoice-parties { display: flex; justify-content: space-between; gap: 30px; margin-bottom: 24px; }
.invoice-party h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: #9ca3af; }
.invoice-party p { margin: 2px 0; font-size: 14px; color: #111827; }

.invoice-box table.data-table th { background: #1e1b4b; color: #fff; }
.invoice-totals { max-width: 320px; margin-left: auto; margin-top: 18px; }
.invoice-totals .row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; color: #374151; }
.invoice-totals .row.grand { font-size: 17px; font-weight: 700; color: #111827; border-top: 2px solid #e5e7eb; margin-top: 6px; padding-top: 10px; }
.invoice-totals .row.due { color: #be123c; font-weight: 700; }
.invoice-footer {
  margin-top: 34px; padding-top: 18px; border-top: 1px dashed #d1d5db;
  display: flex; justify-content: space-between; font-size: 12.5px; color: #6b7280;
}
.invoice-actions { max-width: 900px; margin: 16px auto 0; display: flex; gap: 10px; justify-content: flex-end; }

@media print {
  .sidebar, .topbar, .invoice-actions, .no-print { display: none !important; }
  .main { margin-left: 0 !important; }
  .content { padding: 0 !important; }
  body { background: #fff !important; }
  .invoice-box { box-shadow: none; padding: 0; max-width: 100%; }
}

/* ===== POS Checkout Mode ===== */
.pos-shell {
  display: flex; gap: 16px; height: calc(100vh - 130px); margin: -22px -26px; padding: 16px 26px;
}
.pos-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pos-topbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.pos-barcode-input, .pos-search-input {
  flex: 1; min-width: 220px; padding: 12px 14px; border: 2px solid #4f46e5; border-radius: 10px; font-size: 15px; outline: none;
}
.pos-search-input { border-color: #d1d5db; }
.pos-cat-tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.pos-cat-tab {
  padding: 8px 16px; border-radius: 20px; border: 1px solid #d1d5db; background: #fff; cursor: pointer; font-weight: 600; font-size: 13px;
}
.pos-cat-tab.active { background: #4f46e5; color: #fff; border-color: #4f46e5; }
.pos-grid {
  flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px; align-content: start; padding-bottom: 20px;
}
.pos-tile {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 12px; padding: 14px 10px; text-align: center;
  cursor: pointer; transition: all 0.12s; box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.pos-tile:hover { border-color: #4f46e5; box-shadow: 0 4px 12px rgba(79,70,229,0.15); transform: translateY(-2px); }
.pos-tile.out-of-stock { cursor: not-allowed; background: #f8f9fd; }
.pos-tile.out-of-stock .pos-tile-price, .pos-tile.out-of-stock .pos-tile-stock { opacity: 0.4; }
.pos-tile-name { font-weight: 700; font-size: 13px; margin-bottom: 6px; min-height: 34px; color: #111827; word-break: break-word; }
.pos-tile-price { color: #16a34a; font-weight: 700; font-size: 14px; }
.pos-tile-stock { font-size: 11px; color: #9ca3af; margin-top: 4px; }

.pos-cart {
  width: 340px; flex-shrink: 0; background: #fff; border-radius: 14px; padding: 18px;
  box-shadow: 0 4px 20px rgba(17,24,39,0.06); display: flex; flex-direction: column;
  height: 100%; min-height: 0;
}
.pos-cart-items { flex: 1 1 auto; overflow-y: auto; margin-bottom: 12px; min-height: 60px; }
.pos-cart-line { padding: 8px 0; border-bottom: 1px solid #f1f2f8; }
.pos-cart-line-name { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.pos-cart-line-controls { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.pos-cart-line-controls button {
  width: 24px; height: 24px; border-radius: 6px; border: 1px solid #d1d5db; background: #f8f9fd; cursor: pointer; font-weight: 700;
}
.pos-qty-input {
  width: 46px; text-align: center; padding: 3px 2px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 13px; font-weight: 700;
}
.pos-cart-line-total { margin-left: auto; font-weight: 700; color: #16a34a; }
.pos-remove-btn { border: none !important; background: none !important; color: #be123c; font-weight: 700; }

.pos-cart-totals { border-top: 1px solid #eceef5; padding-top: 10px; }
.pos-total-row { display: flex; justify-content: space-between; align-items: center; font-size: 13.5px; margin-bottom: 6px; }
.pos-total-row.grand { font-weight: 700; font-size: 16px; color: #4f46e5; border-top: 1px dashed #d1d5db; padding-top: 8px; margin-top: 4px; }
.pos-mini-input { width: 90px; padding: 5px 8px; border: 1px solid #e2e4ee; border-radius: 6px; text-align: right; font-size: 13px; }

@media (max-width: 900px) {
  .pos-shell { flex-direction: column; height: auto; }
  .pos-cart { width: 100%; order: -1; max-height: 45vh; }
  .pos-main { order: 2; }
}

.pos-toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%) translateY(-20px);
  background: #111827; color: #fff; padding: 12px 22px; border-radius: 10px; font-weight: 700; font-size: 14px;
  z-index: 9999; opacity: 0; pointer-events: none; transition: all 0.2s; box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.pos-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================================================
   MOBILE RESPONSIVE — applies across the whole app
   ============================================================ */

/* Off-canvas sidebar below 900px */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: 10px 0 40px rgba(0,0,0,0.25); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close-btn {
    display: block; background: none; border: none; color: #cbd5e1; font-size: 20px;
    cursor: pointer; padding: 4px 8px;
  }
  .main { margin-left: 0; }
  .hamburger-btn { display: block; }
}

/* Tablet & phone: tighter spacing, stacked forms, icon-only quick actions */
@media (max-width: 780px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; row-gap: 10px; }
  .topbar-left { flex: 1 1 100%; order: 1; }
  .topbar-actions { flex: 1 1 100%; order: 2; justify-content: flex-start; gap: 14px; }
  .search-box { flex: 1; }

  .content { padding: 16px; }
  .panel { padding: 14px; }

  .form-row { grid-template-columns: 1fr; gap: 10px; }
  .grid-2 { gap: 14px; }

  .stat-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  .stat-card { padding: 14px; gap: 10px; }
  .stat-card .icon-box { width: 36px; height: 36px; font-size: 16px; }
  .stat-card .value { font-size: 16px; }
  .stat-card .label { font-size: 11px; }

  .btn { padding: 9px 14px; font-size: 13.5px; }
  .panel-title { font-size: 14.5px; }

  /* Any inline flex header/filter row wraps instead of overflowing */
  [style*="display:flex"] { flex-wrap: wrap !important; row-gap: 8px; }

  /* Invoice pages */
  .invoice-box { padding: 20px 16px; }
  .invoice-head { flex-wrap: wrap; gap: 16px; }
  .invoice-meta { text-align: left; }
  .invoice-parties { flex-wrap: wrap; gap: 16px; }
  .invoice-totals { max-width: 100%; }
  .invoice-footer { flex-wrap: wrap; gap: 8px; }
  .invoice-actions { justify-content: flex-start; flex-wrap: wrap; }

  /* POS mode */
  .pos-shell { margin: -16px; padding: 16px; }
  .pos-barcode-input, .pos-search-input { min-width: 100%; }
  .pos-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}

/* Small phones */
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr !important; }
  .sidebar { width: 82vw; max-width: 300px; }
  .login-card { padding: 26px 20px; }
  .search-box { display: none; } /* saves space on the smallest screens; still reachable via Inventory page */
  .topbar-action-link em { display: none; } /* icon-only quick actions to save space */
  .user-chip-name { display: none; }
  .avatar { margin: 0; }
  .data-table { font-size: 12.5px; }
  .data-table th, .data-table td { padding: 8px 8px; }
}
