/* ============================================================
   FinTrack Pro — Excel AI Dashboard Styles
   Microsoft Office-inspired light theme
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --excel-green:     #1d6f42;
  --excel-green-lt:  #217346;
  --excel-green-bg:  #e8f5e9;
  --excel-blue:      #2b579a;
  --excel-blue-lt:   #4472c4;
  --ribbon-bg:       #f3f2f1;
  --ribbon-border:   #d4d4d4;
  --grid-border:     #d0d7de;
  --grid-header-bg:  #f0f0f0;
  --grid-header-txt: #444;
  --grid-sel:        #e8f0fe;
  --grid-sel-border: #4472c4;
  --grid-row-hover:  #f8f8f8;
  --formula-bg:      #fff;
  --tab-active:      #fff;
  --tab-inactive:    #e1e1e1;
  --text-primary:    #202020;
  --text-muted:      #666;
  --accent-green:    #00c853;
  --accent-red:      #d32f2f;
  --accent-orange:   #f57c00;
  --accent-blue:     #1976d2;
  --accent-purple:   #7b1fa2;

  --font: 'Segoe UI', 'Inter', Arial, sans-serif;
  --cell-h: 22px;
  --row-hdr-w: 52px;
}

html, body {
  font-family: var(--font);
  background: #fff;
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  font-size: 13px;
  display: flex;
  flex-direction: column;
}

/* ── TITLE BAR ───────────────────────────────────────────── */
.title-bar {
  height: 36px;
  background: var(--excel-green-lt);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
  color: #fff;
  flex-shrink: 0;
  user-select: none;
}
.title-left { display: flex; align-items: center; gap: 8px; }
.excel-logo {
  width: 28px; height: 28px; border-radius: 4px;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.file-name { font-size: 13px; font-weight: 600; }
.saved-badge {
  font-size: 11px; color: rgba(255,255,255,.75);
  display: flex; align-items: center; gap: 4px;
}
.title-center { font-size: 13px; font-weight: 400; color: rgba(255,255,255,.9); }
.title-right { display: flex; gap: 6px; }
.tbtn {
  background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.25);
  color: #fff; border-radius: 4px; padding: 4px 10px;
  font-size: 12px; cursor: pointer; display: flex; align-items: center; gap: 5px;
  font-family: var(--font); transition: background .15s;
}
.tbtn:hover { background: rgba(255,255,255,.28); }
.tbtn-green { background: rgba(0,200,83,.3); }
.tbtn-purple { background: rgba(123,31,162,.3); }

/* ── RIBBON ─────────────────────────────────────────────── */
.ribbon {
  background: var(--ribbon-bg);
  border-bottom: 2px solid var(--excel-green-lt);
  flex-shrink: 0;
}
.ribbon-tabs {
  display: flex; gap: 0;
  padding: 0 12px;
  border-bottom: 1px solid var(--ribbon-border);
}
.rtab {
  padding: 6px 16px; font-size: 12.5px; font-weight: 500;
  background: none; border: none; cursor: pointer;
  color: var(--text-primary); font-family: var(--font);
  border-bottom: 3px solid transparent;
  margin-bottom: -1px; transition: all .15s;
}
.rtab:hover { background: rgba(0,0,0,.05); }
.rtab.active { border-bottom-color: var(--excel-green-lt); color: var(--excel-green-lt); font-weight: 600; }

.ribbon-panel {
  display: none; flex-direction: row; align-items: flex-start;
  padding: 6px 12px; gap: 4px; flex-wrap: wrap;
}
.ribbon-panel.active { display: flex; }

.rgroup {
  display: flex; flex-direction: column; align-items: flex-start;
  border-right: 1px solid var(--ribbon-border);
  padding: 0 10px 0 6px; min-width: 60px;
}
.rgroup:last-child { border-right: none; }
.rgroup-title {
  font-size: 10px; color: var(--text-muted); text-align: center;
  width: 100%; margin-top: 2px; order: 99;
}
.rbtn-row { display: flex; flex-direction: row; gap: 3px; }

/* ribbon buttons inside group shown as row */
.rgroup { flex-direction: row; align-items: center; gap: 3px; position: relative; padding-bottom: 18px; }
.rgroup-title { position: absolute; bottom: 0; left: 0; right: 0; text-align: center; }

