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

:root {
  --bg: #0d0d1a;
  --bg-card: #16162a;
  --bg-card-hover: #1c1c34;
  --bg-nav: #111126;
  --primary: #00d4aa;
  --primary-dim: rgba(0, 212, 170, 0.15);
  --danger: #ff4757;
  --danger-dim: rgba(255, 71, 87, 0.15);
  --warning: #f0a500;
  --warning-dim: rgba(240, 165, 0, 0.15);
  --info: #1e90ff;
  --info-dim: rgba(30, 144, 255, 0.15);
  --green: #2ed573;
  --text: #e8e8f0;
  --text-muted: #7a7a8a;
  --text-dim: #4a4a5a;
  --border: #22223a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg-nav);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.app-header h1 {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.3px;
}

.app-header .logo-sub {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 400;
}

.app-main {
  padding: 60px 0 72px 0;
  min-height: 100vh;
}

.page {
  display: none;
  padding: 16px;
  animation: fadeIn 0.25s ease;
}

.page.active {
  display: block;
}

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

.section {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 600px;
  margin: 0 auto;
}

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

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
}

/* Dashboard */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-width: 600px;
  margin: 0 auto 14px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.stat-card .stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}

.stat-card .stat-value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.stat-card .stat-icon {
  position: absolute;
  right: 12px;
  bottom: 8px;
  font-size: 28px;
  opacity: 0.15;
}

.stat-ingresos { border-left: 3px solid var(--primary); }
.stat-gastos { border-left: 3px solid var(--danger); }
.stat-neta { border-left: 3px solid var(--warning); }
.stat-km { border-left: 3px solid var(--info); }
.stat-gasolina { border-left: 3px solid var(--warning); }
.stat-fondo { border-left: 3px solid var(--green); }
.stat-disponible { border-left: 3px solid #a55eea; }

/* Resumen */
.resumen-semanal {
  max-width: 600px;
  margin: 0 auto;
}

.resumen-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.resumen-row:last-child {
  border-bottom: none;
}

.resumen-total {
  font-weight: 700;
  font-size: 15px;
  padding: 10px 0;
  margin-top: 4px;
  border-top: 2px solid var(--border);
  border-bottom: none;
}

.resumen-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.resumen-grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.resumen-item {
  text-align: center;
  padding: 10px;
  background: rgba(255,255,255,0.03);
  border-radius: var(--radius-sm);
}

.resumen-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.resumen-valor {
  font-size: 16px;
  font-weight: 700;
}

/* Forms */
.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

input, select, textarea {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}

input:focus, select:focus {
  border-color: var(--primary);
  background: rgba(0, 212, 170, 0.05);
}

input::placeholder {
  color: var(--text-dim);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

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

.btn-full {
  width: 100%;
}

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

.btn-primary:hover {
  background: #00e6b5;
}

.btn-secondary {
  background: var(--info);
  color: #fff;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-outline:hover {
  border-color: var(--text-muted);
}

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

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

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
  border-radius: var(--radius-sm);
  gap: 8px;
}

.list-item-main {
  flex: 1;
  min-width: 0;
}

.list-item-title {
  font-size: 14px;
  font-weight: 600;
}

.list-item-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.btn-delete {
  background: var(--danger-dim);
  color: var(--danger);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

.btn-delete:active {
  background: var(--danger);
  color: #fff;
}

/* Text colors */
.text-green { color: var(--primary); }
.text-red { color: var(--danger); }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }

/* Empty state */
.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 20px 0;
  font-size: 13px;
}

/* Badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.badge-comida { background: rgba(255, 71, 87, 0.15); color: #ff4757; }
.badge-arriendo { background: rgba(30, 144, 255, 0.15); color: #1e90ff; }
.badge-servicios { background: rgba(240, 165, 0, 0.15); color: #f0a500; }
.badge-internet { background: rgba(46, 213, 115, 0.15); color: #2ed573; }
.badge-mercado { background: rgba(165, 94, 234, 0.15); color: #a55eea; }
.badge-transporte { background: rgba(0, 212, 170, 0.15); color: #00d4aa; }
.badge-otros { background: rgba(255, 255, 255, 0.1); color: #aaa; }

/* Category bars */
.cat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 13px;
}

