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

  :root {
    --bg: #0d0f12;
    --bg2: #13161b;
    --bg3: #1a1e25;
    --bg4: #222731;
    --border: rgba(255,255,255,0.07);
    --border2: rgba(255,255,255,0.12);
    --text: #e8eaf0;
    --text2: #8b90a0;
    --text3: #565c6e;
    --accent: #4ade80;
    --accent2: #22c55e;
    --accent-dim: rgba(74,222,128,0.08);
    --accent-dim2: rgba(74,222,128,0.15);
    --red: #f87171;
    --red-dim: rgba(248,113,113,0.1);
    --amber: #fbbf24;
    --amber-dim: rgba(251,191,36,0.1);
    --blue: #60a5fa;
    --blue-dim: rgba(96,165,250,0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --mono: 'DM Mono', monospace;
    --sans: 'Sora', sans-serif;
  }

  html { font-size: 15px; }
  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    min-height: 100vh;
    line-height: 1.6;
  }

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

  .mobile-header { display: none; }
  .mobile-drawer-overlay { display: none; }

  .sidebar {
    width: 220px;
    min-height: 100vh;
    background: var(--bg2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
  }

  .sidebar-logo {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text3);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-bottom: 0.3rem;
  }
  .sidebar-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2rem;
  }

  .nav-label {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--text3);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
    padding-left: 0.5rem;
  }

  .nav-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.87rem;
    color: var(--text2);
    transition: all 0.15s;
    margin-bottom: 2px;
    border: 1px solid transparent;
    user-select: none;
  }
  .nav-item:hover { background: var(--bg3); color: var(--text); }
  .nav-item.active { background: var(--accent-dim2); color: var(--accent); border-color: rgba(74,222,128,0.2); }
  .nav-icon { width: 16px; height: 16px; opacity: 0.7; flex-shrink: 0; }
  .nav-item.active .nav-icon { opacity: 1; }

  .sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
  }
  .sidebar-month-btn {
    width: 100%;
    background: var(--bg3);
    border: 1px solid var(--border2);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.75rem;
    font-family: var(--sans);
    font-size: 0.82rem;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
  }
  .sidebar-month-btn:hover { background: var(--bg4); }
  .sidebar-month-label { font-family: var(--mono); font-size: 10px; color: var(--text3); display: block; margin-bottom: 2px; text-transform: uppercase; letter-spacing: 0.08em; }

  .main {
    margin-left: 220px;
    flex: 1;
    padding: 2rem 2.5rem;
    max-width: 1400px;
    width: 100%;
  }

  /* PAGES */
  .page { display: none; }
  .page.active { display: block; }

  /* HEADER */
  .page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 2rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
  }
  .page-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
  }
  .page-subtitle {
    font-size: 0.82rem;
    color: var(--text3);
    font-family: var(--mono);
    margin-top: 2px;
  }

  /* CARDS GRID */
  .cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.75rem;
  }

  .metric-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.25rem 1rem;
    transition: border-color 0.2s;
    overflow: hidden;
    min-width: 0;
  }
  .metric-card:hover { border-color: var(--border2); }
  .metric-card.saldo-card {
    cursor: pointer;
    border-color: var(--border2);
  }
  .metric-card.saldo-card:hover { border-color: var(--accent); }
  .metric-label {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--text3);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
  }
  .metric-value {
    font-size: clamp(1rem, 2.5vw, 1.75rem);
    font-weight: 600;
    font-family: var(--mono);
    color: var(--text);
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
  .metric-value.green { color: var(--accent); }
  .metric-value.red { color: var(--red); }
  .metric-value.amber { color: var(--amber); }
  .metric-value.blue { color: var(--blue); }
  .metric-sub {
    font-size: 0.75rem;
    color: var(--text3);
    margin-top: 0.3rem;
    font-family: var(--mono);
  }
  .metric-edit-hint {
    color: var(--text3);
    font-size: 10px;
    font-family: var(--mono);
    margin-top: 0.15rem;
  }

  /* TWO COLUMN */
  .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin-bottom: 1.25rem; }
  .three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1.25rem; margin-bottom: 1.25rem; }

  /* PANEL */
  .panel {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
  }
  .panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
  }
  .panel-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
  }
  .panel-body { padding: 0.5rem 0; }

  /* TABLE ROWS */
  .table-row {
    display: flex;
    align-items: center;
    padding: 0.65rem 1.25rem;
    border-bottom: 1px solid var(--border);
    gap: 0.75rem;
    transition: background 0.1s;
  }
  .table-row:last-child { border-bottom: none; }
  .table-row:hover { background: var(--bg3); }
  .row-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
  }
  .row-name { flex: 1; font-size: 0.87rem; color: var(--text); }
  .row-date { font-family: var(--mono); font-size: 0.78rem; color: var(--text3); min-width: 60px; }
  .row-val { font-family: var(--mono); font-size: 0.87rem; font-weight: 500; min-width: 100px; text-align: right; }
  .row-val.green { color: var(--accent); }
  .row-val.red { color: var(--red); }
  .row-val.amber { color: var(--amber); }
  .row-actions { display: flex; gap: 4px; }
  .btn-icon {
    background: none; border: none; cursor: pointer;
    color: var(--text3); padding: 3px 5px; border-radius: 4px;
    font-size: 13px; transition: all 0.1s; line-height: 1;
  }
  .btn-icon:hover { background: var(--bg4); color: var(--text); }

  /* BADGE */
  .badge {
    font-family: var(--mono);
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 20px;
    font-weight: 500;
    letter-spacing: 0.05em;
  }
  .badge-green { background: var(--accent-dim2); color: var(--accent); }
  .badge-red { background: var(--red-dim); color: var(--red); }
  .badge-amber { background: var(--amber-dim); color: var(--amber); }
  .badge-blue { background: var(--blue-dim); color: var(--blue); }
  .badge-gray { background: var(--bg4); color: var(--text2); }

  /* FLUXO */
  .fluxo-row {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
  }
  .fluxo-row:last-child { border-bottom: none; }
  .fluxo-dia {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text3);
    min-width: 70px;
  }
  .fluxo-desc { flex: 1; font-size: 0.85rem; color: var(--text); }
  .fluxo-mov {
    font-family: var(--mono);
    font-size: 0.85rem;
    font-weight: 600;
    min-width: 100px;
    text-align: right;
  }
  .fluxo-saldo {
    font-family: var(--mono);
    font-size: 0.78rem;
    color: var(--text3);
    min-width: 110px;
    text-align: right;
  }
  .fluxo-row.quinzena-break {
    background: transparent;
    padding: 0.4rem 1.25rem 0.25rem;
    border-top: 1px solid var(--border);
    border-bottom: none;
  }
  .quinzena-label {
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }

  /* BUTTONS */
  .btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-family: var(--sans);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    border: none;
  }
  .btn-primary {
    background: var(--accent);
    color: #0d1a10;
  }
  .btn-primary:hover { background: var(--accent2); }
  .btn-ghost {
    background: var(--bg3);
    border: 1px solid var(--border2);
    color: var(--text2);
  }
  .btn-ghost:hover { background: var(--bg4); color: var(--text); }
  .btn-danger {
    background: var(--red-dim);
    border: 1px solid rgba(248,113,113,0.2);
    color: var(--red);
  }
  .btn-danger:hover { background: rgba(248,113,113,0.18); }

  /* MODAL */
  .modal-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.65);
    z-index: 1000;
    align-items: center;
    justify-content: center;
  }
  .modal-overlay.open { display: flex; }
  .modal {
    background: var(--bg2);
    border: 1px solid var(--border2);
    border-radius: var(--radius);
    padding: 1.75rem;
    width: 420px;
    max-width: 95vw;
  }
  .modal-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: var(--text);
  }
  .form-group { margin-bottom: 1rem; }
  .form-label {
    display: block;
    font-size: 0.78rem;
    color: var(--text2);
    margin-bottom: 0.35rem;
    font-family: var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }
  .form-input {
    width: 100%;
    background: var(--bg3);
    border: 1px solid var(--border2);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 0.55rem 0.75rem;
    font-family: var(--sans);
    font-size: 0.87rem;
    transition: border-color 0.15s;
    outline: none;
  }
  .form-input:focus { border-color: var(--accent); }
  .form-select {
    width: 100%;
    background: var(--bg3);
    border: 1px solid var(--border2);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 0.55rem 0.75rem;
    font-family: var(--sans);
    font-size: 0.87rem;
    outline: none;
    cursor: pointer;
  }
  .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
  .modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.5rem; }

  /* QUINZENA BARS */
  .quinzena-bar-wrap { padding: 1.25rem; }
  .q-bar-label { display: flex; justify-content: space-between; margin-bottom: 0.4rem; }
  .q-bar-name { font-size: 0.82rem; color: var(--text2); }
  .q-bar-val { font-family: var(--mono); font-size: 0.82rem; font-weight: 500; }
  .q-bar-track {
    height: 6px;
    background: var(--bg4);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 1rem;
  }
  .q-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
  }

  /* PROGRESS BAR */
  .progress-wrap { margin-bottom: 0.35rem; }
  .progress-track { height: 4px; background: var(--bg4); border-radius: 2px; overflow: hidden; margin-top: 6px; }
  .progress-fill { height: 100%; border-radius: 2px; transition: width 0.4s; }

  /* ALERTA */
  .alert {
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    font-size: 0.82rem;
    margin-bottom: 1rem;
    border-left: 3px solid;
  }
  .alert-warn { background: var(--amber-dim); border-color: var(--amber); color: var(--amber); }
  .alert-ok { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
  .alert-info { background: var(--blue-dim); border-color: var(--blue); color: var(--blue); }

  /* TOAST */
  #toast-container {
    position: fixed;
    right: 1.5rem;
    bottom: 1.5rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-end;
    pointer-events: none;
  }
  .toast {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--blue);
    border-radius: var(--radius-sm);
    color: var(--blue);
    font-family: var(--mono);
    font-size: 0.83rem;
    padding: 0.75rem 1.25rem;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    box-shadow: 0 10px 30px rgba(0,0,0,0.22);
    pointer-events: auto;
  }
  .toast.show {
    opacity: 1;
    transform: translateY(0);
  }
  .toast-success { border-left-color: var(--accent); color: var(--accent); }
  .toast-error { border-left-color: var(--red); color: var(--red); }
  .toast-info { border-left-color: var(--blue); color: var(--blue); }

  /* SCROLLBAR */
  ::-webkit-scrollbar { width: 5px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }

  /* EMPTY STATE */
  .empty-state {
    text-align: center;
    padding: 2rem;
    color: var(--text3);
    font-size: 0.85rem;
  }

  /* MONTH SELECTOR */
  .month-display {
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }
  .month-nav-btn {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--text2);
    width: 28px; height: 28px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.1s;
  }
  .month-nav-btn:hover { background: var(--bg4); color: var(--text); }

  .tag-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 1rem 1.25rem; }

  /* RESPONSIVE */
  @media (max-width: 1024px) {
    .metric-value { font-size: 1.35rem; }
  }

  @media (max-width: 768px) {
    .mobile-header {
      position: fixed;
      top: 0; left: 0; right: 0;
      z-index: 90;
      height: 52px;
      background: var(--bg2);
      border-bottom: 1px solid var(--border);
      display: grid;
      grid-template-columns: 52px 1fr 52px;
      align-items: center;
      padding: 0 0.5rem;
    }
    .mobile-menu-btn {
      background: none;
      border: none;
      color: var(--text);
      cursor: pointer;
      font-size: 20px;
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: var(--radius-sm);
    }
    .mobile-menu-btn:hover { background: var(--bg3); }
    .mobile-header-title {
      color: var(--text);
      font-size: 14px;
      font-weight: 600;
      text-align: center;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      padding: 0 0.75rem;
    }
    .mobile-header .month-nav-btn { justify-self: end; }
    .mobile-drawer-overlay {
      display: block;
      position: fixed;
      inset: 0;
      background: rgba(0,0,0,0.6);
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.25s ease;
      z-index: 95;
    }
    .mobile-drawer-overlay.open {
      opacity: 1;
      pointer-events: auto;
    }
    .sidebar {
      width: 220px;
      transform: translateX(-100%);
      transition: transform 0.25s ease;
      z-index: 100;
    }
    .sidebar.open { transform: translateX(0); }
    .main {
      margin-left: 0;
      padding: 4.25rem 1rem 1.5rem;
      max-width: none;
      width: 100%;
    }
    .page-header {
      align-items: flex-start;
      gap: 1rem;
      flex-direction: column;
    }
    .page-header > div:last-child {
      width: 100%;
      flex-wrap: wrap;
      justify-content: space-between;
    }
    .cards-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
    .two-col { grid-template-columns: 1fr; }
    .three-col { grid-template-columns: 1fr; }
    .panel { overflow-x: auto; }
    .table-row { min-width: 480px; }
    .fluxo-row { min-width: 560px; }
    #historico-table .table-row,
    #comparacao-direta-body .table-row {
      min-width: 760px;
    }
    .cards-grid .metric-card { min-width: 0; }
    .modal { width: 92vw; }
  }

  @media (max-width: 480px) {
    html { font-size: 14px; }
    .main { padding-left: 0.75rem; padding-right: 0.75rem; }
    .page-header { margin-bottom: 1.25rem; padding-bottom: 1rem; }
    .page-header h1 { font-size: 1.25rem; }
    .cards-grid { gap: 0.75rem; }
    .metric-card { padding: 1rem; }
    .metric-value { font-size: 1.25rem; }
    .form-row { grid-template-columns: 1fr; }
    .modal { padding: 1.25rem; }
  }

  /* BACKUP */
  .sidebar-backup-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 8px; }
  .sidebar-backup-btn {
    flex: 1 1 auto;
    min-width: fit-content;
    white-space: nowrap;
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--text2);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.5rem;
    font-family: var(--sans);
    font-size: 0.75rem;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
  }
  .sidebar-backup-btn:hover { background: var(--bg4); color: var(--text); }

  /* TEMA CLARO */
  [data-theme="light"] {
    --bg: #f5f5f2;
    --bg2: #ffffff;
    --bg3: #f0f0ed;
    --bg4: #e5e5e2;
    --border: rgba(0,0,0,0.08);
    --border2: rgba(0,0,0,0.14);
    --text: #1a1a1a;
    --text2: #555555;
    --text3: #999999;
    --amber: #b45309;
    --amber-dim: #fef3c7;
  }