/* ══════════════════════════════════════════════════════════════
   LexBooks portal — global styles
   ══════════════════════════════════════════════════════════════ */
:root {
  --bg:           #0b0d14;
  --bg-2:         #0f1117;
  --surface:      #151925;
  --surface-2:    #1c2132;
  --surface-3:    #242a3e;
  --border:       #262c41;
  --border-light: #343c58;
  --accent:       #3d7fff;
  --accent-2:     #13B5EA;
  --accent-hover: #5a94ff;
  --accent-glow:  rgba(61,127,255,0.18);
  --danger:       #ef5a5a;
  --success:      #3ecf8e;
  --warning:      #f5a623;
  --text:         #e8eaf2;
  --text-2:       #9aa2bb;
  --text-muted:   #5a6485;
  --radius:       10px;
  --radius-lg:    14px;
  --sidebar-w:    248px;
  --topbar-h:     60px;
  --shadow-lg:    0 20px 60px rgba(0,0,0,0.45);
}

* , *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px; line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(1200px 600px at 100% -10%, rgba(61,127,255,0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(19,181,234,0.06), transparent 60%);
  background-attachment: fixed;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ── SIDEBAR ────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #10131c 0%, #0c0f17 100%);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 100; transition: transform 0.28s ease;
}
.brand { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand-link { display: flex; align-items: center; gap: 12px; }
.brand-logo { flex-shrink: 0; filter: drop-shadow(0 4px 12px rgba(61,127,255,0.35)); }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-size: 17px; font-weight: 800; letter-spacing: -0.02em; background: linear-gradient(135deg,#fff 20%,#a8c4ff 100%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-sub { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.12em; font-family: 'IBM Plex Mono', monospace; margin-top: 2px; }
.sidebar-close { display: none; background: transparent; border: none; color: var(--text-2); font-size: 28px; cursor: pointer; line-height: 1; }

.nav { flex: 1; padding: 14px 12px; overflow-y: auto; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; margin-bottom: 2px; border-radius: 8px;
  color: var(--text-2); font-size: 13.5px; font-weight: 500;
  transition: background 0.15s, color 0.15s;
  position: relative;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active {
  background: linear-gradient(135deg, rgba(61,127,255,0.18), rgba(19,181,234,0.08));
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(61,127,255,0.35);
}
.nav-link.active::before {
  content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-radius: 0 3px 3px 0;
}
.nav-link svg { opacity: 0.85; flex-shrink: 0; }
.nav-section {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--text-muted); font-family: 'IBM Plex Mono', monospace;
  padding: 16px 14px 8px; font-weight: 600;
}

.sidebar-foot { padding: 14px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; font-size: 15px; flex-shrink: 0; }
.user-meta { min-width: 0; flex: 1; }
.user-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em; font-family: 'IBM Plex Mono', monospace; }

.sidebar-scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 90; opacity: 0; transition: opacity 0.25s; }

