/* ==========================================================================
   Cheltuieli — stylesheet
   ========================================================================== */

:root {
  --bg: #0f172a;
  --bg-elevated: #1e293b;
  --bg-elevated-2: #263449;
  --bg-elevated-3: #2d3d54;
  --border: #334155;
  --border-soft: #1e293b;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-tertiary: #64748b;

  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.15);

  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --success: #22c55e;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-float: 0 8px 24px rgba(0, 0, 0, 0.45);

  --nav-h: 64px;
  --header-h: 96px;

  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

.hidden { display: none !important; }

.icon { width: 20px; height: 20px; flex-shrink: 0; }

/* ==========================================================================
   Header
   ========================================================================== */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.92);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-soft);
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 18px 20px 16px;
}

.header-inner h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle {
  margin: 2px 0 0;
  font-size: 14px;
  color: var(--text-secondary);
}

/* ==========================================================================
   Main / views
   ========================================================================== */

.main {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 16px 100px;
}

.view { display: none; }
.view.active { display: block; animation: fadeIn 0.18s ease; }

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

/* ==========================================================================
   Stat grid (Dashboard)
   ========================================================================== */

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.stat-card--accent {
  background: linear-gradient(155deg, var(--accent-soft), var(--bg-elevated) 65%);
  border-color: #2b4a75;
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border-soft));
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-sub {
  font-size: 12.5px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   Cards
   ========================================================================== */

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

.card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.card-header h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.card-header-sub {
  font-size: 12.5px;
  color: var(--text-tertiary);
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
}

/* ==========================================================================
   Chart card
   ========================================================================== */

.chart-card-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chart-wrap {
  position: relative;
  height: 220px;
  margin: 0 auto;
  width: 100%;
  max-width: 260px;
}

.chart-wrap--bar {
  height: 220px;
  max-width: none;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13.5px;
  padding: 0 20px;
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
}

.legend-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.legend-pct {
  color: var(--text-tertiary);
  font-size: 12px;
  min-width: 34px;
  text-align: right;
}

/* ==========================================================================
   Transaction list
   ========================================================================== */

.tx-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.tx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  width: 100%;
  text-align: left;
}

.tx-item:last-child { border-bottom: none; }

.tx-item:active { background: var(--bg-elevated-2); }

.tx-emoji {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  flex-shrink: 0;
}

.tx-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

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

.tx-meta {
  font-size: 12.5px;
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tx-amount {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ==========================================================================
   Search & filters (Tranzactii)
   ========================================================================== */

.search-row { margin-bottom: 10px; }

.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  padding: 10px 14px;
}

.search-input-wrap .icon { color: var(--text-tertiary); }

.search-input-wrap input {
  background: none;
  border: none;
  outline: none;
  flex: 1;
  font-size: 14.5px;
  min-width: 0;
}

.search-input-wrap input::placeholder { color: var(--text-tertiary); }

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.select-input {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-elevated) url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' 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") no-repeat right 10px center / 16px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 10px 30px 10px 12px;
  font-size: 13.5px;
  min-width: 0;
  width: 100%;
}

.tx-list--full { background: var(--bg-elevated); border: 1px solid var(--border-soft); border-radius: var(--radius-md); padding: 6px 12px; }

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

.empty-icon { font-size: 40px; margin-bottom: 10px; }

.empty-state p { margin: 0 0 4px; color: var(--text-secondary); font-weight: 600; font-size: 15px; }
.empty-state span { font-size: 13px; }

/* ==========================================================================
   Categories
   ========================================================================== */

.category-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.category-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  text-align: left;
}

.category-card:active { background: var(--bg-elevated-2); }

.category-emoji-badge {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
}

.category-name {
  font-size: 14.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-count {
  font-size: 12.5px;
  color: var(--text-tertiary);
}

/* ==========================================================================
   Reports
   ========================================================================== */

.top-cat-list, .monthly-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.top-cat-row { display: flex; flex-direction: column; gap: 6px; }

.top-cat-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13.5px;
}

.top-cat-row-head .name { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); font-weight: 500; }

.top-cat-row-head .value { font-weight: 700; font-variant-numeric: tabular-nums; }

.progress-track {
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-elevated-2);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  transition: width 0.4s ease;
}

.monthly-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-soft);
}

.monthly-row:last-child { border-bottom: none; padding-bottom: 0; }

.monthly-row .month-name { font-size: 14.5px; font-weight: 500; text-transform: capitalize; }
.monthly-row .month-count { font-size: 12.5px; color: var(--text-tertiary); }
.monthly-row .month-total { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Settings
   ========================================================================== */

.form-field { margin-bottom: 14px; }
.form-field:last-child { margin-bottom: 0; }

.form-field label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 6px;
}

.optional-tag {
  color: var(--text-tertiary);
  font-weight: 400;
  font-size: 12px;
}

