:root {
  --coral: #FF6B6B;
  --mint: #4ECDC4;
  --sun: #FFE66D;
  --purple: #A78BFA;
  --sky: #60A5FA;
  --bg: #FFF8F1;
  --card: #FFFFFF;
  --ink: #2D3142;
  --muted: #8A8FA3;
  --line: #F1E8DD;
  --shadow: 0 8px 24px rgba(255,107,107,.08), 0 2px 6px rgba(0,0,0,.04);
  --radius: 20px;
  --radius-sm: 12px;
}
[data-theme="dark"] {
  --bg: #1B1D2A;
  --card: #262A3D;
  --ink: #F0F2F8;
  --muted: #9CA3B8;
  --line: #353A52;
  --shadow: 0 8px 24px rgba(0,0,0,.4);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: 'Nunito', system-ui, sans-serif; background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* AUTH */
.auth-screen { min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, #FFE5D9, #C8F0EC, #E0D7FF); }
.auth-card { width: 100%; max-width: 420px; background: var(--card); border-radius: 28px; padding: 32px; box-shadow: 0 20px 60px rgba(0,0,0,.12); }
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-brand .brand-icon { font-size: 56px; }
.auth-brand h1 { margin: 6px 0 0; font-size: 28px; letter-spacing: -.5px; }
.auth-brand .tagline { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.auth-tabs { display: flex; gap: 6px; background: var(--line); padding: 6px; border-radius: 14px; margin-bottom: 18px; }
.tab-btn { flex: 1; padding: 10px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 700; transition: .2s; }
.tab-btn.active { background: var(--card); color: var(--coral); box-shadow: 0 2px 6px rgba(0,0,0,.06); }
.auth-form { display: none; flex-direction: column; gap: 12px; }
.auth-form.active { display: flex; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.auth-form input, .auth-form select { padding: 12px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); color: var(--ink); font-size: 15px; font-family: inherit; }
.auth-form input:focus, .auth-form select:focus { outline: none; border-color: var(--coral); }
.btn-primary { background: linear-gradient(135deg, var(--coral), #FF8C8C); color: white; border: 0; padding: 14px; border-radius: 14px; font-weight: 800; font-size: 16px; box-shadow: 0 6px 18px rgba(255,107,107,.4); transition: .2s; }
.btn-primary:hover { transform: translateY(-2px); }
.btn-ghost { background: transparent; border: 0; color: var(--muted); padding: 10px; border-radius: 10px; }
.btn-ghost:hover { background: var(--line); }
.hint { font-size: 12px; color: var(--muted); text-align: center; margin: 0; }
.auth-msg { margin-top: 12px; font-size: 14px; min-height: 20px; text-align: center; color: var(--coral); font-weight: 600; }

/* APP SHELL */
.app-shell { display: grid; grid-template-columns: 240px 1fr; grid-template-rows: 64px 1fr; min-height: 100dvh; }
.sidebar { grid-row: 1 / span 2; background: var(--card); border-right: 1px solid var(--line); padding: 20px 16px; display: flex; flex-direction: column; gap: 16px; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; padding: 6px; }
.sidebar-brand .brand-icon { font-size: 28px; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px; font-weight: 700; color: var(--muted); font-size: 15px; transition: .2s; }
.nav-item:hover { background: var(--line); color: var(--ink); }
.nav-item.active { background: linear-gradient(135deg, var(--coral), #FF8C8C); color: white; box-shadow: 0 4px 12px rgba(255,107,107,.3); }
.sidebar-foot { display: flex; flex-direction: column; gap: 8px; }
.conn-pill { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding: 6px 10px; border-radius: 999px; background: var(--line); }
.conn-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn-pill.online .dot { background: var(--mint); box-shadow: 0 0 0 4px rgba(78,205,196,.2); }
.topbar { grid-column: 2; background: var(--card); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 0 20px; }
.hamburger { display: none; background: transparent; border: 0; font-size: 22px; }
.topbar-title { font-weight: 800; font-size: 18px; flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar-user span { font-size: 24px; }
.topbar-user .who { display: flex; flex-direction: column; line-height: 1.2; }
.topbar-user small { color: var(--muted); font-size: 11px; }
.view { grid-column: 2; padding: 24px; overflow-y: auto; }
.bottom-nav { display: none; }

/* RESPONSIVE */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: 56px 1fr 64px; }
  .sidebar { display: none; position: fixed; top: 0; left: 0; bottom: 0; width: 80%; max-width: 280px; z-index: 50; }
  .sidebar.open { display: flex; }
  .topbar { grid-column: 1; }
  .view { grid-column: 1; padding: 16px; padding-bottom: 80px; }
  .hamburger { display: block; }
  .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--line); padding: 8px 4px env(safe-area-inset-bottom); justify-content: space-around; z-index: 40; }
  .bn { flex: 1; display: flex; flex-direction: column; align-items: center; font-size: 20px; color: var(--muted); padding: 6px; border-radius: 10px; }
  .bn small { font-size: 10px; margin-top: 2px; font-weight: 700; }
  .bn.active { color: var(--coral); }
}

/* CARDS GENERICAS */
.card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card h2, .card h3 { margin: 0 0 12px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* STAT CARDS */
.stat { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat .label { color: var(--muted); font-size: 13px; font-weight: 700; }
.stat .value { font-size: 28px; font-weight: 800; margin-top: 4px; }
.stat .ico { position: absolute; right: 12px; top: 12px; font-size: 32px; opacity: .25; }
.stat.coral { background: linear-gradient(135deg, #FFE5E5, #FFD0D0); }
.stat.mint { background: linear-gradient(135deg, #DBF7F4, #BDEFE9); }
.stat.sun { background: linear-gradient(135deg, #FFF7C8, #FFEFA0); }
.stat.purple { background: linear-gradient(135deg, #EAE0FF, #D8C8FF); }
[data-theme="dark"] .stat.coral, [data-theme="dark"] .stat.mint, [data-theme="dark"] .stat.sun, [data-theme="dark"] .stat.purple { background: var(--card); }

/* BUTTONS */
.btn { padding: 10px 16px; border-radius: 12px; border: 0; font-weight: 700; font-size: 14px; transition: .2s; }
.btn-coral { background: var(--coral); color: white; }
.btn-mint { background: var(--mint); color: white; }
.btn-outline { background: transparent; border: 2px solid var(--line); color: var(--ink); }
.btn-danger { background: #EF4444; color: white; }
.btn:hover { transform: translateY(-1px); }
.btn-fab { position: fixed; bottom: 90px; right: 20px; width: 60px; height: 60px; border-radius: 50%; background: linear-gradient(135deg, var(--coral), #FF8C8C); color: white; font-size: 28px; border: 0; box-shadow: 0 8px 20px rgba(255,107,107,.4); z-index: 30; }
@media (min-width: 900px) { .btn-fab { bottom: 30px; } }

/* PROGRESS BARS */
.bar { background: var(--line); border-radius: 999px; height: 10px; overflow: hidden; }
.bar > div { height: 100%; border-radius: 999px; transition: width .4s ease; background: linear-gradient(90deg, var(--mint), var(--sun)); }
.bar > div.warn { background: linear-gradient(90deg, var(--sun), #FFB84D); }
.bar > div.danger { background: linear-gradient(90deg, #FFB84D, var(--coral)); }
.bar > div.over { background: linear-gradient(90deg, var(--coral), #B91C1C); }

/* TICKET LIST */
.ticket-row { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--radius-sm); transition: background .2s; }
.ticket-row:hover { background: var(--line); }
.ticket-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--line); display: grid; place-items: center; font-size: 20px; flex-shrink: 0; }
.ticket-info { flex: 1; min-width: 0; }
.ticket-info strong { display: block; font-size: 14px; }
.ticket-info small { color: var(--muted); font-size: 12px; }
.ticket-amount { font-weight: 800; font-size: 16px; }

/* TARJETAS BILLETERA */
.wallet-card { aspect-ratio: 1.586/1; border-radius: 18px; padding: 18px; color: white; box-shadow: 0 10px 24px rgba(0,0,0,.15); position: relative; overflow: hidden; transition: transform .3s, box-shadow .3s; cursor: pointer; display: flex; flex-direction: column; justify-content: space-between; }
.wallet-card:hover { transform: translateY(-4px) rotate(-1deg); box-shadow: 0 16px 32px rgba(0,0,0,.25); }
.wallet-card.warn { animation: pulse-warn 2s infinite; }
@keyframes pulse-warn { 0%, 100% { box-shadow: 0 10px 24px rgba(0,0,0,.15); } 50% { box-shadow: 0 0 0 6px rgba(255,107,107,.5), 0 10px 24px rgba(0,0,0,.15); } }
.wallet-chip { width: 36px; height: 28px; border-radius: 6px; background: linear-gradient(135deg, #f7e08c, #d6a83a); }
.wallet-num { font-size: 18px; letter-spacing: 2px; font-weight: 700; font-family: 'Courier New', monospace; }
.wallet-foot { display: flex; justify-content: space-between; align-items: end; font-size: 12px; }
.wallet-brand { font-weight: 800; font-size: 16px; font-style: italic; }

/* MODAL */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; z-index: 100; padding: 20px; backdrop-filter: blur(4px); }
.modal-card { background: var(--card); border-radius: var(--radius); padding: 28px; max-width: 480px; width: 100%; max-height: 90dvh; overflow-y: auto; position: relative; }
.modal-card.crop-modal { max-width: 760px; }
.modal-close { position: absolute; top: 12px; right: 12px; background: transparent; border: 0; font-size: 28px; color: var(--muted); width: 36px; height: 36px; border-radius: 50%; }
.modal-close:hover { background: var(--line); color: var(--ink); }

/* TOASTS */
.toasts { position: fixed; bottom: 80px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: white; padding: 12px 18px; border-radius: 14px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: slidein .3s; max-width: 300px; }
.toast.success { background: var(--mint); }
.toast.error { background: var(--coral); }
@keyframes slidein { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* FORMS */
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.form-row label { font-size: 13px; font-weight: 700; color: var(--muted); }
.form-row input, .form-row select, .form-row textarea { padding: 11px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); color: var(--ink); font-size: 15px; font-family: inherit; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { outline: none; border-color: var(--coral); }
.smart-cat-btn { align-self: flex-start; padding: 8px 10px; font-size: 12px; }
.ops-panel { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; background: rgba(78,205,196,.06); }
.ops-panel summary { cursor: pointer; font-weight: 800; color: var(--ink); }
.checkline { display: flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 800; }
.checkline input { width: 18px; height: 18px; }

/* DROPZONE */
.dropzone { border: 3px dashed var(--line); border-radius: var(--radius); padding: 40px; text-align: center; transition: .2s; cursor: pointer; }
.dropzone:hover, .dropzone.over { border-color: var(--coral); background: rgba(255,107,107,.05); }
.dropzone .icon { font-size: 48px; margin-bottom: 8px; }
.native-capture-actions { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.qr-reader { width: 100%; min-height: 240px; border: 2px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--line); }
.qr-reader video, .qr-native-video { width: 100% !important; min-height: 240px; display: block; object-fit: cover; border-radius: var(--radius-sm); }
#ocr-preview textarea { width: 100%; margin-top: 6px; padding: 11px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); color: var(--ink); font-size: 13px; font-family: inherit; resize: vertical; }
.code-paste { display: grid; gap: 8px; }
.code-paste textarea { width: 100%; padding: 11px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); color: var(--ink); font-size: 14px; font-family: inherit; resize: vertical; }
.crop-stage { width: 100%; display: grid; place-items: center; background: var(--line); border-radius: var(--radius-sm); padding: 10px; overflow: hidden; touch-action: none; }
.crop-stage canvas { max-width: 100%; height: auto; border-radius: 8px; cursor: move; touch-action: none; box-shadow: 0 6px 18px rgba(0,0,0,.18); }
.crop-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* TABLA */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; }
tr:hover td { background: var(--line); }
.report-filters { display: grid; grid-template-columns: minmax(220px, 1.7fr) repeat(4, minmax(140px, 1fr)); gap: 8px; }
.report-filters input, .report-filters select { min-width: 0; padding: 10px 12px; border-radius: 10px; border: 2px solid var(--line); background: var(--card); color: var(--ink); font-family: inherit; }
.report-filters input:focus, .report-filters select:focus { outline: none; border-color: var(--coral); }
@media (max-width: 900px) { .report-filters { grid-template-columns: 1fr; } }

/* ANALISIS */
.insight-list { display: flex; flex-direction: column; gap: 10px; }
.insight-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.insight-row:last-child { border-bottom: 0; }
.insight-row small { display: block; color: var(--muted); margin-top: 2px; }
.kpi { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; background: rgba(255,255,255,.42); }
.kpi span { color: var(--muted); font-size: 12px; font-weight: 800; display: block; }
.kpi strong { display: block; margin-top: 4px; font-size: 22px; }

/* ALERTAS */
.alert-card { display: flex; gap: 14px; padding: 14px; border-radius: var(--radius-sm); border-left: 6px solid; align-items: center; }
.alert-card.yellow { background: #FFF8DC; border-color: var(--sun); }
.alert-card.orange { background: #FFE9CC; border-color: #FFB84D; }
.alert-card.red { background: #FFE0E0; border-color: var(--coral); }
.alert-card.green { background: #DBF7F4; border-color: var(--mint); }
[data-theme="dark"] .alert-card.yellow, [data-theme="dark"] .alert-card.orange, [data-theme="dark"] .alert-card.red, [data-theme="dark"] .alert-card.green { background: var(--card); }
.alert-ico { font-size: 26px; }

/* ESTADOS DE CUENTA */
.statement-list { display: flex; flex-direction: column; gap: 10px; }
.statement-item { display: flex; justify-content: space-between; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); align-items: flex-start; }
.statement-item strong { display: block; }
.statement-item small { display: block; color: var(--muted); margin-top: 3px; }
.statement-note { max-width: 48ch; overflow-wrap: anywhere; }
.safe-check { display: flex; align-items: flex-start; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 700; margin: 6px 0 14px; }
.safe-check input { margin-top: 3px; }
@media (max-width: 700px) {
  .statement-item { flex-direction: column; }
}

/* SWITCH */
.switch { position: relative; display: inline-block; width: 48px; height: 26px; }
.switch input { display: none; }
.switch .slider { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .3s; }
.switch .slider::before { content: ''; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; background: white; border-radius: 50%; transition: .3s; box-shadow: 0 2px 4px rgba(0,0,0,.2); }
.switch input:checked + .slider { background: var(--mint); }
.switch input:checked + .slider::before { transform: translateX(22px); }

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.muted { color: var(--muted); }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-12 { margin-bottom: 12px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.center { align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
