/*
  E-Billing Platform — Design System
  Direction: "a well-kept ledger" — precise alignment, hairline rules doing
  the work of hierarchy instead of shadows/gradients, monospace numerals
  for financial data, restrained single accent reserved for actions/status.
  Entity-level branding (logo/accent_color) is separate from this app
  chrome by design — see views/entity/branding.php.
*/

:root {
  --ink: #16213E;
  --ink-soft: #2B3A5C;
  --paper: #F5F6F5;
  --surface: #FFFFFF;
  --line: #DADFE3;
  --line-strong: #B9C0C7;

  --text-primary: #16213E;
  --text-secondary: #5B6472;
  --text-muted: #8A93A0;

  --accent: #0F6B5C;
  --accent-soft: #E4F2EF;
  --accent-text: #0B4E43;

  --amber: #B7791F;
  --amber-soft: #FBF0DD;
  --red: #B3261E;
  --red-soft: #FBEAE9;
  --green: #2E7D32;
  --green-soft: #E8F3E9;

  --radius: 4px;
  --font-sans: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

html {
  overflow-x: hidden;
  width: 100%;
}
body {
  font-family: var(--font-sans);
  background: var(--paper);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.005em;
  overflow-x: hidden;
  width: 100%;
  margin: 0;
}

h1, h2, h3, h4, h5 {
  font-family: var(--font-sans);
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  color: var(--accent-text);
  text-decoration: underline;
}

/* ---------- App shell: fixed left sidebar ---------- */

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

.app-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--ink);
  color: #C9D2E0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  overflow-y: auto;
}

.app-sidebar .brand {
  padding: 20px 20px 16px;
  font-weight: 600;
  font-size: 16px;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.app-sidebar .brand small {
  display: block;
  font-weight: 400;
  font-size: 11px;
  color: #8291AC;
  margin-top: 2px;
}

.app-nav {
  padding: 12px 0;
  flex: 1;
}

.app-nav-section-label {
  font-size: 11px;
  color: #6E7C99;
  padding: 16px 20px 6px;
}

.app-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: #C9D2E0;
  font-size: 14px;
  border-left: 3px solid transparent;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.app-nav a svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.75;
  transition: opacity 0.15s ease;
}

.app-nav a:hover svg,
.app-nav a.active svg {
  opacity: 1;
}

.app-nav a:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
  text-decoration: none;
}

.app-nav a.active {
  background: rgba(15,107,92,0.25);
  border-left-color: var(--accent);
  color: #fff;
}

.app-sidebar .user-block {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 13px;
}

.app-sidebar .user-block .role-badge {
  display: inline-block;
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 3px;
  background: rgba(255,255,255,0.1);
  color: #C9D2E0;
  margin-top: 4px;
}

.app-content {
  margin-left: 240px;
  flex: 1;
  padding: 32px 40px;
  max-width: 1600px;
  animation: content-fade-in 0.2s ease;
}
@keyframes content-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* On very wide monitors, cap total line length for readability without
   leaving as much dead space as the old 1280px cap did on typical large
   screens (1440px–1920px wide). */
@media (min-width: 1900px) {
  .app-content { max-width: 1800px; }
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: none;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.stat-card {
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.stat-card:hover {
  box-shadow: 0 4px 14px rgba(22, 33, 62, 0.08);
  transform: translateY(-1px);
}

/* Rows with onclick navigation (invoice lists, report tables) — a
   quiet hover cue that they're clickable, beyond the cursor:pointer
   already set inline. */
.table tbody tr[onclick] {
  transition: background-color 0.1s ease;
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 12px 16px;
}

/* Metric / stat card */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  height: 100%;
  min-height: 92px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.stat-card .stat-value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
  color: var(--ink);
}
.stat-card .text-secondary.small {
  /* subtitle line under stat-value (e.g. "8 invoices") — margin-top only
     applies when present, so cards without one don't get extra height
     from an invisible gap the way a fixed min-height on the value alone
     would cause. */
  margin-top: 2px;
}

/* ---------- Tables (the ledger) ---------- */

.table {
  margin-bottom: 0;
}
.table thead th {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--line-strong) !important;
  border-top: none !important;
  padding: 10px 16px;
  background: transparent;
}
.table tbody td {
  padding: 11px 16px;
  border-top: 1px solid var(--line);
  vertical-align: middle;
  color: var(--text-primary);
}
.table tbody tr:hover {
  background: #FAFBFA;
}
.table .num,
.table td.text-end {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ---------- Buttons ---------- */

.btn {
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  box-shadow: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}
.btn:active {
  transform: translateY(1px);
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-text);
  border-color: var(--accent-text);
  box-shadow: 0 2px 8px rgba(15, 107, 92, 0.25);
}
.btn-outline-primary {
  color: var(--accent);
  border-color: var(--accent);
}
.btn-outline-primary:hover {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-color: var(--accent);
}
.btn-outline-secondary {
  color: var(--text-secondary);
  border-color: var(--line-strong);
}

/* ---------- Status badges ---------- */

.badge {
  font-weight: 500;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 3px;
}
.status-draft { background: #EEEFEC; color: var(--text-secondary); }
.status-pending_approval,
.status-sent { background: var(--amber-soft); color: var(--amber); }
.status-approved,
.status-partially_paid { background: var(--accent-soft); color: var(--accent-text); }
.status-paid { background: var(--green-soft); color: var(--green); }
.status-overdue,
.status-cancelled { background: var(--red-soft); color: var(--red); }

/* ---------- Forms ---------- */

.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 4px;
}
.form-control, .form-select {
  border-color: var(--line-strong);
  border-radius: var(--radius);
  font-size: 14px;
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-text {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Login screen ---------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  background-image:
    radial-gradient(rgba(255,255,255,0.06) 1px, transparent 1px),
    linear-gradient(180deg, var(--ink) 0%, #1C2B4D 100%);
  background-size: 22px 22px, 100% 100%;
}
.login-card {
  background: var(--surface);
  border-radius: 6px;
  width: 380px;
  padding: 32px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  animation: login-card-in 0.35s ease;
}
@keyframes login-card-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.login-card .brand-mark {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 4px;
}

/* ---------- Mobile nav (hamburger + off-canvas sidebar) ---------- */

.mobile-topbar {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 768px) {
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    left: 0;
    width: 100%;
    box-sizing: border-box;
    z-index: 1040;
    background: var(--ink);
    color: #fff;
    padding: 12px 16px;
  }
  .mobile-topbar .brand-mini {
    font-weight: 600;
    font-size: 15px;
  }
  .hamburger-btn {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 22px;
    line-height: 1;
    padding: 4px 8px;
    cursor: pointer;
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: -260px;
    width: 240px;
    z-index: 1060;
    transition: left 0.25s ease;
  }
  .app-sidebar.is-open {
    left: 0;
  }

  .sidebar-backdrop.is-open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1050;
  }

  .app-content {
    margin-left: 0;
    padding: 20px;
    max-width: 100%;
  }

  /* Page headers, action-button rows, and other .d-flex containers
     across the app (e.g. "+ New Invoice / Manage Entities / Manage
     Users") don't wrap by default, which — combined with overflow-x:
     hidden on body — was causing them to get silently clipped rather
     than scroll on narrow screens. Wrapping is the right fix: nothing
     should need horizontal scroll just to see a row of buttons. */
  .d-flex {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  /* Stat-card grids and report filter rows already stack via Bootstrap's
     col-md-* becoming full-width below 768px — no extra rule needed. */
}