:root {
  --bg-body: #f8fafc;
  --bg-gradient-from: #e0e7ff;
  --bg-gradient-to: #fce7f3;
  --bg-card: #ffff;
  --bg-card-soft: #f1f5f9;
  --border-subtle: #e2e8f0;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.1);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.1);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.1);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.1);
  --radius-md: 0.75rem;
  --radius-lg: 1.25rem;
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.08);
  --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.05);
}

body.dark-mode {
  --bg-body: #0f172a;
  --bg-gradient-from: #1e3a8a;
  --bg-gradient-to: #7c3aed;
  --bg-card: #1e293b;
  --bg-card-soft: #0f172a;
  --border-subtle: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --accent: #60a5fa;
  --accent-soft: rgba(96, 165, 250, 0.15);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.15);
  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.15);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.15);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.4);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, var(--bg-gradient-from), var(--bg-gradient-to));
  color: var(--text-primary);
  min-height: 100vh;
  padding: 1rem;
  display: flex;
  align-items: stretch;
  justify-content: center;
  transition: background 0.3s ease, color 0.3s ease;
}

.app-shell {
  width: 100%;
  max-width: 1280px;
  background: var(--bg-card);
  border-radius: 1.5rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-subtle);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: relative;
  overflow: hidden;
}

.content {
  position: relative;
  z-index: 1;
}

/* HEADER */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.header-main {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-circle {
  width: 3rem;
  height: 3rem;
  border-radius: 999px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  box-shadow: 0 8px 20px rgba(59, 130, 246, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}

.header-text h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.header-text p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

#darkModeToggle {
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  padding: 0.5rem 0.85rem;
  background: var(--bg-card-soft);
  color: var(--text-primary);
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

#darkModeToggle:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* LAYOUT GRID */
.layout-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 1.5rem;
  align-items: flex-start;
}

@media (max-width: 1024px) {
  .layout-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  body {
    padding: 0.5rem;
  }
  .app-shell {
    border-radius: 1rem;
    padding: 1rem;
  }
  .header-text h1 {
    font-size: 1.25rem;
  }
  .header-text p {
    font-size: 0.75rem;
  }
}

@media (max-width: 640px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
  }
  .logo-circle {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.25rem;
  }
}

/* CARDS */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-soft);
  position: relative;
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  font-weight: 600;
}

.card-title span.icon {
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 999px;
  background: var(--accent-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.card-subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

/* SUMMARY CARDS */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

@media (max-width: 1024px) {
  .summary-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 640px) {
  .summary-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .summary-grid {
    grid-template-columns: 1fr;
  }
}

.summary-card {
  background: var(--bg-card-soft);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-height: 4rem;
}

.summary-card[data-type='income'] {
  border-color: var(--success);
  box-shadow: 0 4px 12px var(--success-soft);
}

.summary-card[data-type='expense'] {
  border-color: var(--danger);
  box-shadow: 0 4px 12px var(--danger-soft);
}

.summary-card[data-type='savings'] {
  border-color: var(--accent);
  box-shadow: 0 4px 12px var(--accent-soft);
}

.summary-card[data-type='investment'] {
  border-color: #a855f7;
  box-shadow: 0 4px 12px rgba(168, 85, 247, 0.15);
}

.summary-card[data-type='emergency'] {
  border-color: var(--warning);
  box-shadow: 0 4px 12px var(--warning-soft);
}

.summary-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.summary-value {
  font-size: 1rem;
  font-weight: 600;
}

.summary-pill {
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  align-self: flex-start;
}

/* FORMS */
.forms-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

@media (max-width: 768px) {
  .forms-grid {
    grid-template-columns: 1fr;
  }
}

.form-grid {
  display: grid;
  gap: 0.75rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 640px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
  display: block;
}

input,
select,
textarea {
  width: 100%;
  padding: 0.65rem;
  border-radius: 0.6rem;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card-soft);
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%),
    linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%);
  background-position: calc(100% - 14px) calc(50% - 3px), calc(100% - 10px) calc(50% - 3px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2rem;
}

