:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-soft: #e0e7ff;
  --border: #e2e8f0;
  --confirm-bg: #fef3c7;
  --confirm-text: #1f2937;
  --shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
  --radius: 16px;
}

body.dark {
  --bg: #0f172a;
  --card: #111827;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #1f2937;
  --primary: #3b82f6;
  --primary-soft: #1e293b;
  --confirm-bg: #111827;
  --confirm-text: #e2e8f0;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Inter", "Segoe UI", sans-serif;
}

html,
body {
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s ease, color 0.3s ease;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 72px;
  overflow-x: hidden;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 40px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 14px;
}

.auth-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-email {
  font-size: 14px;
  color: var(--text);
}

button {
  border: none;
  padding: 10px 16px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

button.primary {
  background: var(--primary);
  color: #ffffff;
}

button.ghost {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
}

button.danger {
  background: #ef4444;
  color: #ffffff;
}

button.small {
  padding: 8px 12px;
  font-size: 12px;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.app-main {
  flex: 1;
  padding: 20px 40px 40px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

.page {
  display: none;
  animation: fadeIn 0.3s ease;
  min-width: 0;
}

.page.active {
  display: block;
}

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

.page-title {
  font-size: 22px;
  font-weight: 700;
}

.page-subtitle {
  color: var(--muted);
  font-size: 14px;
  margin-top: 4px;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--card);
  padding: 24px;
  border-radius: var(--radius);
  height: calc(100vh - 260px);
  box-shadow: var(--shadow);
}

.chat-history {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-right: 8px;
  min-width: 0;
}

.chat-bubble {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.4;
  animation: bubbleIn 0.25s ease;
  word-break: break-word;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--primary);
  color: #ffffff;
  border-bottom-right-radius: 6px;
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--primary-soft);
  color: var(--text);
  border-bottom-left-radius: 6px;
}

.chat-bubble.loading {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.chat-bubble.loading span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--muted);
  animation: pulse 1s infinite ease-in-out;
}

.chat-bubble.loading span:nth-child(2) {
  animation-delay: 0.2s;
}

.chat-bubble.loading span:nth-child(3) {
  animation-delay: 0.4s;
}

.chat-input {
  display: flex;
  gap: 10px;
  background: var(--card);
}

.chat-input input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}

.chat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
}

.chip {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--text);
  border: 1px solid transparent;
}

.chip:hover {
  border-color: var(--border);
}

.confirmation-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.confirmation-card {
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--confirm-bg);
  color: var(--confirm-text);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.confirmation-summary {
  display: grid;
  gap: 10px;
}

.confirmation-title {
  font-weight: 600;
}

.confirmation-rows {
  display: grid;
  gap: 8px;
}

.confirmation-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--border);
}

.confirmation-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.confirmation-value {
  font-weight: 600;
}

.confirmation-source {
  font-size: 12px;
  color: var(--muted);
}

.confirmation-actions {
  display: flex;
  gap: 10px;
}

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

.confirmation-edit input,
.confirmation-edit select {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}

.confirmation-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.confirmation-field.full {
  grid-column: 1 / -1;
}

.field-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.summary-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.summary-card {
  background: var(--card);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}

.card-value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 6px;
}

.card-subvalue {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.budget-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.budget-usage {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.budget-bar {
  margin-top: 10px;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.budget-progress {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: #22c55e;
  transition: width 0.3s ease, background 0.3s ease;
}

.breakdown-list {
  margin-top: 12px;
  display: grid;
  gap: 12px;
}

.breakdown-item {
  display: grid;
  gap: 6px;
}

.breakdown-header {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}

.breakdown-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.breakdown-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
}

.recent-transactions {
  display: grid;
  gap: 12px;
  margin-top: 10px;
}

.transaction-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  color: var(--text);
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  gap: 12px;
}

.transaction-main {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.transaction-merchant {
  font-weight: 600;
}

.transaction-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.transaction-category {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--text);
  font-weight: 600;
}

.transaction-date {
  display: inline-flex;
  align-items: center;
}

.transaction-amount {
  font-weight: 700;
  white-space: nowrap;
}

.alerts-panel {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.alert-item {
  padding: 10px 12px;
  border-radius: 12px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 14px;
}

.alert-empty {
  color: var(--muted);
  font-size: 14px;
}

.history-panel {
  display: grid;
  gap: 16px;
}

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

.history-filters input,
.history-filters select {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
}

.history-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.history-sub {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.history-actions {
  display: flex;
  gap: 10px;
}

.settings-panel {
  display: grid;
  gap: 16px;
}

.data-warning {
  margin-top: 12px;
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #fee2e2;
  border: 1px solid #fecaca;
  color: #991b1b;
  display: grid;
  gap: 6px;
}

.data-warning-title {
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.data-warning-text {
  font-size: 13px;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.settings-label {
  font-weight: 600;
}

.settings-caption {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.settings-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}

.category-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.category-item {
  background: var(--bg);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.category-info {
  display: grid;
  gap: 4px;
}

.category-name {
  font-weight: 600;
}

.category-tag {
  font-size: 12px;
  color: var(--muted);
}

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

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--border);
  border-radius: 999px;
  transition: 0.3s;
}

.slider::before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: var(--card);
  border-radius: 999px;
  transition: 0.3s;
}

.switch input:checked + .slider {
  background: var(--primary);
}

.switch input:checked + .slider::before {
  transform: translateX(22px);
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 10px 16px;
  gap: 12px;
  z-index: 10;
}

.nav-item {
  background: transparent;
  color: var(--muted);
  border-radius: 14px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.nav-item .nav-icon {
  width: 22px;
  height: 22px;
}

.nav-item svg {
  width: 100%;
  height: 100%;
}

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: var(--card);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-6px);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  width: min(420px, 100%);
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
}

.modal-body {
  color: var(--muted);
  font-size: 14px;
}

.modal-form {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.modal-form input,
.modal-form select {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@keyframes bubbleIn {
  from {
    transform: translateY(6px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 1;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (max-width: 960px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 16px 20px;
  }
  .app-main {
    padding: 16px 20px 28px;
  }
  .chat-panel {
    height: calc(100vh - 220px);
  }
  .summary-grid {
    grid-template-columns: 1fr;
  }
  .history-filters {
    grid-template-columns: 1fr;
  }
}
