/* Paleta y componentes tomados de doko-paraguay (app/css/estilo.css) -- mismo criterio
   visual entre las apps del usuario, no un "estilo doko aproximado". */
:root {
  --bg: #F9F6F0;
  --card: #FFFFFF;
  --ink: #2E2E2E;
  --text-secondary: #4A4A4A;
  --muted: #5C5C5C;
  --border: #E5DFD2;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --primary: #2E5077;
  --primary-dark: #223C5C;
  --primary-tint: #E6ECF1;
  --success: #16A34A;
  --success-tint: #E7F8EC;
  --success-ink: #2E7D32;
  --warning: #F5A524;
  --warning-tint: #FEF3DA;
  --warning-ink: #8a5a00;
  --danger: #F2545B;
  --danger-tint: #FDE7E8;
  --danger-ink: #a4222c;
  --shadow: 0 10px 30px rgba(30, 40, 90, 0.08);
}
:root[data-theme="dark"] {
  --bg: #14161c;
  --card: #1e2027;
  --ink: #EAEAEC;
  --text-secondary: #c7c7c9;
  --muted: #9096A3;
  --border: #2c2f38;
  --primary: #6FA3D1;
  --primary-dark: #17314a;
  --primary-tint: #1f3145;
  --success: #22C55E;
  --success-tint: #123821;
  --success-ink: #4ADE80;
  --warning: #FBBF24;
  --warning-tint: #3a2c0f;
  --warning-ink: #FFC670;
  --danger: #FB7185;
  --danger-tint: #3a1b1f;
  --danger-ink: #ff9aa2;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
  padding-top: env(safe-area-inset-top);
}
.card, .field input, .field select, .chip, .proyecto-card, .entrada, .quick-action {
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.wrap { max-width: 460px; margin: 0 auto; padding: 20px 16px calc(90px + env(safe-area-inset-bottom, 0px)); min-height: 100vh; }

.word { font-family: 'Poppins', sans-serif; font-weight: 800; font-size: 1.6rem; color: var(--primary); }

/* ---------- login ---------- */
.login-shell { min-height: calc(100vh - 40px); display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; background: var(--card); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 36px 30px; }
.login-card .word { display: block; text-align: center; margin-bottom: 6px; }
.h1 { font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 1.5rem; margin: 10px 0 4px; text-align: center; }
.sub { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; text-align: center; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; height: 50px; border-radius: var(--radius-md); border: 1.5px solid var(--border);
  background: var(--card); padding: 0 18px; font-family: inherit; font-size: 14.5px; color: var(--ink);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(46,80,119,0.13); }
.field-password { position: relative; }
.field-password input { padding-right: 46px; }
.field-password .toggle-pass {
  position: absolute; right: 4px; top: 32px; width: 42px; height: 42px; border: none; background: transparent;
  color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.field-password .toggle-pass:active { opacity: 0.6; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 52px; border-radius: var(--radius-md); border: none;
  font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 15.5px; cursor: pointer;
  transition: transform 0.1s ease, opacity 0.1s ease;
}
.btn:active { transform: scale(0.97); opacity: 0.88; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 10px 20px rgba(46,80,119,0.28); }
.btn-primary:disabled { opacity: 0.6; cursor: default; box-shadow: none; }
.btn-ghost { background: transparent; color: var(--primary); font-weight: 700; height: auto; padding: 0; width: auto; }

.error-box { background: var(--danger-tint); color: var(--danger-ink); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; margin-bottom: 14px; display: none; }
.error-box.show { display: block; }

/* ---------- topbar + tabbar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.topbar .word { font-size: 1.15rem; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--border); background: var(--card);
  color: var(--muted); display: flex; align-items: center; justify-content: center; cursor: pointer;
  position: relative; transition: transform 0.1s ease, background-color 0.15s ease, border-color 0.15s ease;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn.activo { color: var(--primary); border-color: var(--primary); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 100;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(30,40,90,0.06);
}
.tabbar-inner { width: 100%; max-width: 460px; display: flex; padding: 8px 6px calc(8px + env(safe-area-inset-bottom, 0px)); }
.tab-item {
  position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; font-weight: 600; color: var(--muted);
  text-decoration: none; padding: 4px 0; border: none; background: none; font-family: inherit; cursor: pointer;
}
.tab-item i { font-size: 18px; }
.tab-item.active { color: var(--primary); }
.tab-badge {
  position: absolute; top: -2px; left: 50%; margin-left: 6px; min-width: 15px; height: 15px; padding: 0 3px;
  border-radius: 8px; background: var(--danger); color: #fff; border: 2px solid var(--card);
  font-size: 9px; font-weight: 800; font-family: 'Poppins', sans-serif;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- tarjetas genericas ---------- */
.card { background: var(--card); border-radius: var(--radius-lg); padding: 18px 20px; margin-bottom: 14px; box-shadow: 0 6px 18px rgba(30,40,90,0.06); }
.card h3 { font-family: 'Poppins', sans-serif; font-size: 1.05rem; font-weight: 700; margin: 0 0 12px; }
.empty-note { color: var(--muted); font-size: 13px; padding: 0; margin: 0; }

/* tarjeta de sugerencia (patron tarjetaComparador de doko/inicio.html) */
.card.sugerencia { background: var(--primary-tint); box-shadow: none; }
.card.sugerencia.aviso { background: var(--warning-tint); }
.card.sugerencia h3 { display: flex; align-items: center; gap: 8px; font-size: 1rem; }
.card.sugerencia h3 i { color: var(--primary); }
.card.sugerencia.aviso h3 i { color: var(--warning-ink); }
.card.sugerencia .btn-ghost { margin-top: 8px; font-size: 13px; }

/* ---------- chips (filtros) ---------- */
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 4px; margin: -2px -2px 0; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit; font-size: 12.5px; font-weight: 600;
  padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--border);
  background: var(--card); color: var(--ink); cursor: pointer; white-space: nowrap;
  transition: transform 0.1s ease, background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.chip:active { transform: scale(0.96); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(46,80,119,0.25); }
.chip .chip-badge {
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 800; display: flex; align-items: center; justify-content: center;
}

/* ---------- buscador ---------- */
.buscador-wrap { position: relative; margin-bottom: 12px; }
.buscador-wrap i { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; }
#buscar {
  width: 100%; height: 44px; border-radius: var(--radius-md); border: 1.5px solid var(--border);
  background: var(--card); color: var(--ink); padding: 0 14px 0 40px; font-family: inherit; font-size: 14px;
}
#buscar:focus { outline: none; border-color: var(--primary); }
#buscar::placeholder { color: var(--muted); }