/* ── TOPBAR ─────────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: var(--sidebar-w); right: 0; height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px; padding: 0 28px;
  background: rgba(15,17,23,0.72); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  z-index: 50;
}
.hamburger { display: none; background: transparent; border: 1px solid var(--border); color: var(--text); width: 38px; height: 38px; border-radius: 8px; cursor: pointer; align-items: center; justify-content: center; }
.topbar-title { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.topbar-meta { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.topbar-user { font-size: 12px; color: var(--text-2); font-family: 'IBM Plex Mono', monospace; }

/* ── MAIN ───────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  padding: calc(var(--topbar-h) + 28px) 32px 80px;
  max-width: 100%;
}
.container { max-width: 1280px; margin: 0 auto; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 26px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; }
.page-head p { color: var(--text-2); margin-top: 4px; font-size: 13.5px; }
.page-head .head-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ── CARDS ──────────────────────────────────────────────────── */
.card {
  background: linear-gradient(180deg, var(--surface) 0%, #131825 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 22px rgba(0,0,0,0.28);
  overflow: hidden;
  margin-bottom: 20px;
}
.card-header {
  padding: 16px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.card-header h2 {
  font-size: 13px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-2);
}
.card-header .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.card-header .dot.blue { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.card-header .dot.green { background: var(--success); box-shadow: 0 0 10px var(--success); }
.card-header .dot.orange { background: var(--warning); box-shadow: 0 0 10px var(--warning); }
.card-header .dot.red { background: var(--danger); box-shadow: 0 0 10px var(--danger); }
.card-body { padding: 22px; }

/* ── KPI GRID ───────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 22px; }
.kpi-card {
  position: relative;
  background: linear-gradient(180deg, var(--surface) 0%, #131825 100%);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px 22px;
  transition: border-color 0.2s, transform 0.2s;
  overflow: hidden;
}
.kpi-card::after {
  content: ''; position: absolute; inset: 0; background: radial-gradient(400px 100px at 100% 0%, rgba(61,127,255,0.08), transparent 60%); pointer-events: none;
}
.kpi-card:hover { border-color: var(--border-light); transform: translateY(-1px); }
.kpi-label { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted); font-family: 'IBM Plex Mono', monospace; margin-bottom: 10px; }
.kpi-value { font-size: 28px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; font-family: 'IBM Plex Mono', monospace; }
.kpi-value.danger { color: var(--danger); }
.kpi-value.success { color: var(--success); }
.kpi-value.warning { color: var(--warning); }
.kpi-value.accent { background: linear-gradient(135deg, var(--accent-hover), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ── TABLES ─────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; font-size: 10px; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace; font-weight: 600;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.01);
}
.data-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); color: var(--text-2); font-size: 13px; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface-2); color: var(--text); }
.data-table .amount { font-family: 'IBM Plex Mono', monospace; text-align: right; }
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--accent); }
.sort-arrow { font-size: 9px; margin-left: 3px; }

/* ── STATUS PILLS ───────────────────────────────────────────── */
.status-pill { display: inline-block; padding: 3px 10px; border-radius: 100px; font-size: 10px; font-weight: 700; font-family: 'IBM Plex Mono', monospace; letter-spacing: 0.06em; text-transform: uppercase; }
.status-pill.authorised { background: rgba(62,207,142,0.12); color: var(--success); border: 1px solid rgba(62,207,142,0.3); }
.status-pill.paid { background: rgba(61,127,255,0.12); color: var(--accent); border: 1px solid rgba(61,127,255,0.3); }
.status-pill.draft { background: rgba(154,162,187,0.12); color: var(--text-2); border: 1px solid rgba(154,162,187,0.3); }
.status-pill.voided { background: rgba(239,90,90,0.12); color: var(--danger); border: 1px solid rgba(239,90,90,0.3); }
.status-pill.overdue { background: rgba(245,166,35,0.12); color: var(--warning); border: 1px solid rgba(245,166,35,0.3); }
.status-pill.active { background: rgba(62,207,142,0.12); color: var(--success); border: 1px solid rgba(62,207,142,0.3); }
.status-pill.inactive, .status-pill.disabled { background: rgba(154,162,187,0.12); color: var(--text-2); border: 1px solid rgba(154,162,187,0.3); }
.status-pill.admin { background: rgba(19,181,234,0.12); color: var(--accent-2); border: 1px solid rgba(19,181,234,0.3); }
.status-pill.user { background: rgba(61,127,255,0.12); color: var(--accent); border: 1px solid rgba(61,127,255,0.3); }

/* ── BUTTONS ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border-light);
  color: var(--text); padding: 9px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all 0.15s; text-decoration: none;
}
.btn:hover { border-color: var(--accent); color: var(--accent-hover); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #fff; font-weight: 600;
  box-shadow: 0 6px 22px rgba(61,127,255,0.35);
}
.btn-primary:hover { color: #fff; transform: translateY(-1px); box-shadow: 0 10px 30px rgba(61,127,255,0.5); }
.btn-danger { color: var(--danger); border-color: rgba(239,90,90,0.35); }
.btn-danger:hover { background: rgba(239,90,90,0.12); color: var(--danger); border-color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ── FORMS ──────────────────────────────────────────────────── */
.field { display: block; margin-bottom: 16px; }
.field label { display: block; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); font-family: 'IBM Plex Mono', monospace; margin-bottom: 8px; font-weight: 600; }
.input, .select, textarea.input {
  width: 100%;
  background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text); font-family: inherit; font-size: 14px;
  padding: 11px 14px; border-radius: 9px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, textarea.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61,127,255,0.18);
}
.input::placeholder { color: var(--text-muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

.alert { padding: 12px 16px; border-radius: 10px; font-size: 13px; margin-bottom: 16px; border: 1px solid; }
.alert-success { background: rgba(62,207,142,0.1); border-color: rgba(62,207,142,0.35); color: var(--success); }
.alert-danger  { background: rgba(239,90,90,0.1); border-color: rgba(239,90,90,0.35); color: var(--danger); }
.alert-info    { background: rgba(61,127,255,0.1); border-color: rgba(61,127,255,0.35); color: var(--accent-hover); }
.alert-warning { background: rgba(245,166,35,0.1); border-color: rgba(245,166,35,0.35); color: var(--warning); }

/* ── GRID 2 ─────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 960px) { .grid-2 { grid-template-columns: 1fr; } }

.org-info { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.org-info .info-item label { display: block; font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); font-family: 'IBM Plex Mono', monospace; margin-bottom: 4px; }
.org-info .info-item .value { font-size: 14px; font-weight: 500; }

.pnl-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); }
.pnl-row:last-child { border-bottom: none; }
.pnl-row.header { color: var(--text-muted); font-size: 10px; text-transform: uppercase; font-family: 'IBM Plex Mono', monospace; letter-spacing: 0.1em; }
.pnl-row.total { font-weight: 700; border-top: 2px solid var(--border-light); padding-top: 12px; margin-top: 4px; }

/* ── AP AGING / VENDORS / PAGINATION ────────────────────────── */
.ap-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 20px; }
.ap-filter-group { display: flex; gap: 4px; flex-wrap: wrap; }
.ap-filter-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-2);
  font-family: 'IBM Plex Mono', monospace; font-size: 11px; font-weight: 500;
  padding: 7px 14px; border-radius: 8px; cursor: pointer; transition: all 0.15s;
}
.ap-filter-btn:hover { border-color: var(--border-light); color: var(--text); }
.ap-filter-btn.active { background: var(--accent-glow); border-color: var(--accent); color: var(--accent-hover); }
.ap-search {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  font-family: 'IBM Plex Mono', monospace; font-size: 12px; padding: 8px 14px;
  border-radius: 8px; width: 240px; outline: none;
}
.ap-search:focus { border-color: var(--accent); }
.ap-search::placeholder { color: var(--text-muted); }

