:root {
  --primary: #4f46e5;
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #1f2937;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  margin: 0;
  padding-bottom: 70px; /* nav space */
}

/* Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 60px;
  background: var(--card);
  display: flex;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  z-index: 100;
}
.nav-item {
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.8rem;
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  background: #e5e7eb;
}
.btn.primary { background: var(--primary); color: white; }
.btn.success { background: var(--success); color: white; }
.btn.warn { background: var(--warn); color: white; }
.btn.danger { background: var(--danger); color: white; }
.btn.small { padding: 4px 8px; font-size: 0.8rem; }

/* Calendar */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: #ddd;
  border: 1px solid #ddd;
  width: 100%;
  min-width: 640px;
}
.calendar-grid-wrapper {
  overflow-x: auto;
  padding-bottom: 4px;
}
.calendar-day {
  background: var(--card);
  min-height: 80px;
  padding: 4px;
}
.calendar-day.header {
  background: #f9fafb;
  min-height: auto;
  text-align: center;
  font-weight: bold;
}
.calendar-day.today { background: #eff6ff; border: 2px solid var(--primary); }
.calendar-day.this-week { background: #fffbeb; }
.day-num { font-size: 0.8rem; font-weight: bold; }

.event-item {
  font-size: 0.7rem;
  padding: 2px 4px;
  margin-top: 2px;
  border-radius: 3px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.event-item.income { background: #d1fae5; color: #065f46; }
.event-item.expense { background: #fee2e2; color: #991b1b; }
.event-item.paid { opacity: 0.6; text-decoration: line-through; }
.event-item.delayed { border: 1px solid var(--danger); background: #fee2e2; }

/* Toast */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #333;
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.9rem;
  z-index: 2000;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.danger { background: var(--danger); }
.toast.success { background: var(--success); }
.toast.warn { background: var(--warn); }

/* Tutorial Overlay */
.tutorial-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 3000;
}
.tutorial-card {
  background: white;
  width: 90%;
  max-width: 400px;
  padding: 30px;
  border-radius: 16px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  text-align: center;
}
.tutorial-card h3 {
  margin-top: 0;
  color: var(--primary);
}
.tutorial-card p {
  line-height: 1.6;
  color: #4b5563;
}
.tutorial-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}
.tutorial-progress {
  margin-top: 15px;
  font-size: 0.8rem;
  color: #9ca3af;
}

@keyframes blink {
  0% { opacity: 1; }
  50% { opacity: 0.5; }
  100% { opacity: 1; }
}
.blink {
  animation: blink 1s infinite;
}

@media (max-width: 640px) {
  .calendar-grid {
    min-width: 560px;
  }
  .calendar-day {
    min-height: 70px;
  }
  .event-item {
    font-size: 0.65rem;
    white-space: normal;
  }
}

/* Master List */
.master-header {
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.master-list {
  padding: 0 16px 16px;
}
.sub-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.sub-tab {
  border: none;
  padding: 8px 12px;
  border-radius: 999px;
  background: #e5e7eb;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
}
.sub-tab.active {
  background: var(--primary);
  color: #fff;
}
.master-group {
  margin-bottom: 18px;
}
.master-group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  color: #111827;
  margin: 8px 0;
}
.master-group-count {
  font-size: 0.7rem;
  background: #e5e7eb;
  color: #374151;
  padding: 2px 6px;
  border-radius: 999px;
}
.master-group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}
.master-item {
  background: var(--card);
  margin-bottom: 12px;
  padding: 16px;
  border-radius: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  border-left: 4px solid var(--primary);
}
.master-item-card {
  margin-bottom: 0;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}
.master-item-card .actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}
.master-item.inactive { opacity: 0.6; grayscale: 1; border-left-color: #9ca3af; }
.master-item.bank { border-left-color: var(--success); }
.master-item .info { display: flex; flex-direction: column; gap: 4px; }
.master-item .name { font-weight: bold; font-size: 1rem; }
.master-item .amount { font-size: 0.9rem; color: #374151; }
.master-item .type { font-size: 0.75rem; padding: 2px 6px; border-radius: 4px; display: inline-block; width: fit-content; }
.master-item .type.income { background: #d1fae5; color: #065f46; }
.master-item .type.expense { background: #fee2e2; color: #991b1b; }
.master-item .type.bank { background: #dcfce7; color: #166534; }
.master-item .actions { display: flex; gap: 8px; }
.tag-vehicle { background: #cffafe; color: #155e75; }
.tag-car { background: #cffafe; color: #155e75; }
.tag-bike { background: #cffafe; color: #155e75; }
.tag-business { background: #fef3c7; color: #92400e; }
.link-button {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-align: left;
}
.link-button:hover {
  text-decoration: underline;
}
.collapsible {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 10px 12px;
  background: #ffffff;
  margin-top: 10px;
}
.collapsible summary {
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}
.collapsible summary::-webkit-details-marker {
  display: none;
}
.collapsible summary::after {
  content: "▾";
  float: right;
  color: #6b7280;
}
.collapsible[open] summary::after {
  content: "▴";
}
.collapsible-body {
  margin-top: 10px;
}

.tag-badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.tag-fixed { background: #e0e7ff; color: #3730a3; }
.tag-variable { background: #fef9c3; color: #854d0e; }
.tag-card { background: #fee2e2; color: #991b1b; }
.tag-loan { background: #ffe4e6; color: #9f1239; }

/* Credit Card Styling */
.master-item.card-type {
  border-left: none;
  border-top: none;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  color: #fff;
  position: relative;
  overflow: hidden;
  padding: 20px;
  min-height: 160px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.master-item.card-type .tag-badge {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  backdrop-filter: blur(4px);
}
.master-item.card-type::after {
  content: "";
  position: absolute;
  top: -20px;
  right: -20px;
  width: 100px;
  height: 100px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 50%;
}
.card-chip {
  width: 40px;
  height: 30px;
  background: linear-gradient(135deg, #fbbf24 0%, #d97706 100%);
  border-radius: 4px;
  margin-bottom: 10px;
  position: relative;
  border: 1px solid rgba(0, 0, 0, 0.1);
}
.card-chip::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(0, 0, 0, 0.1);
}
.card-chip::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(0, 0, 0, 0.1);
}
.master-item.card-type .name {
  color: #fff;
  font-size: 1.2rem;
  letter-spacing: 0.05em;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
.master-item.card-type .bank-link {
  color: rgba(255, 255, 255, 0.8) !important;
}
.master-item.card-type .info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  background: rgba(255, 255, 255, 0.1) !important;
  backdrop-filter: blur(4px);
  padding: 10px !important;
  border-radius: 8px;
  margin-top: auto;
}
.master-item.card-type .info-grid div div:first-child {
  color: rgba(255, 255, 255, 0.6) !important;
  font-size: 0.65rem !important;
  text-transform: uppercase;
}
.master-item.card-type .info-grid div div:last-child {
  color: #fff !important;
  font-weight: 700 !important;
}
.logo-candidate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 8px;
  margin-top: 8px;
  max-height: 150px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
}
.logo-candidate {
  cursor: pointer;
  padding: 4px;
  border: 2px solid transparent;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.logo-candidate:hover {
  background: #f3f4f6;
}
.logo-candidate.selected {
  border-color: var(--primary);
  background: #eef2ff;
}
.logo-candidate img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  background: white;
  border-radius: 4px;
  padding: 2px;
}
.logo-candidate span {
  font-size: 0.6rem;
  text-align: center;
  word-break: break-all;
}
.tag-tax { background: #ede9fe; color: #5b21b6; }
.tag-service { background: #dcfce7; color: #166534; }

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}
.modal.hidden { display: none !important; }
.modal-content {
  background: var(--card);
  padding: 24px;
  border-radius: 12px;
  width: 95%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
  box-sizing: border-box;
}
.modal-content h3 {
  margin-top: 0;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--bg);
  padding-bottom: 10px;
}
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #4b5563;
  margin-bottom: 6px;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px;
  border: 1.5px solid #e5e7eb;
  border-radius: 8px;
  font-size: 0.95rem;
  box-sizing: border-box;
}
.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
input[inputmode="numeric"] {
  text-align: right;
  font-family: 'Courier New', Courier, monospace;
  font-weight: bold;
}
.hint-text {
  font-size: 0.75rem;
  color: #6b7280;
  margin-top: 6px;
}
.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: #374151;
  user-select: none;
}
.inline-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
}
.form-group.field-error label {
  color: var(--danger);
}
.form-group.field-error input,
.form-group.field-error select,
.form-group.field-error textarea {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.hidden { display: none !important; }

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}
.loading-content {
  background: white;
  padding: 30px 50px;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f4f6;
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 15px;
}
.loading-message {
  font-weight: 600;
  color: #374151;
}
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.dashboard-header, .master-header, .analysis-header, .settings-header {
  padding: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card);
  margin-bottom: 1px;
}
.month-nav { display: flex; align-items: center; gap: 10px; }
/* Analysis */
.card {
  background: var(--card);
  padding: 15px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: bold;
}
.badge.success { background: #d1fae5; color: #065f46; }
.analysis-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 15px 0;
  flex-wrap: wrap;
}
.analysis-tab {
  border: none;
  padding: 8px 12px;
  border-radius: 999px;
  background: #e5e7eb;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
}
.analysis-tab.active {
  background: var(--primary);
  color: #fff;
}
.highlight-card {
  background: #f1f5f9;
  border-radius: 10px;
  padding: 12px;
  border-left: 4px solid var(--primary);
}
.highlight-title {
  font-size: 0.8rem;
  color: #64748b;
  margin-bottom: 4px;
}
.highlight-value {
  font-size: 1.1rem;
  font-weight: 700;
}
.highlight-sub {
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 4px;
}
.sparkline {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin: 8px 0 4px;
  flex-wrap: wrap;
}
.sparkbar {
  width: 36px;
  height: 80px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
}
.sparkbar-fill {
  width: 100%;
  background: #93c5fd;
  border-radius: 6px 6px 0 0;
  min-height: 6px;
}
.sparkbar-label {
  font-size: 0.7rem;
  color: #64748b;
}
.spark-section {
  margin-bottom: 10px;
}
.spark-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
}
.bar-row {
  display: grid;
  grid-template-columns: 120px 1fr 110px;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}
.bar-label {
  font-size: 0.8rem;
  color: #374151;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-track {
  height: 10px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 999px;
}
.bar-value {
  font-size: 0.8rem;
  color: #6b7280;
  text-align: right;
}
.chart-grid {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
  align-items: start;
}
.pie-chart {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  margin: 0 auto 10px;
}
.pie-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
}
.pie-legend-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.pie-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.pie-legend-value {
  color: #6b7280;
}
@media (max-width: 640px) {
  .bar-row {
    grid-template-columns: 1fr;
  }
  .bar-value {
    text-align: left;
  }
  .chart-grid {
    grid-template-columns: 1fr;
  }
  .pie-chart {
    width: 160px;
    height: 160px;
  }
}

/* Login */
.login-screen {
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  text-align: center;
  padding: 20px;
}
.login-card {
  background: white;
  color: var(--text);
  padding: 40px;
  border-radius: 20px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  width: 90%;
  max-width: 400px;
}

/* Tabs */
.tabs {
  display: flex;
  background: var(--card);
  padding: 4px;
  margin: 16px;
  border-radius: 12px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  font-weight: 600;
  color: #6b7280;
}
.tab-btn.active {
  background: var(--primary);
  color: white;
  border-bottom: none;
}

/* Debt summary in dashboard */
.debt-summary-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px;
}
.summary-card {
  background: var(--card);
  padding: 15px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.summary-card h4 { margin: 0 0 5px 0; font-size: 0.8rem; color: #6b7280; }
.summary-card .value { font-size: 1.2rem; font-weight: bold; }

.debt-list-card {
  background: var(--card);
  margin: 10px;
  padding: 15px;
  border-radius: 8px;
}
.debt-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #f3f4f6;
}
.debt-row:last-child { border-bottom: none; }
