/* v2.5 - Last known good state */
:root {
  /* --- Gemini / Material Dark Theme Palette --- */
  --bg: #131314;           
  --panel: #1E1F20;        
  --panel2: #2D2E31;       
  --stroke: #444746;       
  --text: #E3E3E3;         
  --muted: #C4C7C5;        
  
  --pill: #2D2E31;         
  --pillActive: #4C8DF6;   
  
  --header: #1E1F20;       
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  --danger: #F2B8B5;       
  
  --font-family: "Google Sans Flex", "Google Sans", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; outline: none; }

body {
  margin: 0;
  font-family: var(--font-family);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  line-height: 1.5;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 16px;
  gap: 16px;
}

/* Header */
.topbar {
  flex: 0 0 60px;
  background: var(--header);
  border: 1px solid var(--stroke);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { height: 28px; width: auto; display: block; }
.brand-mark { font-weight: 500; font-size: 18px; letter-spacing: -0.5px; opacity: 1; color: var(--text); }
.brand-title { font-size: 14px; color: var(--muted); opacity: 0.8; font-weight: 400; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* Buttons */
.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.icon-btn:hover { 
  background: var(--panel2); 
  color: var(--text);
  transform: scale(1.05);
}
.icon-btn:active { transform: scale(0.95); }
.icon-btn svg, .icon-btn img { width: 20px; height: 20px; display: block; }

/* Layout Sections */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
  min-height: 0;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  flex: 0 0 auto;
}

.kpi-card {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 16px;
  padding: 16px 20px;
  box-shadow: var(--shadow);
  min-height: 80px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.kpi-label { 
  font-size: 12px; 
  font-weight: 500;
  text-transform: uppercase; 
  color: var(--muted); 
  margin-bottom: 4px; 
  letter-spacing: 0.8px; 
}
.kpi-value { 
  font-size: 28px;
  font-weight: 400;
  color: var(--text);
}

.subtotals {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
  flex: 0 0 auto;
}
.subtotals-item { font-size: 13px; color: var(--muted); font-weight: 400; }
.subtotals-item span { margin-left: 8px; color: var(--text); font-weight: 600; }

/* Pills & Search */
.pillbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: 0 0 auto;
  padding-bottom: 4px;
  align-items: center;
}
.pill {
  background: var(--panel2);
  border: 1px solid var(--stroke);
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 100px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.2s ease;
  height: 36px;
  display: flex;
  align-items: center;
}
.pill:hover { 
  background: #3c3d40; 
  color: var(--text); 
  border-color: #555;
}
.pill.active { 
  background: var(--pillActive); 
  border-color: var(--pillActive); 
  color: #000;
  font-weight: 600;
}

.global-search {
  background: var(--panel2);
  border: 1px solid var(--stroke);
  color: var(--text);
  padding: 0 16px;
  height: 36px;
  border-radius: 100px;
  font-size: 13px;
  width: 180px;
  transition: all 0.2s;
  font-family: inherit;
}
.global-search:focus { 
  border-color: var(--pillActive); 
  background: #232426;
  outline: none; 
  width: 220px;
}
.global-search::placeholder { color: var(--muted); opacity: 0.6; }

/* Table Container */
.table-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
  min-height: 200px;
}

.statusline {
  flex: 0 0 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--stroke);
  background: var(--panel);
  font-size: 11px;
  color: var(--muted);
  font-family: monospace;
}

.table-wrap {
  flex: 1;
  overflow: auto;
  position: relative;
  background: var(--bg);
}

.table-wrap::-webkit-scrollbar { width: 8px; height: 8px; }
.table-wrap::-webkit-scrollbar-track { background: var(--bg); }
.table-wrap::-webkit-scrollbar-thumb { background: #444746; border-radius: 4px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: #5E5E5E; }

.grid {
  width: 100%;
  border-collapse: collapse;
  min-width: 1000px;
}

.grid thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--panel2);
  color: var(--text);
  border-bottom: 1px solid var(--stroke);
  border-right: 1px solid var(--stroke);
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  user-select: none;
}

