/* ── Design Tokens ── */
:root {
  --surface:      #ffffff;
  --surface-2:    #f8fafc;
  --border:       #e2e8f0;
  --accent:       #16a34a;
  --accent-bg:    #f0fdf4;
  --accent-ring:  rgba(22,163,74,.2);
  --text:         #0f172a;
  --muted:        #64748b;
  --danger:       #dc2626;
  --warn:         #d97706;
  --info:         #2563eb;
  --radius:       14px;
  --radius-sm:    10px;
  --shadow:       0 1px 8px rgba(0,0,0,.07);
  --shadow-md:    0 4px 20px rgba(0,0,0,.11);
}

/* ── Base ── */
body {
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  background: #f1f5f9;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ── Typography ── */
h1, h2, h3, h4, h5, h6 { font-family: 'Nunito', system-ui, sans-serif; letter-spacing: -0.02em; color: var(--text); }
h2 { font-size: 1.45rem; font-weight: 800; }
h5 { font-weight: 700; }
h6 { font-weight: 700; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em; }
.text-muted { color: var(--muted) !important; }

/* ── Navbar ── */
.navbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  background: #15803d !important;
  border-bottom: 1px solid #14532d;
  padding: 10px 16px;
  box-shadow: 0 2px 12px rgba(0,0,0,.15);
}
.navbar-brand {
  font-size: 17px;
  font-weight: 800;
  color: #ffffff !important;
  letter-spacing: -0.02em;
}
.navbar-toggler { border: none !important; padding: 4px 6px; }
.navbar-toggler:focus { box-shadow: none; }
.navbar-toggler-icon { filter: brightness(10); }
.home-icon  { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.brand-name { font-size: 1rem; }

/* ── Side Drawer ── */
#sideDrawer { width: 300px; background: #fff; border-right: 1px solid var(--border); }
.offcanvas-header.bg-success {
  background: #15803d !important;
  border-bottom: 1px solid #14532d;
  padding: 18px 20px;
}
.offcanvas-title { font-weight: 800; font-size: 1rem; letter-spacing: -0.01em; color: #fff; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.offcanvas-body  { background: #fff; padding: 0; }
.btn-close-white { filter: brightness(10); }

.drawer-user-info {
  padding: 14px 20px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--accent-bg);
}
.drawer-user-info .label { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.06em; }
.drawer-user-info .name  { font-size: 18px; font-weight: 800; color: var(--text); margin-top: 2px; }

.drawer-nav { display: flex; flex-direction: column; padding: 10px 12px; }
.drawer-link {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 14px;
  font-size: 16px; font-weight: 700;
  color: var(--muted); text-decoration: none;
  border-radius: var(--radius-sm); margin-bottom: 2px;
  transition: all 0.15s;
}
.drawer-link:hover  { background: var(--accent-bg); color: var(--accent); }
.drawer-link.active { background: var(--accent-bg); color: var(--accent); font-weight: 800; }
.drawer-icon { font-size: 1.25rem; width: 30px; text-align: center; }

.drawer-actions {
  padding: 0 16px 16px;
  margin-top: 24px;
  display: flex; flex-direction: column; gap: 10px;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  border-bottom-color: var(--border);
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text);
}

