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

:root {
  --dark:    #0D1B2A;
  --darker:  #07111C;
  --primary: #00557e;
  --accent:  #00A3C4;
  --amber:   #F4A830;
  --red:     #ef4444;
  --green:   #10b981;
  --muted:   rgba(255,255,255,0.45);
  --border:  rgba(255,255,255,0.07);
  --card:    rgba(255,255,255,0.04);
  --radius:  0.75rem;
  --sidebar: 220px;
}

html, body { height: 100%; font-family: 'Inter', system-ui, sans-serif; background: var(--darker); color: #fff; }
.hidden { display: none !important; }

/* ── LOGIN ──────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--darker);
}
.login-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  padding: 2.5rem 2rem;
  width: 100%; max-width: 340px;
  text-align: center;
}
.login-logo {
  font-family: 'Montserrat', sans-serif;
  font-size: 2.5rem; font-weight: 900;
  color: var(--accent); margin-bottom: 0.25rem;
}
.login-sub { font-size: 0.82rem; color: var(--muted); margin-bottom: 2rem; }
.login-box input {
  width: 100%; padding: 0.75rem 1rem;
  background: rgba(255,255,255,0.06); border: 1px solid var(--border);
  border-radius: 0.5rem; color: #fff; font-size: 0.95rem;
  margin-bottom: 1rem; outline: none;
}
.login-box input:focus { border-color: var(--accent); }
.login-box button {
  width: 100%; padding: 0.75rem;
  background: var(--accent); color: var(--dark);
  border: none; border-radius: 0.5rem;
  font-weight: 700; font-size: 0.95rem; cursor: pointer;
}
.login-error { color: var(--red); font-size: 0.82rem; margin-top: 0.75rem; }

/* ── APP SHELL ──────────────────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── SIDEBAR ────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar); flex-shrink: 0;
  background: var(--dark); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 1.5rem 1rem;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 0.5rem;
  margin-bottom: 2rem;
}
.sidebar-logo {
  font-family: 'Montserrat', sans-serif;
  font-size: 1.35rem; font-weight: 900; color: var(--accent);
}
.sidebar-name { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 0.25rem; }
.nav-item {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.65rem 0.75rem; border-radius: 0.5rem;
  color: var(--muted); font-size: 0.88rem; font-weight: 500;
  text-decoration: none; cursor: pointer; position: relative;
  transition: background 0.15s, color 0.15s;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: var(--card); color: #fff; }
.nav-item.active { background: rgba(0,163,196,0.12); color: var(--accent); }
.nav-badge {
  margin-left: auto; background: var(--accent);
  color: var(--dark); font-size: 0.65rem; font-weight: 800;
  padding: 0.1rem 0.45rem; border-radius: 999px; min-width: 18px;
  text-align: center;
}
.nav-badge.red { background: var(--red); color: #fff; }
.nav-badge:empty { display: none; }
.sidebar-footer { margin-top: 2rem; display: flex; flex-direction: column; gap: 0.5rem; }
.digest-btn, .logout-btn {
  padding: 0.55rem; border-radius: 0.5rem;
  font-size: 0.78rem; font-weight: 600; cursor: pointer; border: none;
}
.digest-btn { background: rgba(0,163,196,0.15); color: var(--accent); }
.digest-btn:hover { background: rgba(0,163,196,0.25); }
.logout-btn { background: rgba(255,255,255,0.05); color: var(--muted); }
.logout-btn:hover { background: rgba(255,255,255,0.1); }

/* ── MAIN ───────────────────────────────────────────────── */
.main { flex: 1; overflow-y: auto; padding: 2rem; }
.view-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 2rem; flex-wrap: wrap; gap: 1rem;
}
.view-header h1 {
  font-family: 'Montserrat', sans-serif;
  font-size: 1.6rem; font-weight: 900;
}
.view-date { font-size: 0.82rem; color: var(--muted); }
.btn-primary {
  background: var(--accent); color: var(--dark);
  border: none; padding: 0.6rem 1.25rem; border-radius: 0.5rem;
  font-size: 0.85rem; font-weight: 700; cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.85; }

