/* ── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: 'Inter', system-ui, sans-serif; background: #f0f2f7; color: #1e293b; line-height: 1.5; }

/* ── Tokens ──────────────────────────────────────────────────── */
:root {
  --primary: #1a1a2e;
  --accent: #4f46e5;
  --accent-h: #4338ca;
  --accent-l: #eef2ff;
  --success: #16a34a;
  --success-l: #dcfce7;
  --warn: #d97706;
  --warn-l: #fef3c7;
  --danger: #dc2626;
  --danger-l: #fee2e2;
  --muted: #64748b;
  --border: #e2e8f0;
  --surface: #ffffff;
  --sidebar-w: 220px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
}

/* ── Utilities ───────────────────────────────────────────────── */
.hidden { display: none !important; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.ml-auto { margin-left: auto; }
.text-muted { color: var(--muted); font-size: .85rem; }
.text-sm { font-size: .85rem; }
.text-right { text-align: right; }
.w-full { width: 100%; }
.mono { font-family: 'JetBrains Mono', monospace; }

/* ── Login ───────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 60%, #0f3460 100%);
}
.login-box {
  background: var(--surface); border-radius: 16px; padding: 2.5rem;
  width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo { display: flex; align-items: center; gap: .75rem; margin-bottom: 1.75rem; }
.login-logo span { font-weight: 700; font-size: 1.2rem; color: var(--primary); }
.login-box h2 { font-size: 1.4rem; font-weight: 600; margin-bottom: 1.5rem; color: var(--primary); }

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

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); background: var(--primary); display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; height: 100vh; z-index: 100;
}
.sidebar-header {
  display: flex; align-items: center; gap: .75rem; padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-title { color: white; font-weight: 600; font-size: .95rem; }
.sidebar-nav { flex: 1; padding: .75rem 0; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: .75rem; padding: .65rem 1rem;
  color: rgba(255,255,255,.6); text-decoration: none; font-size: .875rem;
  transition: all .15s; border-left: 3px solid transparent;
}
.nav-item svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; flex-shrink: 0; }
.nav-item:hover { color: white; background: rgba(255,255,255,.06); }
.nav-item.active { color: white; background: rgba(79,70,229,.25); border-left-color: var(--accent); }
.sidebar-footer { padding: .75rem; border-top: 1px solid rgba(255,255,255,.08); }
.btn-logout {
  display: flex; align-items: center; gap: .5rem; width: 100%; padding: .6rem .75rem;
  background: none; border: none; color: rgba(255,255,255,.5); cursor: pointer;
  font-size: .82rem; border-radius: 6px; transition: .15s;
}
.btn-logout:hover { color: white; background: rgba(255,255,255,.06); }
.btn-logout svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; }

/* ── Logo mark ───────────────────────────────────────────────── */
.logo-mark {
  width: 32px; height: 32px; background: var(--accent);
  border-radius: 8px; position: relative; flex-shrink: 0;
}
.logo-mark::before {
  content: 'F'; position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; color: white; font-weight: 800; font-size: 15px;
  font-family: 'Inter', sans-serif;
}
.logo-mark.small { width: 26px; height: 26px; border-radius: 6px; }
.logo-mark.small::before { font-size: 12px; }

/* ── Content ─────────────────────────────────────────────────── */
.content { margin-left: var(--sidebar-w); flex: 1; padding: 2rem; min-height: 100vh; }
.page { display: none; }
.page.active { display: block; }

/* ── Page header ─────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.75rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.page-header .subtitle { color: var(--muted); font-size: .9rem; margin-top: .15rem; }

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.card-body { padding: 1.25rem; }
.card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .75rem; }
.card-header h3 { font-size: .95rem; font-weight: 600; }

/* ── Stat cards ──────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 1.25rem; border: 1px solid var(--border); box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 500; }
.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; color: var(--primary); margin-top: .25rem; line-height: 1; }
.stat-card .stat-value.accent { color: var(--accent); }
.stat-card .stat-value.success { color: var(--success); }
.stat-card .stat-value.warn { color: var(--warn); }
.stat-card .stat-value.danger { color: var(--danger); }
.stat-card .stat-sub { font-size: .78rem; color: var(--muted); margin-top: .5rem; }

/* ── Table ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: .6rem .85rem; text-align: left; border-bottom: 2px solid var(--border); white-space: nowrap; }
td { padding: .7rem .85rem; border-bottom: 1px solid var(--border); font-size: .875rem; color: var(--primary); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .6rem; border-radius: 100px; font-size: .75rem; font-weight: 600;
}
.badge-draft { background: #f1f5f9; color: var(--muted); }
.badge-issued { background: var(--accent-l); color: var(--accent); }
.badge-paid { background: var(--success-l); color: var(--success); }
.badge-cancelled { background: var(--danger-l); color: var(--danger); }
.badge-dot::before { content: ''; display: block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ── Forms ───────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .8rem; font-weight: 500; color: #374151; margin-bottom: .35rem; }
.form-row { display: grid; gap: .75rem; }
.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; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
select, textarea {
  width: 100%; padding: .55rem .75rem; border: 1.5px solid var(--border); border-radius: 7px;
  font-size: .875rem; color: var(--primary); background: white; outline: none;
  transition: border-color .15s, box-shadow .15s; font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
input::placeholder, textarea::placeholder { color: #b0bbc9; }
textarea { resize: vertical; min-height: 70px; }
.input-hint { font-size: .75rem; color: var(--muted); margin-top: .3rem; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem; padding: .55rem 1rem;
  border-radius: 7px; font-size: .875rem; font-weight: 500; cursor: pointer;
  border: 1.5px solid transparent; transition: all .15s; text-decoration: none;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; flex-shrink: 0; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-h); }
.btn-secondary { background: var(--surface); color: var(--primary); border-color: var(--border); }
.btn-secondary:hover { background: #f8fafc; border-color: #c4cdd7; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: none; color: var(--muted); border-color: transparent; padding: .4rem .6rem; }
.btn-ghost:hover { color: var(--primary); background: #f1f5f9; }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-group { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── Alert ───────────────────────────────────────────────────── */
.alert { padding: .75rem 1rem; border-radius: 7px; font-size: .875rem; margin-bottom: 1rem; }
.alert-error { background: var(--danger-l); color: var(--danger); border: 1px solid #fca5a5; }
.alert-success { background: var(--success-l); color: var(--success); }
.alert-warn { background: var(--warn-l); color: var(--warn); }

/* ── Dashboard charts (CSS bars) ─────────────────────────────── */
.chart-bars { display: flex; align-items: flex-end; gap: .35rem; height: 120px; padding: .5rem 0; }
.chart-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .3rem; height: 100%; justify-content: flex-end; }
.chart-bar { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; transition: height .4s; }
.chart-bar:hover { background: var(--accent-h); }
.chart-label { font-size: .65rem; color: var(--muted); }
.chart-section { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }

/* ── Client breakdown table ──────────────────────────────────── */
.progress-bar-wrap { display: flex; align-items: center; gap: .5rem; }
.progress-bar { height: 6px; border-radius: 3px; background: var(--accent); flex-shrink: 0; }

/* ── Invoice editor ──────────────────────────────────────────── */
.invoice-editor { max-width: 960px; }
.editor-card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); margin-bottom: 1rem; }
.editor-section { padding: 1.25rem; }
.editor-section + .editor-section { border-top: 1px solid var(--border); }
.section-title { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 1rem; }

