:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #6b7785;
  --border: #dde3ea;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --ok-bg: #e7f6ec; --ok-text: #166534;
  --err-bg: #fdecec; --err-text: #991b1b;
  --warn-bg: #fff6e0; --warn-text: #8a5a00;
  --soon: #f59e0b;
  --late: #dc2626;
  --done: #16a34a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161b; --card: #1b2128; --text: #e6e9ed; --muted: #95a1ae; --border: #2c343e;
    --primary: #3b82f6;
    --ok-bg: #12301d; --ok-text: #86efac;
    --err-bg: #3a1616; --err-text: #fca5a5;
    --warn-bg: #3a2c0c; --warn-text: #fcd34d;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* que ningún display de los estilos lo anule */
body { margin: 0; background: var(--bg); color: var(--text);
       font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
code { background: var(--bg); padding: 1px 4px; border-radius: 4px; }

.topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem;
          padding: .75rem 1rem; background: var(--card); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; }

.container { max-width: 900px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px;
        padding: 1.25rem; margin-bottom: 1rem; }
.card.narrow { max-width: 400px; margin: 2rem auto; }
.card.empty { text-align: center; color: var(--muted); }
.muted { color: var(--muted); font-size: .9rem; }
.center { text-align: center; }

.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok-text); }
.flash.error { background: var(--err-bg); color: var(--err-text); }
.flash.warn, .flash.message { background: var(--warn-bg); color: var(--warn-text); }

label { display: block; margin-bottom: .85rem; font-weight: 500; }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
input, textarea, select { display: block; width: 100%; margin-top: .3rem; padding: .55rem .65rem;
  border: 1px solid var(--border); border-radius: 7px; background: var(--card); color: var(--text); font: inherit; }
label.check input { width: auto; margin: 0; }
input[type=file] { padding: .4rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 1rem; }

.btn { display: inline-block; padding: .5rem .95rem; border: 1px solid var(--border); border-radius: 7px;
       background: var(--card); color: var(--text); font: inherit; cursor: pointer; text-decoration: none; }
.btn:hover { text-decoration: none; filter: brightness(.96); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.full { width: 100%; }
.btn.small { padding: .25rem .55rem; font-size: .85rem; }
button.link { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; }
button.link.danger { color: var(--danger); }
form.inline { display: inline; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

.toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem;
           margin-bottom: .75rem; }
.toolbar h1 { margin: 0; }

.filters { background: var(--card); border: 1px solid var(--border); border-radius: 10px;
           padding: .75rem; margin-bottom: 1rem; }
.filters-row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.filters-row + .filters-row { margin-top: .6rem; }
.filters-row > input, .filters-row > select { width: auto; margin: 0; flex: 1 1 160px; }
.filters label { margin: 0; font-size: .82rem; font-weight: 500; color: var(--muted); flex: 1 1 130px; }
.filters label input, .filters label select { margin-top: .15rem; }
.filter-buttons { display: flex; gap: .4rem; }

fieldset.location { border: 1px solid var(--border); border-radius: 8px; padding: .75rem 1rem 1rem; margin: 0 0 1rem; }
fieldset.location legend { font-weight: 600; padding: 0 .3rem; }
.search-row { display: flex; gap: .5rem; }
.search-row input { margin: 0; flex: 1; }
.geo-results { list-style: none; margin: .5rem 0; padding: 0; border: 1px solid var(--border); border-radius: 7px;
               max-height: 220px; overflow-y: auto; }
.geo-results li { padding: .45rem .65rem; cursor: pointer; font-size: .9rem; border-bottom: 1px solid var(--border);
                  line-height: 1.35; }
.geo-results li .muted { font-size: .82rem; }
.geo-results li:last-child { border-bottom: 0; }
.geo-results li:hover { background: var(--bg); }

.map { width: 100%; border-radius: 8px; border: 1px solid var(--border); z-index: 0; }
.map.small { height: 280px; margin: .5rem 0 1rem; }
.map.large { height: 65vh; min-height: 360px; }
.map-legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: center; font-size: .85rem; margin-bottom: .5rem; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: -1px; border: 2px solid #fff;
       box-shadow: 0 0 0 1px var(--border); }
