/* ========================================
   Finance Tracker — Design Tokens
   ======================================== */

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: rgba(255,255,255,0.03);
  --bg-card-hover: rgba(255,255,255,0.06);
  --text-primary: #f0f0f5;
  --text-secondary: #8a8a9a;
  --text-muted: #55556a;
  --indigo: #6366f1;
  --violet: #8b5cf6;
  --blue: #3b82f6;
  --cyan: #06b6d4;
  --success: #22c55e;
  --error: #f87171;
  --warning: #fbbf24;
  --border-subtle: rgba(255,255,255,0.06);
  --border-hover: rgba(255,255,255,0.12);
  --gradient-primary: linear-gradient(135deg, #6366f1, #8b5cf6, #3b82f6);
  --gradient-text: linear-gradient(135deg, #818cf8, #a78bfa, #60a5fa);
  --gradient-glow: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(139,92,246,0.15), rgba(59,130,246,0.15));
  --radius: 12px;
  --radius-lg: 20px;
}

/* ========================================
   Reset & Base
   ======================================== */

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

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
  padding-bottom: 80px;
  min-height: 100vh;
}

/* ========================================
   Login View
   ======================================== */

.login-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.login-card h1 {
  font-size: 24px;
  margin-bottom: 8px;
}

.login-card p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 32px;
}

.pin-input-wrapper {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 24px;
}

.pin-digit {
  width: 52px;
  height: 60px;
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  font-family: 'Outfit', sans-serif;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
  -webkit-text-security: disc;
}

.pin-digit:focus {
  border-color: var(--indigo);
}

.login-error {
  color: var(--error);
  font-size: 13px;
  margin-top: -12px;
  margin-bottom: 16px;
  display: none;
}

.login-error.visible {
  display: block;
}

.login-btn {
  width: 100%;
  padding: 14px;
  background: var(--gradient-primary);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.login-btn:hover { opacity: 0.9; }
.login-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ========================================
   Bottom Navigation
   ======================================== */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-around;
  padding: 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s;
  text-decoration: none;
}

.nav-item.active { color: var(--indigo); }
.nav-item:hover { color: var(--text-secondary); }

.nav-item svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ========================================
   Dashboard View
   ======================================== */

.dashboard-view { padding-top: 24px; }

.dashboard-header {
  margin-bottom: 24px;
}

.dashboard-header h1 {
  font-size: 22px;
  margin-bottom: 4px;
}

.dashboard-header .month-label {
  color: var(--text-secondary);
  font-size: 14px;
}

.totals-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.total-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 14px;
}

.total-card .label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.total-card .value {
  font-family: 'Outfit', sans-serif;
  font-size: 20px;
  font-weight: 700;
}

.total-card .value.income { color: var(--success); }
.total-card .value.expense { color: var(--error); }
.total-card .value.net-positive { color: var(--success); }
.total-card .value.net-negative { color: var(--error); }

/* Entity Pills */
.entity-section {
  margin-bottom: 24px;
}

.entity-section h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.entity-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.entity-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  font-size: 13px;
  flex: 1;
  min-width: 0;
}

.entity-pill .entity-name {
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entity-pill .entity-net {
  margin-left: auto;
  font-weight: 700;
  font-family: 'Outfit', sans-serif;
  white-space: nowrap;
}

/* Recent Transactions */
.recent-section {
  margin-bottom: 24px;
}

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

.section-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.section-header a {
  font-size: 13px;
  color: var(--indigo);
  text-decoration: none;
}

/* Transaction List */
.tx-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  color: inherit;
}

.tx-item:hover { background: var(--bg-card-hover); }

.tx-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}

.tx-icon.income { background: rgba(34,197,94,0.1); color: var(--success); }
.tx-icon.expense { background: rgba(248,113,113,0.1); color: var(--error); }

.tx-details {
  flex: 1;
  min-width: 0;
}

