:root {
  --bg: #0e1116;
  --panel: #161b22;
  --border: #262c36;
  --text: #e6e6e6;
  --muted: #8b949e;
  --green: #22c55e;
  --red: #ef4444;
  --accent: #3b82f6;
  --panel-alpha: 1;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
}
.login-card {
  background: rgba(22, 27, 34, var(--panel-alpha));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 340px;
  text-align: center;
}
.login-card h1 {
  margin: 0 0 4px;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}
.login-card input {
  width: 100%;
  padding: 12px;
  margin: 16px 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0e1116;
  color: var(--text);
  font-size: 16px;
}
.error { color: var(--red); min-height: 20px; font-size: 14px; }

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
}
.btn-primary { background: var(--green); color: #0e1116; }
.btn-primary.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-sm { padding: 8px 16px; font-size: 14px; }

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

.sidebar {
  width: 240px;
  min-width: 240px;
  background: rgba(22, 27, 34, var(--panel-alpha));
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar h1 {
  margin: 0;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-nav button {
  width: 100%;
  text-align: left;
}
.month-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 4px;
}
.month-nav select { width: 100%; font-size: 13px; padding: 8px; }
.month-nav-arrows { display: flex; gap: 8px; justify-content: center; }
.month-nav-arrows .btn-arrow {
  flex: none;
  width: 48px;
  padding: 8px 0;
  font-size: 13px;
  border-radius: 8px;
  text-align: center;
}
.sidebar button:focus,
.sidebar select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.dashboard-month-title { margin: 0 0 4px; font-size: 22px; font-weight: 700; }

.content-area {
  flex: 1;
  min-width: 0;
  position: relative;
}
.content-bg {
  position: fixed;
  top: 0;
  left: 240px;
  right: 0;
  bottom: 0;
  z-index: -1;
  background-size: cover;
  background-position: center;
}

.topbar-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.logo-dollar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  min-width: 26px;
  border-radius: 50%;
  background: var(--green);
  color: #0e1116;
  font-weight: 800;
  font-size: 15px;
  line-height: 1;
}

select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}

.btn-arrow {
  padding: 8px 12px;
  font-size: 14px;
}

.toggle-group {
  display: flex;
  gap: 4px;
  background: #0e1116;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}
.toggle-btn {
  background: transparent;
  color: var(--muted);
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 6px;
}
.toggle-btn.active {
  background: var(--panel);
  color: var(--text);
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}
.card {
  background: rgba(22, 27, 34, var(--panel-alpha));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card-label { color: var(--muted); font-size: 14px; }
.card-value { font-size: 26px; font-weight: 700; }
.card-income .card-value { color: var(--green); }
.card-expense .card-value { color: var(--red); }
.card-saldo .card-value { color: var(--accent); }

.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 700px) {
  .charts { grid-template-columns: 1fr; }
}

.panel {
  background: rgba(22, 27, 34, var(--panel-alpha));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.panel h2 { margin: 0 0 16px; font-size: 16px; }
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.panel-header h2 { margin: 0; }

.tx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.tx-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}
.tx-table th[data-sort] {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.tx-table th[data-sort]:hover {
  color: var(--text);
}
.tx-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}
.tx-table tr:hover td { background: #1c2128; }
.amount-income { color: var(--green); font-weight: 600; }
.amount-expense { color: var(--red); font-weight: 600; }
.row-actions button {
  padding: 4px 10px;
  font-size: 13px;
  margin-right: 4px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.modal-card {
  background: #161b22;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: 340px;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card label {
  font-size: 13px;
  color: var(--muted);
  margin-top: 12px;
  margin-bottom: 4px;
}
.modal-card input, .modal-card select {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0e1116;
  color: var(--text);
  font-size: 15px;
}
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}
.modal-actions button { flex: 1; }

#tx-color-field input[type="color"] {
  width: 100%;
  height: 40px;
  padding: 2px;
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
}

.categories-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 400px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 12px;
}
.categories-list::-webkit-scrollbar {
  width: 6px;
}
.categories-list::-webkit-scrollbar-track {
  background: transparent;
}
.categories-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.category-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.category-row-label {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  font-size: 14px;
}
.category-row-label span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.category-swatch {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 0;
  cursor: pointer;
  background: none;
}
.category-swatch input[type="color"] {
  width: 28px;
  height: 28px;
  border: none;
  padding: 0;
  border-radius: 8px;
  cursor: pointer;
}

#categories-modal .modal-card {
  width: 380px;
}

.inline-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
}
.inline-form input, .inline-form select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0e1116;
  color: var(--text);
  font-size: 14px;
  flex: 1;
}
.inline-form input[type="color"] { flex: none; width: 40px; padding: 2px; }
.inline-form button { white-space: nowrap; }

.checkbox-row { margin-top: 12px; }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}
.checkbox-label input { width: auto; }
#tx-installment-count-wrap { margin-top: 8px; }

.cards-summary-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}
.slider-row input[type="range"] {
  flex: 1;
}
.slider-row span {
  font-size: 13px;
  color: var(--muted);
  min-width: 40px;
  text-align: right;
}
.card-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  background: #0e1116;
  border-left: 4px solid;
  cursor: pointer;
}
.card-summary-row:hover {
  background: #161b22;
}
.card-summary-details {
  padding: 4px 10px 4px 14px;
  display: flex;
  flex-direction: column;
}
.card-detail-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

/* ---------- Mobile ---------- */
.mobile-menu-btn { display: none; }
.mobile-backdrop { display: none; }

@media (max-width: 768px) {
  .login-card { width: 92vw; max-width: 340px; padding: 24px; }

  .mobile-menu-btn {
    display: block;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 101;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 20px;
    color: var(--text);
  }
  .mobile-backdrop.hidden { display: none; }
  .mobile-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 98;
  }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 99;
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }
  .sidebar.open { transform: translateX(0); }

  .content-bg { left: 0; }
  .container { padding: 16px 12px; padding-top: 64px; }
  .cards { grid-template-columns: 1fr; }
  .charts { grid-template-columns: 1fr; }
  .panel { padding: 14px; }

  .tx-table { display: block; overflow-x: auto; white-space: nowrap; }
  .modal-card { width: 92vw; max-width: 360px; }
  .inline-form { flex-wrap: wrap; }
  .panel-header { flex-wrap: wrap; gap: 8px; }
}

.dashboard-month-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.dashboard-month-row .dashboard-month-title { margin: 0; }
.dashboard-month-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}
.dashboard-month-controls select {
  font-size: 13px;
  padding: 6px 8px;
}
.dashboard-month-controls .btn-arrow {
  padding: 6px 10px;
  font-size: 12px;
}
@media (max-width: 480px) {
  .dashboard-month-row { flex-direction: column; align-items: flex-start; }
}

.installment-row {
  padding: 10px;
  border-radius: 8px;
  background: #0e1116;
  margin-bottom: 8px;
}
.installment-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.installment-progress-bar {
  width: 100%;
  height: 8px;
  background: #1c2128;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 8px;
}
.installment-progress-fill {
  height: 100%;
  background: var(--green);
}
