@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

:root {
  --sidebar-w: 240px;
  --sidebar-bg: #0f172a;
  --sidebar-hover: rgba(255,255,255,.07);
  --sidebar-active: rgba(99,102,241,.25);
  --accent: #6366f1;
  --accent-dark: #4f46e5;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--surface-2);
  color: var(--text);
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
}

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-logo .wordmark {
  font-size: 1.25rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.5px;
  line-height: 1;
}
.sidebar-logo .wordmark span { color: var(--accent); }
.sidebar-logo .tagline {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: rgba(255,255,255,.35);
  margin-top: 3px;
}

.sidebar-nav { padding: 16px 12px; flex: 1; }
.nav-section-label {
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(255,255,255,.25);
  padding: 0 8px;
  margin: 16px 0 6px;
}
.nav-section-label:first-child { margin-top: 0; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,.6);
  text-decoration: none;
  font-size: .84rem;
  font-weight: 500;
  transition: all .15s;
  margin-bottom: 2px;
}
.sidebar-link i { font-size: 1rem; flex-shrink: 0; }
.sidebar-link:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-link.active { background: var(--sidebar-active); color: #fff; }
.sidebar-link.active i { color: var(--accent); }

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid rgba(255,255,255,.07);
}
.sidebar-footer .sidebar-link { color: rgba(255,255,255,.4); }

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: .9rem; font-weight: 600; color: var(--text-muted); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-avatar {
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: .8rem;
}

.page-content { padding: 28px; flex: 1; max-width: 1400px; }

/* ── Page header ───────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}
.page-header .subtitle {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Cards ─────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.card-header-clean {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: .88rem;
}
.card-body-padded { padding: 20px; }

/* ── Stat cards ─────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,.08); }
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.stat-card.indigo::before { background: var(--accent); }
.stat-card.green::before  { background: var(--success); }
.stat-card.amber::before  { background: var(--warning); }
.stat-card.blue::before   { background: var(--info); }

.stat-card .stat-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  margin-bottom: 14px;
}
.stat-card.indigo .stat-icon { background: #ede9fe; color: var(--accent); }
.stat-card.green .stat-icon  { background: #d1fae5; color: var(--success); }
.stat-card.amber .stat-icon  { background: #fef3c7; color: var(--warning); }
.stat-card.blue .stat-icon   { background: #dbeafe; color: var(--info); }

.stat-card .stat-value {
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  margin-bottom: 4px;
}
.stat-card .stat-label {
  font-size: .75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ── Buttons ────────────────────────────────── */
