:root {
  --bg: #09090B;
  --surface: #121216;
  --surface-2: #1A1A20;
  --border: #27272A;
  --text: #F4F4F5;
  --muted: #A1A1AA;
  --emerald: #10B981;
  --emerald-bg: rgba(16, 185, 129, 0.12);
  --gold: #F59E0B;
  --gold-bg: rgba(245, 158, 11, 0.12);
  --purple: #A855F7;
  --blue: #3B82F6;
  --danger: #EF4444;
  --radius: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
  min-height: 100dvh;
  overflow-x: hidden;
  padding-top: env(safe-area-inset-top);
}

.hidden {
  display: none !important;
}

/* PANTALLA BLOQUEO PIN */
.lock-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
}

.lock-box {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.brand-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--emerald);
  background: var(--emerald-bg);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 6px 14px;
  border-radius: 999px;
  margin-bottom: 14px;
}

.lock-subtitle {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 20px;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 12px;
}

.pin-dots span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  transition: all 0.15s ease;
}

.pin-dots span.filled {
  background: var(--emerald);
  border-color: var(--emerald);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

.pin-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 20px;
  margin-bottom: 12px;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.keypad button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 22px;
  font-weight: 600;
  height: 62px;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}

.keypad button:active {
  transform: scale(0.95);
  background: var(--surface-2);
}

.keypad button.key-fn {
  font-size: 16px;
  color: var(--muted);
}

/* ESTRUCTURA PRINCIPAL */
.app-shell {
  max-width: 520px;
  margin: 0 auto;
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: rgba(9, 9, 11, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald);
}

.status-dot.offline {
  background: var(--gold);
  box-shadow: 0 0 8px var(--gold);
}

.main-content {
  padding: 16px;
}

.tab-panel {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.tab-panel.active {
  display: flex;
}

/* TARJETAS HERO Y KPI */
.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.emerald-glow {
  border-color: rgba(16, 185, 129, 0.35);
  background: linear-gradient(160deg, rgba(16, 185, 129, 0.12) 0%, var(--surface) 65%);
}

.gold-glow {
  border-color: rgba(245, 158, 11, 0.35);
  background: linear-gradient(160deg, rgba(245, 158, 11, 0.12) 0%, var(--surface) 65%);
}

.hero-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--emerald);
  margin-bottom: 6px;
}

.hero-amount {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 16px;
}

.hero-split {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 13px;
}

.hero-split div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.text-gold { color: var(--gold); }
.text-purple { color: var(--purple); }
.text-blue { color: var(--blue); }
.text-emerald { color: var(--emerald); }
.text-danger { color: var(--danger); }

.kpi-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-card strong {
  font-size: 20px;
}

.purple-border { border-color: rgba(168, 85, 247, 0.4); }
.blue-border { border-color: rgba(59, 130, 246, 0.4); }

.vat-banner {
  background: var(--gold-bg);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

/* BARRA COMANDO RÁPIDO */
.voice-bar {
  display: flex;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px 6px 6px 14px;
}

.voice-bar input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.voice-bar button {
  background: var(--emerald);
  color: #052e16;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-weight: 800;
  cursor: pointer;
}

/* ACORDEONES Y GRÁFICOS */
.accordion-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.accordion-card summary {
  list-style: none;
  padding: 14px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.accordion-card summary::-webkit-details-marker {
  display: none;
}

.accordion-card summary::after {
  content: "▾";
  font-size: 14px;
  transition: transform 0.2s ease;
}

.accordion-card[open] summary::after {
  transform: rotate(180deg);
}

.chart-wrap {
  padding: 8px 14px 16px;
  height: 210px;
  position: relative;
}

.guide-body {
  padding: 0 16px 16px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.guide-body code {
  background: var(--surface-2);
  color: var(--emerald);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 12px;
}

/* LISTADOS Y TARJETAS DE ELEMENTOS */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
}

.section-header h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.item-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.item-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-sub {
  font-size: 12px;
  color: var(--muted);
}

.item-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.item-amount {
  font-size: 15px;
  font-weight: 700;
}

.progress-bar {
  width: 100%;
  height: 7px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 999px;
  transition: width 0.3s ease;
}

/* AJUSTES Y FORMULARIOS */
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-card h3 {
  font-size: 15px;
  font-weight: 600;
}

.inline-form {
  display: flex;
  gap: 8px;
}

.inline-form input,
.stack-form input,
.stack-form select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 14px;
  outline: none;
}

.copy-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}

.copy-box code {
  font-size: 11px;
  color: var(--emerald);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* BOTONES */
button {
  font-family: inherit;
}

.btn-primary-sm,
.btn-gold-sm,
.btn-ghost-sm,
.btn-icon-sm {
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary-sm {
  background: var(--emerald);
  color: #052e16;
}

.btn-gold-sm {
  background: var(--gold);
  color: #271700;
}

.btn-ghost-sm {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-icon-sm {
  background: transparent;
  color: var(--muted);
  padding: 4px 8px;
  font-size: 14px;
}

.btn-primary-full,
.btn-gold-full,
.btn-danger-full {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 13px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary-full {
  background: var(--emerald);
  color: #052e16;
}

.btn-gold-full {
  background: var(--gold);
  color: #271700;
}

.btn-danger-full {
  background: rgba(239, 68, 68, 0.14);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.35);
}

/* NAVEGACIÓN INFERIOR */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 520px;
  margin: 0 auto;
  background: rgba(18, 18, 22, 0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  z-index: 60;
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
}

.nav-ico {
  font-size: 18px;
  line-height: 1;
}

.nav-btn.active {
  color: var(--emerald);
}

/* MODALES */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding: 12px;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  margin-bottom: env(safe-area-inset-bottom);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-head h3 {
  font-size: 16px;
}

.modal-close {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.field-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: -5px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 12px;
}

.segmented label {
  cursor: pointer;
}

.segmented input {
  display: none;
}

.segmented span {
  display: block;
  text-align: center;
  padding: 8px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.segmented input:checked + span {
  background: var(--emerald);
  color: #052e16;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.checkbox-row input {
  width: auto;
}

/* TOAST NOTIFICACIÓN */
.toast {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--emerald);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}