/* ── DASHBOARD ──────────────────────────────────────────── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem; margin-bottom: 2rem;
}
.stat-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
}
.stat-card .stat-num {
  font-family: 'Montserrat', sans-serif;
  font-size: 2rem; font-weight: 900; color: var(--accent);
  line-height: 1;
}
.stat-card .stat-label { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }
.stat-card.amber .stat-num { color: var(--amber); }
.stat-card.red .stat-num { color: var(--red); }
.stat-card.green .stat-num { color: var(--green); }

.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr));
  gap: 1.5rem;
}
.full-width { grid-column: 1 / -1; }
.panel {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem;
}
.panel-head h2 { font-family: 'Montserrat',sans-serif; font-size: 0.95rem; font-weight: 700; }
.panel-total {
  font-size: 0.82rem; font-weight: 700; color: var(--red);
  background: rgba(239,68,68,0.1); padding: 0.2rem 0.6rem; border-radius: 999px;
}

.overdue-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.65rem 0; border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.overdue-item:last-child { border-bottom: none; }
.overdue-item .client { font-weight: 600; }
.overdue-item .amount { color: var(--red); font-weight: 700; font-family: 'Montserrat',sans-serif; }
.overdue-item .days { font-size: 0.72rem; color: var(--muted); }

.cold-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.65rem 0; border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.cold-item:last-child { border-bottom: none; }
.cold-item .name { font-weight: 600; }
.cold-item .stage { font-size: 0.72rem; background: rgba(0,163,196,0.12); color: var(--accent); padding: 0.15rem 0.5rem; border-radius: 999px; }

.activity-item {
  padding: 0.5rem 0; border-bottom: 1px solid var(--border);
  font-size: 0.82rem; color: rgba(255,255,255,0.7);
}
.activity-item:last-child { border-bottom: none; }
.activity-item .time { color: var(--muted); font-size: 0.72rem; float: right; }
.activity-type-badge {
  display: inline-block; font-size: 0.65rem; font-weight: 700;
  padding: 0.1rem 0.45rem; border-radius: 4px; margin-right: 0.4rem;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.badge-lead { background: rgba(0,163,196,0.15); color: var(--accent); }
.badge-project { background: rgba(244,168,48,0.15); color: var(--amber); }
.badge-invoice { background: rgba(239,68,68,0.15); color: var(--red); }

/* ── KANBAN ─────────────────────────────────────────────── */
.kanban {
  display: flex; gap: 1rem; overflow-x: auto;
  padding-bottom: 1rem; align-items: flex-start;
}
.kanban-col {
  flex-shrink: 0; width: 240px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
}
.kanban-col-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.kanban-col-head h3 {
  font-size: 0.78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--muted);
}
.kanban-col-count {
  font-size: 0.72rem; background: rgba(255,255,255,0.08);
  color: #fff; padding: 0.1rem 0.45rem; border-radius: 999px; font-weight: 600;
}
.kanban-cards { display: flex; flex-direction: column; gap: 0.65rem; min-height: 40px; }
.kanban-card {
  background: rgba(255,255,255,0.06); border: 1px solid var(--border);
  border-radius: 0.6rem; padding: 0.9rem; cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.kanban-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.kanban-card .card-name { font-size: 0.88rem; font-weight: 600; margin-bottom: 0.25rem; }
.kanban-card .card-company { font-size: 0.75rem; color: var(--muted); }
.kanban-card .card-value { font-size: 0.78rem; color: var(--green); font-weight: 700; margin-top: 0.4rem; }
.kanban-card .card-followup {
  font-size: 0.7rem; color: var(--amber); margin-top: 0.3rem;
}
.kanban-card .card-followup.overdue { color: var(--red); }

/* ── INVOICE TABLE ──────────────────────────────────────── */
.invoice-table-wrap { overflow-x: auto; }
.invoice-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.invoice-table th {
  text-align: left; padding: 0.75rem 1rem;
  font-size: 0.72rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border);
}
.invoice-table td {
  padding: 0.9rem 1rem; border-bottom: 1px solid var(--border);
}
.invoice-table tr:last-child td { border-bottom: none; }
.invoice-table tr:hover td { background: rgba(255,255,255,0.02); }
.balance-cell { color: var(--red); font-weight: 700; font-family: 'Montserrat',sans-serif; }
.status-pill {
  font-size: 0.68rem; font-weight: 700; padding: 0.2rem 0.55rem;
  border-radius: 999px; text-transform: uppercase; letter-spacing: 0.05em;
}
.status-overdue { background: rgba(239,68,68,0.15); color: var(--red); }
.status-sent { background: rgba(244,168,48,0.15); color: var(--amber); }
.status-partial { background: rgba(0,163,196,0.15); color: var(--accent); }
.btn-chase {
  background: rgba(239,68,68,0.12); color: var(--red);
  border: 1px solid rgba(239,68,68,0.3); border-radius: 0.4rem;
  padding: 0.35rem 0.75rem; font-size: 0.75rem; font-weight: 700;
  cursor: pointer; transition: background 0.15s;
}
.btn-chase:hover { background: rgba(239,68,68,0.25); }
.total-owed {
  font-family: 'Montserrat',sans-serif; font-size: 1.5rem; font-weight: 900;
  color: var(--red);
}
.empty-state { text-align: center; padding: 3rem; color: var(--muted); font-size: 0.9rem; }

