/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface2: #f0f1f6;
  --border: #e2e4ed;
  --text: #1a1d2e;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-light: #eff6ff;
  --income: #16a34a;
  --income-bg: #f0fdf4;
  --expense: #dc2626;
  --expense-bg: #fef2f2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  font-size: 15px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }

/* ===== LAYOUT ===== */
#app { display: flex; flex-direction: column; min-height: 100vh; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky; top: 0; z-index: 100;
}

.logo { font-weight: 700; font-size: 1.1rem; letter-spacing: -.3px; display: flex; align-items: center; gap: .5rem; }
.logo-icon { width: 28px; height: 28px; background: var(--accent); border-radius: 6px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: .85rem; font-weight: 800; }

.header-meta { font-size: .8rem; color: var(--text-muted); display: flex; align-items: center; gap: 1rem; }
.balance-badge { background: var(--accent-light); color: var(--accent); padding: .25rem .75rem; border-radius: 20px; font-weight: 600; font-size: .8rem; }

.lang-switcher { display: flex; gap: .25rem; margin-left: 1rem; }
.lang-btn { padding: .25rem .6rem; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface2); color: var(--text-muted); font-size: .78rem; font-weight: 700; cursor: pointer; font-family: inherit; transition: all .15s; }
.lang-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.lang-btn:hover:not(.active) { background: var(--border); }

main { flex: 1; padding: 1.5rem 2rem; max-width: 1400px; margin: 0 auto; width: 100%; }

/* ===== UPLOAD SCREEN ===== */
#upload-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: calc(100vh - 56px);
  flex-direction: column; gap: 2rem;
}

.upload-card {
  background: var(--surface); border-radius: var(--radius); padding: 3rem;
  text-align: center; max-width: 480px; width: 100%;
  box-shadow: var(--shadow-md); border: 1px solid var(--border);
}

.upload-icon { font-size: 3rem; margin-bottom: 1rem; }
.upload-card h2 { font-size: 1.4rem; margin-bottom: .5rem; }
.upload-card p { color: var(--text-muted); font-size: .9rem; margin-bottom: 1.5rem; line-height: 1.6; }

.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 2rem; cursor: pointer; transition: all .2s;
  background: var(--surface2);
}
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--accent); background: var(--accent-light); }
.drop-zone input { display: none; }
.drop-zone label { cursor: pointer; display: block; }
.drop-zone .drop-text { color: var(--text-muted); font-size: .9rem; margin-top: .5rem; }
.drop-zone .btn-link { color: var(--accent); font-weight: 600; }

.upload-hint { font-size: .78rem; color: var(--text-muted); }

.privacy-notice {
  display: flex; align-items: center; gap: .5rem;
  background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: var(--radius-sm);
  color: #15803d; font-size: .82rem; font-weight: 600;
  padding: .6rem .9rem; margin-top: 1rem; text-align: left;
}

/* ===== DASHBOARD ===== */
#dashboard { display: none; flex-direction: column; gap: 1.5rem; }

/* ===== FILTERS BAR ===== */
.filters-bar {
  background: var(--surface); border-radius: var(--radius); padding: 1rem 1.25rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}

.filter-group { display: flex; align-items: center; gap: .5rem; }
.filter-group label { font-size: .8rem; font-weight: 600; color: var(--text-muted); white-space: nowrap; }

select, input[type="text"], input[type="date"] {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .4rem .75rem; font-size: .85rem; background: var(--surface);
  color: var(--text); outline: none; font-family: inherit;
  transition: border-color .15s;
}
select:focus, input:focus { border-color: var(--accent); }

.btn {
  padding: .45rem 1rem; border-radius: var(--radius-sm); border: none;
  font-size: .85rem; font-weight: 600; cursor: pointer; transition: all .15s;
  font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }

.spacer { flex: 1; }

/* ===== KPI CARDS ===== */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }

.kpi-card {
  background: var(--surface); border-radius: var(--radius); padding: 1.2rem 1.25rem;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: .25rem;
}
.kpi-label { font-size: .75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 1.5rem; font-weight: 700; letter-spacing: -.5px; }
.kpi-sub { font-size: .78rem; color: var(--text-muted); }
.kpi-value.income { color: var(--income); }
.kpi-value.expense { color: var(--expense); }
.kpi-value.neutral { color: var(--text); }
.kpi-trend { font-size: .78rem; font-weight: 600; }
.kpi-trend.up { color: var(--income); }
.kpi-trend.down { color: var(--expense); }

/* ===== CHARTS GRID ===== */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.charts-grid .chart-card.full { grid-column: 1 / -1; }

.chart-card {
  background: var(--surface); border-radius: var(--radius); padding: 1.25rem;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.chart-card h3 { font-size: .9rem; font-weight: 700; margin-bottom: 1rem; color: var(--text); }
.chart-card .chart-subtitle { font-size: .78rem; color: var(--text-muted); margin-top: -.75rem; margin-bottom: 1rem; }
.chart-wrap { position: relative; }

/* ===== TABLE ===== */
.table-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border); overflow: hidden;
}

