/* Inspecciones de Seguros · estilos mobile-first sin dependencias */
:root {
  --azul: #1f3a5f;
  --azul-2: #2c5282;
  --fondo: #f3f5f8;
  --card: #ffffff;
  --texto: #1b2430;
  --muted: #5d6b7c;
  --borde: #d8dee6;
  --ok: #2e7d32;
  --warn: #b26a00;
  --danger: #b3261e;
  --info: #1565c0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fondo); color: var(--texto);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--azul-2); }
h1 { font-size: 1.45rem; margin: .2rem 0 .6rem; }
h2 { font-size: 1.08rem; margin: 0 0 .7rem; color: var(--azul); }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.text-danger { color: var(--danger); }
.inline { display: inline; }
.req { color: var(--danger); }

/* --- Barra superior --- */
.topbar {
  position: sticky; top: 0; z-index: 30; background: var(--azul); color: #fff;
  display: flex; align-items: center; flex-wrap: wrap; padding: .55rem 1rem; gap: .5rem;
}
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.05rem; }
.brand-mark { color: #8fb8ff; }
.nav-toggle { margin-left: auto; background: none; border: 1px solid rgba(255,255,255,.35); color: #fff; font-size: 1.2rem; border-radius: 8px; padding: .2rem .6rem; }
.nav { display: none; width: 100%; flex-direction: column; gap: .2rem; padding: .4rem 0; }
.nav.open { display: flex; }
.nav a, .nav .link { color: #fff; text-decoration: none; padding: .45rem .3rem; background: none; border: 0; font: inherit; text-align: left; cursor: pointer; }
.nav a:hover, .nav .link:hover { text-decoration: underline; }
.nav .nav-cta { background: #fff; color: var(--azul); border-radius: 8px; padding: .4rem .8rem; font-weight: 600; }
.nav-user { color: #c9d8ee; font-size: .85rem; padding: .3rem; }
@media (min-width: 900px) {
  .nav-toggle { display: none; }
  .nav { display: flex; flex-direction: row; width: auto; margin-left: auto; align-items: center; padding: 0; gap: .4rem; }
}

/* --- Contenedores --- */
.container { max-width: 1180px; margin: 0 auto; padding: 1rem; }
.container-wide { max-width: 1400px; }
.container-mobile { max-width: 720px; }
.has-bottom-bar { padding-bottom: 6rem; }
.card { background: var(--card); border: 1px solid var(--borde); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.empty { text-align: center; padding: 2rem; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .6rem; margin-bottom: .6rem; }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-2 > .card { margin-bottom: 0; } .grid-2 { margin-bottom: 1rem; } }

/* --- Botones --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  min-height: 44px; padding: .5rem .95rem; border-radius: 8px; border: 1px solid var(--borde);
  background: #fff; color: var(--texto); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--azul-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--azul-2); border-color: var(--azul-2); color: #fff; }
.btn-primary:hover { background: var(--azul); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-outline { color: var(--danger); border-color: #e7b3ae; }
.btn-block { display: flex; width: 100%; margin-top: .6rem; }
.btn-lg { min-height: 50px; font-size: 1.05rem; }
.btn-sm { min-height: 34px; padding: .25rem .6rem; font-size: .88rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .4rem; }
.btn-file { position: relative; overflow: hidden; }
.btn-file input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }

/* --- Formularios --- */
label, .label { display: block; font-weight: 600; font-size: .93rem; margin-bottom: .25rem; }
input[type=text], input[type=email], input[type=tel], input[type=url], input[type=password], input[type=number],
input[type=search], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; min-height: 44px; padding: .5rem .65rem; border: 1px solid #b9c3cf; border-radius: 8px;
  font: inherit; background: #fff; color: var(--texto);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(44, 82, 130, .25); border-color: var(--azul-2); }
input.upper { text-transform: uppercase; }
.field { margin-bottom: .9rem; }
.field-check label { display: flex; gap: .5rem; align-items: center; font-weight: 600; }
.field-check input { width: 22px; height: 22px; }
.has-error input, .has-error select, .has-error textarea, .has-error .choices { border-color: var(--danger); }
.has-error .choices { border: 1px solid var(--danger); border-radius: 8px; padding: .3rem; }
.error { color: var(--danger); display: block; font-size: .86rem; margin-top: .2rem; }
.error:empty { display: none; }
.help { color: var(--muted); display: block; font-size: .84rem; margin-top: .2rem; }
fieldset { border: 0; padding: 0; margin: 0 0 .6rem; }
legend { font-weight: 700; color: var(--azul); margin-bottom: .5rem; }
.grid-form { display: grid; grid-template-columns: 1fr; column-gap: 1rem; }
@media (min-width: 760px) { .grid-form { grid-template-columns: 1fr 1fr; } }
.form-narrow { max-width: 560px; }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .6rem; flex-wrap: wrap; }
.conflict-box { background: #fff7e6; border: 1px solid #f2c46d; border-radius: 8px; padding: .7rem; }
.choices { display: flex; flex-wrap: wrap; gap: .4rem; }
.choice {
  display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; margin: 0;
  border: 1px solid var(--borde); border-radius: 999px; padding: .45rem .8rem; min-height: 42px; background: #fafbfc; cursor: pointer;
}
.choice input { width: 18px; height: 18px; margin: 0; }
.choice:has(input:checked) { background: #e7effa; border-color: var(--azul-2); color: var(--azul); }

/* --- Filtros --- */
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; }
.filters input[type=search] { flex: 1 1 240px; }
.f-inline { display: flex; flex-direction: column; font-size: .8rem; color: var(--muted); font-weight: 600; flex: 1 1 140px; margin: 0; }
.f-inline select, .f-inline input { margin-top: .15rem; }

/* --- Mensajes --- */
.messages { margin-bottom: .8rem; }
.alert { padding: .7rem .9rem; border-radius: 8px; margin-bottom: .5rem; border: 1px solid; }
.alert p { margin: .2rem 0; }
.alert-success { background: #ecf7ee; border-color: #b7dfbd; color: #1e5a22; }
.alert-info { background: #eaf2fd; border-color: #b9d2f5; color: #164a8a; }
.alert-warning { background: #fff7e6; border-color: #f2c46d; color: #6d4300; }
.alert-error { background: #fdecea; border-color: #f2b8b5; color: #8c1d18; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 5.5rem; z-index: 50; max-width: 92vw;
  padding: .75rem 1.1rem; border-radius: 10px; color: #fff; font-weight: 600; box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
.toast-ok { background: var(--ok); }
.toast-error { background: var(--danger); }

/* --- Insignias --- */
.badge { display: inline-block; padding: .14rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; vertical-align: middle; white-space: nowrap; }
.badge-agendada { background: #e3eefc; color: var(--info); }
.badge-proceso { background: #fff1d6; color: var(--warn); }
.badge-completada { background: #e3f3e5; color: var(--ok); }
.badge-cancelada { background: #f6e1e3; color: #8e2430; }
.badge-vencida { background: var(--danger); color: #fff; }

/* --- KPIs --- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; margin-bottom: 1rem; }
@media (min-width: 760px) { .kpis { grid-template-columns: repeat(6, 1fr); } }
.kpi { background: #fff; border: 1px solid var(--borde); border-left: 5px solid var(--azul); border-radius: var(--radius); padding: .8rem; text-decoration: none; color: var(--texto); box-shadow: var(--shadow); }
.kpi-n { display: block; font-size: 1.8rem; font-weight: 800; line-height: 1.1; }
.kpi-l { color: var(--muted); font-size: .88rem; }
.kpi-agendada { border-left-color: var(--info); }
.kpi-proceso { border-left-color: var(--warn); }
.kpi-completada { border-left-color: var(--ok); }
.kpi-cancelada { border-left-color: #8e2430; }
.kpi-vencida { border-left-color: var(--danger); }
.kpi-vencida .kpi-n { color: var(--danger); }
.bar { height: 5px; background: #edf1f6; border-radius: 3px; margin-top: .3rem; }
.bar span { display: block; height: 100%; background: var(--azul-2); border-radius: 3px; }

/* --- Agenda / tarjetas --- */
.agenda-item { display: flex; gap: .7rem; align-items: center; padding: .6rem .3rem; border-bottom: 1px solid #eef1f5; text-decoration: none; color: inherit; }
.agenda-item:last-child { border-bottom: 0; }
.agenda-hora { font-weight: 800; color: var(--azul); min-width: 3.4rem; }
.agenda-body { flex: 1; }
.section-title { margin-top: 1.2rem; }
.insp-card { padding: 0; overflow: hidden; }
.insp-card-main { display: block; padding: .9rem 1rem .6rem; text-decoration: none; color: inherit; }
.insp-card-top { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.insp-time { font-weight: 800; color: var(--azul); }
.insp-client { font-size: 1.08rem; font-weight: 700; margin: .25rem 0 .1rem; }
.insp-card-actions { display: flex; gap: .4rem; padding: .6rem 1rem .9rem; flex-wrap: wrap; }
.insp-card-actions .btn, .insp-card-actions form { flex: 1 1 auto; }
.insp-card-actions form .btn { width: 100%; }

/* --- Tablas (se convierten en tarjetas en móvil) --- */
.table-wrap { overflow-x: auto; padding: 0; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .6rem .7rem; text-align: left; border-bottom: 1px solid #edf1f5; vertical-align: top; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f8fafc; }
.table.compact th, .table.compact td { padding: .45rem .5rem; }
.row-link { cursor: pointer; }
.row-link:hover { background: #f6f9fd; }
.actions a { margin-right: .6rem; }
@media (max-width: 759px) {
  .table thead { display: none; }
  .table tr { display: block; border-bottom: 1px solid var(--borde); padding: .4rem 0; }
  .table td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .25rem .8rem; }
  .table td[data-label]::before { content: attr(data-label); font-weight: 600; color: var(--muted); font-size: .85rem; }
}
.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; margin: 1rem 0; }

/* --- Detalle --- */
.dl-grid { display: grid; grid-template-columns: 1fr; gap: .55rem 1rem; margin: 0; }
@media (min-width: 600px) { .dl-grid { grid-template-columns: 1fr 1fr; } .span-2 { grid-column: span 2; } }
.dl-grid dt { font-size: .8rem; color: var(--muted); font-weight: 600; }
.dl-grid dd { margin: 0; word-break: break-word; }
.note { background: #fffbea; border: 1px solid #f1e3a7; border-radius: 8px; padding: .7rem; margin-top: .8rem; }
.result-card { border-left: 5px solid var(--ok); }
.pending { margin: 0; padding-left: 1.2rem; color: #8c1d18; }
.alert-box { border-left: 5px solid var(--danger); }
.ok-box { border-left: 5px solid var(--ok); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .5rem 0 .5rem 1rem; border-left: 3px solid #dbe3ee; margin-left: .3rem; }
.tl-date { display: block; font-size: .8rem; color: var(--muted); }

/* --- Galería --- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .8rem; }
.gallery.editable { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); margin-top: 1rem; }
.thumb { margin: 0; background: #fafbfc; border: 1px solid var(--borde); border-radius: 8px; overflow: hidden; }
.thumb img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: #e9edf2; }
.thumb figcaption { padding: .45rem .55rem; font-size: .86rem; }
.photo-edit { display: flex; flex-direction: column; gap: .3rem; margin: .35rem 0; }
.photo-edit select, .photo-edit input { min-height: 38px; font-size: .9rem; padding: .3rem .45rem; }
.photo-actions { display: flex; gap: .35rem; }
.photo-actions form { flex: 1; }
.photo-actions .btn { width: 100%; }
.photo-cat-label { font-weight: 700; }

/* --- Ejecución en móvil --- */
.exec-head { display: grid; grid-template-columns: 1fr auto; gap: .4rem .6rem; position: sticky; top: 52px; z-index: 20; }
.exec-links { display: flex; gap: .3rem; align-items: flex-start; }
.save-status { grid-column: 1 / -1; font-size: .85rem; font-weight: 600; padding: .3rem .55rem; border-radius: 6px; background: #eef2f7; color: var(--muted); }
.save-status[data-state=saved] { background: #e3f3e5; color: var(--ok); }
.save-status[data-state=dirty] { background: #fff1d6; color: var(--warn); }
.save-status[data-state=saving] { background: #e3eefc; color: var(--info); }
.save-status[data-state=warning] { background: #fff1d6; color: var(--warn); }
.save-status[data-state=error] { background: var(--danger); color: #fff; }
details.section { padding: 0; }
details.section > summary { padding: 1rem; font-weight: 700; color: var(--azul); cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
details.section > summary::after { content: "▾"; }
details.section[open] > summary::after { content: "▴"; }
details.section > summary::-webkit-details-marker { display: none; }
.section-body { padding: 0 1rem .4rem; }
.checklist { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .4rem; }
.chk { border: 1px solid var(--borde); background: #fff; border-radius: 999px; padding: .4rem .75rem; font: inherit; font-size: .88rem; cursor: pointer; min-height: 38px; }
.chk .chk-icon::before { content: "○"; }
.chk.done { background: #e3f3e5; border-color: #a9d5ae; color: var(--ok); }
.chk.done .chk-icon::before { content: "✔"; }
.chk.missing { border-color: #f2b8b5; color: #8c1d18; }
.upload-box { background: #f6f9fd; border: 1px dashed #9fb4cf; border-radius: 10px; padding: .8rem; }
.upload-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-top: .4rem; }
.progress { position: relative; height: 26px; background: #e3e9f1; border-radius: 6px; margin-top: .6rem; overflow: hidden; }
.progress span { position: absolute; inset: 0 auto 0 0; width: 0; background: #8fb3e0; transition: width .2s; }
.progress em { position: relative; display: block; text-align: center; font-style: normal; font-size: .82rem; line-height: 26px; font-weight: 600; }
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; gap: .5rem; justify-content: center;
  padding: .6rem .8rem calc(.6rem + env(safe-area-inset-bottom)); background: rgba(255,255,255,.97); border-top: 1px solid var(--borde);
}
.bottom-bar > * { flex: 1; max-width: 340px; }
.bottom-bar form .btn { width: 100%; }

/* --- Calendario --- */
.cal-title { font-size: 1.25rem; }
.calendar { padding: 0; overflow-x: auto; }
.cal-row { display: grid; grid-template-columns: repeat(7, minmax(110px, 1fr)); }
.cal-head div { padding: .4rem; font-weight: 700; font-size: .82rem; color: var(--muted); text-align: center; background: #f8fafc; border-bottom: 1px solid var(--borde); }
.cal-day { min-height: 110px; border-right: 1px solid #edf1f5; border-bottom: 1px solid #edf1f5; padding: .3rem; }
.cal-out { background: #fafbfc; color: #a0aab6; }
.cal-today { background: #f0f6ff; }
.cal-day-head { display: flex; justify-content: space-between; }
.cal-num { font-weight: 700; text-decoration: none; color: inherit; }
.cal-add { text-decoration: none; color: var(--muted); font-weight: 700; padding: 0 .3rem; }
.cal-item { display: block; font-size: .76rem; margin-top: .2rem; padding: .12rem .3rem; border-radius: 4px; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-agendada { background: #e3eefc; color: var(--info); }
.st-en_proceso { background: #fff1d6; color: var(--warn); }
.st-completada { background: #e3f3e5; color: var(--ok); }
.st-cancelada { background: #f6e1e3; color: #8e2430; text-decoration: line-through; }
.cal-more { font-size: .75rem; }
.legend .cal-item { display: inline-block; }

/* --- Login --- */
.login-page main { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 400px; }
.login-card h1 { font-size: 1.3rem; color: var(--azul); }
.login-card input { margin-bottom: .8rem; }

/* --- Módulo de Seguridad --- */
.subnav { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; margin-bottom: 1rem; padding: .4rem; background: #fff; border: 1px solid var(--borde); border-radius: var(--radius); }
.subnav a { text-decoration: none; color: var(--texto); padding: .45rem .75rem; border-radius: 8px; font-weight: 600; font-size: .92rem; }
.subnav a.active, .subnav a:hover { background: #e7effa; color: var(--azul); }
.subnav-title { font-weight: 800; color: var(--azul); padding: 0 .5rem; }
.kpis-3 { grid-template-columns: repeat(3, 1fr); }
@media (min-width: 760px) { .kpis-3 { grid-template-columns: repeat(3, 1fr); } }
.perm-grid { display: grid; gap: .8rem; grid-template-columns: 1fr; }
@media (min-width: 760px) { .perm-grid { grid-template-columns: 1fr 1fr; } }
.perm-group { border: 1px solid var(--borde); border-radius: 10px; padding: .8rem; background: #fafbfc; margin: 0; }
.perm-group legend { padding: 0 .3rem; }
.perm-item { display: flex; gap: .55rem; align-items: flex-start; font-weight: 500; padding: .35rem 0; cursor: pointer; }
.perm-item input { width: 20px; height: 20px; margin-top: .1rem; flex: none; }
.perm-locked { opacity: .65; }
.perm-locked .perm-item { cursor: not-allowed; }
.perm-list { columns: 2 260px; margin: 0; padding-left: 0; list-style: none; color: var(--ok); }
.perm-list li { padding: .15rem 0; break-inside: avoid; }
.rol-card h2 { margin-bottom: .2rem; }
