/* ================================================================
   Legal Entity Analyzer — Dedicated Styles
   Extends main.css (loaded via ../main.css)
   ================================================================ */

/* Layout: Filter sidebar + main content */
.lea-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  margin-bottom: 24px;
  align-items: start;
}

/* ---- Filter Sidebar ---- */
.lea-filters {
  background: #ffffff;
  border-radius: 12px;
  padding: 20px;
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.lea-filter-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #747480;
  margin: 0 0 4px 0;
}

.lea-filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lea-filter-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  font-size: 13px;
  color: #2e2e38;
  background: #fff;
  outline: none;
  transition: border-color 0.2s;
}

.lea-filter-input:focus {
  border-color: #2e2e38;
}

.lea-filter-input::placeholder {
  color: #bbb;
}

.lea-year-checks {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.lea-year-checks label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  cursor: pointer;
  color: #2e2e38;
}

.lea-year-checks input[type="checkbox"] {
  accent-color: #2e2e38;
}

.lea-match-toggles {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lea-match-toggles label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  cursor: pointer;
  color: #555;
}

.lea-filter-divider {
  border: none;
  border-top: 1px solid #eee;
  margin: 4px 0;
}

/* ---- Main Content Area ---- */
.lea-main {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0; /* prevent grid blowout */
}

/* ---- Registrant Info Bar ---- */
.lea-registrant-bar {
  background: #ffffff;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.lea-registrant-bar .lea-reg-name {
  font-size: 18px;
  font-weight: 600;
  color: #2e2e38;
}

.lea-registrant-bar .lea-reg-ticker {
  font-size: 14px;
  font-weight: 600;
  color: #ffe600;
  background: #2e2e38;
  padding: 2px 10px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.lea-registrant-bar .lea-reg-meta {
  font-size: 12px;
  color: #747480;
}

/* ---- Tabs (same base as main.css, extend for 5-tab layout) ---- */
.lea-tabs {
  display: flex;
  gap: 28px;
  border-bottom: 1px solid #e0e0e0;
  margin-bottom: 0;
  background: #ffffff;
  border-radius: 12px 12px 0 0;
  padding: 0 20px;
}

.lea-tab {
  background: none;
  border: none;
  padding: 14px 0;
  font-size: 13px;
  color: #747480;
  cursor: pointer;
  position: relative;
  font-weight: 500;
  white-space: nowrap;
  transition: color 0.15s;
}

.lea-tab:hover {
  color: #2e2e38;
}

.lea-tab.active {
  color: #2e2e38;
}

.lea-tab.active::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background-color: #2e2e38;
}

.lea-tab .tab-badge {
  font-size: 10px;
  background: #e0e0e0;
  color: #555;
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: 6px;
  font-weight: 600;
}

/* ---- Tab Content Panels ---- */
.lea-tab-content {
  background: #ffffff;
  border-radius: 0 0 12px 12px;
  padding: 24px 20px;
  min-height: 400px;
}

/* ---- Data Tables ---- */
.lea-table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 70vh;
  margin-top: 12px;
}

.lea-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.lea-table th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid #e0e0e0;
  font-weight: 600;
  color: #555;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  background: #ffffff;
}

.lea-table th.lea-sortable {
  cursor: pointer;
  user-select: none;
}

.lea-table th:hover {
  color: #2e2e38;
}

.lea-table th .sort-arrow {
  margin-left: 4px;
  font-size: 10px;
}

.lea-table td {
  padding: 9px 12px;
  border-bottom: 1px solid #f0f0f0;
  color: #2e2e38;
  font-family: "SF Mono", "Cascadia Code", "Consolas", monospace;
  font-size: 12.5px;
}

.lea-table tbody tr:hover {
  background: #fafafa;
}

.lea-table .cell-number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.lea-table .cell-clickable {
  cursor: pointer;
  color: #2563eb;
}

.lea-table .cell-clickable:hover {
  text-decoration: underline;
}