.btn {
  border-radius: 0.7rem;
  border: none;
  padding: 0.65rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #ffff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-success {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #ffff;
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #ffff;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-warning {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #ffff;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  box-shadow: none;
}

.btn:hover {
  transform: translateY(-1px);
  opacity: 0.9;
}

.btn:active {
  transform: translateY(0);
}

.btn-full {
  width: 100%;
}

.btn-small {
  padding: 0.4rem 0.65rem;
  font-size: 0.75rem;
  border-radius: 999px;
}

.btn-icon-only {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 999px;
  font-size: 0.85rem;
}

/* TWO COLUMN GRID */
.two-column-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-top: 1rem;
}

@media (max-width: 768px) {
  .two-column-grid {
    grid-template-columns: 1fr;
  }
}

.section-chip {
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.tip-box {
  margin-top: 1rem;
  padding: 0.75rem;
  border-radius: 0.75rem;
  border: 1px dashed var(--border-subtle);
  background: var(--warning-soft);
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  gap: 0.5rem;
}

/* CATEGORY MANAGER */
.category-form {
  display: grid;
  grid-template-columns: 1.5fr 1fr auto;
  gap: 0.75rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

@media (max-width: 640px) {
  .category-form {
    grid-template-columns: 1fr;
  }
}

.category-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0.75rem 0 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.category-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.category-tag {
  padding: 0.35rem 0.65rem 0.35rem 0.5rem;
  border-radius: 999px;
  background: var(--bg-card-soft);
  border: 1px solid var(--border-subtle);
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-secondary);
}

.category-tag button {
  border: none;
  background: var(--danger);
  color: #ffff;
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 999px;
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: opacity 0.2s ease;
}

.category-tag button:hover {
  opacity: 0.8;
}

/* CHART */
.chart-wrapper {
  height: 260px;
  position: relative;
}

@media (max-width: 640px) {
  .chart-wrapper {
    height: 220px;
  }
}

textarea#notesArea {
  min-height: 120px;
  resize: vertical;
  font-family: inherit;
}

.notes-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* TRANSACTIONS */
.transactions-list {
  max-height: 300px;
  overflow-y: auto;
  border-radius: 0.75rem;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card-soft);
}

.transactions-list::-webkit-scrollbar {
  width: 6px;
}

.transactions-list::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 999px;
}

.transaction-item {
  padding: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.85rem;
}

.transaction-item:last-child {
  border-bottom: none;
}

.transaction-main {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}

.transaction-title {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transaction-meta {
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.transaction-value-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.transaction-value {
  font-weight: 600;
  font-size: 0.85rem;
}

.transaction-value.positive {
  color: var(--success);
}

.transaction-value.negative {
  color: var(--danger);
}

.empty-state {
  padding: 1.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* NOTIFICATIONS */
.notification {
  position: fixed;
  top: 1rem;
  right: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 9999;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: slideIn 0.3s ease-out;
  max-width: 90vw;
}

.notification-success {
  background: var(--success);
  color: #ffff;
}

.notification-error {
  background: var(--danger);
  color: #ffff;
}

.notification-info {
  background: var(--accent);
  color: #ffff;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px) translateX(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0) translateX(0);
  }
}

@keyframes slideOut {
  from {
    opacity: 1;
    transform: translateY(0) translateX(0);
  }
  to {
    opacity: 0;
    transform: translateY(-10px) translateX(10px);
  }
}

@media (max-width: 640px) {
  .notification {
    top: 0.5rem;
    right: 0.5rem;
    left: 0.5rem;
    max-width: none;
  }
}

/* ==== TELA DE LOGIN ==== */
.login-shell {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg-gradient-from), var(--bg-gradient-to));
  padding: 1rem;
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-subtle);
  max-width: 420px;
  width: 100%;
}

.login-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-header .logo-circle {
  margin: 0 auto 0.75rem;
}

.login-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.login-header p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.login-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--border-subtle);
}

.login-tab {
  flex: 1;
  padding: 0.65rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s ease;
}

.login-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-footer {
  margin-top: 1.5rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-secondary);
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
}

@media (max-width: 480px) {
  .login-card {
    padding: 1.5rem;
  }
}