.rbtn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 5px 8px; border: 1px solid transparent;
  background: transparent; border-radius: 3px; cursor: pointer;
  font-size: 11px; font-family: var(--font); color: var(--text-primary);
  min-width: 36px; transition: all .12s;
}
.rbtn:hover { background: rgba(0,0,0,.06); border-color: var(--ribbon-border); }
.rbtn i { font-size: 14px; }
.rbtn-icon { font-size: 13px; font-weight: 700; min-width: 28px; }
.rbtn-color {
  width: 26px; height: 22px; border-radius: 3px;
  background: var(--c); border: 1px solid #ccc; cursor: pointer;
  min-width: 26px; padding: 0; font-size: 11px; color: #666;
  display: flex; align-items: center; justify-content: center;
}
.tbtn-ai { color: var(--accent-purple) !important; font-weight: 700; }

.rselect {
  height: 22px; border: 1px solid var(--ribbon-border);
  background: #fff; font-size: 12px; font-family: var(--font);
  border-radius: 2px; padding: 0 4px; cursor: pointer;
}
.rselect-sm { width: 44px; }

/* ── FORMULA BAR ─────────────────────────────────────────── */
.formula-bar {
  display: flex; align-items: center;
  background: var(--formula-bg);
  border-bottom: 1px solid var(--ribbon-border);
  height: 26px; flex-shrink: 0;
}
.cell-ref {
  width: 60px; min-width: 60px; text-align: center;
  font-size: 12px; font-weight: 600; color: var(--text-primary);
  border-right: 1px solid var(--ribbon-border);
  padding: 0 8px; height: 100%;
  display: flex; align-items: center; justify-content: center;
}
.formula-eq {
  padding: 0 8px; color: var(--excel-blue);
  font-weight: 700; font-size: 14px;
  border-right: 1px solid var(--ribbon-border);
  height: 100%; display: flex; align-items: center;
}
.formula-input {
  flex: 1; border: none; outline: none;
  padding: 0 8px; font-size: 12.5px; font-family: var(--font);
  background: transparent; color: var(--text-primary);
}

/* ── WORKBOOK AREA ───────────────────────────────────────── */
.workbook-area {
  flex: 1; display: flex; overflow: hidden;
}

/* ── SPREADSHEET ─────────────────────────────────────────── */
.spreadsheet-wrap {
  flex: 1; overflow: hidden; position: relative;
}

.sheet { display: none; height: 100%; flex-direction: column; }
.sheet.active { display: flex; }

.sheet-header-row {
  display: flex; align-items: center;
  background: var(--grid-header-bg);
  border-bottom: 1px solid var(--grid-border);
  position: sticky; top: 0; z-index: 20;
  flex-shrink: 0;
  overflow: hidden;
}
.row-header-corner {
  width: var(--row-hdr-w); min-width: var(--row-hdr-w);
  height: 22px; border-right: 1px solid var(--grid-border);
  background: var(--grid-header-bg);
}

.grid-scroll-wrap {
  flex: 1; overflow: auto;
  position: relative;
}

/* ── GRID TABLE ─────────────────────────────────────────── */
.grid-container {
  position: relative;
  min-width: 100%;
}

.xls-table {
  border-collapse: collapse;
  min-width: 100%;
  table-layout: fixed;
}
.xls-table th, .xls-table td {
  border: 1px solid var(--grid-border);
  height: var(--cell-h);
  min-height: var(--cell-h);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 2px 6px;
  font-size: 12.5px;
  vertical-align: middle;
  position: relative;
}

