/* Vyapar Business Management - Main Stylesheet */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --primary: #1a56db;
  --primary-dark: #1447c7;
  --primary-light: #ebf0fe;
  --secondary: #6875f5;
  --success: #057a55;
  --success-light: #def7ec;
  --danger: #c81e1e;
  --danger-light: #fde8e8;
  --warning: #c27803;
  --warning-light: #fdf6b2;
  --info: #0e9f6e;
  --bg: #f4f6fb;
  --card: #ffffff;
  --sidebar: #111827;
  --sidebar-text: #9ca3af;
  --sidebar-active: #1a56db;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.07), 0 4px 12px rgba(0,0,0,.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
  --font: 'Plus Jakarta Sans', sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --sidebar-w: 240px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 99px; }

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

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .3s;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-logo .brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none;
}
.sidebar-logo .brand-icon {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: #fff;
}
.sidebar-logo .brand-name {
  font-size: 18px; font-weight: 800;
  color: #fff; letter-spacing: -.3px;
}
.sidebar-logo .brand-name span { color: var(--secondary); }

.sidebar-nav { padding: 16px 0; flex: 1; }
.nav-section-title {
  font-size: 10px; font-weight: 700; letter-spacing: 1.2px;
  color: rgba(255,255,255,.3);
  padding: 8px 20px 4px; text-transform: uppercase;
}

.nav-item { display: block; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 0;
  transition: all .18s;
  font-size: 13.5px; font-weight: 500;
  position: relative;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,.05); }
.nav-link.active {
  color: #fff;
  background: rgba(26,86,219,.3);
}
.nav-link.active::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--primary); border-radius: 0 3px 3px 0;
}
.nav-link .icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.07);
}
.user-mini {
  display: flex; align-items: center; gap: 10px;
}
.user-avatar-sm {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.user-name-sm { color: #fff; font-size: 13px; font-weight: 600; }
.user-role-sm { color: var(--sidebar-text); font-size: 11px; }

/* ── Main Content ── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex; flex-direction: column;
}

/* ── Topbar ── */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 16px; }
.page-title { font-size: 18px; font-weight: 700; color: var(--text); }
.breadcrumb { font-size: 12px; color: var(--text-muted); }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.topbar-btn {
  background: none; border: none; cursor: pointer;
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--text-muted);
  transition: background .15s;
}
.topbar-btn:hover { background: var(--bg); color: var(--text); }

.notification-badge {
  position: relative;
}
.notification-badge::after {
  content: '';
  position: absolute; top: 4px; right: 4px;
  width: 8px; height: 8px;
  background: var(--danger); border-radius: 50%;
  border: 2px solid var(--card);
}

/* ── Page Content ── */
.page-content { padding: 24px; flex: 1; }

/* ── Cards ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 15px; font-weight: 700; }
.card-body { padding: 20px; }

/* ── Stat Cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex; align-items: flex-start; gap: 14px;
  transition: transform .2s, box-shadow .2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon {
  width: 46px; height: 46px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-icon.yellow { background: var(--warning-light); color: var(--warning); }
.stat-icon.purple { background: #ede9fe; color: #6d28d9; }
.stat-icon.teal { background: #ccfbf1; color: #0f766e; }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; margin-bottom: 2px; }
.stat-value { font-size: 22px; font-weight: 800; color: var(--text); line-height: 1.2; }
.stat-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.stat-trend { font-size: 11px; font-weight: 600; }
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--bg); padding: 10px 14px;
  text-align: left; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px; vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbff; }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 99px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px;
}
.badge-paid { background: var(--success-light); color: var(--success); }
.badge-unpaid { background: var(--danger-light); color: var(--danger); }
.badge-partial { background: var(--warning-light); color: var(--warning); }
.badge-confirmed { background: #dbeafe; color: #1e40af; }
.badge-draft { background: #f3f4f6; color: #6b7280; }
.badge-cancelled { background: #f3f4f6; color: #9ca3af; }
.badge-low { background: var(--danger-light); color: var(--danger); }
.badge-ok { background: var(--success-light); color: var(--success); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 7px;
  font-family: var(--font); font-size: 13.5px; font-weight: 600;
  cursor: pointer; border: none; text-decoration: none;
  transition: all .15s; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #046c4e; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #9b1c1c; }
.btn-outline {
  background: transparent; border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.btn-ghost { background: var(--bg); color: var(--text); }
.btn-ghost:hover { background: var(--border); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-icon { padding: 7px 9px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.form-label.required::after { content: ' *'; color: var(--danger); }
.form-control {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--border); border-radius: 7px;
  font-family: var(--font); font-size: 13.5px; color: var(--text);
  background: var(--card); transition: border .15s;
  outline: none;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,.1); }
.form-control.error { border-color: var(--danger); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; gap: 16px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* ── Alerts / Flash ── */
.alert {
  padding: 12px 16px; border-radius: 8px;
  font-size: 13.5px; font-weight: 500; margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}
.alert-success { background: var(--success-light); color: var(--success); }
.alert-danger { background: var(--danger-light); color: var(--danger); }
.alert-warning { background: var(--warning-light); color: var(--warning); }
.alert-info { background: var(--primary-light); color: var(--primary); }

