:root {
  --navy: #0f1b33;
  --navy-light: #16233f;
  --bg: #f7f8fa;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-muted: #6b7280;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --orange: #f97316;
  --green: #16a34a;
  --red: #dc2626;
  --radius: 8px;
  --sidebar-width: 240px;
  --sidebar-width-collapsed: 68px;
}

* { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  margin: 0;
}

a { text-decoration: none; color: inherit; }

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--navy);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.2s ease;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 40;
}
.app-shell.sidebar-collapsed .sidebar { width: var(--sidebar-width-collapsed); }
.app-shell.sidebar-collapsed .sidebar-brand-name,
.app-shell.sidebar-collapsed .nav-link span,
.app-shell.sidebar-collapsed .nav-group-label,
.app-shell.sidebar-collapsed .sidebar-footer span {
  display: none;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-logo { width: 32px; height: 32px; border-radius: 6px; object-fit: cover; }
.sidebar-logo-placeholder {
  width: 32px; height: 32px; border-radius: 6px;
  background: var(--blue); display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar-brand-name { font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-toggle {
  margin-left: auto; background: none; border: none; color: #94a3b8; cursor: pointer;
  padding: 4px;
}

.sidebar-nav { padding: 8px; flex: 1; }
.nav-group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: #64748b; padding: 14px 12px 4px;
}
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 6px; color: #cbd5e1;
  font-size: 13.5px; white-space: nowrap;
}
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.active { background: var(--blue); color: #fff; }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 10px;
}
.sidebar-footer-business, .sidebar-footer-user {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; font-size: 12.5px; color: #94a3b8;
  margin: 0;
}
.btn-logout {
  margin-left: auto; background: none; border: none; color: #94a3b8; cursor: pointer;
}
.btn-logout:hover { color: #fff; }

/* ---------- Main ---------- */
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex; align-items: center; gap: 12px;
  position: sticky; top: 0; z-index: 30;
}
.topbar-title { font-size: 18px; font-weight: 600; margin: 0; color: var(--text); }
.topbar-menu-btn { display: none; background: none; border: none; font-size: 20px; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.topbar-user-name { font-size: 13px; color: var(--text-muted); white-space: nowrap; }
@media (max-width: 576px) { .topbar-user-name { display: none; } }

.main-content { padding: 24px; flex: 1; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.stat-card .stat-label { font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; }
.stat-card .stat-value { font-size: 22px; font-weight: 700; color: var(--text); }

/* ---------- Buttons ---------- */
.btn-primary-app {
  background: var(--blue); border-color: var(--blue); color: #fff;
}
.btn-primary-app:hover { background: var(--blue-dark); border-color: var(--blue-dark); color: #fff; }
.btn-accent {
  background: var(--orange); border-color: var(--orange); color: #fff;
}
.btn-accent:hover { background: #ea580c; border-color: #ea580c; color: #fff; }

/* ---------- Tables ---------- */
.table-app {
  font-size: 13.5px;
}
.table-app th {
  background: #f9fafb;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 11.5px;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table-app td { vertical-align: middle; }
.table-scroll { overflow-x: auto; }

.status-badge { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; font-weight: 600; }
.status-paid { background: #dcfce7; color: var(--green); }
.status-partial { background: #fef3c7; color: #b45309; }
.status-unpaid { background: #fee2e2; color: var(--red); }

/* ---------- Forms ---------- */
.form-section-title {
  font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); margin: 20px 0 10px; padding-top: 12px; border-top: 1px solid var(--border);
}
.form-section-title:first-child { border-top: none; margin-top: 0; padding-top: 0; }

/* ---------- Invoice form ---------- */
.invoice-item-row td { padding: 6px 8px; }
.invoice-item-row input, .invoice-item-row select { font-size: 13px; }
/* Fixed so it floats above the table's scroll container instead of being clipped by it;
   invoice-form.js positions it under the active input. */
.autocomplete-menu {
  position: fixed; z-index: 1050; background: #fff; border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 8px 24px rgba(15, 27, 51, 0.14); max-height: 260px; overflow-y: auto;
}
.autocomplete-menu:empty { display: none; }
.autocomplete-item { padding: 8px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #f1f5f9; }
.autocomplete-item:hover, .autocomplete-item.active { background: #eff6ff; }
.autocomplete-item .ac-sub { font-size: 11.5px; color: var(--text-muted); }

.hsn-suggestion-item {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 6px;
  display: flex; justify-content: space-between; align-items: center; font-size: 12.5px;
}

/* ---------- Sale invoice page ---------- */
.sale-page {
  --sale-accent: #0f766e;
  --sale-accent-dark: #115e59;
  --sale-accent-soft: #ecfdf5;
  max-width: 1320px;
  font-variant-numeric: tabular-nums;
}

.sale-eyebrow {
  display: flex; width: fit-content; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--sale-accent); background: var(--sale-accent-soft);
  padding: 4px 10px; border-radius: 999px; margin-bottom: 14px;
}

.sale-hero {
  display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 20px;
  background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--sale-accent);
  border-radius: 10px; padding: 20px 24px; margin-bottom: 20px;
}
.sale-hero-customer { flex: 1 1 320px; max-width: 600px; }
.sale-hero-dates { display: grid; grid-template-columns: repeat(2, minmax(150px, 190px)); gap: 12px; }

.sale-panel {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 18px 20px; margin-bottom: 20px;
}
.sale-panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.sale-panel-title {
  font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); margin: 0 0 12px;
}
.sale-panel-head .sale-panel-title { margin: 0; }

.sale-add-row {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--sale-accent); border: 1px dashed var(--sale-accent); background: transparent; font-weight: 600;
}
.sale-add-row:hover { background: var(--sale-accent-soft); color: var(--sale-accent-dark); border-color: var(--sale-accent-dark); }

/* Items table: fixed layout so inputs get their real column widths */
.sale-items-table { table-layout: fixed; min-width: 1000px; }
.sale-items-table th { background: #f8fafc; }
.sale-items-table td { padding: 8px 6px; vertical-align: middle; }
.sale-items-table tbody tr:hover { background: #fafcfc; }
.sale-items-table .c-num  { width: 36px; }
.sale-items-table .c-item { width: auto; min-width: 220px; }
.sale-items-table .c-qty  { width: 76px; }
.sale-items-table .c-unit { width: 60px; }
.sale-items-table .c-price { width: 104px; }
.sale-items-table .c-disc { width: 130px; }
.sale-items-table .c-gst  { width: 56px; }
.sale-items-table .c-amt  { width: 96px; text-align: right; }
.sale-items-table .c-del  { width: 40px; }
.sale-items-table .row-number { color: var(--text-muted); }
.sale-items-table .taxable-cell,
.sale-items-table .cgst-cell,
.sale-items-table .sgst-cell,
.sale-items-table .igst-cell,
.sale-items-table .total-cell { text-align: right; white-space: nowrap; }
.sale-items-table .unit-display { color: var(--text-muted); font-size: 12.5px; }

/* Hide number spinners — they eat most of a narrow input */
.sale-page input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.sale-page input[type="number"]::-webkit-outer-spin-button,
.sale-page input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.sale-disc-group { flex-wrap: nowrap; }
.sale-disc-group .form-control { min-width: 0; }
.sale-disc-group .form-select { flex: 0 0 54px; padding-left: 8px; padding-right: 22px; background-position: right 6px center; }

.sale-remove-row {
  width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: 6px; background: transparent; color: #94a3b8; font-size: 15px;
}
.sale-remove-row:hover { background: #fee2e2; color: var(--red); }

.sale-page .form-control:focus,
.sale-page .form-select:focus {
  border-color: var(--sale-accent); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

/* Bottom: payment + receipt-style summary */
.sale-bottom { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
.sale-bottom .sale-panel { margin-bottom: 0; }
.sale-payment-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sale-balance {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 16px; padding: 12px 14px; border-radius: 8px; background: #f8fafc;
}
.sale-balance-value { font-size: 18px; font-weight: 700; }

.sale-receipt {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 18px 20px 0; overflow: hidden;
}
.sale-receipt-row { display: flex; justify-content: space-between; align-items: center; font-size: 13.5px; padding: 4px 0; }
.sale-receipt-row > span:last-child { white-space: nowrap; }
.sale-receipt-divider { border-top: 1px dashed #cbd5e1; margin: 10px 0; }
.sale-inv-discount { display: flex; gap: 4px; width: 150px; }
.sale-inv-discount .form-select { flex: 0 0 58px; }
.sale-receipt-total {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 14px -20px 0; padding: 16px 20px;
  background: var(--navy); color: #fff; font-size: 20px; font-weight: 700;
}
.sale-receipt-total span:first-child { font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: #94a3b8; }

/* Sticky action bar */
.sale-actionbar {
  position: sticky; bottom: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  margin: 20px -24px -24px; padding: 12px 24px;
  background: rgba(255, 255, 255, 0.96); backdrop-filter: blur(6px);
  border-top: 1px solid var(--border); box-shadow: 0 -4px 16px rgba(15, 27, 51, 0.06);
}
.sale-actionbar-label { font-size: 12px; color: var(--text-muted); }
.sale-actionbar-total { font-size: 20px; font-weight: 700; color: var(--text); }
.sale-btn-save { background: var(--sale-accent); border-color: var(--sale-accent); color: #fff; font-weight: 600; padding: 8px 20px; }
.sale-btn-save:hover { background: var(--sale-accent-dark); border-color: var(--sale-accent-dark); color: #fff; }
.sale-btn-save kbd { background: rgba(255, 255, 255, 0.18); font-size: 11px; margin-left: 6px; }
.sale-btn-ghost { border: 1px solid var(--border); background: #fff; color: var(--text); }
.sale-btn-ghost:hover { background: #f1f5f9; }

@media (max-width: 991.98px) {
  .sale-bottom { grid-template-columns: 1fr; }
}
@media (max-width: 575.98px) {
  .main-content:has(.sale-page) { padding: 16px; }
  .sale-hero { padding: 16px; }
  .sale-hero-dates, .sale-payment-grid { grid-template-columns: 1fr 1fr; width: 100%; }
  .sale-actionbar { margin: 16px -16px -16px; padding: 10px 16px; }
  .sale-btn-save kbd, .sale-btn-ghost { display: none; }
}

/* ---------- Empty / loading states ---------- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state i { font-size: 40px; display: block; margin-bottom: 10px; }

/* ---------- Auth ---------- */
.auth-wrapper {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--navy);
}
.auth-card { width: 380px; background: #fff; border-radius: 12px; padding: 32px; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .app-shell.mobile-open .sidebar { transform: translateX(0); }
  .topbar-menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar-toggle { display: none; }
}

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main-content { padding: 0 !important; }
}
