/* ── Variables ─────────────────────────────────────────── */
:root {
  --sidebar-w:          240px;
  --topbar-h:           60px;
  --primary:            #2563eb;
  --primary-dark:       #1d4ed8;
  --primary-light:      #eff6ff;
  --primary-subtle:     rgba(37,99,235,.08);
  --sidebar-bg:         #0f172a;
  --sidebar-text:       #94a3b8;
  --sidebar-hover:      rgba(255,255,255,.06);
  --body-bg:            #f1f5f9;
  --card-bg:            #ffffff;
  --border:             #e2e8f0;
  --text:               #0f172a;
  --text-muted:         #64748b;
  --radius:             10px;
  --radius-lg:          14px;
  --shadow-xs:          0 1px 2px rgba(0,0,0,.05);
  --shadow-sm:          0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:             0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
  --shadow-md:          0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.04);
  --shadow-lg:          0 20px 25px -5px rgba(0,0,0,.12), 0 8px 10px -6px rgba(0,0,0,.06);
}

/* ── Reset / Base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  background: var(--body-bg);
  color: var(--text);
  margin: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Topbar ────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 14px;
  z-index: 1000;
  box-shadow: 0 1px 0 rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.03);
}

.sidebar-toggle {
  background: none;
  border: none;
  padding: 7px 9px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--body-bg); color: var(--text); }

.brand {
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
}
.brand-icon {
  width: 32px; height: 32px;
  background: var(--primary);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand-icon i { color: #fff; font-size: 17px; }
.brand-name { font-size: 15px; font-weight: 700; color: var(--text); letter-spacing: -.3px; }
.brand-tag {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  background: var(--body-bg); border: 1px solid var(--border);
  padding: 2px 7px; border-radius: 5px; line-height: 1.6;
}

/* Keep old classes working */
.brand-primary { font-size: 15px; font-weight: 700; color: var(--text); letter-spacing: -.3px; }
.brand-sub { font-size: 11px; font-weight: 600; color: var(--text-muted); }

.topbar-search { flex: 1; max-width: 440px; }
.search-wrap { position: relative; }
.search-icon {
  position: absolute; left: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted); font-size: 13px; pointer-events: none;
}
.search-wrap .form-control {
  padding-left: 33px;
  border-radius: 8px;
  background: var(--body-bg);
  border-color: var(--border);
  font-size: 13.5px;
  height: 36px;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.search-wrap .form-control:focus {
  background: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.search-wrap .form-control::placeholder { color: #a0aec0; font-size: 13px; }

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px); left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 9999;
  max-height: 340px;
  overflow-y: auto;
}
.search-result-item {
  padding: 9px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--body-bg);
  text-decoration: none;
  color: var(--text);
  transition: background .1s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--body-bg); }
.search-result-item .sr-icon {
  width: 30px; height: 30px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0;
}
.search-result-item .sr-main { font-weight: 500; font-size: 13px; }
.search-result-item .sr-sub  { font-size: 11.5px; color: var(--text-muted); }

/* User avatar */
.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  letter-spacing: 0;
  text-transform: uppercase;
}

.user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 30px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.user-btn:hover { background: var(--body-bg); border-color: #c8d4e3; }
.user-btn .caret { font-size: 10px; color: var(--text-muted); }

/* legacy ghost button */
.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  transition: background .15s;
}
.btn-ghost:hover { background: var(--body-bg); }

/* ── Layout ────────────────────────────────────────────── */
.layout-wrapper {
  display: flex;
  padding-top: var(--topbar-h);
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  flex-shrink: 0;
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform .22s cubic-bezier(.4,0,.2,1), width .22s cubic-bezier(.4,0,.2,1);
  z-index: 900;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: #2d3748 transparent;
}
.sidebar.collapsed { transform: translateX(-100%); }

.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 10px 0 16px;
  flex: 1;
}

.nav-section {
  padding: 18px 18px 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: #475569;
  text-transform: uppercase;
}

.nav-item { margin: 0; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin: 1px 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: 8px;
  transition: background .15s, color .15s;
}
.nav-link i { font-size: 16px; flex-shrink: 0; width: 18px; text-align: center; }
.nav-link:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav-link.active {
  background: rgba(37,99,235,.22);
  color: #93c5fd;
}
.nav-link.active i { color: #60a5fa; }

.sidebar-footer {
  padding: 12px 18px;
  border-top: 1px solid rgba(255,255,255,.06);
}

/* ── Main content ──────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  transition: margin-left .22s cubic-bezier(.4,0,.2,1);
  padding-bottom: 48px;
}
.main-content.expanded { margin-left: 0; }

/* ── Page header ───────────────────────────────────────── */
.page-header {
  padding: 20px 28px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
}
.page-title {
  font-size: 19px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -.3px;
  color: var(--text);
}
.page-subtitle { font-size: 12.5px; color: var(--text-muted); margin: 3px 0 0; }

/* ── Cards ─────────────────────────────────────────────── */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: var(--card-bg);
}
.card-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  font-weight: 600;
  font-size: 13.5px;
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--text);
}

/* ── Stat cards ────────────────────────────────────────── */
.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s ease, transform .2s ease;
  cursor: default;
}
.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.stat-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.stat-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.stat-value {
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.6px;
  color: var(--text);
}
.stat-label { font-size: 12.5px; color: var(--text-muted); font-weight: 500; }