.cat-label {
  width: 80px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.cat-bar {
  flex: 1;
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
}

.cat-bar span {
  display: block;
  height: 100%;
  background: var(--danger);
  border-radius: 3px;
  transition: width 0.3s;
}

.cat-val {
  width: 70px;
  text-align: right;
  font-weight: 600;
}

/* Calc result */
.calc-result {
  text-align: center;
  padding: 8px;
  background: var(--primary-dim);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--primary);
}

/* Fondo */
.fondo-display {
  text-align: center;
  padding: 16px;
}

.fondo-valor {
  font-size: 36px;
  font-weight: 800;
  color: var(--green);
  letter-spacing: -1px;
}

.fondo-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Alertas */
.alerta {
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
}

.alerta-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(255, 71, 87, 0.2);
}

.alerta-warning {
  background: var(--warning-dim);
  color: var(--warning);
  border: 1px solid rgba(240, 165, 0, 0.2);
}

.alerta-info {
  background: var(--info-dim);
  color: var(--info);
  border: 1px solid rgba(30, 144, 255, 0.2);
}

/* Progress bar */
.progreso-bar {
  height: 8px;
  background: rgba(255,255,255,0.06);
  border-radius: 4px;
  overflow: hidden;
}

.progreso-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--green));
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* Bottom navigation */
.app-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg-nav);
  display: flex;
  border-top: 1px solid var(--border);
  padding: 4px 0;
  padding-bottom: env(safe-area-inset-bottom, 4px);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.app-nav::-webkit-scrollbar { display: none; }

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 8px;
  cursor: pointer;
  color: var(--text-dim);
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  text-decoration: none;
  font-size: 10px;
  gap: 2px;
  border: none;
  background: none;
  font-family: inherit;
  white-space: nowrap;
}

@media (max-width: 599px) {
  .app-nav .nav-item {
    flex: none;
  }
}

@media (min-width: 600px) {
  .nav-item {
    flex: 1;
    padding: 6px 0;
  }
}

.nav-item .nav-icon {
  font-size: 20px;
  line-height: 1;
}

.nav-item .nav-label {
  font-size: 9px;
  font-weight: 500;
}

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

.nav-item:active {
  opacity: 0.6;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: all 0.3s;
  z-index: 200;
  pointer-events: none;
  white-space: nowrap;
}

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

.toast-success { border-color: var(--primary); }
.toast-error { border-color: var(--danger); color: var(--danger); }

/* Canvas charts */
canvas {
  width: 100% !important;
  height: auto !important;
  border-radius: var(--radius-sm);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--text-dim);
  border-radius: 2px;
}

/* Responsive */
@media (min-width: 600px) {
  .dashboard-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .app-main {
    padding: 64px 0 0 0;
    max-width: 800px;
    margin: 0 auto;
  }

  .app-nav {
    display: none;
  }

  .desktop-nav {
    display: flex !important;
  }

  .page {
    padding: 24px;
  }
}

.desktop-nav {
  display: none;
  position: fixed;
  top: 48px;
  left: 0;
  bottom: 0;
  width: 200px;
  background: var(--bg-nav);
  border-right: 1px solid var(--border);
  flex-direction: column;
  padding: 12px 8px;
  gap: 2px;
  overflow-y: auto;
}

.desktop-nav .nav-item {
  flex: none;
  flex-direction: row;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  gap: 10px;
  font-size: 13px;
  width: 100%;
}

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

.desktop-nav .nav-item .nav-icon {
  font-size: 16px;
}

.desktop-nav .nav-item .nav-label {
  font-size: 13px;
}

@media (min-width: 600px) {
  .app-main {
    margin-left: 200px;
  }
}

.inline-flex {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