.aging-bar-container { margin-bottom: 16px; }
.aging-bar { display: flex; height: 34px; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.aging-bar .segment { display: flex; align-items: center; justify-content: center; font-family: 'IBM Plex Mono', monospace; font-size: 10px; font-weight: 700; color: #fff; min-width: 2px; transition: width 0.5s ease; }
.aging-bar .segment.current { background: var(--success); }
.aging-bar .segment.d1-30 { background: var(--warning); }
.aging-bar .segment.d31-60 { background: #e08a3e; }
.aging-bar .segment.d61-90 { background: var(--danger); }
.aging-bar .segment.d90plus { background: #8b2252; }
.aging-legend { display: flex; gap: 18px; margin-top: 10px; flex-wrap: wrap; }
.aging-legend-item { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-2); font-family: 'IBM Plex Mono', monospace; }
.aging-legend-item .dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

.vendor-bar-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.vendor-bar-row:last-child { border-bottom: none; }
.vendor-name { width: 180px; flex-shrink: 0; font-size: 12.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vendor-bar-track { flex: 1; height: 20px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.vendor-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 4px; transition: width 0.5s ease; min-width: 2px; }
.vendor-amount { width: 110px; text-align: right; font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--text); flex-shrink: 0; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 18px; }
.page-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text-2); font-family: 'IBM Plex Mono', monospace; font-size: 11px; padding: 7px 14px; border-radius: 8px; cursor: pointer; transition: all 0.15s; }
.page-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.page-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.page-info { font-size: 11px; color: var(--text-muted); font-family: 'IBM Plex Mono', monospace; }

/* ── LOADING / SPINNER ──────────────────────────────────────── */
.loading { text-align: center; padding: 80px 20px; color: var(--text-muted); }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

.badge-connected {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(62,207,142,0.12); border: 1px solid rgba(62,207,142,0.3); color: var(--success);
  font-family: 'IBM Plex Mono', monospace; font-size: 10px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase; padding: 5px 11px; border-radius: 100px;
}
.badge-disconnected {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(245,166,35,0.12); border: 1px solid rgba(245,166,35,0.3); color: var(--warning);
  font-family: 'IBM Plex Mono', monospace; font-size: 10px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase; padding: 5px 11px; border-radius: 100px;
}

.last-updated { font-size: 11px; color: var(--text-muted); font-family: 'IBM Plex Mono', monospace; }

/* ══════════════════════════════════════════════════════════════
   AUTH PAGES (login / reset)
   ══════════════════════════════════════════════════════════════ */
.auth-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 40px 20px;
  background:
    radial-gradient(900px 500px at 30% 20%, rgba(61,127,255,0.15), transparent 60%),
    radial-gradient(700px 400px at 80% 80%, rgba(19,181,234,0.12), transparent 60%),
    var(--bg);
  position: relative; overflow: hidden;
}
.auth-wrap::before {
  content: ''; position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(61,127,255,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(61,127,255,0.06) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: radial-gradient(circle at center, black 30%, transparent 75%);
  -webkit-mask-image: radial-gradient(circle at center, black 30%, transparent 75%);
  pointer-events: none;
}
.auth-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 440px;
  background: linear-gradient(180deg, rgba(24,28,38,0.88) 0%, rgba(15,17,23,0.92) 100%);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
}
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.auth-brand .brand-logo { filter: drop-shadow(0 6px 24px rgba(61,127,255,0.5)); }
.auth-brand .brand-name { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; background: linear-gradient(135deg,#fff 20%,#a8c4ff 100%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-brand .brand-sub { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.14em; font-family: 'IBM Plex Mono', monospace; display:block; margin-top:2px; }
.auth-card h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 6px; }
.auth-card .sub { color: var(--text-2); font-size: 13.5px; margin-bottom: 24px; }
.auth-card .btn-primary { width: 100%; justify-content: center; padding: 12px 20px; font-size: 14px; }
.auth-foot { text-align: center; margin-top: 20px; font-size: 13px; color: var(--text-2); }
.auth-foot a { color: var(--accent-hover); }
.auth-foot a:hover { color: #fff; }

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim.open { display: block; opacity: 1; }
  .sidebar-close { display: block; }
  .topbar { left: 0; padding: 0 18px; }
  .hamburger { display: inline-flex; }
  .main { margin-left: 0; padding: calc(var(--topbar-h) + 20px) 18px 60px; }
  .page-head h1 { font-size: 22px; }
  .kpi-value { font-size: 24px; }
  .topbar-user { display: none; }
  .data-table th, .data-table td { padding: 10px 12px; }
  .ap-search { width: 100%; }
}
@media (max-width: 560px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .kpi-card { padding: 16px; }
  .kpi-value { font-size: 20px; }
  .auth-card { padding: 32px 22px; border-radius: 14px; }
  .main { padding: calc(var(--topbar-h) + 16px) 14px 60px; }
  .card-body { padding: 16px; }
}