.btn {
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  font-size: .84rem;
  border-radius: 8px;
  padding: 8px 16px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.btn-primary   { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn-success   { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #059669; color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover  { background: #dc2626; color: #fff; }
.btn-outline   { background: transparent; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--surface-2); border-color: #cbd5e1; color: var(--text); }
.btn-ghost     { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 5px 12px; font-size: .78rem; border-radius: 6px; }
.btn-icon { padding: 7px; width: 34px; height: 34px; justify-content: center; }

/* ── Tables ─────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  padding: 10px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  text-align: left;
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #fafbff; }
.data-table .num { font-weight: 600; color: var(--accent); text-decoration: none; }
.data-table .num:hover { text-decoration: underline; }

/* ── Status badges ──────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .2px;
}
.badge-draft   { background: #f1f5f9; color: #64748b; }
.badge-sent    { background: #dbeafe; color: #1d4ed8; }
.badge-paid    { background: #d1fae5; color: #065f46; }
.badge-overdue { background: #fee2e2; color: #991b1b; }

/* ── Forms ──────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.form-control, .form-select {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: .85rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.form-hint { font-size: .74rem; color: var(--text-muted); margin-top: 4px; }
textarea.form-control { min-height: 80px; resize: vertical; }
.input-group { display: flex; gap: 0; }
.input-group .form-control { border-radius: 8px 0 0 8px; }
.input-group .input-addon {
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-left: none;
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
  font-size: .84rem;
  white-space: nowrap;
}

/* ── Alert / Flash ──────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: .84rem;
  font-weight: 500;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger  { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* ── Invoice preview ────────────────────────── */
.invoice-paper {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.invoice-paper .inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 2px solid #f1f5f9;
}
.invoice-paper .company-name {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: -1px;
  line-height: 1;
}
.invoice-paper .company-meta {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.7;
}
.invoice-paper .inv-label {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.invoice-paper .inv-number {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text);
  margin: 2px 0 6px;
}
.invoice-paper .bill-label {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}
.invoice-paper .bill-name { font-size: 1rem; font-weight: 700; }
.invoice-paper .bill-meta { font-size: .8rem; color: var(--text-muted); line-height: 1.6; }

.inv-items-table { width: 100%; border-collapse: collapse; margin: 24px 0; }
.inv-items-table thead tr {
  background: var(--accent);
  color: white;
}
.inv-items-table thead th {
  padding: 10px 14px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
}
.inv-items-table thead th:first-child { border-radius: 8px 0 0 8px; }
.inv-items-table thead th:last-child  { border-radius: 0 8px 8px 0; }
.inv-items-table tbody tr { border-bottom: 1px solid var(--border); }
.inv-items-table tbody tr:last-child { border-bottom: none; }
.inv-items-table tbody td { padding: 12px 14px; font-size: .85rem; }

.inv-totals { display: flex; justify-content: flex-end; }
.inv-totals table { min-width: 240px; }
.inv-totals td { padding: 5px 0; font-size: .85rem; }
.inv-totals .total-row td {
  padding-top: 10px;
  border-top: 2px solid var(--border);
  font-size: 1rem;
  font-weight: 700;
}
.inv-totals .total-row .amount { color: var(--accent); }

/* ── Line items editor ──────────────────────── */
.items-editor { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.items-header {
  display: grid;
  grid-template-columns: 1fr 80px 110px 110px 40px;
  gap: 0;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 8px 14px;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
}
.item-row {
  display: grid;
  grid-template-columns: 1fr 80px 110px 110px 40px;
  gap: 0;
  border-bottom: 1px solid var(--border);
  padding: 8px 14px;
  align-items: center;
  animation: fadeIn .2s ease;
}
.item-row:last-child { border-bottom: none; }
.item-row .form-control { border-radius: 6px; padding: 6px 10px; font-size: .82rem; }
.item-row .row-amount { font-weight: 600; color: var(--accent); text-align: right; padding-right: 8px; }
.item-row .btn-remove {
  width: 28px; height: 28px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; color: #cbd5e1;
  border-radius: 6px; cursor: pointer; font-size: 1rem;
  transition: all .15s;
}
.item-row .btn-remove:hover { background: #fee2e2; color: var(--danger); }

/* ── Tabs ────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab-bar a {
  padding: 8px 16px;
  font-size: .82rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  border-radius: 6px 6px 0 0;
  transition: all .15s;
}
.tab-bar a:hover { color: var(--accent); }
.tab-bar a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ── Breadcrumb ─────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .sep { color: #cbd5e1; }

/* ── Empty state ─────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state i { font-size: 2.5rem; opacity: .25; display: block; margin-bottom: 12px; }
.empty-state p { margin: 0 0 16px; }

/* ── Quick actions panel ─────────────────────── */
.action-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.action-panel-title {
  padding: 14px 18px;
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.action-panel .btn {
  width: 100%;
  justify-content: flex-start;
  border-radius: 0;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 12px 18px;
  font-size: .84rem;
}
.action-panel .btn:last-child { border-bottom: none; }
.action-panel .btn:hover { background: var(--surface-2); }
.action-panel .btn-danger-ghost { color: var(--danger); }
.action-panel .btn-danger-ghost:hover { background: #fff5f5; }

/* ── Summary panel ───────────────────────────── */
.summary-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}
.summary-panel .summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  font-size: .83rem;
}
.summary-panel .summary-row:last-child { border-bottom: none; }
.summary-panel .summary-row .label { color: var(--text-muted); }
.summary-panel .summary-row .value { font-weight: 600; }
.summary-panel .summary-row.total .label,
.summary-panel .summary-row.total .value { font-size: .95rem; font-weight: 700; }
.summary-panel .summary-row.total .value { color: var(--accent); }

/* ── Login ───────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #1e293b 100%);
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  overflow: hidden;
  box-shadow: 0 25px 60px rgba(0,0,0,.35);
}
.login-card-top {
  background: var(--accent);
  padding: 28px 32px 24px;
  text-align: center;
}
.login-card-top .logo-text {
  font-size: 1.8rem;
  font-weight: 900;
  color: #fff;
  letter-spacing: -1px;
  line-height: 1;
}
.login-card-top .logo-text span { opacity: .65; }
.login-card-top .sub {
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: rgba(255,255,255,.6);
  margin-top: 4px;
}
.login-card-body { padding: 28px 32px; }

/* ── Misc ────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.text-muted { color: var(--text-muted) !important; }
.text-accent { color: var(--accent); }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.gap-2 { gap: 8px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.ms-auto { margin-left: auto; }
.w-100 { width: 100%; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 24px; }
.p-0 { padding: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main-content { margin-left: 0; }
  .page-content { padding: 16px; }
  .items-header { display: none; }
  .item-row { grid-template-columns: 1fr 1fr; gap: 6px; }
  .inv-header { flex-direction: column; gap: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Preview Modal ───────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(3px);
  z-index: 500;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 32px 16px 32px;
  overflow-y: auto;
  animation: fadeOverlay .15s ease;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--surface-2);
  border-radius: 16px;
  width: 100%;
  max-width: 780px;
  box-shadow: 0 24px 80px rgba(0,0,0,.3);
  overflow: hidden;
  animation: slideUp .2s ease;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.modal-header .modal-title { font-weight: 700; font-size: .95rem; }
.modal-close {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  font-size: 1.1rem;
  transition: all .15s;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body { padding: 24px; }

@keyframes fadeOverlay { from { opacity:0; } to { opacity:1; } }
@keyframes slideUp { from { transform:translateY(20px); opacity:0; } to { transform:translateY(0); opacity:1; } }

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

/* ── Print ───────────────────────────────────── */
@media print {
  .sidebar, .topbar, .action-panel, .breadcrumb, .btn { display: none !important; }
  .main-content { margin-left: 0; }
  .invoice-paper { border: none; box-shadow: none; padding: 0; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