.table-header {
  padding: 1rem 1.25rem; display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.table-header h3 { font-size: .9rem; font-weight: 700; }

.search-wrap { position: relative; display: flex; align-items: center; }
.search-wrap input { padding-left: 2rem; width: 220px; border-radius: var(--radius-sm) 0 0 var(--radius-sm); border-right: none; }
.search-wrap .search-icon { position: absolute; left: .6rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: .85rem; pointer-events: none; }
.search-case-btn {
  padding: .4rem .6rem; border: 1px solid var(--border); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface2); color: var(--text-muted); font-size: .78rem; font-weight: 700;
  cursor: pointer; font-family: monospace; white-space: nowrap; transition: all .15s;
  line-height: 1; height: 100%;
}
.search-case-btn:hover { background: var(--border); }
.search-case-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 900; }
.search-case-btn.active:hover { background: #1d4ed8; }
.amount-wrap { position: relative; }
.amount-wrap input { width: 90px; padding-left: 1.6rem; }
.amount-icon { position: absolute; left: .6rem; top: 50%; transform: translateY(-50%); font-style: normal; font-weight: 600; font-size: .85rem; color: var(--text-muted); pointer-events: none; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .83rem; }
thead tr { background: var(--surface2); }
th { padding: .6rem 1rem; text-align: left; font-size: .75rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; cursor: pointer; user-select: none; }
th:hover { color: var(--accent); }
th .sort-icon { margin-left: .25rem; opacity: .4; }
th.sorted .sort-icon { opacity: 1; color: var(--accent); }
td { padding: .65rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }

.amount-positive { color: var(--income); font-weight: 600; }
.amount-negative { color: var(--expense); font-weight: 600; }

.badge {
  display: inline-block; padding: .15rem .6rem; border-radius: 20px;
  font-size: .72rem; font-weight: 600; white-space: nowrap;
}
.badge-income { background: var(--income-bg); color: var(--income); }
.badge-expense { background: var(--expense-bg); color: var(--expense); }

tfoot td { padding: .6rem 1rem; border-top: 2px solid var(--border); background: var(--surface2); }

.table-footer {
  padding: .75rem 1.25rem; display: flex; align-items: center; justify-content: space-between;
  border-top: 1px solid var(--border); font-size: .8rem; color: var(--text-muted);
}
.pagination { display: flex; gap: .25rem; }
.page-btn {
  padding: .3rem .6rem; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: .8rem; font-family: inherit;
  transition: all .15s;
}
.page-btn:hover { background: var(--surface2); }
.page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.reset-filters-btn {
  padding: .4rem .8rem; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface2); color: var(--text-muted); font-size: .8rem; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all .15s; white-space: nowrap;
}
.reset-filters-btn:hover { background: var(--expense-bg); color: var(--expense); border-color: var(--expense); }
.table-footer-top { border-top: none; border-bottom: 1px solid var(--border); }

/* ===== QUICK SEARCH ===== */
.qs-cell { white-space: nowrap; padding-right: .5rem; }
.qs-btn {
  display: inline-block; margin: .1rem .15rem; padding: .15rem .5rem;
  border-radius: 20px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text-muted);
  font-size: .68rem; font-weight: 500; cursor: pointer;
  font-family: inherit; transition: all .15s;
  opacity: 0; pointer-events: none;
  max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  vertical-align: middle;
}
tr:hover .qs-btn { opacity: 1; pointer-events: auto; }
.qs-btn:hover { background: var(--accent-light); color: var(--accent); border-color: var(--accent); }

.filter-chart-hint {
  text-align: center; padding: 2rem; color: var(--text-muted);
  font-size: .85rem; font-style: italic;
}
.tabs { display: flex; gap: .25rem; border-bottom: 2px solid var(--border); margin-bottom: 1rem; }
.tab-btn { padding: .5rem 1rem; font-size: .85rem; font-weight: 600; color: var(--text-muted); background: none; border: none; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; font-family: inherit; }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-btn:hover { color: var(--text); }

/* ===== RANGE PILLS ===== */
.range-pills { display: flex; gap: .25rem; }
.range-pill { padding: .3rem .75rem; border-radius: 20px; font-size: .78rem; font-weight: 600; background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); cursor: pointer; transition: all .15s; font-family: inherit; }
.range-pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ===== EMPTY / LOADING ===== */
.empty-state { text-align: center; padding: 3rem; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 2rem; margin-bottom: .5rem; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  main { padding: 1rem; }
  .charts-grid { grid-template-columns: 1fr; }
  .charts-grid .chart-card.full { grid-column: 1; }
  header { padding: 0 1rem; }
}
@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .filters-bar { flex-direction: column; align-items: stretch; }
  .table-header { flex-direction: column; align-items: stretch; }
  .search-wrap input { width: 100%; }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #c0c4d0; }

/* ===== FILE UPLOAD BUTTON ===== */
.upload-new-btn { position: fixed; bottom: 1.5rem; right: 1.5rem; background: var(--accent); color: #fff; border: none; border-radius: 50px; padding: .65rem 1.25rem; font-size: .85rem; font-weight: 600; cursor: pointer; box-shadow: var(--shadow-md); font-family: inherit; transition: all .15s; z-index: 50; }
.upload-new-btn:hover { background: #1d4ed8; }