.dot.trade-electricidad { background: #f59e0b; }
.dot.trade-fontaneria { background: #2563eb; }
.dot.trade-ambas { background: #9333ea; }
.dot.trade-none { background: #6b7785; }
.dot.ring { background: var(--bg); border-color: #dc2626; }

.badge.trade-electricidad { background: #fef3c7; border-color: #f59e0b; color: #92400e; text-transform: none; }
.badge.trade-fontaneria { background: #dbeafe; border-color: #2563eb; color: #1e40af; text-transform: none; }
.badge.trade-ambas { background: #f3e8ff; border-color: #9333ea; color: #6b21a8; text-transform: none; }
.tabs { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.tab { padding: .45rem .9rem; color: var(--text); background: var(--card); }
.tab.active { background: var(--primary); color: var(--primary-text); }
.tab:hover { text-decoration: none; }

.task-list { list-style: none; padding: 0; margin: 0; }
.task { display: flex; align-items: center; gap: .75rem; background: var(--card); border: 1px solid var(--border);
        border-left: 4px solid var(--border); border-radius: 8px; padding: .7rem .9rem; margin-bottom: .5rem; }
.task-main { flex: 1; min-width: 0; color: var(--text); }
.task-main:hover { text-decoration: none; }
.task-title { display: block; font-weight: 600; overflow-wrap: anywhere; }
.status-hecha .task-title { text-decoration: line-through; color: var(--muted); }
.task-meta { display: flex; flex-wrap: wrap; gap: .6rem; font-size: .85rem; color: var(--muted); margin-top: .2rem; }
.task-meta.big { margin-bottom: 1rem; }

.status-próxima { border-left-color: var(--soon); }
.status-vencida { border-left-color: var(--late); }
.status-hecha { border-left-color: var(--done); }
.card.status-próxima, .card.status-vencida, .card.status-hecha { border-left-width: 4px; }

.checkbox { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border); background: var(--card);
            color: #fff; cursor: pointer; font-size: .85rem; padding: 0; flex-shrink: 0; }
.checkbox:hover { border-color: var(--done); }
.checkbox.checked { background: var(--done); border-color: var(--done); }

.badge { padding: 1px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border);
         font-size: .78rem; text-transform: capitalize; }
.prio-alta { color: var(--late); border-color: var(--late); }
.prio-media { color: var(--soon); border-color: var(--soon); }
.status-próxima .badge.st { background: var(--soon); border-color: var(--soon); color: #fff; }
.status-vencida .badge.st { background: var(--late); border-color: var(--late); color: #fff; }
.status-hecha .badge.st { background: var(--done); border-color: var(--done); color: #fff; }

.details { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0 0 1rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.description { white-space: pre-wrap; padding: .9rem; background: var(--bg); border-radius: 8px; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.gallery figure { margin: 0; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.gallery figcaption { display: flex; justify-content: space-between; gap: .3rem; font-size: .8rem; }
.upload { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.upload input { flex: 1 1 220px; margin: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr.inactive td { color: var(--muted); }
.row-actions { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.small-input { display: inline-block; width: 140px; margin: 0; padding: .25rem .45rem; font-size: .85rem; }

/* ---------------------------------------------------------------- trabajadores y WhatsApp */
.chips { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: .5rem; }
label.chip { display: inline-flex; align-items: center; gap: .35rem; margin: 0; padding: .3rem .7rem; font-weight: 400;
             border: 1px solid var(--border); border-radius: 999px; background: var(--card); cursor: pointer; }
label.chip input { width: auto; margin: 0; }
label.chip:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, var(--card)); }
label.chip:has(input:disabled) { opacity: .45; cursor: not-allowed; }
.badge.worker { text-transform: none; }

.worker-new { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.worker-new label { margin: 0; flex: 1 1 200px; }
.worker-edit { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }

.btn.wa { background: #25d366; border-color: #25d366; color: #fff; font-weight: 600; }
.btn.wa-outline { border-color: #25d366; color: #128c4a; }
@media (prefers-color-scheme: dark) { .btn.wa-outline { color: #4ade80; } }
.wa-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .6rem; }
.wa-other { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: flex-end; margin-bottom: .8rem; }
.wa-other label { margin: 0; flex: 1 1 220px; }
.wa-other label.check { flex: 0 0 auto; padding-bottom: .55rem; }
.wa-history ul { list-style: none; padding: 0; margin: .2rem 0 0; font-size: .9rem; }
.wa-history li { padding: .15rem 0; }
.badge.sent { color: #128c4a; border-color: #25d366; text-transform: none; }

/* Menú: enlace de la página actual y, en el móvil, una sola fila que se desliza */
.topbar nav a.current { font-weight: 700; text-decoration: underline; text-underline-offset: 4px; }
@media (max-width: 640px) {
  .topbar { padding: .6rem 1rem .4rem; padding-top: max(.6rem, env(safe-area-inset-top)); }
  .topbar nav { flex-wrap: nowrap; overflow-x: auto; width: 100%; gap: 1.1rem; padding-bottom: .35rem;
                -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .topbar nav::-webkit-scrollbar { display: none; }
  .topbar nav > * { flex-shrink: 0; white-space: nowrap; }
  .container { padding-left: 1rem; padding-right: 1rem; }
  .toolbar h1 { font-size: 1.3rem; }
  .btn { padding: .6rem .95rem; }  /* más fáciles de pulsar con el dedo */
  .checkbox { width: 32px; height: 32px; }
}

.more-filters { margin-top: .6rem; }
.more-filters summary { cursor: pointer; color: var(--primary); font-size: .9rem; width: fit-content; }
.more-filters[open] summary { margin-bottom: .6rem; }

/* Usuarios */
.badge.role-admin { color: #6b21a8; border-color: #9333ea; text-transform: none; }
.badge.role-oficina { color: #1e40af; border-color: #2563eb; text-transform: none; }
.badge.role-trabajador { color: #92400e; border-color: #f59e0b; text-transform: none; }
.users-table td { vertical-align: top; }
.user-actions summary { list-style: none; cursor: pointer; display: inline-block; }
.user-actions summary::-webkit-details-marker { display: none; }
.user-actions[open] summary { background: var(--bg); }
.user-actions-body { display: grid; gap: .8rem; margin-top: .6rem; padding: .75rem; min-width: 240px;
                     border: 1px solid var(--border); border-radius: 8px; background: var(--card); }
form.stack label { margin-bottom: .5rem; font-size: .88rem; }
.worker-fields { display: contents; }

/* Recorridos */
.list-summary { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem;
                margin-bottom: .5rem; }
.list-summary p { margin: 0; }
.route-icon { font-size: 1.3rem; flex-shrink: 0; }
.warn-text { color: var(--warn-text); }
fieldset.picker { border: 1px solid var(--border); border-radius: 8px; padding: .75rem 1rem 1rem; margin: 0 0 1rem; }
fieldset.picker legend { font-weight: 600; padding: 0 .3rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .6rem; }
label.chip { display: inline-flex; align-items: center; gap: .35rem; margin: 0; padding: .3rem .7rem; font-weight: 400;
             border: 1px solid var(--border); border-radius: 999px; cursor: pointer; }
label.chip input { width: auto; margin: 0; }
label.chip:has(input:checked) { border-color: var(--primary); background: var(--bg); }
.picker-filters { margin-bottom: .6rem; }
.picker-filters label.check { margin: 0; flex: 0 0 auto; }
.pick-list { list-style: none; margin: 0 0 .5rem; padding: 0; max-height: 420px; overflow-y: auto;
             border: 1px solid var(--border); border-radius: 7px; }
.pick-list li { border-bottom: 1px solid var(--border); }
.pick-list li:last-child { border-bottom: 0; }
.pick-list li.picked { background: var(--bg); }
.pick-list label { display: flex; gap: .6rem; align-items: flex-start; margin: 0; padding: .5rem .7rem; font-weight: 400;
                   cursor: pointer; }
.pick-list input { width: auto; margin: .25rem 0 0; flex-shrink: 0; }
.progress { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; margin-top: .3rem; max-width: 240px; }
.progress span { display: block; height: 100%; background: var(--done); }
.stops { list-style: none; padding: 0; margin: 0 0 1rem; }
.stop { display: flex; align-items: center; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.stop:last-child { border-bottom: 0; }
.stop-main { flex: 1; min-width: 0; }
.stop-main .task-title { color: var(--text); }
.stop-desc { display: block; margin-top: .2rem; white-space: pre-wrap; }
.stop-actions { display: flex; gap: .3rem; align-items: center; flex-shrink: 0; }
.stop-actions .btn[disabled] { opacity: .35; cursor: default; }
.stop-pin { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px;
            border-radius: 50%; color: #fff; font-weight: 700; font-size: .85rem; border: 2px solid #fff;
            box-shadow: 0 1px 4px rgba(0,0,0,.35); flex-shrink: 0; }
.stop-pin.done { opacity: .45; }
.trade-bg-electricidad { background: #f59e0b; }
.trade-bg-fontaneria { background: #2563eb; }
.trade-bg-ambas { background: #9333ea; }
.trade-bg-none { background: #6b7785; }
.status-hecha .stop-main .task-title { text-decoration: line-through; color: var(--muted); }
@media (max-width: 560px) {
  .stop { flex-wrap: wrap; }
  .stop-actions { width: 100%; justify-content: flex-end; }
}
.wa-preview summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.wa-preview pre { white-space: pre-wrap; font: inherit; font-size: .88rem; background: var(--bg); padding: .75rem;
                  border-radius: 8px; margin: .5rem 0 0; }

/* ---------------------------------------------------------------- panel de proyectos */
.container:has(.project-grid) { max-width: 1280px; }
.updated { margin: .15rem 0 0; }
.tab .count { display: inline-block; min-width: 1.4em; padding: 0 .35em; margin-left: .2rem; border-radius: 999px;
              background: var(--bg); color: var(--muted); font-size: .78rem; text-align: center; }
.tab.active .count { background: rgba(255,255,255,.25); color: var(--primary-text); }
.filters .tabs { flex-wrap: wrap; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: .8rem 1rem;
       display: flex; flex-direction: column; }
.kpi-num { font-size: 1.75rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-label { color: var(--muted); font-size: .85rem; }
.kpi-late { border-color: var(--late); }
.kpi-late .kpi-num { color: var(--late); }

.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .9rem; }
.project { position: relative; display: flex; flex-direction: column; gap: .7rem; background: var(--card);
           border: 1px solid var(--border); border-top: 4px solid var(--primary); border-radius: 10px; padding: 1rem; }
.project.phase-taller { border-top-color: var(--soon); }
.project.phase-etn { border-top-color: var(--done); }
.project.dl-late { border-top-color: var(--late); }
.project-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.project-title { margin: 0; font-size: 1.02rem; line-height: 1.3; overflow-wrap: anywhere; }
.code { flex-shrink: 0; padding: 1px 7px; border-radius: 6px; background: var(--bg); border: 1px solid var(--border);
        color: var(--muted); font-size: .75rem; font-family: ui-monospace, Consolas, monospace; white-space: nowrap; }

.progress { height: 6px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.progress-bar { height: 100%; background: var(--done); border-radius: 999px; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.step { display: grid; grid-template-columns: 84px auto 1fr; align-items: center; gap: .5rem; font-size: .88rem; }
.step-label { color: var(--muted); font-weight: 500; }
.step-by { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill { justify-self: start; padding: 1px 9px; border-radius: 999px; font-size: .76rem; font-weight: 600;
        white-space: nowrap; border: 1px solid transparent; }
.pill.k-hecho { background: #dcfce7; color: #166534; }
.pill.k-proceso { background: #ede9fe; color: #5b21b6; }
.pill.k-pendiente { background: #fef3c7; color: #92400e; }
.pill.k-no-tiene { background: #fee2e2; color: #991b1b; }
.pill.k-vacio { background: transparent; color: var(--muted); border-color: var(--border); font-weight: 400; }
@media (prefers-color-scheme: dark) {
  .pill.k-hecho { background: #14361f; color: #86efac; }
  .pill.k-proceso { background: #2b2250; color: #c4b5fd; }
  .pill.k-pendiente { background: #3a2c0c; color: #fcd34d; }
  .pill.k-no-tiene { background: #3a1616; color: #fca5a5; }
}

.dates { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: 0; padding-top: .6rem;
         border-top: 1px solid var(--border); font-size: .88rem; }
.dates dt { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; }
.dates dd { margin: 0; font-weight: 500; }
.when { display: block; font-size: .78rem; font-weight: 500; color: var(--muted); }
.when.soon { color: var(--soon); }
.when.late { color: var(--late); }

.project-info { margin: 0; padding: .5rem .65rem; background: var(--warn-bg); color: var(--warn-text);
                border-radius: 7px; font-size: .82rem; overflow-wrap: anywhere; }
.phase-tag { align-self: flex-start; font-size: .75rem; color: var(--muted); }

@media (max-width: 560px) {
  .details { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(3, 1fr); gap: .5rem; }
  .kpi { padding: .55rem .65rem; }
  .kpi-num { font-size: 1.35rem; }
  .kpi-label { font-size: .75rem; line-height: 1.25; }
  .step { grid-template-columns: 76px auto; }
  .step-by { grid-column: 2; }
  .details dd { margin-bottom: .4rem; }
}