/* ---------- tarjetas de proyecto ---------- */
.proyectos { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 8px; margin-bottom: 16px; }
.proyecto-card {
  background: var(--card); border: 1.5px solid var(--border); border-radius: var(--radius-md);
  padding: 12px 14px; cursor: pointer;
}
.proyecto-card.activa { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(46,80,119,0.12); }
.proyecto-card:active { transform: scale(0.98); }
.proyecto-card.nueva { animation: destacarNueva 2.5s ease-out; }
.proyecto-card .nombre { font-family: 'Poppins', sans-serif; font-size: 13px; font-weight: 700; margin-bottom: 5px; word-break: break-word; }
.proyecto-card .meta { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.proyecto-card .preview { font-size: 11px; color: var(--muted); margin-top: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.badge-dot.info { background: var(--primary); }
.badge-dot.ok { background: var(--success); }
.badge-dot.atencion { background: var(--warning); }
.badge-dot.error { background: var(--danger); }

.icono-estado { width: 12px; height: 12px; vertical-align: -2px; margin-right: 4px; flex: none; }
.icono-estado.ok { color: var(--success); }
.icono-estado.atencion { color: var(--warning-ink); }
.icono-estado.error { color: var(--danger); }

/* ---------- separador de dia (sticky, con conteo) ---------- */
.period-label {
  font-family: 'Poppins', sans-serif; font-size: 11.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
  margin: 18px 0 8px; padding: 6px 2px; position: sticky; top: 0; background: var(--bg); z-index: 5;
}

/* ---------- entradas ---------- */
.entrada { background: var(--card); border-radius: var(--radius-md); border-left: 4px solid var(--primary); padding: 12px 14px; margin-bottom: 8px; box-shadow: 0 3px 10px rgba(30,40,90,0.05); }
.entrada.ok { border-left-color: var(--success); }
.entrada.atencion { border-left-color: var(--warning); }
.entrada.error { border-left-color: var(--danger); }
.entrada .cab { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.entrada .proyecto { font-size: 12px; font-weight: 700; color: var(--primary); }
.entrada .proyecto.repetida { opacity: 0.45; }
.entrada .sesion { font-size: 11px; color: var(--muted); font-weight: 500; }
.entrada .hora { font-size: 11px; color: var(--muted); white-space: nowrap; }
.entrada .hora-rel { opacity: 0.75; }
.entrada .mensaje {
  font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; color: var(--ink);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  max-height: 480px; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.entrada .mensaje.presionando { opacity: 0.6; }
.entrada .mensaje mark { background: var(--primary); color: #fff; border-radius: 3px; padding: 0 2px; }

.badge-nuevo {
  font-size: 9.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em;
  color: #fff; background: var(--primary); border-radius: 5px; padding: 2px 6px; margin-left: 6px; white-space: nowrap;
  font-family: 'Poppins', sans-serif;
}
.entrada .ver-mas { display: inline-block; margin: 6px 0 -6px; padding: 6px 10px 6px 0; font-size: 12.5px; font-weight: 700; color: var(--primary); cursor: pointer; }
.entrada .ver-mas:active { opacity: 0.6; }
.entrada .detalle {
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); font-size: 13px; line-height: 1.55;
  color: var(--text-secondary); white-space: pre-wrap; word-break: break-word;
  max-height: 320px; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.entrada .detalle.cargando { font-style: italic; }

/* ---------- control de loop (detener / cambiar intervalo, por proyecto filtrado) ---------- */
.control-loop { background: var(--primary-tint); border-radius: var(--radius-md); padding: 12px 14px; margin-bottom: 14px; }
.control-loop-titulo { display: flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 700; color: var(--primary); margin-bottom: 10px; }
.control-loop-fila { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn-detener-loop {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: 999px; border: 1.5px solid var(--danger); background: var(--danger-tint);
  color: var(--danger-ink); font-family: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer;
}
.btn-detener-loop:active { opacity: 0.7; }
.control-intervalo { display: flex; gap: 6px; align-items: center; }
.control-intervalo input {
  width: 62px; height: 34px; border-radius: var(--radius-sm); border: 1.5px solid var(--border);
  background: var(--card); color: var(--ink); padding: 0 8px; font-family: inherit; font-size: 13px; text-align: center;
}
.control-intervalo input:focus { outline: none; border-color: var(--primary); }
.btn-aplicar-intervalo {
  height: 34px; padding: 0 12px; border-radius: 999px; border: none; background: var(--primary);
  color: #fff; font-family: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer;
}
.btn-aplicar-intervalo:active { opacity: 0.8; }
.control-loop-nota { font-size: 11px; color: var(--muted); margin: 8px 0 0; }

/* ---------- responder (entradas estado=atencion) ---------- */
.btn-responder {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 8px;
  height: 34px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--warning-ink);
  background: var(--warning-tint); color: var(--warning-ink); font-family: inherit;
  font-size: 12.5px; font-weight: 700; cursor: pointer;
}
.btn-responder:active { opacity: 0.7; }
.responder-form { margin-top: 10px; }
.responder-form textarea {
  width: 100%; resize: vertical; min-height: 56px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--card); color: var(--ink);
  padding: 10px 12px; font-family: inherit; font-size: 13.5px; line-height: 1.4;
}
.responder-form textarea:focus { outline: none; border-color: var(--primary); }
.responder-acciones { display: flex; justify-content: flex-end; gap: 14px; margin-top: 8px; }
.btn-cancelar-responder {
  background: none; border: none; color: var(--muted); font-family: inherit;
  font-size: 12.5px; font-weight: 600; cursor: pointer; padding: 8px 2px;
}
.btn-enviar-responder {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 16px;
  border-radius: 999px; border: none; background: var(--primary); color: #fff;
  font-family: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer;
}
.btn-enviar-responder:active { opacity: 0.8; }
.btn-enviar-responder:disabled { opacity: 0.55; cursor: default; }
.respondida-ok {
  display: flex; align-items: center; gap: 6px; margin-top: 8px;
  font-size: 12px; font-weight: 600; color: var(--success-ink);
}

.state-msg { text-align: center; color: var(--muted); font-size: 14px; padding: 60px 0; }

@keyframes destacarNueva {
  0% { background: var(--primary-tint); }
  100% { background: var(--card); }
}
.entrada.nueva { animation: destacarNueva 2.5s ease-out; }

/* ---------- estadoConexion ---------- */
#estadoConexion { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); margin-bottom: 10px; }
#estadoConexion .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
#estadoConexion.off .dot { background: var(--danger); }

/* ---------- toast ---------- */
.toast {
  position: fixed; top: 14px; left: 50%; transform: translate(-50%, -140%);
  max-width: 420px; width: calc(100% - 32px); z-index: 400;
  border-radius: 14px; padding: 12px 16px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow); text-align: center; transition: transform 0.25s ease; pointer-events: none;
  background: var(--card); color: var(--ink); border: 1.5px solid var(--border);
}
.toast.show { transform: translate(-50%, 0); }

/* ---------- pull-to-refresh ---------- */
#pull {
  position: fixed; left: 50%; top: calc(8px + env(safe-area-inset-top)); transform: translateX(-50%) translateY(-40px);
  background: var(--card); border: 1.5px solid var(--border); color: var(--muted);
  font-size: 12px; padding: 7px 14px; border-radius: 16px; opacity: 0; pointer-events: none;
  transition: transform 0.15s ease, opacity 0.15s ease; z-index: 200;
  display: flex; align-items: center; gap: 6px; white-space: nowrap; box-shadow: var(--shadow);
}
#pull.visible { opacity: 1; }
#pull.listo { color: var(--primary); border-color: var(--primary); }
#pull i { transition: transform 0.15s ease; }
#pull.listo i { transform: rotate(180deg); }
#pull.cargando i { animation: girar 0.7s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }

/* ---------- skeleton ---------- */
@keyframes skeleton-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
.skeleton-card { border-radius: var(--radius-lg); background: var(--card); border: 1.5px solid var(--border); margin-bottom: 14px; animation: skeleton-pulse 1.3s ease-in-out infinite; }

/* ---------- estadisticas: tiles + grafico ---------- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.tile { background: var(--card); border-radius: var(--radius-md); padding: 14px 10px; text-align: center; box-shadow: 0 3px 10px rgba(30,40,90,0.05); }
.tile .num { font-family: 'Poppins', sans-serif; font-weight: 800; font-size: 1.35rem; color: var(--primary); line-height: 1.1; }
.tile .lbl { font-size: 10.5px; color: var(--muted); margin-top: 4px; line-height: 1.3; }

.grafico-svg { display: block; width: 100%; height: auto; }
.grafico-leyenda { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 11px; color: var(--muted); }
.grafico-leyenda span { display: inline-flex; align-items: center; gap: 5px; }
.grafico-leyenda .punto { width: 8px; height: 8px; border-radius: 50%; }

.barra-proyecto { display: flex; height: 8px; border-radius: 999px; overflow: hidden; background: var(--border); margin: 8px 0 4px; }
.barra-proyecto span { height: 100%; }

/* ---------- ajustes (Inicio) ---------- */
.ajustes-fila { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.ajustes-fila:last-child { border-bottom: none; }
.ajustes-fila i { width: 18px; text-align: center; color: var(--primary); }
.ajustes-fila button { background: none; border: none; padding: 0; margin: 0; font-family: inherit; font-size: inherit; color: var(--ink); cursor: pointer; text-align: left; flex: 1; }
.ajustes-fila.peligro button { color: var(--danger); }
