:root {
  --navy: #0b3954;
  --navy-2: #12507a;
  --teal: #087e8b;
  --bg: #f2f5f8;
  --card: #ffffff;
  --text: #1b2a36;
  --muted: #5e6f7d;
  --line: #d9e1e8;
  --red: #c0392b;
  --orange: #d9822b;
  --blue: #1f6fa8;
  --green: #2e8b57;
  --purple: #6c4fb3;
  --amber: #b7791f;
  --gray: #7b8a96;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(11, 57, 84, .08), 0 1px 2px rgba(11, 57, 84, .06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; }
a { color: var(--blue); }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; color: var(--navy); }
h2 { font-size: 1.15rem; margin: 1.25rem 0 .6rem; color: var(--navy); }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
p { line-height: 1.45; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }

/* ---------- Estructura ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .6rem;
  background: var(--navy); color: #fff; padding: .55rem 1rem; min-height: 56px;
}
.topbar .brand { font-weight: 700; letter-spacing: .02em; white-space: nowrap; display: flex; align-items: center; gap: .45rem; color: #fff; text-decoration: none; }
/* El logotipo es azul: sobre una placa clara se distingue de la barra azul oscuro. */
.topbar .brand .logo { height: 40px; width: auto; display: block; margin: -4px 0; background: linear-gradient(180deg, #ffffff 0%, #e6eef4 100%); border-radius: 8px; padding: 2px 8px; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.topbar .boat-pick { display: inline-flex; align-items: center; gap: .45rem; }
.topbar .boat-pick img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; border: 2px solid rgba(255,255,255,.6); flex: none; margin: -3px 0; }
.topbar .boat-pick .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.topbar .boat-pick { background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.25); border-radius: 8px; padding: .35rem .6rem; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: inherit; cursor: pointer; }
.topbar .spacer { flex: 1; }
.sync-badge { display: inline-flex; align-items: center; gap: .4rem; border-radius: 999px; padding: .3rem .7rem; font-size: .85rem; font-weight: 600; text-decoration: none; color: #fff; background: rgba(255,255,255,.12); white-space: nowrap; }
.sync-badge .dot { width: 10px; height: 10px; border-radius: 50%; background: #9fb3c2; }
.sync-badge.ok .dot { background: #4cd38a; }
.sync-badge.pending .dot { background: #ffb347; }
.sync-badge.offline .dot { background: #c9d3db; }
.sync-badge.conflict { background: var(--red); }
.sync-badge.conflict .dot { background: #fff; }
.user-btn { background: none; border: 0; color: #fff; font: inherit; cursor: pointer; padding: .3rem .4rem; border-radius: 8px; }
.user-btn:hover { background: rgba(255,255,255,.12); }

.layout { display: flex; min-height: calc(100vh - 56px); }
.sidenav { width: 220px; flex: none; background: #fff; border-right: 1px solid var(--line); padding: .75rem .5rem; position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto; }
.sidenav a { display: flex; align-items: center; gap: .65rem; padding: .65rem .8rem; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 500; }
.sidenav a:hover { background: var(--bg); }
.sidenav a.active { background: #e3eef6; color: var(--navy); font-weight: 700; }
.sidenav a .ico { width: 22px; text-align: center; }
.sidenav .count { margin-left: auto; background: var(--red); color: #fff; border-radius: 999px; font-size: .75rem; padding: 0 .45rem; }
main { flex: 1; min-width: 0; padding: 1.25rem; max-width: 1200px; }
.bottomnav { display: none; }

@media (max-width: 820px) {
  .sidenav { display: none; }
  main { padding: .9rem .8rem 5.5rem; }
  .topbar .brand span, .user-btn .small { display: none; }
  .topbar .brand .logo { height: 30px; padding: 2px 5px; }
  /* El nombre del barco ocupa el hueco libre en vez de un ancho fijo. */
  .topbar .spacer, .user-btn { display: none; } /* «Mi cuenta» está en el menú «Más» */
  .topbar { gap: .35rem; }
  .topbar .boat-pick { flex: 1 1 auto; min-width: 0; max-width: none; padding: .3rem .45rem; }
  .sync-badge { padding: .3rem .55rem; }
  .topbar { gap: .4rem; padding: .5rem .6rem; }
  .topbar .boat-pick { max-width: 52vw; }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a, .bottomnav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: .45rem 0 .5rem; font-size: .72rem; color: var(--muted); text-decoration: none; background: none; border: 0; font-family: inherit; }
  .bottomnav .ico { font-size: 1.25rem; }
  .bottomnav a.active { color: var(--navy); font-weight: 700; }
}

/* ---------- Componentes ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: .8rem; }
.grid.kpis { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kpi { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: .85rem 1rem; text-decoration: none; color: var(--text); border-left: 5px solid var(--gray); display: block; }
.kpi .n { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.kpi .l { color: var(--muted); font-size: .9rem; }
.kpi.red { border-color: var(--red); } .kpi.red .n { color: var(--red); }
.kpi.orange { border-color: var(--orange); } .kpi.orange .n { color: var(--orange); }
.kpi.blue { border-color: var(--blue); }
.kpi.purple { border-color: var(--purple); }
.kpi.amber { border-color: var(--amber); }
.kpi.green { border-color: var(--green); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid var(--navy-2); background: #fff; color: var(--navy); font: inherit; font-weight: 600; padding: .6rem 1rem; border-radius: 8px; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn:hover { background: #eef4f9; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: var(--navy-2); }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { background: #fff; color: var(--red); border-color: var(--red); }
.btn.danger.solid { background: var(--red); color: #fff; }
.btn.big { font-size: 1.05rem; padding: .9rem 1.2rem; min-height: 56px; }
.btn.small { min-height: 34px; padding: .3rem .7rem; font-size: .875rem; }
.btn.link { border: 0; background: none; color: var(--blue); padding: .2rem; min-height: 0; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #e7edf2; color: var(--muted); white-space: nowrap; }
.badge.vencida, .badge.urgente, .badge.averiado, .badge.nueva, .badge.rechazado, .badge.anomalia { background: #fbe3e0; color: var(--red); }
.badge.proxima, .badge.alta, .badge.revision, .badge.pendiente_comprobacion { background: #fdecd9; color: #a35a12; }
.badge.pendiente, .badge.normal, .badge.asignado, .badge.asignada, .badge.registrado { background: #e0edf8; color: var(--blue); }
.badge.en_curso, .badge.en_reparacion { background: #ece6f8; color: var(--purple); }
.badge.finalizado, .badge.pendiente_validacion { background: #fbf0d6; color: var(--amber); }
.badge.validado, .badge.completado, .badge.operativo, .badge.resuelta, .badge.correcto, .badge.completada { background: #ddf2e6; color: var(--green); }
.badge.cancelado, .badge.cerrada, .badge.inactiva, .badge.fuera_servicio, .badge.na, .badge.espera { background: #eceff2; color: var(--gray); }
.badge.pend { background: #fff3cd; color: #8a6d00; }
.badge.conf { background: var(--red); color: #fff; }
.badge.demo { background: #fff3cd; color: #8a6d00; border: 1px dashed #c9a400; }

.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; background: #fff; }
table.list th, table.list td { text-align: left; padding: .6rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: .82rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: #f7f9fb; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #f4f8fb; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem; }

.list-items { display: flex; flex-direction: column; gap: .5rem; }
.item { display: flex; gap: .75rem; align-items: center; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: .75rem .9rem; text-decoration: none; color: var(--text); border-left: 4px solid transparent; }
.item:hover { background: #f8fbfd; }
.item .main { flex: 1; min-width: 0; }
.item .t { font-weight: 600; }
.item .s { color: var(--muted); font-size: .875rem; margin-top: 2px; }
.item.vencida { border-left-color: var(--red); }
.item.proxima { border-left-color: var(--orange); }
.item.pendiente { border-left-color: var(--blue); }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .8rem; align-items: flex-end; }
.filters input, .filters select { min-width: 150px; flex: 1 1 150px; }
/* Si no caben, las pestañas pasan a otra línea (en el móvil se desplazan de lado). */
.tabs { display: flex; flex-wrap: wrap; gap: .25rem; border-bottom: 2px solid var(--line); margin-bottom: 1rem; }
@media (max-width: 820px) { .tabs { flex-wrap: nowrap; overflow-x: auto; } }
.tabs a { padding: .6rem .9rem; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs a.active { color: var(--navy); border-color: var(--navy); }

/* ---------- Formularios ---------- */
form.f { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .8rem 1rem; }
form.f .full, .field.full { grid-column: 1 / -1; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
.field .help { color: var(--muted); font-size: .8rem; margin-top: .2rem; }
.field.check label { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
input, select, textarea { width: 100%; font: inherit; padding: .6rem .7rem; border: 1px solid #b9c6d1; border-radius: 8px; background: #fff; color: var(--text); min-height: 44px; }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; min-height: 0; padding: 0; vertical-align: middle; margin: 0 .35rem 0 0; }
input[type=color] { padding: 2px; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(31,111,168,.25); border-color: var(--blue); }
.req::after { content: ' *'; color: var(--red); }
.form-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }

dl.props { display: grid; grid-template-columns: minmax(130px, max-content) 1fr; gap: .45rem 1rem; margin: 0; }
dl.props dt { color: var(--muted); font-size: .9rem; }
dl.props dd { margin: 0; white-space: pre-wrap; word-break: break-word; }

.photos { display: flex; flex-wrap: wrap; gap: .5rem; }
.photos .ph { position: relative; width: 96px; height: 96px; border-radius: 8px; overflow: hidden; background: #e7edf2; display: flex; align-items: center; justify-content: center; font-size: .75rem; color: var(--muted); text-align: center; }
.photos .ph img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.photos .ph button { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; }
.photos .add { border: 2px dashed #b9c6d1; background: #fff; cursor: pointer; font-size: .85rem; color: var(--navy); }
/* Lista de comprobación */
.ck-item { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: .8rem; margin-bottom: .6rem; border-left: 5px solid var(--line); }
.ck-item.correcto { border-left-color: var(--green); }
.ck-item.anomalia { border-left-color: var(--red); }
.ck-item.na { border-left-color: var(--gray); }
.ck-item .txt { font-weight: 600; margin-bottom: .5rem; }
.ck-choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; }
.ck-choices button { min-height: 48px; border-radius: 8px; border: 1px solid #b9c6d1; background: #fff; font: inherit; font-weight: 600; cursor: pointer; font-size: .85rem; }
.ck-choices button.on.correcto { background: var(--green); color: #fff; border-color: var(--green); }
.ck-choices button.on.anomalia { background: var(--red); color: #fff; border-color: var(--red); }
.ck-choices button.on.na { background: var(--gray); color: #fff; border-color: var(--gray); }
.ck-choices button.on.pendiente { background: var(--blue); color: #fff; border-color: var(--blue); }
.ck-extra { margin-top: .6rem; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .5rem 0 .5rem 1rem; border-left: 3px solid var(--line); position: relative; }
.timeline li::before { content: ''; position: absolute; left: -7px; top: .8rem; width: 11px; height: 11px; border-radius: 50%; background: var(--navy-2); }

.banner { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.banner.warn { background: #fff3cd; color: #6b5200; border: 1px solid #f0d77a; }
.banner.err { background: #fbe3e0; color: #7d2117; border: 1px solid #efb3ab; }
.banner.info { background: #e3eef6; color: var(--navy); border: 1px solid #bcd5e8; }

#toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: .4rem; width: min(92vw, 460px); }
.toast { background: var(--navy); color: #fff; padding: .75rem 1rem; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
@media (max-width: 820px) { #toasts { bottom: 5rem; } }

dialog { border: 0; border-radius: 12px; padding: 0; width: min(94vw, 560px); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(11,57,84,.45); }
dialog .dlg { padding: 1.1rem; }
dialog .dlg h2 { margin-top: 0; }
dialog.photo-view { width: auto; max-width: 96vw; background: #000; }
dialog.photo-view img { max-width: 96vw; max-height: 90vh; display: block; }

.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.2rem; padding: 1rem; background: linear-gradient(160deg, var(--navy) 0%, var(--teal) 100%); }
.login-logo { display: block; width: 100%; max-width: 320px; height: auto; margin: 0 auto 1.2rem; }
.login-card { background: #fff; border-radius: 14px; padding: 1.6rem; width: min(100%, 400px); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.login-card form { display: flex; flex-direction: column; gap: .8rem; }
.boat-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .8rem; }
.boat-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; text-decoration: none; color: var(--text); border-top: 5px solid var(--teal); }
.boat-card .name { font-weight: 700; font-size: 1.1rem; color: var(--navy); }

.perm-table td, .perm-table th { text-align: center; }
.perm-table td:first-child, .perm-table th:first-child { text-align: left; }

/* Informe en pantalla con aspecto de hoja A4 */
.report-tools { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.sheet { background: #fff; width: 100%; max-width: 210mm; margin: 0 auto 2rem; padding: 14mm 12mm; box-shadow: 0 2px 10px rgba(0,0,0,.15); font-size: 10.5pt; color: #000; }
.sheet h1 { font-size: 16pt; color: #000; margin: 0; }
.sheet h2 { font-size: 12pt; color: #000; border-bottom: 1.5px solid #000; padding-bottom: 2px; margin: 14px 0 6px; }
.sheet .rh { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 2.5px solid var(--navy); padding-bottom: 6px; margin-bottom: 10px; }
.sheet .rh .meta { text-align: right; font-size: 9pt; color: #333; }
.sheet .rh { align-items: center; }
.sheet .rh .rmain { flex: 1; min-width: 0; }
.sheet .rh .rlogo { height: 62px; width: auto; flex: none; }
.sheet table { width: 100%; border-collapse: collapse; margin: 4px 0 8px; }
.sheet th, .sheet td { border: 1px solid #999; padding: 4px 5px; text-align: left; vertical-align: top; font-size: 9pt; }
.sheet th { background: #e8edf1; }
.sheet dl.props { grid-template-columns: 150px 1fr; gap: 3px 10px; font-size: 10pt; }
.sheet .sign { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 28px; page-break-inside: avoid; }
.sheet .sign div { border-top: 1px solid #000; padding-top: 4px; font-size: 9pt; min-height: 60px; }
.sheet .rf { margin-top: 16px; font-size: 8pt; color: #555; border-top: 1px solid #ccc; padding-top: 4px; }
.sheet .photos .ph { width: 120px; height: 120px; }
.sheet .box { display: inline-block; width: 12px; height: 12px; border: 1px solid #000; vertical-align: middle; }

@media print {
  @page { size: A4; margin: 12mm; }
  html, body { background: #fff; }
  .topbar, .sidenav, .bottomnav, #toasts, .no-print, .report-tools, .page-head .actions, .btn, .tabs, .filters { display: none !important; }
  main { padding: 0; max-width: none; }
  .layout { display: block; }
  .sheet { box-shadow: none; margin: 0; padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ccc; }
  a { color: #000; text-decoration: none; }
  tr, .ck-item { page-break-inside: avoid; }
}