/* ── Tables ── */
.table { font-size: 15px; --bs-table-color: var(--text); }
.table td, .table th {
  padding: 10px 12px;
  vertical-align: middle;
  border-color: var(--border);
  color: var(--text);
}
thead.table-dark th {
  background: #1e293b !important;
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-bottom: 1px solid #1e293b;
  position: sticky; top: 0; z-index: 1;
}
.table-hover tbody tr:hover { background: #f0fdf4 !important; }
.table-responsive {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  box-shadow: var(--shadow);
  background: #fff;
  -webkit-overflow-scrolling: touch;
}
.table-striped > tbody > tr:nth-of-type(odd) > * { --bs-table-accent-bg: #f8fafc; }
.table-success, .table-success > td { background: #f0fdf4 !important; }
.table-warning, .table-warning > td { background: #fffbeb !important; }
.table-danger,  .table-danger  > td { background: #fef2f2 !important; }
.table-secondary { background: #f8fafc !important; color: var(--text) !important; }
.table-secondary td { color: var(--text) !important; }

/* ── Forms ── */
.form-control, .form-select {
  font-family: 'Nunito', system-ui, sans-serif;
  font-size: 16px;
  font-weight: 600;
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  color: var(--text);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.form-control::placeholder { color: #94a3b8; }
.form-control-lg, .form-select-lg { font-size: 17px; padding: 12px 16px; }
.form-label { font-weight: 700; font-size: 13px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.form-text  { font-size: 12px; color: var(--muted); }
.input-group-text {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--muted);
  font-weight: 700;
  font-family: 'Nunito', system-ui, sans-serif;
}

/* ── Buttons ── */
.btn {
  font-family: 'Nunito', system-ui, sans-serif;
  font-weight: 700;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  letter-spacing: -0.01em;
}
.btn-lg  { font-size: 16px; padding: 12px 22px; }
.btn-sm  { font-size: 13px; padding: 5px 12px; border-radius: 8px; }

.btn-success         { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-success:hover   { background: #15803d; border-color: #15803d; color: #fff; }
.btn-outline-success { border-color: var(--accent); color: var(--accent); background: transparent; }
.btn-outline-success:hover { background: var(--accent); color: #fff; }

.btn-primary         { background: #2563eb; border-color: #2563eb; color: #fff; }
.btn-primary:hover   { background: #1d4ed8; border-color: #1d4ed8; }
.btn-outline-primary { border-color: #2563eb; color: #2563eb; }
.btn-outline-primary:hover { background: #2563eb; color: #fff; }

.btn-warning         { background: #f59e0b; border-color: #f59e0b; color: #fff; }
.btn-warning:hover   { background: #d97706; border-color: #d97706; color: #fff; }
.btn-outline-warning { border-color: #f59e0b; color: #b45309; }
.btn-outline-warning:hover { background: #f59e0b; color: #fff; }

.btn-danger          { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn-danger:hover    { background: #b91c1c; border-color: #b91c1c; }
.btn-outline-danger  { border-color: #dc2626; color: #dc2626; }

.btn-secondary       { background: #e2e8f0; border-color: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; border-color: #cbd5e1; color: var(--text); }
.btn-outline-secondary { border-color: var(--border); color: var(--muted); background: transparent; }
.btn-outline-secondary:hover { background: var(--surface-2); color: var(--text); border-color: #94a3b8; }

/* ── Alerts ── */
.alert {
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  position: relative;
}
.alert-dismissible { padding-right: 3rem; }
.alert-dismissible .btn-close {
  position: absolute;
  top: 50%;
  right: 0.75rem;
  transform: translateY(-50%);
  padding: 0;
}
.alert-success { background: #f0fdf4; color: #14532d; border: 1px solid #bbf7d0; }
.alert-warning { background: #fffbeb; color: #78350f; border: 1px solid #fde68a; }
.alert-danger  { background: #fef2f2; color: #7f1d1d; border: 1px solid #fecaca; }
.alert-info    { background: #eff6ff; color: #1e3a5f; border: 1px solid #bfdbfe; }

/* ── Badges ── */
.badge {
  font-family: 'Nunito', system-ui, sans-serif;
  font-weight: 700;
  border-radius: 8px;
  padding: 4px 9px;
}

/* ── Modals ── */
.modal-dialog {
  margin-left: auto;
  margin-right: auto;
}
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-header { border-bottom-color: var(--border); padding: 18px 20px; }
.modal-header.bg-success { background: #15803d !important; border-bottom-color: #14532d !important; }
.modal-footer { border-top-color: var(--border); }
.modal-body   { padding: 20px; }
.modal-title  { font-weight: 800; }

/* ── Nav Tabs (Billing) ── */
.nav-tabs { border-bottom-color: var(--border); }
.nav-tabs .nav-link {
  color: var(--muted);
  border-color: transparent;
  font-weight: 700; font-size: 14px;
  padding: 8px 16px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: all 0.15s;
}
.nav-tabs .nav-link:hover  { color: var(--text); background: var(--surface-2); }
.nav-tabs .nav-link.active {
  background: var(--surface);
  border-color: var(--border) var(--border) var(--surface);
  color: var(--accent);
}
.tab-close { opacity: .5; transition: opacity 0.15s; }
.tab-close:hover { opacity: 1; }

/* ── Home Screen ── */
.home-screen { max-width: 560px; margin: 0 auto; padding: 4px 0 24px; }
.home-greeting {
  text-align: center;
  padding: 28px 16px 22px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.home-greeting-icon { margin-bottom: 6px; }
.home-greeting-icon img { width: auto; height: 120px; max-width: 200px; }
.home-grid { display: flex; flex-direction: column; gap: 8px; padding: 0 12px 20px; }
.home-card {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-decoration: none; color: var(--text);
  box-shadow: var(--shadow);
  transition: all 0.15s;
  position: relative; overflow: hidden;
}
.home-card::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--accent); opacity: 0; transition: opacity 0.15s;
}
.home-card:hover {
  border-color: #86efac; color: var(--text);
  transform: translateX(3px);
  box-shadow: var(--shadow-md);
}
.home-card:hover::before { opacity: 1; }
.home-card-icon {
  font-size: 1.75rem; width: 52px; height: 52px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.home-card-body   { flex: 1; }
.home-card-title  { font-size: 17px; font-weight: 800; color: var(--text); }
.home-card-desc   { font-size: 13px; color: var(--muted); margin-top: 2px; font-weight: 500; }
.home-card-arrow  { font-size: 1.4rem; color: #cbd5e1; }

/* ── Dashboard Analytics ── */
.analytic-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  background: var(--surface);
  text-align: center;
  box-shadow: var(--shadow);
}
.analytic-num   { font-size: 1.55rem; font-weight: 900; letter-spacing: -0.03em; }
.analytic-label { font-size: 10px; color: var(--muted); margin-top: 4px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }


/* ── Basket Cards ── */
.basket-type-card {
  border: 2px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  background: var(--surface);
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}
.basket-type-card.active { border-color: var(--accent); background: var(--accent-bg); }
.basket-type-card:hover  { border-color: #94a3b8; }
.basket-icon-box {
  font-size: 1.4rem;
  background: var(--accent-bg);
  border-radius: 8px; padding: 6px 8px; line-height: 1; flex-shrink: 0;
}
.basket-qty { font-size: 1.4rem !important; font-weight: 900 !important; }

/* ── Billing ── */
.billing-tabs { overflow-x: auto; flex-wrap: nowrap; white-space: nowrap; scrollbar-width: none; -ms-overflow-style: none; }
.billing-tabs::-webkit-scrollbar { display: none; }
.billing-tabs .nav-item { flex-shrink: 0; }
.billing-tabs .nav-link { font-size: 14px; padding: 8px 16px; }
.billing-pane { background: var(--surface); }
.success-banner {
  display: flex; flex-direction: column; gap: 10px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-sm); padding: 14px 16px; margin-bottom: 12px;
}
.success-icon { font-size: 1.4rem; }
.success-text { font-size: 15px; font-weight: 700; color: #14532d; }

/* ── Login ── */
.login-wrap {
  min-height: calc(100vh - 62px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: visible;
  box-shadow: 0 8px 40px rgba(0,0,0,.12);
}
.login-header {
  background: #15803d;
  padding: 28px 24px;
  text-align: center;
  border-bottom: 1px solid #14532d;
}
.login-header .app-logo { font-size: 2.8rem; margin-bottom: 10px; }
.login-header h2        { color: #ffffff; font-size: 1.4rem; font-weight: 900; margin-bottom: 4px; }
.login-header p         { color: #bbf7d0; font-size: 14px; font-weight: 500; opacity: .9; margin: 0; }
.login-body             { padding: 28px 24px 24px; }

/* ── Settings Lock ── */
.lock-wrap {
  min-height: calc(100vh - 62px);
  display: flex; align-items: center; justify-content: center; padding: 24px 16px;
}
.lock-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,.12);
}
.lock-header {
  background: #fffbeb; padding: 24px; text-align: center;
  border-bottom: 1px solid #fde68a;
}
.lock-header .lock-icon { font-size: 2.5rem; margin-bottom: 8px; }
.lock-header h5         { color: #78350f; font-weight: 800; margin: 0; }
.lock-body              { padding: 24px; }

/* ── Frozen table (sticky header + sticky first column) ── */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Freeze header row */
.table-freeze thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  /* background set by thead.table-dark in existing rule */
}

/* Freeze second column (Date) — Customer scrolls off, Date stays pinned */
.table-freeze td:nth-child(2),
.table-freeze th:nth-child(2) {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #ffffff;
  box-shadow: 3px 0 6px rgba(0,0,0,.07);
}

/* Corner cell (Date header) sits above both axes */
.table-freeze thead th:nth-child(2) {
  z-index: 3;
  background: #1e293b;
}

/* Match frozen cell background to row state */
.table-freeze tbody tr:nth-child(odd)    td:nth-child(2) { background: #f8fafc; }
.table-freeze tbody tr.table-success     td:nth-child(2) { background: #f0fdf4; }
.table-freeze tbody tr.table-warning     td:nth-child(2) { background: #fffbeb; }
.table-freeze tbody tr.table-danger      td:nth-child(2) { background: #fef2f2; }
.table-freeze tbody tr.table-secondary   td:nth-child(2) { background: #f8fafc; }
.table-freeze tfoot tr                   td:nth-child(2) { background: #f8fafc; }
.table-freeze tbody tr:hover             td:nth-child(2) { background: #f0fdf4; }

/* Freeze first column (Customer) — for reports all-customers table */
.freeze-col1 td:nth-child(1),
.freeze-col1 th:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #ffffff;
  box-shadow: 3px 0 6px rgba(0,0,0,.07);
}
.freeze-col1 thead th:nth-child(1) {
  z-index: 3;
  background: #1e293b;
}
.freeze-col1 tbody tr:nth-child(odd) td:nth-child(1) { background: #f8fafc; }
.freeze-col1 tfoot tr                td:nth-child(1) { background: #f8fafc; }
.freeze-col1 tbody tr:hover          td:nth-child(1) { background: #f0fdf4; }

/* ── Dashboard toolbar ── */
.dash-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.dash-toolbar .search-box { flex: 1 1 160px; max-width: 220px; }
.dash-toolbar .sort-box   { flex: 1 1 140px; max-width: 180px; }

/* ── Mobile ── */
@media (max-width: 575px) {
  body { font-size: 15px; }
  .table td, .table th { font-size: 13px; padding: 8px 6px; }
  .btn-lg { font-size: 15px; padding: 11px 16px; }
  h2 { font-size: 1.25rem; }
  .basket-type-card { padding: 12px; }
  .home-card { padding: 16px 14px; gap: 12px; }
  .home-card-icon { width: 46px; height: 46px; font-size: 1.55rem; }
  .home-card-title { font-size: 16px; }
  .home-grid { padding: 0 8px 16px; }
  .home-greeting { padding: 20px 16px 18px; }

  /* Analytic cards — Tamil labels are 2-3× longer; drop letter-spacing, allow wrap */
  .analytic-num   { font-size: 1.2rem; }
  .analytic-label { font-size: 10px; letter-spacing: 0 !important; line-height: 1.3; word-break: break-word; }
  /* Customer cards — letter-spacing fragments Tamil ligatures */
  .cust-stat-lbl  { font-size: 0.63rem; letter-spacing: 0 !important; }

  /* Dashboard toolbar — heading gets its own full row; sort fills full width below search */
  .dash-toolbar h6        { flex: 0 0 100%; margin-bottom: 0; }
  .dash-toolbar .search-box { flex: 1 1 auto; max-width: none; min-width: 0; }
  .dash-toolbar .sort-box   { flex: 1 1 100%; max-width: none; }

  /* Manage-customers search bar — sort dropdown wraps to its own row */
  #custSort { flex: 1 1 100% !important; width: 100% !important; min-width: 0 !important; }

  /* ── Action buttons in dashboard table — bigger touch targets ── */
  .cust-action-btn { padding: 0.45rem 0.25rem; min-height: 38px; font-size: 0.72rem; }

  /* ── Billing tab close — bigger hit area ── */
  .tab-close { font-size: 1rem !important; min-width: 28px; min-height: 28px;
               display: inline-flex; align-items: center; justify-content: center; }

  /* ── Product card inputs — 16px prevents iOS auto-zoom on focus ── */
  .pc-body .form-control { font-size: 16px !important; }
  .pc-head select.pc-product { font-size: 15px !important; }

  /* ── Grand total bar — stack label above value on tiny screens ── */
  .grand-bar { flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px 14px; }
  .grand-bar-val { align-self: flex-end; }

  /* ── Customer detail — reduce inline min-widths so table is less wide ── */
  .table td[style*="min-width"] { min-width: 60px !important; }

  /* ── Pagination — bigger touch targets ── */
  .pagination-sm .page-link { min-width: 36px; min-height: 36px;
    display: flex; align-items: center; justify-content: center; }

  /* ── Modal — full-width on small screens ── */
  .modal-dialog[style*="max-width"] { max-width: calc(100vw - 24px) !important; }
}