/* ── Line items ──────────────────────────────────────────────── */
.lines-table { width: 100%; border-collapse: collapse; }
.lines-table th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .5rem .5rem; text-align: left; border-bottom: 2px solid var(--border); }
.lines-table td { padding: .35rem .4rem; vertical-align: top; }
.lines-table td input, .lines-table td select { padding: .4rem .5rem; font-size: .82rem; }
.lines-table td textarea { padding: .4rem .5rem; font-size: .8rem; min-height: 46px; }
.line-concept-cell { min-width: 200px; }
.line-actions { width: 36px; }
.btn-remove-line {
  width: 28px; height: 28px; border-radius: 6px; border: none;
  background: none; color: var(--muted); cursor: pointer; display: flex;
  align-items: center; justify-content: center; transition: .15s; padding: 0;
}
.btn-remove-line:hover { background: var(--danger-l); color: var(--danger); }
.btn-remove-line svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; }

.totals-block { max-width: 340px; margin-left: auto; }
.totals-row { display: flex; justify-content: space-between; padding: .4rem 0; font-size: .875rem; border-bottom: 1px solid var(--border); }
.totals-row:last-child { border-bottom: none; }
.totals-total { display: flex; justify-content: space-between; padding: .75rem; background: var(--accent); color: white; border-radius: 8px; margin-top: .5rem; font-weight: 700; font-size: 1.05rem; }
.totals-label { color: var(--muted); }

/* ── Filters bar ─────────────────────────────────────────────── */
.filters-bar { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; margin-bottom: 1.25rem; }
.filters-bar input, .filters-bar select { max-width: 180px; margin-bottom: 0; }

/* ── Toast ───────────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  padding: .75rem 1.1rem; border-radius: 9px; font-size: .875rem; font-weight: 500;
  box-shadow: var(--shadow-md); animation: slideUp .2s ease; min-width: 220px; max-width: 340px;
  display: flex; align-items: center; gap: .5rem;
}
.toast-success { background: #1a1a2e; color: white; }
.toast-error { background: var(--danger); color: white; }
.toast-warn { background: var(--warn); color: white; }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px;
  max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow-md);
  animation: scaleIn .15s ease;
}
@keyframes scaleIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-body { padding: 1.25rem; }
.modal-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; gap: .5rem; justify-content: flex-end; }
.btn-close-modal { background: none; border: none; cursor: pointer; color: var(--muted); padding: .25rem; border-radius: 5px; }
.btn-close-modal:hover { color: var(--primary); background: #f1f5f9; }
.btn-close-modal svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; display: block; }

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state { padding: 3rem; text-align: center; color: var(--muted); }
.empty-state svg { width: 48px; height: 48px; fill: none; stroke: var(--border); stroke-width: 1.5; margin: 0 auto 1rem; display: block; }
.empty-state p { font-size: .9rem; }

/* ── Misc ─────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 1rem 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
.tag { display: inline-block; padding: .15rem .5rem; border-radius: 4px; font-size: .75rem; background: var(--accent-l); color: var(--accent); font-family: 'JetBrains Mono', monospace; }

/* ── Logo upload zones ───────────────────────────────────────── */
.logo-upload-zone {
  border: 2px dashed var(--border); border-radius: 10px; padding: 1rem;
  cursor: pointer; transition: border-color .15s, background .15s;
  min-height: 110px; display: flex; align-items: center; justify-content: center;
  background: #fafbfc;
}
.logo-upload-zone:hover { border-color: var(--accent); background: var(--accent-l); }
.logo-upload-zone.small { min-height: 70px; }
.logo-preview { display: flex; align-items: center; justify-content: center; width: 100%; }
.logo-upload-placeholder {
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  color: var(--muted);
}
.logo-upload-placeholder svg {
  width: 32px; height: 32px; fill: none; stroke: currentColor; stroke-width: 1.5;
}
.logo-upload-placeholder span { font-size: .8rem; font-weight: 500; }
