:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #6d28d9;
  --primary-soft: #ede9fe;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --radius: 14px;
  --tab-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --card: #1e293b; --text: #f1f5f9; --muted: #94a3b8; --line: #334155;
    --primary-soft: #3b1d6e; --danger-soft: #7f1d1d; --ok-soft: #14532d; --warn-soft: #78350f;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; font-size: 16px; -webkit-tap-highlight-color: transparent; }
body { overscroll-behavior-y: contain; }
[hidden] { display: none !important; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0 0 8px; }
h2 { font-size: 1.05rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-top: 18px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }

/* ---- login ---- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { background: var(--card); border-radius: 20px; padding: 32px 24px; max-width: 380px; width: 100%; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.08); }
.login-logo { width: 84px; height: 84px; border-radius: 22px; margin-bottom: 12px; }
.login-card p { color: var(--muted); }
.btn-google { display: inline-flex; gap: 10px; align-items: center; justify-content: center; width: 100%; margin-top: 16px; background: #fff; color: #111; border: 1px solid #d1d5db; text-decoration: none; }
.link { display: inline-block; margin-top: 14px; }

/* ---- layout ---- */
.topbar { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line);
  padding: calc(10px + var(--safe-t)) 16px 10px; display: flex; align-items: center; justify-content: space-between; }
.topbar-title { font-weight: 700; font-size: 1.25rem; }
.topbar-right { display: flex; gap: 10px; align-items: center; }
.avatar { width: 32px; height: 32px; border-radius: 50%; }
#main { padding: 12px 14px calc(var(--tab-h) + var(--safe-b) + 90px); max-width: 720px; margin: 0 auto; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--card); border-top: 1px solid var(--line); display: flex; }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 600; }
.tabbar a .ico { font-size: 1.3rem; }
.tabbar a.active { color: var(--primary); }
.fab { position: fixed; right: 18px; bottom: calc(var(--tab-h) + var(--safe-b) + 18px); z-index: 6; width: 60px; height: 60px; border-radius: 50%;
  background: var(--primary); color: #fff; border: 0; font-size: 2rem; line-height: 1; box-shadow: 0 8px 20px rgba(109,40,217,.45); cursor: pointer; }

/* ---- botones / inputs ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 12px 16px; border-radius: 12px; border: 0;
  background: var(--primary); color: #fff; font-weight: 600; font-size: 1rem; cursor: pointer; text-decoration: none; }
.btn.secondary { background: var(--primary-soft); color: var(--primary); }
@media (prefers-color-scheme: dark) { .btn.secondary { color: #ddd6fe; } }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.ok { background: var(--ok); }
.btn.wa { background: #25d366; color: #fff; }
.btn.block { width: 100%; }
.btn.sm { padding: 8px 12px; font-size: .9rem; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.iconbtn { background: transparent; border: 0; font-size: 1.4rem; color: var(--muted); cursor: pointer; padding: 4px 6px; }
label.field { display: block; margin-top: 12px; font-size: .85rem; color: var(--muted); font-weight: 600; }
input[type=text], input[type=email], input[type=tel], input[type=date], input[type=time], input[type=password], textarea, select {
  width: 100%; margin-top: 4px; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 1rem; font-family: inherit; }
textarea { min-height: 84px; resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; padding: 10px 0; font-size: 1rem; }
.check input { width: 22px; height: 22px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: .9rem; cursor: pointer; user-select: none; }
.chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.chip.add { border-style: dashed; color: var(--primary); }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

/* ---- tarjetas / listas ---- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.05); margin-bottom: 10px; }
.task { display: flex; gap: 12px; align-items: flex-start; background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.task .tick { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); flex-shrink: 0; margin-top: 2px; display: grid; place-items: center; color: #fff; cursor: pointer; font-size: .9rem; }
.task.done .tick { background: var(--ok); border-color: var(--ok); }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.task .body { flex: 1; min-width: 0; cursor: pointer; }
.task .title { font-weight: 600; word-break: break-word; }
.task .meta { color: var(--muted); font-size: .85rem; margin-top: 3px; display: flex; flex-wrap: wrap; gap: 6px 10px; }
.task.overdue .meta .when { color: var(--danger); font-weight: 600; }
.task.prio-urgent .title::before { content: "❗"; margin-right: 4px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--primary-soft); color: var(--primary); }
@media (prefers-color-scheme: dark) { .badge { color: #ddd6fe; } }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.gray { background: var(--line); color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.empty .big { font-size: 2.4rem; }

/* ---- calendario ---- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 10px; }
.cal-head .month { font-weight: 700; font-size: 1.1rem; text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: .72rem; color: var(--muted); font-weight: 600; padding: 4px 0; }
.cal-day { aspect-ratio: 1; border-radius: 10px; background: var(--card); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer; font-size: .95rem; border: 2px solid transparent; }
.cal-day.other { opacity: .35; }
.cal-day.today { border-color: var(--primary); font-weight: 700; }
.cal-day.sel { background: var(--primary); color: #fff; }
.cal-day .dots { display: flex; gap: 3px; height: 6px; }
.cal-day .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--primary); }
.cal-day .dot.ev { background: var(--warn); }
.cal-day.sel .dot { background: #fff; }
.event { display: flex; gap: 10px; align-items: center; background: var(--card); border-left: 4px solid var(--warn); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 8px; }

/* ---- hoja deslizante ---- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--card); border-radius: 22px 22px 0 0; max-height: 92vh; overflow-y: auto;
  padding: 8px 18px calc(24px + var(--safe-b)); box-shadow: 0 -10px 40px rgba(0,0,0,.2); max-width: 720px; margin: 0 auto; animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 6px auto 12px; }
.sheet h3 { font-size: 1.15rem; }
.actions { display: flex; gap: 10px; margin-top: 18px; }
.actions .btn { flex: 1; }

/* ---- dictado ---- */
.dictate { display: flex; gap: 10px; align-items: flex-end; }
.dictate textarea { flex: 1; margin: 0; }
.mic { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--primary-soft); color: var(--primary); font-size: 1.6rem; cursor: pointer; flex-shrink: 0; }
.mic.rec { background: var(--danger); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(220,38,38,.5);} 100% { box-shadow: 0 0 0 14px rgba(220,38,38,0);} }
.understood { background: var(--primary-soft); border-radius: 12px; padding: 10px 12px; margin-top: 10px; font-size: .95rem; }
.understood .eng { font-size: .75rem; opacity: .7; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 12px; margin-top: 10px; font-size: .9rem; }