.grid tbody td {
  border-bottom: 1px solid #28292a;
  border-right: 1px solid #28292a;
  padding: 8px 12px;
  font-size: 13px;
  white-space: nowrap;
  color: var(--muted);
  transition: color 0.1s;
}
.grid tbody tr:hover td { color: var(--text); background: #1E1F20; }

.editable { background: #232426; cursor: text; color: var(--text); }
.editable:focus { 
  background: #004A77;
  color: #D3E3FD;
  outline: 2px solid var(--pillActive); 
  outline-offset: -2px;
}

.th-wrap { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.th-label { cursor: pointer; font-weight: 600; flex: 1; }

.filter-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  width: 20px;
  height: 20px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 10px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.1s;
}
.filter-btn:hover { background: rgba(255,255,255,0.1); color: var(--text); }

/* Resizable Filter Menu */
.filter-menu {
  position: absolute;
  top: 100%; left: 0; margin-top: 4px;
  background: var(--panel2);
  border: 1px solid var(--stroke);
  border-radius: 8px;
  z-index: 1000;
  width: 240px;
  height: 300px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  display: none;
  padding: 8px;
  flex-direction: column;
  resize: both;
  overflow: hidden;
  min-width: 200px;
  min-height: 150px;
  max-width: 90vw;
  max-height: 80vh;
}
.filter-menu.open { display: flex; }

.filter-search-wrap { display: flex; gap: 6px; margin-bottom: 8px; flex-shrink: 0; }
.filter-search {
  flex: 1; background: var(--bg); border: 1px solid var(--stroke); color: var(--text); padding: 6px; border-radius: 4px; font-size: 12px;
}
.filter-clear-btn {
  background: var(--panel); border: 1px solid var(--stroke); color: var(--muted); font-size: 11px; padding: 0 8px; cursor: pointer; border-radius: 4px;
}

.filter-top { border-bottom: 1px solid var(--stroke); padding-bottom: 6px; margin-bottom: 6px; flex-shrink: 0; }
.filter-top label { display: flex; align-items: center; gap: 8px; font-size: 12px; cursor: pointer; color: var(--text); }

.filter-list { flex: 1; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 2px; }
.filter-item { display: flex; align-items: center; gap: 8px; padding: 4px 6px; font-size: 12px; cursor: pointer; color: var(--muted); border-radius: 4px; }
.filter-item:hover { background: rgba(255,255,255,0.05); color: var(--text); }

.filter-footer { border-top: 1px solid var(--stroke); padding-top: 8px; margin-top: 8px; display: flex; gap: 8px; flex-shrink: 0; }
.filter-footer button { 
  flex: 1; background: transparent; border: 1px solid var(--stroke); color: var(--text); padding: 6px 0; border-radius: 100px; font-size: 11px; cursor: pointer; transition: background 0.1s;
}
.filter-footer button:hover { background: rgba(255,255,255,0.05); border-color: var(--muted); }

/* --- Modals (Common) --- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 3000; backdrop-filter: blur(4px); }
.modal.hidden { display: none; }
.modal-card { 
  width: min(640px, 90vw); 
  background: var(--panel); 
  border: 1px solid var(--stroke); 
  border-radius: 20px; /* Highly rounded Gemini style */
  box-shadow: 0 20px 40px rgba(0,0,0,0.4); 
  display: flex; flex-direction: column; 
}
.modal-head { 
  display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--stroke); 
}
.modal-title { font-weight: 500; font-size: 18px; color: var(--text); }
.modal-body { padding: 24px; font-size: 13px; line-height: 1.6; color: var(--muted); display: flex; flex-direction: column; gap: 20px; }

/* --- NEW: Export Option Grid --- */
.export-section { display: flex; flex-direction: column; gap: 10px; }
.section-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }

.option-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

/* The Selectable "Chip" */
.option-chip {
  background: var(--panel2);
  border: 1px solid var(--stroke);
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex; align-items: center;
  font-family: inherit;
}
.option-chip:hover { background: #37393d; }
.option-chip.active {
  border-color: var(--pillActive);
  background: rgba(76, 141, 246, 0.1); /* Subtle blue tint */
  color: #A8C7FA; /* Lighter blue text */
  box-shadow: 0 0 0 1px var(--pillActive); /* Glow effect */
}

/* Action Buttons */
.modal-actions { display: flex; gap: 12px; margin-top: 8px; }
.action-btn {
  flex: 1;
  padding: 12px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: all 0.2s;
}
.action-btn.secondary {
  background: transparent;
  border: 1px solid var(--stroke);
  color: var(--text);
}
.action-btn.secondary:hover { background: var(--panel2); }

.action-btn.primary {
  background: var(--pillActive);
  color: #000;
  font-weight: 600;
}
.action-btn.primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 12px rgba(76, 141, 246, 0.3);
}

/* --- Highlight --- */
.highlight {
  background-color: rgba(230, 192, 42, 0.45);
  color: inherit;
  font-weight: 700;
  border-radius: 2px;
  padding: 0 2px;
}
/* FORCE EXPORT MODAL TO FRONT */
#export-modal, .export-dialog, .modal-wrapper {
    z-index: 99999 !important; /* Higher than everything else */
    pointer-events: auto !important; /* Force clicks to work */
}

/* Ensure the background overlay is behind the modal but above the page */
.modal-overlay, .backdrop {
    z-index: 99990 !important;
}
/* Report Modal */
.report-text {
  font-family: "Courier New", monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--stroke);
  border-radius: 8px;
  padding: 16px;
  margin: 0;
  max-height: 60vh;
  overflow-y: auto;
  white-space: pre;
}