/* Budget IQ — Modern Responsive Dark UI */
:root {
  --bg: #0b1120;
  --bg-card: #111827;
  --bg-elevated: #1e293b;
  --border: #1f2937;
  --border-light: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #10b981;
  --primary-hover: #059669;
  --accent: #0ea5e9;
  --danger: #f43f5e;
  --warning: #f59e0b;
  --radius: 14px;
  --radius-sm: 10px;
}

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

html, body {
  overflow-x: hidden;
  max-width: 100%;
  touch-action: pan-y;
}

body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--text);
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

/* Layout */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 248px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 16px;
}

.brand img {
  width: 34px;
  height: 34px;
}

.brand-title {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.nav-btn.active {
  background: rgba(16, 185, 129, 0.14);
  color: var(--primary);
}

.nav-icon {
  font-size: 1.1rem;
  width: 22px;
  text-align: center;
}

.sidebar-footer {
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sync-pill {
  font-size: 0.78rem;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgba(148, 163, 184, 0.08);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.sync-pill.connected {
  background: rgba(16, 185, 129, 0.12);
  color: #6ee7b7;
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: 248px;
  padding: 24px 28px 96px;
  max-width: 1220px;
  width: 100%;
}

.demo-banner {
  background: linear-gradient(90deg, rgba(14, 165, 233, 0.14), rgba(16, 185, 129, 0.14));
  border: 1px solid rgba(14, 165, 233, 0.3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.86rem;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.86rem;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--primary);
  color: #022c22;
}

.btn-primary:hover {
  background: var(--primary-hover);
  color: #fff;
}

.btn-secondary {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  color: var(--text);
}

.btn-secondary:hover {
  background: #273549;
}

.btn-danger {
  background: rgba(244, 63, 94, 0.14);
  color: #fda4af;
  border: 1px solid rgba(244, 63, 94, 0.25);
}

.btn-danger:hover {
  background: rgba(244, 63, 94, 0.25);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.78rem;
}

/* Cards & Grids */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.card-title {
  font-size: 0.96rem;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

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

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.kpi-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 6px;
}

.kpi-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.text-green { color: #34d399; }
.text-red { color: #fb7185; }
.text-sky { color: #38bdf8; }
.text-amber { color: #fbbf24; }
.text-muted { color: var(--text-muted); }

/* Accounts strip */
.accounts-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 18px;
}

.account-chip {
  min-width: 195px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  flex-shrink: 0;
}

.account-chip.bourso {
  border-color: rgba(14, 165, 233, 0.35);
}

.account-chip-name {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.account-chip-bal {
  font-size: 1.2rem;
  font-weight: 700;
  margin-top: 6px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-green { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.badge-amber { background: rgba(245, 158, 11, 0.16); color: #fbbf24; }
.badge-red { background: rgba(244, 63, 94, 0.16); color: #fda4af; }
.badge-sky { background: rgba(14, 165, 233, 0.16); color: #38bdf8; }
.badge-slate { background: rgba(148, 163, 184, 0.14); color: #cbd5e1; }

/* Lists & Transactions */
.tx-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tx-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s;
}

.tx-row:hover {
  border-color: var(--border-light);
}

.tx-left {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  flex: 1;
}

.tx-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
  background: var(--bg-elevated);
}

.tx-info {
  min-width: 0;
}

.tx-label {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-meta {
  font-size: 0.77rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 2px;
}

.tx-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.tx-amount {
  font-weight: 700;
  font-size: 0.95rem;
  text-align: right;
  min-width: 82px;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.09);
  color: var(--text);
}

/* Filters & Forms */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.input, .select, .textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  outline: none;
  width: 100%;
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
}

.filters-bar .input, .filters-bar .select {
  width: auto;
  min-width: 140px;
  flex: 1;
}

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group.full {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Progress bars */
.budget-row {
  margin-bottom: 14px;
}

.budget-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.86rem;
  margin-bottom: 6px;
  gap: 8px;
}

.progress-track {
  height: 8px;
  background: var(--bg-elevated);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.25s;
}

/* Charts */
.donut-layout {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.donut-svg {
  width: 175px;
  height: 175px;
  flex-shrink: 0;
}

.donut-legend {
  flex: 1;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.83rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend-val {
  font-weight: 600;
}

.legend-val small {
  color: var(--text-muted);
  font-weight: 400;
}

.bar-legend {
  display: flex;
  gap: 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.bar-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
}

.bar-svg {
  width: 100%;
  height: auto;
}

/* Reconciliation */
.dropzone {
  border: 2px dashed var(--border-light);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  background: rgba(255, 255, 255, 0.015);
  transition: border-color 0.15s, background 0.15s;
}

.dropzone.dragover {
  border-color: var(--primary);
  background: rgba(16, 185, 129, 0.08);
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
}

.tab-btn.active {
  background: var(--bg-elevated);
  color: var(--text);
}

.reconcile-section {
  margin-top: 16px;
}

.reconcile-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.02);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.reconcile-item.diff {
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.05);
}

/* Autocomplete dropdown */
.autocomplete-wrap {
  position: relative;
}

.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: #0f172a;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55);
  max-height: 210px;
  overflow-y: auto;
  z-index: 75;
}

.autocomplete-list.hidden {
  display: none;
}

.autocomplete-item {
  padding: 9px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 0.86rem;
}

.autocomplete-item:hover {
  background: rgba(16, 185, 129, 0.14);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h2 {
  font-size: 1.1rem;
}

.type-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.type-switch button {
  padding: 9px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-weight: 600;
}

.type-switch button.active-expense { background: rgba(244, 63, 94, 0.2); color: #fda4af; }
.type-switch button.active-income { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; }
.type-switch button.active-transfer { background: rgba(14, 165, 233, 0.2); color: #7dd3fc; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  border: 1px solid var(--primary);
  color: var(--text);
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  z-index: 80;
  font-size: 0.88rem;
  font-weight: 500;
  transition: opacity 0.2s;
}

.toast.hidden {
  display: none;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 24px 12px;
  font-size: 0.88rem;
}

/* Preview table */
.table-wrap {
  overflow-x: auto;
  margin-top: 10px;
}

table.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

table.mini-table th, table.mini-table td {
  text-align: left;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.mini-table th {
  color: var(--text-muted);
  font-weight: 600;
}

/* Mobile bottom bar & FAB */
.mobile-nav {
  display: none;
}

.fab {
  display: none;
}

@media (max-width: 860px) {
  .sidebar {
    display: none;
  }
  .app-shell {
    overflow-x: hidden;
    max-width: 100vw;
  }
  .main-content {
    margin-left: 0;
    padding: 14px 12px 110px;
    max-width: 100vw;
    overflow-x: hidden;
  }
  .header-actions {
    width: 100%;
  }
  .header-actions .select {
    width: 100% !important;
    min-width: 0 !important;
  }
  .tx-row {
    flex-wrap: wrap;
    gap: 8px;
  }
  .tx-right {
    width: 100%;
    justify-content: flex-end;
  }
  .grid-3, .grid-2 {
    grid-template-columns: 1fr;
  }
  .modal-backdrop {
    padding: 8px;
  }
  .modal {
    padding: 14px;
    max-height: 94vh;
  }
  .modal-header {
    margin-bottom: 10px;
  }
  .type-switch {
    margin-bottom: 10px;
  }
  .type-switch button {
    padding: 7px 6px;
    font-size: 0.84rem;
  }
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .form-group {
    gap: 3px;
  }
  .form-group label {
    font-size: 0.74rem;
  }
  .modal .input, .modal .select {
    padding: 7px 9px;
    font-size: 0.86rem;
  }
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(17, 24, 39, 0.96);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    z-index: 40;
    padding: 6px 4px 10px;
    justify-content: space-around;
  }
  .mobile-nav button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 0.66rem;
    color: var(--text-muted);
    padding: 4px 6px;
  }
  .mobile-nav button.active {
    color: var(--primary);
  }
  .mobile-nav .m-ico {
    font-size: 1.15rem;
  }
  .fab {
    display: flex;
    position: fixed;
    right: 16px;
    bottom: 72px;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--primary);
    color: #022c22;
    font-size: 1.8rem;
    font-weight: 700;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 24px rgba(16, 185, 129, 0.35);
    z-index: 45;
  }
  .toast {
    bottom: 82px;
    right: 14px;
    left: 14px;
  }
}