.tx-desc {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.tx-amount {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}

.tx-amount.income { color: var(--success); }
.tx-amount.expense { color: var(--error); }

/* Floating Add Button */
.fab {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--gradient-primary);
  border: none;
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(99,102,241,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: transform 0.15s, box-shadow 0.15s;
}

.fab:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 24px rgba(99,102,241,0.4);
}

/* ========================================
   Form View (Add/Edit)
   ======================================== */

.form-view { padding-top: 24px; }

.form-view h1 {
  font-size: 22px;
  margin-bottom: 24px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--indigo);
}

.form-group input::placeholder { color: var(--text-muted); }

.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a8a9a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

/* Type Toggle */
.type-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.type-btn {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.type-btn.active-income {
  border-color: var(--success);
  background: rgba(34,197,94,0.1);
  color: var(--success);
}

.type-btn.active-expense {
  border-color: var(--error);
  background: rgba(248,113,113,0.1);
  color: var(--error);
}

/* Amount Input */
.amount-wrapper {
  position: relative;
}

.amount-wrapper .currency {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-muted);
}

.amount-wrapper input {
  padding-left: 30px;
  font-size: 24px;
  font-weight: 700;
  font-family: 'Outfit', sans-serif;
}

/* Tag Input */
.tag-input-wrapper {
  position: relative;
}

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: rgba(99,102,241,0.1);
  border: 1px solid rgba(99,102,241,0.2);
  border-radius: 6px;
  font-size: 13px;
  color: var(--indigo);
}

.tag-chip button {
  background: none;
  border: none;
  color: var(--indigo);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0;
  margin-left: 2px;
}

.tag-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  margin-top: 4px;
  max-height: 150px;
  overflow-y: auto;
  z-index: 10;
  display: none;
}

.tag-suggestions.visible { display: block; }

.tag-suggestion {
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.1s;
}

.tag-suggestion:hover { background: var(--bg-card-hover); }

/* Entity Selector */
.entity-options {
  display: flex;
  gap: 8px;
}

.entity-opt {
  flex: 1;
  padding: 10px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.entity-opt.active {
  border-color: var(--indigo);
  background: rgba(99,102,241,0.06);
  color: var(--text-primary);
}

/* Form Actions */
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 28px;
}

.btn {
  flex: 1;
  padding: 14px;
  border-radius: 10px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  border: none;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--gradient-primary);
  color: #fff;
}

.btn-secondary {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.btn-danger {
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.2);
  color: var(--error);
}

.btn:hover { opacity: 0.9; }

/* ========================================
   History View
   ======================================== */

.history-view { padding-top: 24px; }

.history-view h1 {
  font-size: 22px;
  margin-bottom: 16px;
}

.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-select {
  padding: 8px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 13px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a8a9a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.filter-select:focus { border-color: var(--indigo); }

.history-total {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ========================================
   Summary View
   ======================================== */

.summary-view { padding-top: 24px; }

.summary-view h1 {
  font-size: 22px;
  margin-bottom: 16px;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.chart-card h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.chart-card canvas {
  width: 100% !important;
  max-height: 250px;
}

.entity-totals-table {
  width: 100%;
  border-collapse: collapse;
}

.entity-totals-table th,
.entity-totals-table td {
  padding: 10px 12px;
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid var(--border-subtle);
}

.entity-totals-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.entity-totals-table td:last-child { text-align: right; }
.entity-totals-table th:last-child { text-align: right; }

/* ========================================
   Empty / Loading / Error States
   ======================================== */

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 14px;
  margin-bottom: 4px;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 14px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--indigo);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-banner {
  padding: 12px 16px;
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.2);
  border-radius: 10px;
  color: var(--error);
  font-size: 13px;
  margin-bottom: 16px;
}

/* ========================================
   Desktop Adjustments
   ======================================== */

@media (min-width: 768px) {
  #app {
    max-width: 600px;
  }

  .bottom-nav {
    max-width: 600px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 16px 16px 0 0;
  }
}
