:root {
  --brand: #0f766e;
  --brand-dark: #115e59;
  --brand-light: #ccfbf1;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f8fafc;
}

body { background: var(--bg); color: var(--ink); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }

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

/* Sidebar */
.sidebar {
  width: 250px; background: #0b3b39; color: #d1fae5; flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1.25rem;
  font-weight: 700; font-size: 1.05rem; color: #fff; border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand i { font-size: 1.4rem; color: #5eead4; }
.sidebar-nav { padding: .75rem .5rem; overflow-y: auto; }
.sidebar-nav a {
  display: flex; align-items: center; gap: .7rem; padding: .6rem .85rem;
  color: #b8e6dd; text-decoration: none; border-radius: 8px; font-size: .92rem; margin-bottom: 2px;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar-nav a.active { background: var(--brand); color: #fff; font-weight: 600; }
.sidebar-nav a i { font-size: 1.05rem; width: 20px; text-align: center; }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1.5rem; background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.topbar-title { font-weight: 600; font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-toggle { display: none; background: none; border: 0; color: var(--ink); font-size: 1.5rem; line-height: 1; padding: .1rem .35rem; cursor: pointer; }
.nav-backdrop { display: none; }
.topbar-user > a { color: var(--ink); text-decoration: none; font-size: .9rem; }
.role-badge {
  background: var(--brand-light); color: var(--brand-dark); font-size: .72rem;
  padding: .1rem .5rem; border-radius: 20px; margin-left: .35rem;
}
.content { padding: 1.5rem; flex: 1; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 1.1rem 1.25rem; }
.stat-card .label { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
.stat-card .value { font-size: 1.6rem; font-weight: 700; margin-top: .25rem; }
.stat-card .sub { font-size: .8rem; color: var(--muted); margin-top: .15rem; }
.stat-card.brand { border-left: 4px solid var(--brand); }
.stat-card.warn { border-left: 4px solid #f59e0b; }
.stat-card.danger { border-left: 4px solid #ef4444; }
.stat-card.good { border-left: 4px solid #10b981; }

/* Cards & tables */
.card { border: 1px solid var(--line); border-radius: 12px; }
.card-header { background: #fff; border-bottom: 1px solid var(--line); font-weight: 600; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; flex-wrap: wrap; gap: .75rem; }
.page-head h1 { font-size: 1.4rem; font-weight: 700; margin: 0; }
.table > :not(caption) > * > * { padding: .6rem .75rem; }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.text-mono { font-variant-numeric: tabular-nums; }
.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-brand:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
a { color: var(--brand-dark); }

.badge-status { font-size: .72rem; padding: .3rem .6rem; border-radius: 20px; font-weight: 600; }
.s-active, .s-paid, .s-closed, .s-disbursed, .s-sent { background: #dcfce7; color: #166534; }
.s-inactive, .s-pending, .s-partial, .s-approved, .s-queued { background: #fef9c3; color: #854d0e; }
.s-terminated, .s-cancelled, .s-rejected, .s-overdue, .s-failed { background: #fee2e2; color: #991b1b; }

/* Auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #0b3b39, #0f766e); padding: 1rem; }
.auth-card { background: #fff; border-radius: 16px; padding: 2.25rem; width: 100%; max-width: 400px; box-shadow: 0 20px 40px rgba(0,0,0,.2); }
.auth-card h1 { font-size: 1.3rem; font-weight: 700; text-align: center; }
.auth-brand { text-align: center; font-size: 2.2rem; color: var(--brand); margin-bottom: .5rem; }

@media (max-width: 820px) {
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 100;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 2px 0 16px rgba(0, 0, 0, .25);
  }
  .app-shell.nav-open .sidebar { transform: translateX(0); }
  .app-shell.nav-open .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 90; background: rgba(0, 0, 0, .45);
  }
  .nav-toggle { display: inline-flex; align-items: center; }
  .topbar { padding: .7rem 1rem; }
  .topbar-title { font-size: 1.05rem; }
  .content { padding: 1rem; }
  .topbar-user .role-badge { display: none; }
}

@media (max-width: 420px) {
  .content { padding: .85rem .75rem; }
  .page-head h1 { font-size: 1.2rem; }
  .stat-card .value { font-size: 1.4rem; }
  /* Keep only the account icon in the top bar on very small screens */
  .topbar-user > a { font-size: 0; }
  .topbar-user > a .bi { font-size: 1.4rem; }
}
