@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: light;

  /* Core palette - Modern Slate & Indigo */
  --bg:          #F8FAFC; /* Slate 50 */
  --bg-strong:   #F1F5F9; /* Slate 100 */
  --surface:     #FFFFFF;
  --surface-soft:#F8FAFC;

  /* Ink / Text */
  --ink:         #0F172A; /* Slate 900 */
  --ink-2:       #334155; /* Slate 700 */
  --muted:       #64748B; /* Slate 500 */
  --faint:       #94A3B8; /* Slate 400 */

  /* Brand / Primary — Indigo */
  --primary:         #4F46E5;
  --primary-hover:   #4338CA;
  --primary-soft:    #EEF2FF;
  --primary-border:  #C7D2FE;

  /* Positive / Green */
  --green:       #059669;
  --green-mid:   #10B981;
  --green-soft:  #ECFDF5;
  --green-border:#A7F3D0;

  /* Negative / Red */
  --red:         #DC2626;
  --red-soft:    #FEF2F2;
  --red-border:  #FECACA;

  /* Warning / Gold */
  --gold:        #D97706;
  --gold-soft:   #FFFBEB;
  --gold-border: #FDE68A;

  /* Info / Blue */
  --blue:        #2563EB;
  --blue-soft:   #EFF6FF;

  /* Structure */
  --line:        #E2E8F0;
  --line-strong: #CBD5E1;

  /* Elevation (Crisp, modern shadows) */
  --shadow-xs:   0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-sm:   0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-md:   0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-lg:   0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);

  /* Radius (More corporate, less round) */
  --r-xs:  6px;
  --r-sm:  8px;
  --r-md:  12px;
  --r-lg:  16px;
  --r-xl:  24px;

  /* Type */
  --font: "Inter", system-ui, -apple-system, sans-serif;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4, p { margin-top: 0; }

/* ── Shell ─────────────────────────────────────────────────── */
.app-shell {
  width: min(1500px, calc(100% - 48px));
  margin: 0 auto;
  padding: 32px 0 64px;
}

/* ── Hero (Dark Mode Premium) ──────────────────────────────── */
.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 340px);
  gap: 32px;
  align-items: stretch;
  padding: 40px;
  background: linear-gradient(145deg, #0F172A 0%, #1E293B 100%);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
  color: #FFFFFF;
}

/* Accent Glow */
.hero-panel::before {
  content: "";
  position: absolute;
  top: -50px; left: -50px;
  width: 300px; height: 300px;
  background: radial-gradient(circle, rgba(79, 70, 229, 0.4) 0%, transparent 70%);
  pointer-events: none;
}

.hero-copy-block { min-width: 0; z-index: 1; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
  color: #818CF8;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.eyebrow::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #818CF8;
  box-shadow: 0 0 8px #818CF8;
}

h1 {
  max-width: 800px;
  margin-bottom: 16px;
  font-size: clamp(2rem, 3.5vw, 3rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: #FFFFFF;
}

.hero-copy {
  max-width: 600px;
  margin-bottom: 0;
  color: #94A3B8;
  font-size: 1rem;
  line-height: 1.6;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 32px;
}

/* Config Selector in Dark Hero */
.upload-config span { color: #94A3B8; }
.upload-config select {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #FFFFFF;
}
.upload-config select option { color: var(--ink); }

/* Upload box (Glassmorphism) */
.upload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  width: 100%;
}

.upload-box {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 72px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-left: 4px solid var(--bank-color, var(--primary));
  border-radius: var(--r-md);
  backdrop-filter: blur(10px);
  cursor: pointer;
  transition: all 200ms ease;
}

.upload-box:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
  box-shadow: 0 10px 20px -10px rgba(0,0,0,0.5);
}

.upload-icon {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: var(--r-sm);
  color: #fff;
  font-size: 1rem;
  font-weight: 800;
}

