:root {
  --brand-primary: #1e3a5f;
  --brand-primary-light: #2c5282;
  --brand-accent: #2563eb;
  --brand-accent-light: #dbeafe;
  --sidebar-bg: #16233d;
  --sidebar-text: #b9c6dc;
  --sidebar-text-active: #ffffff;
  --bg-body: #f4f6fb;
  --card-radius: 14px;
  --shadow-soft: 0 2px 10px rgba(20, 30, 60, 0.06);
  --shadow-med: 0 6px 20px rgba(20, 30, 60, 0.10);
}

* { box-sizing: border-box; }

body {
  background: var(--bg-body);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
  color: #1f2937;
}

/* ---------- Login Page ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-light) 45%, var(--brand-accent) 100%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-med);
  padding: 2.5rem;
}
.auth-logo {
  width: 56px; height: 56px; border-radius: 14px;
  background: var(--brand-accent-light); color: var(--brand-accent);
  display: flex; align-items: center; justify-content: center; font-size: 28px;
  margin: 0 auto 1rem auto;
}

/* ---------- App Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: margin-left .25s ease, transform .25s ease, visibility 0s linear 0s;
}
.sidebar-brand {
  display: flex; align-items: center; gap: .6rem;
  padding: 1.3rem 1.3rem 1rem 1.3rem;
  font-weight: 700; font-size: 1.25rem; color: #fff;
}
.sidebar-brand i { color: #60a5fa; font-size: 1.6rem; }
.sidebar-company {
  padding: 0 1.3rem 1rem 1.3rem; margin-top: -.6rem;
  font-size: .8rem; color: #94a3b8;
}
.sidebar-nav { padding: 0.5rem 0.8rem 2rem 0.8rem; }
.nav-section {
  text-transform: uppercase; font-size: .7rem; letter-spacing: .06em;
  color: #64748b; margin: 1.1rem 0.6rem 0.4rem 0.6rem; font-weight: 600;
}
.sidebar-nav .nav-link {
  color: var(--sidebar-text);
  padding: .55rem .8rem; border-radius: 8px; font-size: .92rem;
  display: flex; align-items: center; gap: .65rem; margin-bottom: 2px;
  transition: background .15s ease, color .15s ease;
}
.sidebar-nav .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; }
.sidebar-nav .nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav .nav-link.active { background: var(--brand-accent); color: #fff; font-weight: 600; }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: #fff; border-bottom: 1px solid #e5e9f0;
  padding: .8rem 1.5rem; display: flex; align-items: center; gap: 1rem;
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 600; font-size: 1.1rem; color: #111827; flex: 1; }
.avatar-circle {
  width: 32px; height: 32px; border-radius: 50%; background: var(--brand-accent);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem;
}

.content-area { padding: 1.5rem; max-width: 1500px; width: 100%; margin: 0 auto; }

/* ---------- Cards ---------- */
.card {
  border: none; border-radius: var(--card-radius); box-shadow: var(--shadow-soft);
}
.card-header {
  background: #fff; border-bottom: 1px solid #eef1f6; font-weight: 600; border-radius: var(--card-radius) var(--card-radius) 0 0 !important;
}

.stat-card {
  border-radius: var(--card-radius); padding: 1.25rem 1.4rem; color: #fff;
  box-shadow: var(--shadow-med); position: relative; overflow: hidden;
}
.stat-card .stat-icon {
  position: absolute; right: 1rem; top: 1rem; font-size: 2.2rem; opacity: .35;
}
.stat-card .stat-label { font-size: .8rem; opacity: .9; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; margin-top: .2rem; }
.stat-card .stat-sub { font-size: .78rem; opacity: .85; margin-top: .3rem; }

.bg-grad-blue { background: linear-gradient(135deg, #2563eb, #1e3a5f); }
.bg-grad-green { background: linear-gradient(135deg, #059669, #065f46); }
.bg-grad-orange { background: linear-gradient(135deg, #ea580c, #9a3412); }
.bg-grad-purple { background: linear-gradient(135deg, #7c3aed, #4c1d95); }
.bg-grad-red { background: linear-gradient(135deg, #dc2626, #7f1d1d); }
.bg-grad-teal { background: linear-gradient(135deg, #0d9488, #134e4a); }

/* ---------- Tables ---------- */
.table-modern thead th {
  background: #eef2f9; color: #374151; font-size: .78rem; text-transform: uppercase;
  letter-spacing: .03em; font-weight: 700; border-bottom: none; white-space: nowrap;
}
.table-modern tbody tr:hover { background: #f8fafc; }
.table-modern td, .table-modern th { vertical-align: middle; padding: .7rem .8rem; }

.badge-status-active { background: #d1fae5; color: #065f46; }
.badge-status-inactive { background: #fee2e2; color: #991b1b; }

/* ---------- Forms ---------- */
.form-label { font-weight: 600; font-size: .85rem; color: #374151; }
.form-control, .form-select { border-radius: 8px; border-color: #d7dce5; }
.form-control:focus, .form-select:focus { border-color: var(--brand-accent); box-shadow: 0 0 0 .2rem rgba(37,99,235,.15); }
.required-mark { color: #dc2626; }

.section-title {
  font-weight: 700; font-size: .95rem; color: var(--brand-primary);
  padding-bottom: .4rem; margin-bottom: 1rem; border-bottom: 2px solid var(--brand-accent-light);
}

/* Invoice item table */
.invoice-item-table th { font-size: .75rem; text-transform: uppercase; background: #eef2f9; }
.invoice-item-table input, .invoice-item-table select { min-width: 80px; }
.invoice-item-table .item-name-col { min-width: 220px; }

.btn-brand { background: var(--brand-accent); border-color: var(--brand-accent); color: #fff; }
.btn-brand:hover { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }

.empty-state { text-align: center; padding: 3rem 1rem; color: #6b7280; }
.empty-state i { font-size: 3rem; color: #cbd5e1; margin-bottom: 1rem; display: block; }

@media print {
  .no-print { display: none !important; }
}

/* ---------- Sidebar collapse / expand ----------
   State lives on <html> so it can be applied before first paint:
   - html.sidebar-collapsed : desktop (>= 992px) sidebar hidden
   - html.sidebar-open      : mobile  (<  992px) sidebar shown
   Mobile is collapsed by default (no class needed). */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .5);
  z-index: 1040;
}

/* Desktop */
@media (min-width: 992px) {
  html.sidebar-collapsed .sidebar {
    margin-left: -250px;
    visibility: hidden;
    transition: margin-left .25s ease, visibility 0s linear .25s;
  }
}

/* Mobile / tablet: off-canvas drawer, collapsed by default */
@media (max-width: 991.98px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    height: 100%;
    z-index: 1050;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform .25s ease, visibility 0s linear .25s;
  }
  html.sidebar-open .sidebar {
    transform: translateX(0);
    visibility: visible;
    transition: transform .25s ease, visibility 0s linear 0s;
    box-shadow: var(--shadow-med);
  }
  html.sidebar-open .sidebar-backdrop { display: block; }
  html.sidebar-open, html.sidebar-open body { overflow: hidden; }
  .topbar { padding: .7rem 1rem; }
  .content-area { padding: 1rem; }
}

@media print {
  .sidebar, .sidebar-backdrop, .topbar { display: none !important; }
}
