:root {
  --brand: #4B4BE5;
  --brand-dark: #3838b0;
  --accent: #99EA48;
  --sidebar-bg: #0f172a;
  --sidebar-fg: #cbd5e1;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: #1e293b; }

.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 240px; background: var(--sidebar-bg); color: var(--sidebar-fg);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
/* Scoped to .sidebar: the dashboard's highlighted stat card also uses .brand. */
.sidebar .brand {
  display: flex; align-items: center; padding: 1.4rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-logo { width: 178px; max-width: 100%; height: auto; }
.sidebar .nav { padding: .75rem; gap: .15rem; }
.sidebar .nav-link {
  color: var(--sidebar-fg); border-radius: 8px; padding: .6rem .8rem;
  display: flex; align-items: center; gap: .65rem; font-size: .95rem;
}
.sidebar .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar .nav-link.active { background: var(--brand); color: #fff; }
.sidebar-footer { margin-top: auto; padding: .75rem; border-top: 1px solid rgba(255,255,255,.08); }
.signed-in { display: flex; align-items: center; gap: .5rem; padding: .35rem .8rem .5rem; color: #e2e8f0; font-weight: 600; font-size: .9rem; }
.signed-in i { color: var(--brand); font-size: 1.1rem; }
.sidebar-account-links .nav-link { color: var(--sidebar-fg); border-radius: 8px; padding: .5rem .8rem; display: flex; align-items: center; gap: .65rem; font-size: .9rem; }
.sidebar-account-links .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-account-links .nav-link.active { background: var(--brand); color: #fff; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--sidebar-bg); padding: 1rem; }
.login-card { background: #fff; border-radius: 14px; padding: 2rem; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login-brand { display: flex; justify-content: center; margin-bottom: .35rem; }
.login-logo { width: 210px; max-width: 100%; height: auto; }
.login-subtitle { text-align: center; color: #64748b; font-size: .85rem; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 1.5rem; }

/* Content */
.content { flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.75rem; background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.page-title { font-size: 1.4rem; margin: 0; font-weight: 700; }
.page-body { padding: 1.75rem; }

/* Cards / stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; }
.stat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1.1rem 1.25rem;
}
.stat-card .label { font-size: .82rem; color: #64748b; text-transform: uppercase; letter-spacing: .03em; }
.stat-card .value { font-size: 1.7rem; font-weight: 700; margin-top: .25rem; }
.stat-card.brand { background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: #fff; border: none; }
.stat-card.brand .label { color: rgba(255,255,255,.8); }

.card { border: 1px solid var(--border); border-radius: 12px; }
.card-header { background: #fff; font-weight: 600; border-bottom: 1px solid var(--border); }

.section-title { font-size: 1.05rem; font-weight: 700; margin: 1.5rem 0 .75rem; }

table.table { background: var(--card); }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: #64748b; }

.badge-soft { padding: .35em .6em; border-radius: 6px; font-weight: 600; font-size: .75rem; }
.prio-high { background: #fee2e2; color: #b91c1c; }
.prio-medium { background: #fef3c7; color: #b45309; }
.prio-low { background: #dcfce7; color: #15803d; }
.st-complete, .st-completed, .st-done { background: #dcfce7; color: #15803d; }
.st-partial, .st-in_progress { background: #fef3c7; color: #b45309; }
.st-unpaid, .st-pending, .st-todo { background: #e2e8f0; color: #475569; }
.st-active { background: #dbeafe; color: #1d4ed8; }

.workflow-step {
  display: flex; align-items: center; gap: .75rem; padding: .6rem .85rem;
  border: 1px solid var(--border); border-radius: 8px; margin-bottom: .5rem; background: #fff;
}
.workflow-step.completed { background: #f0fdf4; border-color: #bbf7d0; }
.step-num {
  width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 700; flex-shrink: 0;
}
.workflow-step.completed .step-num { background: #16a34a; }

.overdue { color: #b91c1c; font-weight: 600; }
.empty { color: #94a3b8; padding: 1.5rem; text-align: center; }
.text-muted-sm { font-size: .82rem; color: #64748b; }

/* Brand-aligned buttons (match logo indigo) */
.btn-primary { background-color: var(--brand); border-color: var(--brand); }
.btn-primary:hover, .btn-primary:focus, .btn-primary:active,
.btn-primary:not(:disabled):active { background-color: var(--brand-dark); border-color: var(--brand-dark); }
.btn-outline-primary { color: var(--brand); border-color: var(--brand); }
.btn-outline-primary:hover, .btn-outline-primary:active { background-color: var(--brand); border-color: var(--brand); color: #fff; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(75,75,229,.18); }
a { color: var(--brand); }
.list-group-item a { color: var(--brand); }

/* ---------- Mobile / PWA ---------- */
.menu-toggle { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  .menu-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    padding: .35rem .6rem; font-size: 1.25rem; line-height: 1;
  }
  .topbar { padding: .75rem 1rem; gap: .6rem; }
  .page-title { font-size: 1.15rem; }
  .page-body { padding: 1rem; }
  .topbar-actions { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
  .topbar-actions .btn { padding: .25rem .5rem; font-size: .8rem; }

  /* Off-canvas sidebar */
  .sidebar {
    position: fixed; top: 0; left: -270px; width: 250px;
    transition: left .25s ease; z-index: 1050;
  }
  .layout.nav-open .sidebar { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .layout.nav-open .sidebar-backdrop {
    display: block; position: fixed; inset: 0;
    background: rgba(0,0,0,.45); z-index: 1040;
  }

  /* Wide tables scroll inside their card instead of breaking the page */
  .card { overflow-x: auto; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .6rem; }
  .stat-card { padding: .8rem .9rem; }
  .stat-card .value { font-size: 1.25rem; }
}

/* Safe-area padding for phones with notches (standalone PWA mode) */
@supports (padding: env(safe-area-inset-top)) {
  @media (max-width: 900px) {
    .topbar { padding-top: calc(.75rem + env(safe-area-inset-top)); }
    .sidebar { padding-top: env(safe-area-inset-top); }
  }
}