/* ---- ajustes ---- */
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting .lbl { flex: 1; }
.setting .lbl .d { font-size: .82rem; color: var(--muted); }
.switch { position: relative; width: 48px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 28px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(20px); }
.person { display: flex; gap: 12px; align-items: center; background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; cursor: pointer; }
.person .ini { width: 40px; height: 40px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.person .info { flex: 1; min-width: 0; }
.person .info .n { font-weight: 600; }
.person .info .c { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- toast ---- */
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 24px); transform: translateX(-50%); z-index: 30; background: #111827; color: #fff;
  padding: 12px 18px; border-radius: 12px; font-size: .95rem; max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.toast.err { background: var(--danger); }
.spin { display: inline-block; width: 18px; height: 18px; border: 3px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: rot .8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* permitir seleccionar/pegar en campos y textos (menú contextual del móvil) */
input, textarea, .task .title, .task .meta, p, h3, code { -webkit-user-select: text; user-select: text; }
input, textarea { -webkit-touch-callout: default; }

.row > input, .row > textarea { flex: 1; min-width: 0; }

.fab-voice { right: 92px; width: 64px; height: 64px; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); padding: 0; background: transparent; box-shadow: none; overflow: visible; }
.fab-voice img { width: 100%; height: 100%; display: block; filter: drop-shadow(0 6px 12px rgba(0,0,0,.45)); }
.fab-voice:active { transform: scale(.95); }

/* Conversación con el asistente de órdenes */
.cmd-log { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 10px; max-height: 34vh; overflow-y: auto; }
.cmd-log:empty { display: none; }
.cmd-msg { padding: 8px 12px; border-radius: 14px; font-size: .95rem; line-height: 1.35; max-width: 92%; }
.cmd-msg.user { align-self: flex-end; background: var(--primary-soft); color: var(--text); border-bottom-right-radius: 4px; }
.cmd-msg.assistant { align-self: flex-start; background: var(--card); color: var(--text); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.cmd-options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.cmd-options .chip-btn { font: inherit; font-size: .95rem; padding: 10px 14px; border-radius: 999px; border: 1px solid var(--primary); background: var(--primary-soft); color: var(--primary); cursor: pointer; }
#cmd-reset[hidden], #cmd-examples[hidden] { display: none !important; }
@media (prefers-color-scheme: dark) { .cmd-options .chip-btn { color: #ddd6fe; border-color: #7c3aed; } }

/* Versión beta */
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.beta-badge { font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: #e8b22a; border: 1px solid #e8b22a; border-radius: 999px; padding: 2px 7px; white-space: nowrap; line-height: 1.3; }
.version-note { font-size: .78rem; color: var(--muted); margin-top: 8px; text-align: center; }

/* Proyectos */
.cat-h { display: flex; align-items: center; gap: 8px; }
.cat-h h2 { flex: 1; }
.project { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; cursor: pointer; }
.project .p-ico { font-size: 1.5rem; }
.project .info { flex: 1; min-width: 0; }
.project .n { font-weight: 600; }
.project .c { font-size: .85rem; color: var(--muted); }
.project .chev { color: var(--muted); font-size: 1.4rem; }
.warn-txt { color: var(--warn); }
.badge.proj { background: var(--warn-soft); color: var(--warn); }
.cat-toggle { flex: 1; display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; }
.cat-toggle h2 { flex: 1; }
.cat-toggle .chev-s { color: var(--muted); font-size: .9rem; width: 1em; display: inline-block; }
.cat-body[hidden] { display: none !important; }

/* Equipo, contactos y Ajustes arriba */
.team-star { background: none; border: 0; font-size: 1.4rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 6px 8px; }
.team-star.on { color: #e8b22a; }
.back-link { display: inline-block; margin: 2px 0 12px; color: var(--primary); text-decoration: none; font-weight: 600; }
#avatar { cursor: pointer; }
#btn-settings.active { color: var(--primary); }
.urgent-h { color: var(--danger); }

/* Equipo */
.member { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; cursor: pointer; }
.member .ini, .member-head .ini { width: 40px; height: 40px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.member-head .ini.big { width: 56px; height: 56px; font-size: 1.25rem; }
.member .info, .member-head .info { flex: 1; min-width: 0; }
.member .n, .member-head .n { font-weight: 600; }
.member-head .n { font-size: 1.15rem; }
.member .c, .member-head .c { font-size: .85rem; color: var(--muted); }
.member .chev { color: var(--muted); font-size: 1.4rem; }
.member-head { display: flex; align-items: center; gap: 14px; margin: 4px 0 12px; }

/* Notas */
.note { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; }
.note-text { line-height: 1.45; word-break: break-word; }
.note-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.note-meta .grow { flex: 1; }
.note-new textarea { min-height: 90px; }

/* «Lista / Calendario» dentro de la Agenda */
.seg { display: flex; gap: 6px; padding: 4px; margin: 0 0 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.seg a { flex: 1; padding: 8px 10px; border-radius: 9px; text-align: center; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .9rem; }
.seg a.on { background: var(--primary); color: #fff; }

/* Tareas urgentes: el título en MAYÚSCULAS */
.task.prio-urgent .title { text-transform: uppercase; letter-spacing: .01em; }

/* Iconos de línea (maletín de Proyectos, capas de Varios): toman el color del texto */
.ico-svg { width: 1em; height: 1em; vertical-align: -0.15em; }
.tabbar a .ico .ico-svg { width: 1.45rem; height: 1.45rem; vertical-align: middle; }
.project .p-ico .ico-svg { color: var(--primary); }

/* Agenda: cabecera de cada día en «Próximos 7 días» */
.day-h { margin: 12px 2px 6px; font-size: .82rem; font-weight: 700; color: var(--muted); }

/* Barra de abajo: los 4 huecos del medio los elige cada persona; nombres largos con puntos suspensivos */
#tab-slots { display: contents; }
.tabbar a { min-width: 0; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.tabbar a .lbl { max-width: 100%; padding: 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Prioridades: una raya de color a la izquierda de cada tarea y su etiqueta */
.task { border-left: 4px solid transparent; }
.task.prio-urgent { border-left-color: var(--danger); }
.task.prio-high { border-left-color: var(--warn); }
.task.prio-medium { border-left-color: var(--primary); }
.task.prio-low { border-left-color: var(--line); }
.badge.prio-urgent { background: var(--danger-soft); color: var(--danger); }
.badge.prio-high { background: var(--warn-soft); color: var(--warn); }
.badge.prio-medium { background: var(--primary-soft); color: var(--primary); }
.badge.prio-low { background: var(--line); color: var(--muted); }
.chip.prio-urgent.on { background: var(--danger); border-color: var(--danger); color: #fff; }
.chip.prio-high.on { background: var(--warn); border-color: var(--warn); color: #fff; }
.chip.prio-low.on { background: var(--muted); border-color: var(--muted); color: #fff; }

/* Código para emparejar el widget de Android: grande y fácil de copiar a mano */
.codigo-widget { text-align: center; margin: 12px 0 4px; }
.codigo-widget .c { font-size: 2.1rem; font-weight: 700; letter-spacing: .35em; color: var(--primary);
  background: var(--primary-soft); border-radius: 12px; padding: 12px 8px 12px 20px; user-select: all; }

/* Prioridad de cada obra o proyecto: la misma raya de color que en las tareas */
.project.prio-urgent { border-left: 4px solid var(--danger); }
.project.prio-high { border-left: 4px solid var(--warn); }
.project.prio-medium { border-left: 4px solid var(--primary); }
.project.prio-low { border-left: 4px solid var(--line); }

/* Pantalla de arranque (mientras la app conecta con el servidor) */
.boot { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: var(--bg); color: var(--muted); padding: 24px; text-align: center; }
.boot[hidden] { display: none; }
.boot-logo { width: 96px; height: 96px; border-radius: 22px; }
.boot-spin { width: 26px; height: 26px; border-color: rgba(167,139,250,.35); border-top-color: var(--primary); }
.boot-msg { font-size: .95rem; max-width: 320px; line-height: 1.4; }

/* Varias tareas de una visita: lista para revisar y crear de golpe */
.visita-item { padding: 6px 0; border-bottom: 1px solid var(--line); }
.visita-item .check { padding: 6px 0; }
.visita-item .vs-titulo { margin-top: 0; padding: 8px 10px; font-size: .95rem; }
.acc-req{padding:8px 0;border-top:1px solid var(--border, rgba(148,163,184,.25))}
.acc-req .row{margin-top:6px}