/* ── MODAL ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 1rem;
}
.modal {
  background: #0f2030; border: 1px solid var(--border);
  border-radius: 1rem; width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-family: 'Montserrat',sans-serif; font-size: 1rem; font-weight: 700; }
.modal-close {
  background: none; border: none; color: var(--muted);
  font-size: 1.1rem; cursor: pointer;
}
#modal-body { padding: 1.5rem; }
.form-group { margin-bottom: 1.1rem; }
.form-group label { display: block; font-size: 0.78rem; color: var(--muted); font-weight: 600; margin-bottom: 0.4rem; text-transform: uppercase; letter-spacing: 0.05em; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%; padding: 0.65rem 0.9rem;
  background: rgba(255,255,255,0.05); border: 1px solid var(--border);
  border-radius: 0.5rem; color: #fff; font-size: 0.9rem;
  font-family: inherit; outline: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--accent); }
.form-group select option { background: #0f2030; }
.form-group textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.25rem; }
.btn-save {
  background: var(--accent); color: var(--dark);
  border: none; padding: 0.65rem 1.5rem; border-radius: 0.5rem;
  font-size: 0.88rem; font-weight: 700; cursor: pointer;
}
.btn-cancel {
  background: rgba(255,255,255,0.06); color: var(--muted);
  border: none; padding: 0.65rem 1.25rem; border-radius: 0.5rem;
  font-size: 0.88rem; cursor: pointer;
}
.btn-delete {
  background: rgba(239,68,68,0.1); color: var(--red);
  border: 1px solid rgba(239,68,68,0.3); padding: 0.65rem 1.25rem; border-radius: 0.5rem;
  font-size: 0.88rem; cursor: pointer; margin-right: auto;
}

/* ── STAGE SELECTOR ─────────────────────────────────────── */
.stage-pills { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }
.stage-pill {
  padding: 0.3rem 0.75rem; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700; cursor: pointer;
  background: rgba(255,255,255,0.06); color: var(--muted); border: none;
  transition: background 0.15s;
}
.stage-pill.selected { background: var(--accent); color: var(--dark); }

/* ── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 640px) {
  .sidebar { width: 60px; }
  .sidebar-name, .nav-item span:last-child, .sidebar-footer { display: none; }
  .nav-item { justify-content: center; padding: 0.65rem; }
  .sidebar-logo { font-size: 1rem; }
  .main { padding: 1rem; }
}

/* ── v2: BILLING QUEUE ──────────────────────────────────── */
.view-note { color: var(--muted, #8b98a5); font-size: 0.83rem; margin: -0.5rem 0 1.25rem; }
.billing-queue { display: flex; flex-direction: column; gap: 0.75rem; }
.billing-card {
  display: flex; align-items: center; gap: 1.25rem;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px; padding: 1rem 1.25rem;
}
.billing-card.billing-error { border-color: rgba(239,68,68,0.4); }
.billing-card-main { flex: 1; min-width: 0; }
.billing-type { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent, #00A3C4); }
.billing-client { font-weight: 700; margin-top: 0.15rem; }
.billing-meta { font-size: 0.75rem; color: var(--muted, #8b98a5); margin-top: 0.15rem; }
.billing-errmsg { font-size: 0.75rem; color: #ef4444; margin-top: 0.35rem; }
.billing-amount { font-family: 'Montserrat', sans-serif; font-weight: 900; font-size: 1.15rem; white-space: nowrap; }
.billing-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }

/* ── v2: TASKS ──────────────────────────────────────────── */
.task-move {
  margin-top: 0.5rem; padding: 0.25rem 0.6rem; font-size: 0.7rem;
  border-radius: 6px; border: 1px solid rgba(255,255,255,0.15);
  background: transparent; color: var(--muted, #8b98a5); cursor: pointer;
}
.task-move:hover { background: rgba(255,255,255,0.08); color: #fff; }

/* ── v2: LEDGER ─────────────────────────────────────────── */
.ledger-controls { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.ledger-controls input[type="date"] {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12);
  color: inherit; border-radius: 8px; padding: 0.45rem 0.6rem; font-size: 0.85rem;
}
.ledger-controls span { color: var(--muted, #8b98a5); font-size: 0.8rem; }

/* ── v2: MISC ───────────────────────────────────────────── */
.row-click { cursor: pointer; }
.row-click:hover td { background: rgba(255,255,255,0.03); }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; cursor: pointer; }
.checkbox-label input { width: auto; }
.line-item-row { align-items: flex-end; }
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translate(-50%, 20px);
  background: #0D1B2A; color: #fff; border: 1px solid rgba(0,163,196,0.4);
  padding: 0.7rem 1.4rem; border-radius: 10px; font-size: 0.85rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5); opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s; z-index: 2000;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.tasks-kanban .kanban-col { min-width: 240px; }
#login-email { margin-bottom: 0.6rem; }