.upload-box strong { display: block; font-size: 0.9rem; color: #F8FAFC; }
.upload-box small  { display: block; margin-top: 4px; color: #94A3B8; font-size: 0.75rem; }

.upload-box input { position: absolute; opacity: 0; pointer-events: none; }

/* Hero side card (Glassmorphism) */
.hero-card {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 28px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--r-lg);
  backdrop-filter: blur(12px);
  z-index: 1;
}

.hero-card-label {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 6px 12px;
  border-radius: var(--r-xs);
  background: rgba(255, 255, 255, 0.1);
  color: #FFFFFF;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.hero-card-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.hero-card-metrics div {
  padding: 16px;
  border-radius: var(--r-sm);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.hero-card-metrics strong {
  display: block;
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1;
  color: #FFFFFF;
  letter-spacing: -0.02em;
}

.hero-card-metrics span {
  display: block;
  margin-top: 8px;
  color: #94A3B8;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hero-card p { color: #CBD5E1; font-size: 0.85rem; }

/* ── Toolbar ───────────────────────────────────────────────── */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: 28px 0;
}

.toolbar-actions { display: flex; gap: 12px; flex-wrap: wrap; }

.period-control {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--ink-2);
  font-size: 0.85rem;
  font-weight: 600;
}

/* Segmented control */
.segmented {
  display: flex;
  padding: 4px;
  border-radius: var(--r-sm);
  background: var(--line);
  gap: 4px;
}

.segment {
  min-height: 36px;
  padding: 0 20px;
  border: none;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 150ms ease;
}

.segment:hover { color: var(--ink); }

.segment.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
}

/* Buttons */
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 20px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 150ms ease;
}

.ghost-button:hover {
  border-color: var(--muted);
  background: var(--bg-strong);
  box-shadow: var(--shadow-xs);
}

.ghost-button:active { transform: translateY(1px); box-shadow: none; }

.ghost-button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #FFFFFF;
}
.ghost-button.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: var(--shadow-md);
}

.ghost-button.danger {
  border-color: transparent;
  background: rgba(255, 255, 255, 0.1);
  color: #FDA4AF;
}
.ghost-button.danger:hover { background: rgba(220, 38, 38, 0.2); color: #FECACA; }

/* ── Panels & Cards ────────────────────────────────────────── */
.filters-panel,
.kpi-card,
.category-card,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.filters-panel { padding: 32px; margin-bottom: 24px; }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  margin-bottom: 6px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.panel-header p { margin-bottom: 0; color: var(--muted); font-size: 0.85rem; }

/* ── Filters ───────────────────────────────────────────────── */
.filters-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr)) minmax(0, 1.5fr);
  gap: 24px;
  align-items: start;
}

.field-block { display: grid; gap: 8px; }

.field-block > span {
  color: var(--ink-2);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.field-block small { color: var(--faint); font-size: 0.75rem; line-height: 1.4; }

.field-block select,
.field-block input {
  width: 100%;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  outline: none;
  font-size: 0.9rem;
  transition: all 200ms;
}

.field-block select:focus,
.field-block input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.field-block select[multiple] { min-height: 200px; padding: 12px; }
.field-block select[multiple] option { padding: 6px; border-radius: 4px; margin-bottom: 2px; }
.field-block select[multiple] option:checked { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

.filters-side-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

.filters-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

/* ── KPI Grid ──────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }

.kpi-card {
  padding: 24px;
  position: relative;
  transition: transform 200ms ease, box-shadow 200ms ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.kpi-card span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.kpi-card strong {
  display: block;
  margin-top: 12px;
  color: var(--ink);
  font-size: clamp(1.5rem, 2vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
}

/* ── Category Cards ────────────────────────────────────────── */
.category-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }

.category-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 130px;
  padding: 20px;
  border-top: 4px solid var(--line-strong);
}

.category-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.category-card.revenue { border-top-color: var(--green-mid); }
.category-card.expense { border-top-color: var(--red); }
.category-card.cost    { border-top-color: var(--gold); }
.category-card.other   { border-top-color: var(--primary); }