/* ── Invoice Items Table ── */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th {
  background: var(--bg); padding: 8px 10px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); text-align: left; border: 1px solid var(--border);
}
.items-table td { padding: 8px 10px; border: 1px solid var(--border); }
.items-table td input, .items-table td select {
  border: none; background: transparent; font-family: var(--font);
  font-size: 13px; color: var(--text); outline: none; width: 100%;
}
.items-table td input:focus { background: #f0f4ff; border-radius: 4px; padding: 2px 4px; }
.items-table .num-cell { font-family: var(--mono); text-align: right; }
.remove-row-btn {
  background: none; border: none; color: var(--danger); cursor: pointer;
  font-size: 16px; padding: 2px 6px; border-radius: 4px;
}
.remove-row-btn:hover { background: var(--danger-light); }
.add-item-row {
  background: none; border: 1.5px dashed var(--border); border-radius: 7px;
  color: var(--primary); font-family: var(--font); font-size: 13px;
  font-weight: 600; cursor: pointer; padding: 8px 16px;
  width: 100%; margin-top: 8px; transition: all .15s;
}
.add-item-row:hover { border-color: var(--primary); background: var(--primary-light); }

/* ── Invoice Totals ── */
.totals-box {
  background: var(--bg); border-radius: 8px; padding: 16px;
  min-width: 280px; border: 1px solid var(--border);
}
.totals-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 0; font-size: 13.5px;
}
.totals-row.total-final {
  border-top: 2px solid var(--border); margin-top: 6px; padding-top: 10px;
  font-size: 16px; font-weight: 800; color: var(--primary);
}

/* ── Modals ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4); z-index: 999;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--card); border-radius: 12px;
  width: 90%; max-width: 600px; max-height: 90vh;
  overflow-y: auto; box-shadow: var(--shadow-md);
  transform: translateY(10px); transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
  padding: 18px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 20px; color: var(--text-muted); line-height: 1;
}
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}
.modal-lg { max-width: 900px; }
.modal-xl { max-width: 1100px; }

/* ── Search Box ── */
.search-box {
  position: relative; display: flex; align-items: center;
}
.search-box input {
  padding-left: 36px; min-width: 220px;
}
.search-box .search-icon {
  position: absolute; left: 11px; color: var(--text-muted); font-size: 14px;
}

/* ── Print Invoice ── */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .page-content { padding: 0 !important; }
  .card { box-shadow: none !important; border: none !important; }
}

/* ── Login Page ── */
.auth-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #1a56db 100%);
}
.auth-card {
  background: var(--card); border-radius: 16px;
  padding: 40px; width: 90%; max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.auth-logo {
  text-align: center; margin-bottom: 28px;
}
.auth-logo .brand-icon-lg {
  width: 56px; height: 56px; background: var(--primary);
  border-radius: 14px; margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; color: #fff;
}
.auth-logo h1 { font-size: 22px; font-weight: 800; }
.auth-logo p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ── Invoice Print ── */
.invoice-print {
  max-width: 800px; margin: 0 auto; padding: 40px;
  background: #fff; font-family: var(--font);
}
.invoice-print-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  border-bottom: 3px solid var(--primary); padding-bottom: 20px; margin-bottom: 20px;
}
.company-name { font-size: 24px; font-weight: 800; color: var(--primary); }
.invoice-title { font-size: 28px; font-weight: 900; color: var(--text-muted); text-align: right; }
.invoice-number { font-size: 16px; font-weight: 700; color: var(--primary); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row.cols-3, .form-row.cols-4 { grid-template-columns: 1fr 1fr; }
  .form-row.cols-2 { grid-template-columns: 1fr; }
  .topbar { padding: 0 16px; }
  .page-content { padding: 16px; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* ── Utilities ── */
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mt-16 { margin-top: 16px; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-primary { color: var(--primary); }
.fw-bold { font-weight: 700; }
.fw-800 { font-weight: 800; }
.font-mono { font-family: var(--mono); }
.w-100 { width: 100%; }
.hidden { display: none; }
.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; font-weight: 500; }

/* ── Chart area ── */
.chart-container { position: relative; height: 260px; }

/* ── Action icons ── */
.action-btns { display: flex; gap: 4px; }
.action-btn {
  background: none; border: none; cursor: pointer;
  padding: 5px 7px; border-radius: 6px; font-size: 14px;
  transition: background .15s;
}
.action-btn.edit:hover { background: #dbeafe; color: var(--primary); }
.action-btn.delete:hover { background: var(--danger-light); color: var(--danger); }
.action-btn.view:hover { background: var(--success-light); color: var(--success); }
.action-btn.print:hover { background: var(--warning-light); color: var(--warning); }

/* ── Tabs ── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab-btn {
  background: none; border: none; cursor: pointer;
  padding: 10px 20px; font-family: var(--font); font-size: 13.5px; font-weight: 600;
  color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: all .15s;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Toasts ── */
#toast-container {
  position: fixed; top: 72px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 16px;
  box-shadow: var(--shadow-md); min-width: 260px;
  display: flex; align-items: center; gap: 10px;
  animation: slideIn .3s ease;
}
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } }
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
