/* ════════════════════════════════════════════════════════
   CapeFA Optimize — Shared Stylesheet
   All design tokens and component styles for every page.
   Per-page tweaks should live in <style> blocks inside the page.
════════════════════════════════════════════════════════ */

/* ─── DESIGN TOKENS ─── */
:root {
  --primary:        #0f2942;
  --primary-light:  #1a3a5c;
  --accent:         #00c6a7;
  --accent-hover:   #00a88d;
  --accent-glow:    rgba(0,198,167,.15);
  --bg:             #fafbfc;
  --bg-alt:         #f6f8fb;
  --white:          #ffffff;
  --border:         #e2e8f0;
  --border-alt:     #e6edf6;
  --text:           #2d3748;
  --text-dark:      #1f2937;
  --text-light:     #64748b;
  --muted:          #6b7280;
  --success:        #10b981;
  --success-bg:     #ecfdf5;
  --warning:        #f59e0b;
  --warning-bg:     #fffbeb;
  --error:          #ef4444;
  --error-bg:       #fef2f2;
  --info:           #3b82f6;
  --info-bg:        #eff6ff;
  --purple:         #8b5cf6;
  --purple-bg:      #f5f3ff;
  --rose:           #f43f5e;
  --rose-bg:        #fff1f2;
  --shadow-sm:      0 4px 18px rgba(15,41,66,.06);
  --shadow:         0 10px 30px rgba(15,41,66,.10);
  --shadow-lg:      0 12px 48px rgba(15,41,66,.12);
  --shadow-xl:      0 18px 55px rgba(15,41,66,.16);
  --radius-sm:      8px;
  --radius:         12px;
  --radius-lg:      16px;
  --radius-xl:      20px;
  --radius-pill:    999px;
  --ease:           all .3s cubic-bezier(.4,0,.2,1);
  --font-sans:      "DM Sans", system-ui, -apple-system, sans-serif;
  --font-serif:     "Fraunces", serif;
  --font-mono:      ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { margin:0; padding:0; box-sizing:border-box; }
html { scroll-behavior:smooth; }
body { font-family:var(--font-sans); color:var(--text); background:var(--bg-alt); display:flex; min-height:100vh; }

/* ─── SIDEBAR ─── */
.sidebar {
  width:260px; background:var(--primary); color:#fff;
  display:flex; flex-direction:column; position:fixed;
  top:0; left:0; bottom:0; z-index:100;
  transition: var(--ease);
}
.sidebar-brand {
  padding:24px 20px 20px; border-bottom:1px solid rgba(255,255,255,.1);
  display:flex; align-items:center; gap:12px;
  font-family:var(--font-serif); font-weight:700; font-size:1.1rem;
}
.sidebar-brand-icon {
  width:36px; height:36px; border-radius:10px;
  background:linear-gradient(135deg,var(--accent),#00e6c3);
  display:grid; place-items:center;
  box-shadow:0 6px 18px rgba(0,198,167,.25);
}
.sidebar-brand-icon svg { width:20px; height:20px; color:#fff; }
.sidebar-brand-sub {
  display:block; font-family:var(--font-sans); font-size:.7rem;
  font-weight:500; opacity:.55; letter-spacing:.5px; margin-top:1px;
}
.sidebar-section-title {
  font-size:.7rem; text-transform:uppercase; letter-spacing:1.5px;
  padding:20px 20px 8px; opacity:.45; font-weight:700;
}
.sidebar-link {
  display:flex; align-items:center; gap:12px;
  padding:11px 20px; font-size:.9rem; font-weight:500;
  color:rgba(255,255,255,.6); cursor:pointer; transition:var(--ease);
  border:none; background:none; width:100%; text-align:left;
  text-decoration:none;
}
.sidebar-link:hover { color:#fff; background:rgba(255,255,255,.08); }
.sidebar-link.active {
  color:#fff; background:rgba(0,198,167,.15);
  border-right:3px solid var(--accent);
}
.sidebar-link svg { width:20px; height:20px; flex-shrink:0; }
.sidebar-footer {
  margin-top:auto; padding:16px 20px; border-top:1px solid rgba(255,255,255,.1);
  display:flex; align-items:center; gap:10px; font-size:.85rem;
}
.sidebar-avatar {
  width:34px; height:34px; border-radius:50%;
  background:linear-gradient(135deg,var(--accent),#00e6c3);
  display:grid; place-items:center; font-weight:700; font-size:.8rem;
}

/* ─── MAIN CONTENT ─── */
.main { margin-left:260px; flex:1; min-height:100vh; }
.topbar {
  background:rgba(255,255,255,.92); backdrop-filter:blur(12px);
  border-bottom:1px solid var(--border); padding:0 32px;
  height:64px; display:flex; align-items:center; justify-content:space-between;
  position:sticky; top:0; z-index:50;
}
.topbar-title {
  font-family:var(--font-serif); font-size:1.35rem; font-weight:700;
  color:var(--primary);
}
.topbar-actions { display:flex; gap:10px; align-items:center; }
.topbar-search {
  padding:10px 16px; border:2px solid var(--border); border-radius:var(--radius);
  font-family:var(--font-sans); font-size:.9rem; width:260px;
  transition:var(--ease); background:var(--bg);
}
.topbar-search:focus { outline:none; border-color:var(--accent); box-shadow:0 0 0 4px var(--accent-glow); }
.topbar-btn {
  width:40px; height:40px; border-radius:var(--radius-sm);
  border:1px solid var(--border); background:var(--white);
  display:grid; place-items:center; cursor:pointer; transition:var(--ease);
  position:relative;
}
.topbar-btn:hover { border-color:var(--accent); background:var(--accent-glow); }
.topbar-btn svg { width:20px; height:20px; color:var(--text-light); }
.topbar-badge {
  position:absolute; top:-4px; right:-4px;
  width:18px; height:18px; border-radius:50%;
  background:var(--error); color:#fff; font-size:.65rem;
  font-weight:700; display:grid; place-items:center;
}

.content { padding:28px 32px 60px; animation:fadeIn .4s ease; }

/* ─── STAT CARDS ─── */
.stat-grid { display:grid; grid-template-columns:repeat(4,1fr); gap:20px; margin-bottom:28px; }
.stat-card {
  background:var(--white); border:1px solid var(--border-alt);
  border-radius:var(--radius-lg); padding:24px; box-shadow:var(--shadow-sm);
  transition:var(--ease);
}
.stat-card:hover { box-shadow:var(--shadow); transform:translateY(-2px); }
.stat-card-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:12px; }
.stat-card-icon {
  width:44px; height:44px; border-radius:var(--radius);
  display:grid; place-items:center;
}
.stat-card-icon svg { width:22px; height:22px; }
.stat-card-value {
  font-family:var(--font-serif); font-size:2rem; font-weight:700;
  color:var(--primary); line-height:1;
}
.stat-card-label { font-size:.85rem; color:var(--muted); font-weight:600; margin-top:4px; }
.stat-card-trend { font-size:.8rem; font-weight:700; margin-top:8px; display:flex; align-items:center; gap:4px; }
.stat-card-trend.up { color:var(--success); }
.stat-card-trend.down { color:var(--error); }

/* ─── TABLES ─── */
.data-table {
  width:100%; border-collapse:collapse; font-size:.9rem;
  background:var(--white); border-radius:var(--radius-lg);
  overflow:hidden; border:1px solid var(--border-alt);
  box-shadow:var(--shadow-sm);
}
.data-table thead { background:var(--primary); color:var(--white); }
.data-table th { padding:14px 16px; text-align:left; font-weight:600; font-size:.85rem; }
.data-table td { padding:14px 16px; border-bottom:1px solid var(--border); }
.data-table tbody tr:last-child td { border-bottom:none; }
.data-table tbody tr:nth-child(even) { background:var(--bg); }
.data-table tbody tr:hover { background:var(--accent-glow); cursor:pointer; }

/* ─── PILLS ─── */
.pill {
  display:inline-flex; align-items:center; gap:6px;
  padding:4px 12px; border-radius:var(--radius-pill);
  font-size:.8rem; font-weight:700;
}
.pill .dot { width:7px; height:7px; border-radius:50%; }
.pill.success { background:var(--success-bg); color:#065f46; border:1px solid #a7f3d0; }
.pill.success .dot { background:var(--success); }
.pill.warning { background:var(--warning-bg); color:#92400e; border:1px solid #fde68a; }
.pill.warning .dot { background:var(--warning); }
.pill.error { background:var(--error-bg); color:#991b1b; border:1px solid #fecaca; }
.pill.error .dot { background:var(--error); }
.pill.info { background:var(--info-bg); color:#1e40af; border:1px solid #bfdbfe; }
.pill.info .dot { background:var(--info); }
.pill.purple { background:var(--purple-bg); color:#5b21b6; border:1px solid #c4b5fd; }
.pill.purple .dot { background:var(--purple); }

/* ─── BUTTONS ─── */
.btn {
  display:inline-flex; align-items:center; gap:8px;
  padding:12px 24px; border-radius:var(--radius-sm);
  font-family:var(--font-sans); font-weight:700; font-size:.95rem;
  border:none; cursor:pointer; transition:var(--ease); text-decoration:none;
}
.btn:hover { transform:translateY(-2px); }
.btn svg { width:18px; height:18px; }
.btn-primary { background:var(--primary); color:var(--white); }
.btn-primary:hover { background:var(--primary-light); box-shadow:var(--shadow-lg); }
.btn-accent { background:var(--accent); color:var(--white); }
.btn-accent:hover { background:var(--accent-hover); box-shadow:0 8px 24px var(--accent-glow); }
.btn-outline { background:transparent; color:var(--primary); border:2px solid var(--border); }
.btn-outline:hover { border-color:var(--primary); background:var(--bg); }
.btn-soft { background:rgba(0,198,167,.12); color:var(--primary); border:1px solid rgba(0,198,167,.18); }
.btn-soft:hover { background:rgba(0,198,167,.18); }
.btn-sm { padding:8px 16px; font-size:.85rem; }

/* ─── CARDS ─── */
.card {
  background:var(--white); border:1px solid var(--border-alt);
  border-radius:var(--radius-lg); box-shadow:var(--shadow-sm);
  overflow:hidden; transition:var(--ease);
}
.card:hover { box-shadow:var(--shadow); }
.card-header {
  padding:18px 24px; border-bottom:1px solid var(--border-alt);
  display:flex; align-items:center; justify-content:space-between;
  font-weight:700; color:var(--primary); font-size:1rem;
}
.card-header-icon { display:flex; align-items:center; gap:10px; }
.card-header-icon svg { width:20px; height:20px; color:var(--accent); }
.card-body { padding:24px; }

/* ─── SECTION HEADERS ─── */
.section-header {
  display:flex; align-items:center; justify-content:space-between;
  margin-bottom:20px;
}
.section-title {
  font-family:var(--font-serif); font-size:1.15rem; font-weight:700;
  color:var(--primary); display:flex; align-items:center; gap:10px;
}
.section-title svg { width:22px; height:22px; color:var(--accent); }

/* ─── UPLOAD ZONE ─── */
.upload-zone {
  border:3px dashed var(--border);
  border-radius:var(--radius-xl); padding:60px 40px;
  text-align:center; background:var(--white);
  transition:var(--ease); cursor:pointer;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color:var(--accent); background:var(--accent-glow);
}
.upload-zone-icon {
  width:80px; height:80px; border-radius:50%;
  background:linear-gradient(135deg,rgba(0,198,167,.15),rgba(0,198,167,.05));
  display:grid; place-items:center; margin:0 auto 20px;
}
.upload-zone-icon svg { width:36px; height:36px; color:var(--accent); }
.upload-zone h3 { font-family:var(--font-serif); font-size:1.3rem; color:var(--primary); margin-bottom:8px; }
.upload-zone p { color:var(--text-light); font-size:.95rem; }
.upload-zone .formats { margin-top:16px; display:flex; gap:8px; justify-content:center; flex-wrap:wrap; }
.upload-zone .format-pill {
  padding:4px 12px; border-radius:var(--radius-pill);
  background:var(--bg-alt); border:1px solid var(--border);
  font-size:.8rem; font-weight:600; color:var(--muted);
}

/* ─── EXTRACTION FORM ─── */
.extract-grid { display:grid; grid-template-columns:1fr 1fr; gap:24px; }
.extract-section {
  background:var(--white); border:1px solid var(--border-alt);
  border-radius:var(--radius-lg); box-shadow:var(--shadow-sm);
  overflow:hidden;
}
.extract-section-header {
  padding:16px 20px; border-bottom:1px solid var(--border-alt);
  display:flex; align-items:center; gap:10px;
  font-weight:700; color:var(--primary); font-size:.95rem;
}
.extract-section-header .icon-wrap {
  width:32px; height:32px; border-radius:var(--radius-sm);
  display:grid; place-items:center;
}
.extract-section-header .icon-wrap svg { width:18px; height:18px; }
.extract-section-body { padding:20px; }
.field-row {
  display:flex; align-items:center; gap:12px; margin-bottom:14px;
}
.field-row:last-child { margin-bottom:0; }
.field-label {
  min-width:140px; font-size:.85rem; font-weight:600;
  color:var(--text-light);
}
.field-input {
  flex:1; padding:10px 14px; border:2px solid var(--border);
  border-radius:10px; font-family:var(--font-sans); font-size:.9rem;
  color:var(--text); transition:var(--ease);
}
.field-input:focus { outline:none; border-color:var(--accent); box-shadow:0 0 0 4px var(--accent-glow); }
.confidence {
  font-size:.75rem; font-weight:700; padding:3px 8px;
  border-radius:var(--radius-pill); min-width:42px; text-align:center;
}
.confidence.high { background:var(--success-bg); color:#065f46; }
.confidence.medium { background:var(--warning-bg); color:#92400e; }
.confidence.low { background:var(--error-bg); color:#991b1b; }

/* ─── SUPPLIER CARDS ─── */
.supplier-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:20px; }
.supplier-card {
  background:var(--white); border:1px solid var(--border-alt);
  border-radius:var(--radius-lg); padding:24px; box-shadow:var(--shadow-sm);
  transition:var(--ease); cursor:pointer;
}
.supplier-card:hover { box-shadow:var(--shadow); transform:translateY(-2px); }
.supplier-card-top { display:flex; align-items:center; gap:14px; margin-bottom:16px; }
.supplier-avatar {
  width:48px; height:48px; border-radius:var(--radius);
  display:grid; place-items:center; font-weight:800; font-size:1.1rem; color:#fff;
}
.supplier-card-name { font-weight:700; color:var(--primary); font-size:1rem; }
.supplier-card-cat { font-size:.8rem; color:var(--muted); font-weight:500; }
.supplier-card-stats { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.supplier-stat { text-align:center; padding:10px; background:var(--bg-alt); border-radius:var(--radius-sm); }
.supplier-stat-val { font-family:var(--font-serif); font-weight:700; color:var(--primary); font-size:1.1rem; }
.supplier-stat-label { font-size:.75rem; color:var(--muted); font-weight:600; }

/* ─── ACCRUAL TIMELINE ─── */
.accrual-grid { display:grid; grid-template-columns:1fr 1fr; gap:24px; }
.period-bar {
  display:flex; align-items:center; gap:12px; padding:14px 16px;
  border-radius:var(--radius); border:1px solid var(--border);
  margin-bottom:10px; background:var(--white); transition:var(--ease);
}
.period-bar:hover { border-color:var(--accent); }
.period-bar-month { font-weight:700; color:var(--primary); min-width:80px; font-size:.9rem; }
.period-bar-fill-wrap { flex:1; height:24px; background:var(--bg-alt); border-radius:var(--radius-pill); overflow:hidden; }
.period-bar-fill {
  height:100%; border-radius:var(--radius-pill);
  background:linear-gradient(90deg,var(--accent),#00e6c3);
  transition:width .6s ease;
}
.period-bar-amount { min-width:90px; text-align:right; font-weight:700; color:var(--primary); font-size:.9rem; }

/* ─── INSIGHT CARDS ─── */
.insight-grid { display:grid; grid-template-columns:repeat(2,1fr); gap:20px; }
.insight-card {
  background:var(--white); border:1px solid var(--border-alt);
  border-radius:var(--radius-lg); padding:24px; box-shadow:var(--shadow-sm);
  transition:var(--ease); border-left:4px solid transparent;
}
.insight-card:hover { box-shadow:var(--shadow); }
.insight-card.savings { border-left-color:var(--success); }
.insight-card.alert { border-left-color:var(--warning); }
.insight-card.risk { border-left-color:var(--error); }
.insight-card.info { border-left-color:var(--info); }
.insight-card-header { display:flex; align-items:center; gap:10px; margin-bottom:10px; }
.insight-card-icon {
  width:36px; height:36px; border-radius:var(--radius-sm);
  display:grid; place-items:center;
}
.insight-card-icon svg { width:18px; height:18px; }
.insight-card-title { font-weight:700; color:var(--primary); font-size:.95rem; }
.insight-card-body { font-size:.9rem; color:var(--text-light); line-height:1.6; }
.insight-card-value { font-family:var(--font-serif); font-weight:700; font-size:1.4rem; color:var(--primary); margin-top:10px; }

/* ─── SPEND CHART (CSS-only) ─── */
.chart-bars { display:flex; align-items:flex-end; gap:8px; height:200px; padding-top:20px; }
.chart-bar-wrap { flex:1; display:flex; flex-direction:column; align-items:center; gap:6px; height:100%; justify-content:flex-end; }
.chart-bar {
  width:100%; border-radius:6px 6px 0 0;
  background:linear-gradient(180deg,var(--accent),rgba(0,198,167,.6));
  transition:height .6s ease; min-height:4px;
}
.chart-bar.alt { background:linear-gradient(180deg,var(--primary),var(--primary-light)); }
.chart-bar-label { font-size:.75rem; color:var(--muted); font-weight:600; }
.chart-bar-val { font-size:.7rem; color:var(--primary); font-weight:700; }

/* ─── UPLOAD ITEMS ─── */
.upload-item {
  display:flex; align-items:center; gap:14px; padding:14px 16px;
  border:1px solid var(--border); border-radius:var(--radius);
  margin-bottom:10px; background:var(--white); transition:var(--ease);
}
.upload-item:hover { border-color:var(--accent); }
.upload-item-icon {
  width:42px; height:42px; border-radius:var(--radius-sm);
  display:grid; place-items:center;
}
.upload-item-icon svg { width:22px; height:22px; }
.upload-item-info { flex:1; }
.upload-item-name { font-weight:700; color:var(--primary); font-size:.9rem; }
.upload-item-meta { font-size:.8rem; color:var(--muted); }
.upload-progress {
  width:120px; height:6px; background:var(--bg-alt);
  border-radius:var(--radius-pill); overflow:hidden;
}
.upload-progress-fill {
  height:100%; border-radius:var(--radius-pill);
  background:linear-gradient(90deg,var(--accent),#00e6c3);
}

/* ─── ALERTS PANEL ─── */
.alert-item {
  display:flex; align-items:flex-start; gap:12px; padding:14px;
  border-radius:var(--radius); margin-bottom:10px;
}
.alert-item.warn { background:var(--warning-bg); border:1px solid #fde68a; }
.alert-item.err { background:var(--error-bg); border:1px solid #fecaca; }
.alert-item.inf { background:var(--info-bg); border:1px solid #bfdbfe; }
.alert-item.suc { background:var(--success-bg); border:1px solid #a7f3d0; }
.alert-icon { width:20px; height:20px; flex-shrink:0; margin-top:2px; }
.alert-text { font-size:.85rem; font-weight:500; line-height:1.5; }

/* ─── DONUT CHART (CSS) ─── */
.donut-wrap { display:flex; align-items:center; gap:24px; }
.donut {
  width:140px; height:140px; border-radius:50%;
  background:conic-gradient(
    var(--accent) 0deg 130deg,
    var(--primary) 130deg 220deg,
    var(--warning) 220deg 280deg,
    var(--purple) 280deg 330deg,
    var(--border) 330deg 360deg
  );
  position:relative; flex-shrink:0;
}
.donut::after {
  content:''; position:absolute;
  top:20%; left:20%; width:60%; height:60%;
  background:var(--white); border-radius:50%;
}
.donut-legend { display:flex; flex-direction:column; gap:8px; }
.donut-legend-item { display:flex; align-items:center; gap:8px; font-size:.85rem; }
.donut-legend-dot { width:10px; height:10px; border-radius:3px; flex-shrink:0; }

/* ─── INVOICE PREVIEW PANEL ─── */
.preview-split { display:grid; grid-template-columns:1fr 1fr; gap:28px; }
.preview-doc {
  background:var(--white); border:1px solid var(--border-alt);
  border-radius:var(--radius-lg); padding:32px; min-height:500px;
  display:flex; align-items:center; justify-content:center;
  box-shadow:var(--shadow-sm);
}
.preview-doc-placeholder { text-align:center; color:var(--muted); }
.preview-doc-placeholder svg { width:64px; height:64px; color:var(--border); margin-bottom:12px; }
.preview-doc-placeholder p { font-size:.9rem; }

/* ─── TAB BAR ─── */
.tab-bar { display:flex; gap:4px; margin-bottom:24px; background:var(--white); padding:4px; border-radius:var(--radius); border:1px solid var(--border); }
.tab-btn {
  padding:10px 20px; border-radius:var(--radius-sm); border:none;
  background:transparent; font-family:var(--font-sans); font-weight:700;
  font-size:.9rem; color:var(--muted); cursor:pointer; transition:var(--ease);
}
.tab-btn:hover { color:var(--primary); background:var(--bg-alt); }
.tab-btn.active { color:var(--primary); background:var(--white); box-shadow:var(--shadow-sm); }

/* ─── HERO BANNER (Accruals/Optimization) ─── */
.hero-banner {
  background:linear-gradient(135deg,var(--primary) 0%,var(--primary-light) 100%);
  color:#fff; border:none;
}
.hero-banner .card-body {
  padding:28px 32px; display:flex; align-items:center; gap:24px; flex-wrap:wrap;
}
.hero-banner-icon {
  width:52px; height:52px; border-radius:var(--radius-lg);
  background:rgba(0,198,167,.2); display:grid; place-items:center; flex-shrink:0;
}

/* ─── MISC ─── */
.two-col { display:grid; grid-template-columns:2fr 1fr; gap:24px; }
.mb-20 { margin-bottom:20px; }
.mb-28 { margin-bottom:28px; }
.text-accent { color:var(--accent); }
.flex-between { display:flex; align-items:center; justify-content:space-between; }

/* ─── ANIMATIONS ─── */
@keyframes fadeIn { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:translateY(0); } }

/* ─── RESPONSIVE ─── */
@media(max-width:1200px) {
  .stat-grid { grid-template-columns:repeat(2,1fr); }
  .supplier-grid { grid-template-columns:repeat(2,1fr); }
  .extract-grid { grid-template-columns:1fr; }
}
@media(max-width:768px) {
  .sidebar { width:60px; }
  .sidebar-brand span, .sidebar-section-title, .sidebar-link span, .sidebar-footer span { display:none; }
  .sidebar-link { justify-content:center; padding:11px 0; }
  .main { margin-left:60px; }
  .stat-grid { grid-template-columns:1fr; }
  .supplier-grid { grid-template-columns:1fr; }
  .insight-grid { grid-template-columns:1fr; }
  .accrual-grid { grid-template-columns:1fr; }
}
