:root {
  --purple: #4f46e5;
  --purple-dark: #3730a3;
  --blue: #2563eb;
  --red: #ef4444;
  --green: #10b981;
  --orange: #f59e0b;
  --teal: #14b8a6;
  --bg: #f3f4f6;
  --card-radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', 'Noto Sans Bengali', Arial, sans-serif;
  background: var(--bg);
  color: #1f2937;
}
#app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 230px;
  background: #ffffff;
  border-right: 1px solid #e5e7eb;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  overflow-y: auto;
  z-index: 50;
  transition: transform .25s ease;
}
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 26px; padding: 0 4px; }
.brand-logo-img { max-height: 72px; max-width: 100%; width: auto; object-fit: contain; }
.brand-icon {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--purple); color: #fff; display: flex;
  align-items: center; justify-content: center; font-size: 20px; font-weight: bold;
}
.brand-text b { display: block; font-size: 16px; color: var(--purple-dark); }
.brand-text span { font-size: 11px; color: #6b7280; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: 10px; color: #374151;
  cursor: pointer; font-size: 14px; margin-bottom: 4px; user-select: none;
  text-decoration: none;
}
.nav-item:hover { background: #f3f4f6; }
.nav-item.active { background: var(--purple); color: #fff; }
.nav-item .ico { font-size: 17px; width: 20px; text-align: center; }

.sidebar-footer {
  margin-top: auto; font-size: 11px; color: #9ca3af; padding: 10px 4px;
  border-top: 1px solid #f0f0f0; line-height: 1.6;
}

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; margin-left: 230px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; background: #fff; border-bottom: 1px solid #e5e7eb;
  position: sticky; top: 0; z-index: 10;
  gap: 10px;
}
.topbar .date-time { font-size: 13px; color: #374151; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .date-time b { color: #111; }
.topbar-right { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.hamburger-btn {
  display: none;
  background: none; border: none; font-size: 22px; cursor: pointer;
  padding: 4px 8px; border-radius: 8px; color: #374151; flex-shrink: 0;
}
.hamburger-btn:hover { background: #f3f4f6; }
.user-pill {
  display: flex; align-items: center; gap: 8px; background: #f3f4f6;
  padding: 6px 12px; border-radius: 20px; font-size: 13px; cursor: pointer;
  text-decoration: none; color: inherit; white-space: nowrap;
}
.user-avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--purple);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0;
}
.content { padding: 22px; flex: 1; min-width: 0; }

/* ---------- Dashboard cards ---------- */
.card-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 22px;
}
@media (max-width: 1200px) { .card-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px) { .card-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 420px) { .card-grid { grid-template-columns: 1fr; } }

/* Fixed 4/3-column summary grids (Stock page, ledger/statement summaries) —
   these still need to collapse on mobile, unlike a plain inline style would. */
.card-grid-4 { display: grid; gap: 14px; margin-bottom: 22px; grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .card-grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 420px) { .card-grid-4 { grid-template-columns: 1fr; } }

.card-grid-3 { display: grid; gap: 14px; margin-bottom: 14px; grid-template-columns: repeat(3, 1fr); }
@media (max-width: 700px) { .card-grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 420px) { .card-grid-3 { grid-template-columns: 1fr; } }

.stat-card {
  border-radius: var(--card-radius); padding: 16px 18px; color: #fff;
  position: relative; overflow: hidden; min-height: 84px;
}
.stat-card .label { font-size: 12px; opacity: .9; letter-spacing: .3px; font-weight: 600; overflow-wrap: break-word; word-break: break-word; }
.stat-card .value { font-size: 21px; font-weight: 700; margin-top: 8px; }
.stat-card .sub { font-size: 11px; opacity: .85; margin-top: 4px; }
.stat-card .ico { position: absolute; right: 14px; top: 14px; font-size: 20px; opacity: .85; }
.c-indigo { background: linear-gradient(135deg,#4338ca,#4f46e5); }
.c-blue   { background: linear-gradient(135deg,#1d4ed8,#2563eb); }
.c-red    { background: linear-gradient(135deg,#dc2626,#ef4444); }
.c-green  { background: linear-gradient(135deg,#059669,#10b981); }
.c-orange { background: linear-gradient(135deg,#d97706,#f59e0b); }
.c-teal   { background: linear-gradient(135deg,#0f766e,#14b8a6); }
.c-purple { background: linear-gradient(135deg,#7c3aed,#8b5cf6); }

.panel { background: #fff; border-radius: var(--card-radius); padding: 18px; border: 1px solid #e5e7eb; }
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.panel-title { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }

.btn { background: var(--purple); color: #fff; border: none; padding: 9px 16px; border-radius: 8px; font-size: 13px; cursor: pointer; font-weight: 600; }
.btn:hover { background: var(--purple-dark); }
.btn.secondary { background: #f3f4f6; color: #374151; }
.btn.secondary:hover { background: #e5e7eb; }
.btn.danger { background: var(--red); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.pill-btn { padding: 6px 12px; border-radius: 20px; border: 1px solid #e5e7eb; background: #fff; font-size: 12px; cursor: pointer; }
.pill-btn.active { background: var(--purple); color: #fff; border-color: var(--purple); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
table th { text-align: left; padding: 10px 8px; color: #6b7280; font-weight: 600; border-bottom: 2px solid #f0f0f0; font-size: 12px; }
table td { padding: 10px 8px; border-bottom: 1px solid #f3f4f6; }
table tr:hover td { background: #fafafa; }
.badge { padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge.green { background: #d1fae5; color: #065f46; }
.badge.red { background: #fee2e2; color: #991b1b; }
.badge.gray { background: #f3f4f6; color: #4b5563; }
.badge.low { background: #fef3c7; color: #92400e; }

input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #d1d5db; border-radius: 8px;
  font-size: 13px; font-family: inherit; margin-top: 4px;
}
label { font-size: 12px; color: #4b5563; font-weight: 600; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row { margin-bottom: 12px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex;
  align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal-box { background: #fff; border-radius: 14px; padding: 22px; width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; overflow-x: hidden; }
.modal-box.wide { max-width: 760px; }
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 16px; }

.item-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.item-row input, .item-row select { margin-top: 0; }

.purchase-item-block { margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px dashed #f0f0f0; }
.new-product-extra {
  display: none; align-items: center; gap: 8px; margin-top: 6px;
  background: #f9fafb; border: 1px dashed #d1d5db; border-radius: 8px; padding: 8px;
}
.new-product-extra.show { display: flex; flex-wrap: wrap; }
.new-product-extra input { margin-top: 0; flex: 1; min-width: 120px; }
.mini-image-upload {
  display: flex; align-items: center; gap: 6px; border: 1px solid #d1d5db; border-radius: 8px;
  padding: 6px 10px; cursor: pointer; font-size: 12px; color: #4b5563; white-space: nowrap; flex-shrink: 0;
}
.mini-image-upload [id^="puNewImagePreview_"] {
  width: 24px; height: 24px; border-radius: 6px; background: #f3f4f6; display: flex;
  align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0;
}

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.chart-wrap { position: relative; height: 300px; width: 100%; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg,#4338ca,#7c3aed); }
.login-box { background: #fff; padding: 36px 32px; border-radius: 16px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-box h2 { text-align: center; color: var(--purple-dark); margin-bottom: 4px; }
.login-logo-img { display: block; max-height: 80px; max-width: 100%; width: auto; object-fit: contain; margin: 0 auto 4px; }
.login-box p.sub { text-align: center; color: #9ca3af; font-size: 13px; margin-bottom: 22px; }
.login-error { color: #dc2626; font-size: 13px; margin-top: 8px; text-align: center; }

.spinner { width: 34px; height: 34px; border: 4px solid #e5e7eb; border-top-color: var(--purple); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; top: 20px; right: 20px; background: #111827; color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 13px; z-index: 200; box-shadow: 0 8px 20px rgba(0,0,0,.2); }
.toast.error { background: #dc2626; }
.toast.success { background: #059669; }

.empty-state { text-align: center; padding: 40px 0; color: #9ca3af; font-size: 13px; }
.hidden { display: none !important; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.mt-8 { margin-top: 8px; }
.text-right { text-align: right; }
.small-muted { font-size: 12px; color: #9ca3af; }

@media print {
  .sidebar, .topbar, .panel-header button, .panel-header input { display: none !important; }
  .main { margin-left: 0; }
  body { background: #fff; }
}

/* ============================================================
   RESPONSIVE / MOBILE
   ============================================================ */
@media (max-width: 900px) {
  /* Sidebar becomes an off-canvas drawer instead of pushing content */
  .sidebar {
    width: 260px;
    max-width: 80vw;
    transform: translateX(-100%);
    box-shadow: 0 0 30px rgba(0,0,0,.15);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }

  .main { margin-left: 0; }
  .hamburger-btn { display: inline-block; }

  .topbar { padding: 12px 14px; }
  .topbar .date-time { font-size: 11px; max-width: 130px; }
  .user-pill .user-name-label { display: none; } /* keep just the avatar + power icon on very small topbars */
  .user-pill { padding: 6px 8px; }

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

  .modal-box { padding: 16px; max-height: 92vh; }
  .modal-box.wide { max-width: 100%; }
}

@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }

  .chart-wrap { height: 260px; }

  /* Sale/Purchase item rows stack into two lines: product select full-width,
     then qty/price/subtotal/remove share the second line */
  .item-row {
    grid-template-columns: 1fr 1fr auto;
    grid-template-areas: "product product product" "qty price remove" "subtotal subtotal subtotal";
    row-gap: 6px;
  }
  .item-row select { grid-area: product; }
  .item-row .s-qty, .item-row .pu-qty { grid-area: qty; }
  .item-row .s-price, .item-row .pu-total { grid-area: price; }
  .item-row .s-subtotal, .item-row .pu-unitprice { grid-area: subtotal; }
  .item-row button { grid-area: remove; }

  .new-product-extra { flex-direction: column; align-items: stretch; }
  .new-product-extra input, .mini-image-upload { width: 100%; }

  .panel-header { flex-direction: column; align-items: stretch; }
  .panel-header > div { display: flex; flex-wrap: wrap; gap: 8px; }
  .panel-header .btn, .panel-header input#stockSearch { width: 100%; }
  #rangeButtons { display: flex; flex-wrap: wrap; gap: 6px; }

  table { font-size: 12px; }
  table th, table td { padding: 8px 6px; }
}

@media (max-width: 420px) {
  .login-box { padding: 26px 20px; }
  .stat-card .value { font-size: 18px; }
}