/* Delta styling */
.lea-delta-pos { color: #dc2626; font-weight: 600; }
.lea-delta-neg { color: #16a34a; font-weight: 600; }
.lea-delta-zero { color: #9ca3af; }

/* Row flags */
.lea-row-warn {
  background: #fef3c7 !important;
}

.lea-row-danger {
  background: #fee2e2 !important;
}

/* ---- Confidence Badge ---- */
.lea-confidence {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.lea-confidence.high { background: #dcfce7; color: #166534; }
.lea-confidence.medium { background: #fef9c3; color: #854d0e; }
.lea-confidence.low { background: #fee2e2; color: #991b1b; }

/* ---- Match Status Badges ---- */
.lea-match { color: #16a34a; font-weight: 600; }
.lea-no-match { color: #dc2626; font-weight: 600; }
.lea-maybe { color: #d97706; font-weight: 600; }

/* ---- Summary Stat Cards ---- */
.lea-stat-row {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.lea-stat-card {
  flex: 1;
  min-width: 140px;
  background: #f8fafc;
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  border: 1px solid #e2e8f0;
}

.lea-stat-card.lea-stat-compact {
  min-width: 0;
  padding: 10px 8px;
}

.lea-stat-compact .lea-stat-value {
  font-size: 1.3rem;
}

.lea-stat-compact .lea-stat-label {
  font-size: 0.68rem;
}

.lea-stat-value {
  font-size: 28px;
  font-weight: 700;
  color: #2e2e38;
  font-variant-numeric: tabular-nums;
}

.lea-stat-label {
  font-size: 11px;
  color: #747480;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-top: 4px;
}

/* ---- Upload Zone (Tax Match tab) ---- */
.lea-upload-zone {
  border: 2px dashed #d1d5db;
  border-radius: 12px;
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.lea-upload-zone:hover,
.lea-upload-zone.dragover {
  border-color: #2e2e38;
  background: #f8fafc;
}

.lea-upload-icon {
  font-size: 36px;
  margin-bottom: 8px;
  opacity: 0.5;
}

.lea-upload-text {
  font-size: 14px;
  color: #555;
}

.lea-upload-text a {
  color: #2563eb;
  cursor: pointer;
}

.lea-upload-hint {
  font-size: 12px;
  color: #9ca3af;
  margin-top: 6px;
}

/* ---- AI Insights ---- */
.lea-insight-card {
  background: #f8fafc;
  border-left: 3px solid #2e2e38;
  border-radius: 0 8px 8px 0;
  padding: 14px 18px;
  margin-bottom: 12px;
  font-size: 13.5px;
  line-height: 1.6;
  color: #2e2e38;
}

.lea-insight-card.insight-warn {
  border-left-color: #f59e0b;
  background: #fffbeb;
}

.lea-insight-card.insight-danger {
  border-left-color: #dc2626;
  background: #fef2f2;
}

.lea-insight-card .insight-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: #747480;
  margin-bottom: 4px;
}

/* ---- Empty / Loading States ---- */
.lea-empty {
  text-align: center;
  padding: 60px 20px;
  color: #9ca3af;
}

.lea-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.lea-empty-title {
  font-size: 16px;
  font-weight: 600;
  color: #555;
  margin-bottom: 6px;
}

.lea-empty-hint {
  font-size: 13px;
  color: #9ca3af;
}

.lea-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e0e0e0;
  border-top-color: #2e2e38;
  border-radius: 50%;
  animation: leaSpin 0.8s linear infinite;
  margin: 0 auto 12px auto;
}

@keyframes leaSpin {
  to { transform: rotate(360deg); }
}

body.dark .lea-spinner {
  border-color: #555;
  border-top-color: #ffe600;
}

/* ---- Footer Export Bar ---- */
.lea-export-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: #ffffff;
  border-radius: 12px;
  margin-top: 16px;
}

.lea-export-bar .lea-freshness {
  margin-left: auto;
  font-size: 11px;
  color: #9ca3af;
}

/* ---- Year Select Dropdowns (Compare tab) ---- */
.lea-compare-selects {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.lea-compare-selects label {
  font-size: 13px;
  font-weight: 500;
  color: #555;
}

.lea-compare-selects select {
  padding: 8px 12px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  color: #2e2e38;
  outline: none;
}

.lea-compare-selects select:focus {
  border-color: #2e2e38;
}

/* ---- Section Sub-Headers ---- */
.lea-section-header {
  font-size: 14px;
  font-weight: 600;
  color: #2e2e38;
  margin: 20px 0 10px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.lea-section-header .lea-count-badge {
  font-size: 11px;
  background: #e0e0e0;
  color: #555;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}

/* ---- Search within table ---- */
.lea-table-search {
  width: 100%;
  max-width: 320px;
  padding: 8px 12px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  margin-bottom: 12px;
}

.lea-table-search:focus {
  border-color: #2e2e38;
}

/* ================================================================
   STATUS LOG PANEL
   ================================================================ */
.lea-status-log {
  margin-top: 18px;
  width: 100%;
  max-width: 520px;
  text-align: left;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.78rem;
}
.lea-status-log-header {
  background: #f5f5f5;
  padding: 6px 12px;
  font-weight: 600;
  font-family: inherit;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #555;
  border-bottom: 1px solid #e0e0e0;
}
.lea-status-log-body {
  max-height: 180px;
  overflow-y: auto;
  padding: 8px 12px;
  background: #fafafa;
}
.lea-status-log-line {
  padding: 2px 0;
  color: #333;
  line-height: 1.5;
}
.lea-status-log-line::before {
  content: "▸ ";
  color: #ffe600;
}

body.dark .lea-status-log {
  border-color: #3a3a4a;
}
body.dark .lea-status-log-header {
  background: #2a2a3a;
  color: #aaa;
  border-bottom-color: #3a3a4a;
}
body.dark .lea-status-log-body {
  background: #1e1e2a;
}
body.dark .lea-status-log-line {
  color: #ccc;
}

/* ---- Three-Column Entity Table Column Groups ---- */
.lea-col-group-base {
  background: #f0fdf4;
  color: #166534;
  text-align: center;
  border-bottom: 2px solid #bbf7d0;
}
.lea-col-group-compare {
  background: #eff6ff;
  color: #1e40af;
  text-align: center;
  border-bottom: 2px solid #bfdbfe;
}

/* ---- Change Breakdown (Summary tab) ---- */
.lea-change-breakdown {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
}
.lea-change-added { color: #dc2626; }
.lea-change-removed { color: #16a34a; }

/* ---- Entity List Row Highlighting ---- */
.lea-row-new { background: #fef2f2 !important; }
.lea-row-removed { background: #f0fdf4 !important; }
.lea-row-maybe { background: #fffbeb !important; }

/* ---- Status Badges ---- */
.lea-badge-match,
.lea-badge-new,
.lea-badge-removed,
.lea-badge-maybe {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.lea-badge-match   { background: #dcfce7; color: #166534; }
.lea-badge-new     { background: #fee2e2; color: #991b1b; }
.lea-badge-removed { background: #dbeafe; color: #1e40af; }
.lea-badge-maybe   { background: #fef9c3; color: #854d0e; }

/* AI Quality Agent correction badge */
.lea-badge-ai {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 9px;
  font-weight: 700;
  background: #e0e7ff;
  color: #3730a3;
  margin-left: 4px;
  vertical-align: middle;
  cursor: help;
}
body.dark .lea-badge-ai {
  background: #312e81;
  color: #a5b4fc;
}

/* AI corrections summary card */
.lea-ai-corrections-summary {
  margin: 12px 0;
  padding: 10px 16px;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  font-size: 13px;
  color: #3730a3;
}
body.dark .lea-ai-corrections-summary {
  background: #1e1b4b;
  border-color: #312e81;
  color: #a5b4fc;
}

/* ---- Insight Section inside Compare tab ---- */
.lea-insight-title {
  font-size: 13px;
  font-weight: 600;
  color: #2e2e38;
  margin-bottom: 4px;
}
.lea-insight-body {
  font-size: 13px;
  line-height: 1.55;
  color: #555;
}
.lea-insight-danger { border-left-color: #dc2626; background: #fef2f2; }
.lea-insight-warn   { border-left-color: #f59e0b; background: #fffbeb; }

/* ---- Small Buttons ---- */
.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
  background: #fff;
  color: #2e2e38;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-sm:hover { background: #f1f5f9; }

/* ================================================================
   DARK MODE OVERRIDES
   ================================================================ */
body.dark .lea-filters {
  background: #23232f;
}

body.dark .lea-filter-title {
  color: #94a3b8;
}

body.dark .lea-filter-input {
  background: #2e2e38;
  border-color: #444;
  color: #e0e0e0;
}

body.dark .lea-filter-input:focus {
  border-color: #ffe600;
}

body.dark .lea-year-checks label {
  color: #e0e0e0;
}

body.dark .lea-year-checks input[type="checkbox"] {
  accent-color: #ffe600;
}

body.dark .lea-match-toggles label {
  color: #94a3b8;
}

body.dark .lea-filter-divider {
  border-top-color: #3a3a48;
}

body.dark .lea-registrant-bar {
  background: #23232f;
}

body.dark .lea-registrant-bar .lea-reg-name {
  color: #e0e0e0;
}

body.dark .lea-tabs {
  background: #23232f;
  border-bottom-color: #3a3a48;
}

body.dark .lea-tab {
  color: #94a3b8;
}

body.dark .lea-tab:hover {
  color: #e0e0e0;
}

body.dark .lea-tab.active {
  color: #ffe600;
}

body.dark .lea-tab.active::after {
  background-color: #ffe600;
}

body.dark .lea-tab .tab-badge {
  background: #3a3a48;
  color: #94a3b8;
}

body.dark .lea-tab-content {
  background: #23232f;
}

body.dark .lea-table th {
  background: #23232f;
  color: #94a3b8;
  border-bottom-color: #3a3a48;
}

body.dark .lea-table th:hover {
  color: #e0e0e0;
}

body.dark .lea-table td {
  color: #e0e0e0;
  border-bottom-color: #2e2e38;
}

body.dark .lea-table tbody tr:hover {
  background: #2a2a36;
}

body.dark .lea-stat-card {
  background: #2e2e38;
  border-color: #3a3a48;
}

body.dark .lea-stat-value {
  color: #e0e0e0;
}

body.dark .lea-stat-label {
  color: #94a3b8;
}

body.dark .lea-upload-zone {
  border-color: #444;
}

body.dark .lea-upload-zone:hover,
body.dark .lea-upload-zone.dragover {
  border-color: #ffe600;
  background: #2a2a36;
}

body.dark .lea-upload-text {
  color: #94a3b8;
}

body.dark .lea-insight-card {
  background: #2a2a36;
  color: #e0e0e0;
  border-left-color: #ffe600;
}

body.dark .lea-insight-card.insight-warn {
  background: #2a2518;
  border-left-color: #f59e0b;
}

body.dark .lea-insight-card.insight-danger {
  background: #2a1818;
  border-left-color: #dc2626;
}

body.dark .lea-insight-card .insight-label {
  color: #94a3b8;
}

body.dark .lea-empty-title {
  color: #94a3b8;
}

body.dark .lea-export-bar {
  background: #23232f;
}

body.dark .lea-compare-selects select {
  background: #2e2e38;
  border-color: #444;
  color: #e0e0e0;
}

body.dark .lea-compare-selects select:focus {
  border-color: #ffe600;
}

body.dark .lea-compare-selects label {
  color: #94a3b8;
}

/* Dark mode: three-column groups */
body.dark .lea-col-group-base { background: #1a2e1a; color: #86efac; border-bottom-color: #2d5a2d; }
body.dark .lea-col-group-compare { background: #1a1e2e; color: #93c5fd; border-bottom-color: #2d3a5a; }
body.dark .lea-row-new { background: #2a1818 !important; }
body.dark .lea-row-removed { background: #1a2e1a !important; }
body.dark .lea-row-maybe { background: #2a2518 !important; }
body.dark .lea-badge-match   { background: #1a2e1a; color: #86efac; }
body.dark .lea-badge-new     { background: #2a1818; color: #fca5a5; }
body.dark .lea-badge-removed { background: #1a1e2e; color: #93c5fd; }
body.dark .lea-badge-maybe   { background: #2a2518; color: #fde68a; }
body.dark .lea-change-added  { color: #fca5a5; }
body.dark .lea-change-removed { color: #86efac; }
body.dark .lea-insight-title { color: #e0e0e0; }
body.dark .lea-insight-body  { color: #94a3b8; }
body.dark .btn-sm { background: #2e2e38; border-color: #444; color: #e0e0e0; }
body.dark .btn-sm:hover { background: #3a3a4a; }

body.dark .lea-section-header {
  color: #e0e0e0;
}

body.dark .lea-section-header .lea-count-badge {
  background: #3a3a48;
  color: #94a3b8;
}

body.dark .lea-table-search {
  background: #2e2e38;
  border-color: #444;
  color: #e0e0e0;
}

body.dark .lea-table-search:focus {
  border-color: #ffe600;
}

body.dark .lea-row-warn {
  background: #2a2518 !important;
}

body.dark .lea-row-danger {
  background: #2a1818 !important;
}

body.dark .lea-confidence.high { background: #14532d; color: #bbf7d0; }
body.dark .lea-confidence.medium { background: #422006; color: #fde68a; }
body.dark .lea-confidence.low { background: #450a0a; color: #fecaca; }

body.dark .lea-table .cell-clickable {
  color: #60a5fa;
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 1024px) {
  .lea-layout {
    grid-template-columns: 1fr;
  }
  .lea-filters {
    position: static;
  }
}

@media (max-width: 768px) {
  .lea-tabs {
    gap: 16px;
    padding: 0 12px;
    overflow-x: auto;
  }
  .lea-tab {
    font-size: 12px;
  }
  .lea-stat-row {
    flex-direction: column;
  }
}