.category-card header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.category-card h3 { margin: 0; font-size: 0.85rem; font-weight: 700; color: var(--ink-2); line-height: 1.3; }
.category-card small { background: var(--bg-strong); color: var(--muted); padding: 2px 6px; border-radius: 4px; font-size: 0.7rem; font-weight: 600; }
.category-card strong { color: var(--ink); font-size: clamp(1.2rem, 1.7vw, 1.5rem); font-weight: 800; letter-spacing: -0.02em; }
.category-card p { margin: auto 0 0 0; color: var(--muted); font-size: 0.75rem; font-weight: 500; }

/* ── Content layout ────────────────────────────────────────── */
.content-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(340px, 0.8fr); gap: 24px; }
.panel { min-width: 0; }
.dre-panel, .transactions-panel { overflow: hidden; }

/* ── Tables ────────────────────────────────────────────────── */
.table-wrap { overflow: auto; }
table { width: 100%; min-width: 720px; border-collapse: separate; border-spacing: 0; }
th, td { padding: 14px 20px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }

th:first-child, td:first-child,
.transactions-panel th:nth-child(2), .transactions-panel td:nth-child(2),
.transactions-panel th:nth-child(3), .transactions-panel td:nth-child(3),
.transactions-panel th:nth-child(4), .transactions-panel td:nth-child(4),
.transactions-panel th:nth-child(5), .transactions-panel td:nth-child(5) {
  text-align: left;
}

th {
  background: var(--bg-strong);
  color: var(--ink-2);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  position: sticky; top: 0; z-index: 10;
}

td { font-size: 0.85rem; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--ink-2); }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background 150ms; }
tbody tr:hover td { background: var(--surface-soft); }

.row-total td { background: var(--primary-soft) !important; color: var(--primary); font-weight: 700; font-size: 0.85rem; }
.row-positive { color: var(--green) !important; font-weight: 700; }
.row-negative { color: var(--red)   !important; font-weight: 700; }

/* ── Chart ─────────────────────────────────────────────────── */
.chart-box { position: relative; min-height: 420px; padding: 24px; }
.chart-box canvas { width: 100% !important; height: 380px !important; }
.chart-fallback { display: grid; min-height: 380px; place-items: center; padding: 24px; border: 1px dashed var(--line-strong); border-radius: var(--r-md); color: var(--muted); font-weight: 500; background: var(--surface-soft); }

.transactions-panel { margin-top: 24px; }
.compact table { min-width: 1100px; }