/* Column header */
.col-header {
  background: var(--grid-header-bg);
  text-align: center;
  color: var(--grid-header-txt);
  font-size: 12px; font-weight: 600;
  cursor: pointer; user-select: none;
  position: sticky; top: 0; z-index: 10;
  border-bottom: 2px solid var(--grid-border);
}
.col-header:hover { background: #e0e0e0; }
.col-header.sorted-asc::after { content: ' ▲'; font-size: 10px; color: var(--excel-blue); }
.col-header.sorted-desc::after { content: ' ▼'; font-size: 10px; color: var(--excel-blue); }

/* Row header */
.row-hdr {
  background: var(--grid-header-bg);
  text-align: center;
  color: var(--grid-header-txt);
  font-size: 11px; font-weight: 500;
  width: var(--row-hdr-w); min-width: var(--row-hdr-w);
  cursor: pointer; user-select: none;
  border-right: 2px solid var(--grid-border);
  position: sticky; left: 0; z-index: 5;
}
.row-hdr:hover { background: #e0e0e0; }

/* CELLS */
.xls-cell {
  cursor: cell;
  font-size: 12.5px;
  font-family: var(--font);
  outline: none;
  min-width: 90px;
  max-width: 240px;
}
.xls-cell:hover { background: var(--grid-row-hover) !important; }
.xls-cell.selected {
  background: var(--grid-sel) !important;
  outline: 2px solid var(--grid-sel-border) !important;
  outline-offset: -2px;
  z-index: 2;
}
.xls-cell.editing {
  outline: 2px solid var(--excel-blue) !important;
  outline-offset: -2px;
  background: #fff !important;
  z-index: 3;
}
.xls-cell input.cell-editor {
  width: 100%; height: 100%;
  border: none; outline: none; padding: 1px 4px;
  font-size: 12.5px; font-family: var(--font);
  background: transparent;
}

/* CELL TYPES */
.cell-header {
  background: var(--excel-green-lt) !important;
  color: #fff !important;
  font-weight: 700;
  text-align: center;
}
.cell-subheader {
  background: #c8e6c9 !important;
  color: #1b5e20 !important;
  font-weight: 600;
}
.cell-formula {
  color: var(--excel-blue);
  font-style: italic;
}
.cell-positive { color: var(--accent-green); font-weight: 600; }
.cell-negative { color: var(--accent-red); font-weight: 600; }
.cell-neutral  { color: var(--text-muted); }
.cell-bold     { font-weight: 700; }
.cell-center   { text-align: center; }
.cell-right    { text-align: right; }

/* PROGRESS BAR CELL */
.progress-cell-wrap {
  display: flex; align-items: center; gap: 6px; width: 100%;
}
.progress-cell-bar {
  flex: 1; height: 10px; background: #e0e0e0;
  border-radius: 20px; overflow: hidden;
}
.progress-cell-fill {
  height: 100%; border-radius: 20px;
  background: var(--excel-green-lt);
}
.progress-cell-pct { font-size: 11px; font-weight: 700; min-width: 35px; color: var(--excel-green-lt); }

/* FILTER ROW */
.filter-row td {
  background: #f5f5f5;
  padding: 2px;
}
.filter-row input {
  width: 100%; border: 1px solid #ccc; border-radius: 2px;
  padding: 2px 4px; font-size: 11px; font-family: var(--font);
}

/* ── SHEET TABS BAR ──────────────────────────────────────── */
.sheet-tabs-bar {
  display: flex; align-items: center;
  background: #f0f0f0;
  border-top: 2px solid var(--ribbon-border);
  height: 28px; flex-shrink: 0;
  padding: 0 4px;
  overflow-x: auto;
  user-select: none;
}
.sheet-tab-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 4px 14px;
  background: var(--tab-inactive); border: 1px solid var(--grid-border);
  border-bottom: none; border-radius: 4px 4px 0 0;
  font-size: 12px; font-family: var(--font); font-weight: 500;
  cursor: pointer; margin-right: 2px;
  color: var(--text-muted); transition: all .12s;
  white-space: nowrap;
}
.sheet-tab-btn:hover { background: #e8e8e8; color: var(--text-primary); }
.sheet-tab-btn.active {
  background: #fff; color: var(--excel-green-lt);
  font-weight: 700; border-color: var(--grid-border);
  border-bottom: 2px solid #fff;
}
.sheet-tab-ai { color: var(--accent-purple); }
.sheet-tab-ai.active { color: var(--accent-purple); }
.sheet-tabs-spacer { flex: 1; }
.status-bar-info {
  font-size: 11px; color: var(--text-muted);
  padding: 0 12px; white-space: nowrap;
}

/* ── CONTEXT MENU ─────────────────────────────────────────── */
.context-menu {
  position: fixed; z-index: 9999;
  background: #fff; border: 1px solid var(--grid-border);
  border-radius: 4px; box-shadow: 0 4px 20px rgba(0,0,0,.18);
  padding: 4px 0; min-width: 180px;
}
.cm-item {
  padding: 7px 16px; font-size: 12.5px; cursor: pointer;
  display: flex; align-items: center; gap: 8px; color: var(--text-primary);
  transition: background .1s;
}
.cm-item:hover { background: var(--grid-sel); }
.cm-item i { color: var(--excel-green-lt); width: 14px; }
.cm-separator { height: 1px; background: var(--ribbon-border); margin: 4px 0; }

/* ── CHARTS SHEET ─────────────────────────────────────────── */
.charts-sheet-container {
  padding: 24px; display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px; overflow: auto; height: 100%;
}
.chart-panel {
  background: #fff; border: 1px solid var(--grid-border);
  border-radius: 6px; padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.chart-panel-title {
  font-size: 13px; font-weight: 700;
  color: var(--excel-green-lt); margin-bottom: 12px;
  display: flex; align-items: center; gap: 6px;
}
.chart-panel-title i { font-size: 14px; }
.chart-panel-wrap { height: 220px; position: relative; }

/* ── AI INSIGHTS PANEL ───────────────────────────────────── */
.ai-panel {
  padding: 24px; overflow: auto; height: 100%;
  background: linear-gradient(135deg, #f8f8ff, #f0fff4);
}
.ai-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 24px;
}
.ai-icon {
  width: 52px; height: 52px; border-radius: 12px;
  background: linear-gradient(135deg, #7b1fa2, #4527a0);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; color: #fff; flex-shrink: 0;
}
.ai-title-wrap h2 { font-size: 20px; font-weight: 700; color: var(--excel-green-lt); }
.ai-title-wrap p { font-size: 12px; color: var(--text-muted); }

.ai-insights-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 16px; margin-bottom: 24px;
}
.ai-insight-card {
  background: #fff; border: 1px solid var(--grid-border);
  border-radius: 8px; padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  border-left: 4px solid var(--excel-green-lt);
  transition: transform .15s;
}
.ai-insight-card:hover { transform: translateY(-2px); }
.ai-insight-card.warning { border-left-color: var(--accent-orange); }
.ai-insight-card.danger  { border-left-color: var(--accent-red); }
.ai-insight-card.info    { border-left-color: var(--accent-blue); }
.ai-insight-card.success { border-left-color: var(--accent-green); }
.ai-insight-card.purple  { border-left-color: var(--accent-purple); }

.ai-card-icon { font-size: 22px; margin-bottom: 8px; }
.ai-card-title { font-size: 13px; font-weight: 700; margin-bottom: 4px; color: var(--text-primary); }
.ai-card-body  { font-size: 12px; color: var(--text-muted); line-height: 1.6; }
.ai-card-metric { font-size: 20px; font-weight: 800; margin: 6px 0; }

.ai-recommendations {
  background: #fff; border: 1px solid var(--grid-border);
  border-radius: 8px; padding: 20px; margin-bottom: 16px;
}
.ai-reco-title { font-size: 14px; font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.ai-reco-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.ai-reco-item {
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 12.5px; padding: 8px; border-radius: 6px;
  background: #f8f9fa;
}
.ai-reco-item .ai-reco-num {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--excel-green-lt); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.ai-reco-item .ai-reco-text { flex: 1; line-height: 1.5; }
.ai-reco-item strong { color: var(--excel-green-lt); }

.ai-formula-tip {
  background: #e8f5e9; border: 1px solid #a5d6a7;
  border-radius: 8px; padding: 16px; margin-bottom: 16px;
}
.ai-formula-tip h4 { font-size: 13px; font-weight: 700; color: var(--excel-green-lt); margin-bottom: 8px; }
.ai-formula-tip code {
  display: block; background: #f1f8e9; border: 1px solid #c5e1a5;
  padding: 8px 12px; border-radius: 4px; font-family: 'Courier New', monospace;
  font-size: 12px; color: #2e7d32; margin: 4px 0;
}

/* ── SUMMARY SHEET ───────────────────────────────────────── */
.summary-kpi-row {
  display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
.summary-kpi {
  flex: 1; min-width: 140px;
  background: var(--excel-green-bg);
  border: 1px solid #a5d6a7; border-radius: 4px;
  padding: 10px 14px;
}
.summary-kpi-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; }
.summary-kpi-value { font-size: 20px; font-weight: 800; color: var(--excel-green-lt); margin-top: 2px; }
.summary-kpi-sub   { font-size: 11px; color: var(--text-muted); }

/* ── SCROLLBAR ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #f5f5f5; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .title-center { display: none; }
  .charts-sheet-container { grid-template-columns: 1fr; }
  .ai-insights-grid { grid-template-columns: 1fr; }
  .ribbon-panel { overflow-x: auto; }
}
@media (max-width: 600px) {
  .title-right .tbtn span { display: none; }
  .rgroup-title { display: none; }
}

/* ── FREEZE INDICATOR ─────────────────────────────────────── */
.freeze-col::after {
  content: '';
  position: absolute; right: 0; top: 0; bottom: 0;
  width: 2px; background: var(--excel-blue);
  opacity: .5;
}

/* ── TABLE STRIPING ───────────────────────────────────────── */
.xls-table tbody tr:nth-child(even) td:not(.row-hdr):not(.cell-header):not(.cell-subheader) {
  background: #fafafa;
}
.xls-table tbody tr:hover td:not(.row-hdr) {
  background: #e8f4fd !important;
}

/* ── SPARKLINE ────────────────────────────────────────────── */
.sparkline-cell { padding: 2px 4px !important; }
.sparkline-canvas { display: block; }

/* ── LOADING ──────────────────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0; background: rgba(255,255,255,.8);
  display: flex; align-items: center; justify-content: center;
  z-index: 9998; font-size: 14px; color: var(--excel-green-lt);
  gap: 10px;
}