.form-field input[type="text"],
.form-field input[type="number"],
.form-field input[type="date"],
.form-field textarea {
  width: 100%;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 15px;
  outline: none;
}

.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
  border-color: var(--accent);
}

.form-field textarea { resize: vertical; min-height: 44px; }

.app-version {
  text-align: center;
  color: var(--text-tertiary);
  font-size: 12.5px;
  margin: 24px 0 8px;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 18px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.btn:active { transform: scale(0.98); }

.btn-block { width: 100%; }

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

.btn-secondary {
  background: var(--bg-elevated-2);
  color: var(--text-primary);
  border: 1px solid var(--border);
  margin-bottom: 10px;
}
.btn-secondary:last-of-type { margin-bottom: 0; }

.btn-danger { background: var(--danger-soft); color: #fca5a5; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.22); }

/* ==========================================================================
   FAB
   ========================================================================== */

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  box-shadow: var(--shadow-float);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 30;
  transition: transform 0.12s ease, background 0.15s ease;
}

.fab:active { transform: scale(0.94); }
.fab svg { width: 24px; height: 24px; }

/* ==========================================================================
   Bottom nav
   ========================================================================== */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(30, 41, 59, 0.94);
  background: color-mix(in srgb, var(--bg-elevated) 94%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border-soft);
  display: flex;
  z-index: 25;
}

.nav-btn {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 6px 2px;
  max-width: 120px;
  margin: 0 auto;
}

.nav-btn span { font-size: 10.5px; font-weight: 600; }

.nav-btn.active { color: var(--accent); }

/* ==========================================================================
   Modals (bottom sheet on mobile, centered on larger screens)
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.modal-overlay.open { display: flex; opacity: 1; }

.modal-sheet {
  background: var(--bg-elevated);
  border-radius: 22px 22px 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.5);
}

.modal-overlay.open .modal-sheet { transform: translateY(0); }

.modal-sheet--small { max-width: 360px; }

.modal-handle {
  width: 36px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--border);
  margin: 10px auto 4px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px 4px;
}

.modal-header h2 { font-size: 17px; font-weight: 700; margin: 0; }

.modal-close {
  background: var(--bg-elevated-2);
  border: none;
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body { padding: 12px 20px 4px; }

.modal-body--confirm { text-align: center; padding-top: 4px; }
.modal-body--confirm h2 { font-size: 18px; margin: 4px 0 8px; }
.modal-body--confirm p { color: var(--text-secondary); font-size: 14px; margin: 0 0 20px; line-height: 1.5; }

.modal-actions { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }

.modal-actions--row { flex-direction: row; }
.modal-actions--row .btn { flex: 1; }

/* Emoji picker */
.emoji-picker {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.emoji-picker button {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-size: 17px;
  padding: 7px 0;
  cursor: pointer;
}

.emoji-picker button:active { background: var(--bg-elevated-3); }

/* Color presets */
.color-row { display: flex; align-items: center; gap: 12px; }

.color-row input[type="color"] {
  width: 46px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated-2);
  padding: 2px;
  cursor: pointer;
  flex-shrink: 0;
}

.color-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
}

.color-presets button {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}

.color-presets button.selected { border-color: var(--text-primary); }

/* ==========================================================================
   Toast
   ========================================================================== */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px);
  transform: translate(-50%, 12px);
  background: var(--bg-elevated-3);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 11px 18px;
  border-radius: var(--radius-pill);
  font-size: 13.5px;
  font-weight: 500;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  box-shadow: var(--shadow-float);
  max-width: 90vw;
  text-align: center;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ==========================================================================
   Scrollbar (desktop niceties)
   ========================================================================== */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--bg-elevated-3); border-radius: var(--radius-pill); }
::-webkit-scrollbar-track { background: transparent; }

/* ==========================================================================
   Responsive — tablet & desktop
   ========================================================================== */

@media (min-width: 640px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .category-list { grid-template-columns: repeat(3, 1fr); }

  .chart-card-body { flex-direction: row; align-items: center; }
  .chart-wrap { flex-shrink: 0; }
  .legend { flex: 1; }

  .modal-overlay { align-items: center; }
  .modal-sheet {
    border-radius: var(--radius-lg);
    transform: translateY(16px) scale(0.98);
    opacity: 0;
  }
  .modal-overlay.open .modal-sheet { transform: translateY(0) scale(1); opacity: 1; }
  .modal-handle { display: none; }
}

@media (min-width: 900px) {
  .category-list { grid-template-columns: repeat(4, 1fr); }

  .bottom-nav {
    max-width: 640px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    bottom: 18px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-soft);
    height: 64px;
  }

  body { padding-bottom: 100px; }

  .fab { bottom: 96px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* Focus visibility for accessibility */
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