/* ── File chips & pills ────────────────────────────────────── */
.file-list { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 6px; background: rgba(255, 255, 255, 0.1); color: #E2E8F0; font-size: 0.75rem; font-weight: 600; border: 1px solid rgba(255,255,255,0.1); }

.category-pill { display: inline-flex; align-items: center; min-height: 26px; padding: 0 10px; border-radius: 6px; background: var(--bg-strong); color: var(--ink-2); font-size: 0.75rem; font-weight: 600; }
.category-pill.revenue { background: var(--green-soft); color: var(--green-mid); }
.category-pill.cost    { background: var(--gold-soft); color: var(--gold); }
.category-pill.expense { background: var(--red-soft);  color: var(--red); }
.category-pill.other   { background: var(--primary-soft); color: var(--primary); }

.cnpj-pill { display: inline-flex; align-items: center; gap: 6px; min-height: 26px; padding: 0 10px; border-radius: 6px; background: var(--surface); color: var(--ink); font-size: 0.75rem; font-weight: 600; border: 1px solid var(--line-strong); }
.cnpj-pill.is-clickable { cursor: pointer; transition: all 150ms; }
.cnpj-pill.is-clickable:hover { background: var(--bg-strong); border-color: var(--muted); }

/* ── Toast de notificação ──────────────────────────────────── */
.toast { position: fixed; bottom: 32px; right: 32px; z-index: 1000; max-width: 400px; padding: 16px 20px; border-radius: var(--r-md); background: var(--ink); color: #fff; font-size: 0.85rem; font-weight: 500; line-height: 1.5; box-shadow: var(--shadow-lg); pointer-events: none; opacity: 0; transform: translateY(16px); transition: all 300ms cubic-bezier(0.16, 1, 0.3, 1); }
.toast--visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.toast--error   { background: var(--red); }
.toast--warning { background: var(--gold); color: var(--ink); }
.toast--success { background: var(--green); }

/* ── Panel header especiais ────────────────────────────────── */
.dre-panel .panel-header, .transactions-panel .panel-header { padding: 24px 28px 0; border-bottom: none; margin-bottom: 12px; }

/* ── Atribuição de categoria inline ────────────────────────── */
.row-uncategorized td { background: var(--gold-soft); }
.row-uncategorized:hover td { background: #FEF3C7 !important; }

.category-inline-select { width: 100%; min-width: 180px; height: 32px; padding: 0 12px; border: 1px solid var(--gold); border-radius: var(--r-xs); background: var(--surface); color: var(--ink); font-size: 0.8rem; font-weight: 600; cursor: pointer; outline: none; transition: all 150ms; }
.category-inline-select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }

.category-pill.is-clickable { cursor: pointer; transition: all 150ms; }
.category-pill.is-clickable:hover { filter: brightness(0.95); transform: scale(0.98); }

/* ── Modais ────────────────────────────────────────────────── */
.rule-modal { position: absolute; top: var(--modal-top, 0); left: var(--modal-left, 0); z-index: 200; width: 360px; padding: 20px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); box-shadow: var(--shadow-lg); animation: modal-in 200ms cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes modal-in { from { opacity: 0; transform: translateY(-8px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.rule-modal__msg { margin: 0 0 16px; font-size: 0.85rem; line-height: 1.6; color: var(--ink-2); }
.rule-modal__msg em { font-style: normal; font-weight: 700; color: var(--ink); background: var(--bg-strong); padding: 2px 4px; border-radius: 4px; }
.rule-modal__actions { display: flex; gap: 10px; }
.rule-modal__actions .ghost-button { flex: 1; min-height: 38px; font-size: 0.8rem; }

.modal-overlay { position: fixed; inset: 0; z-index: 9999; background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 24px; animation: fade-in 200ms ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.rateio-modal { width: 100%; max-width: 460px; background: var(--surface); border-radius: var(--r-lg); padding: 32px; box-shadow: var(--shadow-lg); animation: modal-in 250ms cubic-bezier(0.16, 1, 0.3, 1); }
.rateio-inputs { display: grid; gap: 16px; margin: 24px 0; }
.rateio-summary { margin-top: 20px; padding: 16px; border-radius: var(--r-sm); background: var(--bg-strong); display: flex; justify-content: space-between; align-items: center; font-size: 0.9rem; font-weight: 600; color: var(--ink-2); }
.rateio-summary strong { font-size: 1.1rem; }

/* ── Empty state ───────────────────────────────────────────── */
.empty-state { padding: 40px !important; color: var(--muted) !important; text-align: center !important; background: var(--surface-soft) !important; font-size: 0.9rem !important; font-weight: 500; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 1140px) {
  .hero-panel, .content-grid, .filters-grid, .kpi-grid, .category-grid { grid-template-columns: 1fr; }
  .filters-side-grid { grid-template-columns: 1fr 1fr; }
  .hero-card { order: -1; margin-bottom: 16px; }
}

@media (max-width: 780px) {
  .app-shell { width: 100%; padding: 0 0 40px 0; }
  .hero-panel { padding: 24px; border-radius: 0; margin-bottom: 16px; }
  .filters-panel { padding: 20px; border-radius: 0; border-left: none; border-right: none; }
  h1 { font-size: clamp(1.8rem, 8vw, 2.4rem); }
  .hero-actions, .toolbar, .filters-actions, .toolbar-actions { flex-direction: column; align-items: stretch; }
  .upload-box { min-height: auto; }
  .period-control { flex-direction: column; align-items: flex-start; }
  .segmented, .segment, .ghost-button { width: 100%; }
  .filters-side-grid { grid-template-columns: 1fr; }
  .field-block select[multiple] { min-height: 180px; }
  th, td { padding: 12px 16px; }
  .chart-box { min-height: 320px; padding: 16px; }
  .chart-box canvas { height: 280px !important; }
}