/* ── Tables ────────────────────────────────────────────── */
.table { font-size: 13.5px; }
.table th {
  font-weight: 600;
  white-space: nowrap;
  background: #f8fafc;
  color: var(--text-muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  border-top: none;
}
.table td {
  vertical-align: middle;
  padding: 11px 16px;
  border-color: #f1f5f9;
}
.table-hover tbody tr { transition: background .12s; }
.table-hover tbody tr:hover { background: #f5f8ff; }

/* ── Forms ─────────────────────────────────────────────── */
.form-label { font-weight: 500; font-size: 13px; margin-bottom: 5px; color: var(--text); }
.form-control, .form-select {
  font-size: 13.5px;
  border-color: var(--border);
  border-radius: 8px;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.section-title {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 16px;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn { font-size: 13.5px; border-radius: 8px; font-weight: 500; transition: all .15s; }
.btn-sm { font-size: 12.5px; border-radius: 7px; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  box-shadow: 0 3px 8px rgba(37,99,235,.25);
}
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); }
.btn-outline-secondary { color: var(--text-muted); border-color: var(--border); }
.btn-outline-secondary:hover { background: var(--body-bg); color: var(--text); border-color: #c8d4e3; }
.btn-outline-danger:hover { box-shadow: 0 2px 6px rgba(220,38,38,.2); }

/* ── Flash alerts ──────────────────────────────────────── */
.alert { border-radius: var(--radius); border: none; font-size: 13.5px; }
.alert-success { background: #f0fdf4; color: #166534; }
.alert-warning { background: #fffbeb; color: #92400e; }
.alert-danger  { background: #fef2f2; color: #991b1b; }

/* ── Status badges ─────────────────────────────────────── */
.badge {
  font-size: 11px;
  font-weight: 600;
  border-radius: 20px;
  padding: 3px 9px;
  letter-spacing: .1px;
}

/* ── Line items table ──────────────────────────────────── */
.items-table { font-size: 13px; }
.items-table thead th { padding: 8px 8px; }
.items-table td { padding: 5px 6px; }
.items-table input[type=text],
.items-table input[type=number],
.items-table select { padding: 4px 8px; height: 32px; border-radius: 6px; }

/* ── Totals box ────────────────────────────────────────── */
.totals-box {
  background: var(--body-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.totals-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13.5px; }
.totals-row.grand {
  font-size: 17px;
  font-weight: 700;
  border-top: 2px solid var(--border);
  margin-top: 8px;
  padding-top: 10px;
  color: var(--primary);
}

/* ── Catalog modal ─────────────────────────────────────── */
.catalog-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background .12s;
}
.catalog-item:last-child { border-bottom: none; }
.catalog-item:hover { background: var(--body-bg); }
.catalog-item-name { font-weight: 500; font-size: 13.5px; }
.catalog-item-rate { font-size: 13px; color: var(--primary); font-weight: 600; }

/* ── Approval page ─────────────────────────────────────── */
.approve-wrap { max-width: 680px; margin: 40px auto; padding: 0 16px; }
.approve-card {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.approve-header { background: var(--primary); color: #fff; padding: 28px 32px; }
.approve-body { padding: 28px 32px; }
.approve-items td { padding: 7px 8px; font-size: 13.5px; }

/* ── Print styles ──────────────────────────────────────── */
@media print {
  .topbar, .sidebar, .no-print { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .print-page { padding: 0; }
  body { font-size: 12px; }
}

.invoice-print-wrap { max-width: 800px; margin: 0 auto; background: #fff; padding: 32px; }
.inv-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.inv-company-name { font-size: 22px; font-weight: 800; color: var(--primary); }
.inv-title { font-size: 18px; font-weight: 700; text-align: right; }
.inv-number { font-size: 13px; color: var(--text-muted); text-align: right; }
.inv-divider { border: none; border-top: 2px solid var(--primary); margin: 16px 0; }
.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.inv-party-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-bottom: 4px; }
.inv-items-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-bottom: 20px; }
.inv-items-table th { background: var(--sidebar-bg); color: #fff; padding: 8px 10px; font-size: 11px; }
.inv-items-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); }
.inv-items-table tr:last-child td { border-bottom: none; }
.inv-totals { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.inv-total-row { display: flex; gap: 24px; font-size: 13px; }
.inv-total-row .lbl { color: var(--text-muted); min-width: 120px; text-align: right; }
.inv-total-row .val { min-width: 90px; text-align: right; font-weight: 600; }
.inv-grand-row { font-size: 16px; font-weight: 800; border-top: 2px solid var(--primary); padding-top: 8px; margin-top: 4px; }
.inv-words { background: #f8fafc; border-radius: 6px; padding: 8px 12px; font-size: 12px; font-style: italic; margin-top: 16px; }
.inv-footer { margin-top: 32px; display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); }
.inv-sign { text-align: right; }
.inv-sign-line { border-top: 1px solid #999; width: 160px; margin-top: 40px; margin-left: auto; }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .topbar-search { display: none; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

/* ── Utility ───────────────────────────────────────────── */
.px-24 { padding-left: 28px; padding-right: 28px; }
.text-end { text-align: right !important; }
.fw-600 { font-weight: 600; }
.cursor-pointer { cursor: pointer; }
.text-primary { color: var(--primary) !important; }
a.plain { color: inherit; text-decoration: none; }
a.plain:hover { color: var(--primary); }
.gap-2 { gap: 8px; }
