:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #17202e;
  --muted: #5d6878;
  --line: #d8dde5;
  --accent: #1f3a68;
  --accent-2: #2f62b0;
  --on-accent: #ffffff;
  --ok: #1e7d43;
  --warn: #b25d00;
  --danger: #b3261e;
  --chip: #e7ecf4;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c;
    --card: #1a202a;
    --text: #e8ecf2;
    --muted: #9aa5b5;
    --line: #2d3644;
    --accent: #3d6cc0;
    --accent-2: #6b97e6;
    --chip: #253042;
    --ok: #4cc27a;
    --warn: #f0a24a;
    --danger: #f2766d;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, textarea, select { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: var(--accent); color: var(--on-accent);
}
.topbar h1 { flex: 1; margin: 0; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  border: 0; background: transparent; color: inherit;
  font-size: 28px; line-height: 1; min-width: 40px; min-height: 40px; cursor: pointer;
}
.save-state { font-size: 13px; opacity: .9; white-space: nowrap; }
.save-state.err { color: #ffd59a; }

main { max-width: 760px; margin: 0 auto; padding: 12px 12px 96px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); cursor: pointer; text-decoration: none; color: var(--text);
  white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 32px 8px; }

/* lista de informes */
.report { display: block; color: inherit; text-decoration: none; }
.report h2 { margin: 0 0 2px; font-size: 17px; }
.report .meta { font-size: 14px; color: var(--muted); }
.report .actions { margin-top: 12px; }

/* índice de secciones */
.sections { list-style: none; padding: 0; margin: 0; }
.sections a {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; margin-bottom: 8px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); color: inherit; text-decoration: none;
}
.sections .num {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; font-size: 14px; font-weight: 600;
  background: var(--chip); color: var(--muted);
}
.sections .done .num { background: var(--ok); color: #fff; }
.sections .name { flex: 1; }
.sections .count { font-size: 13px; color: var(--muted); }

/* formularios */
.field { margin-bottom: 18px; }
.field > label, .field > .label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=tel], input[type=date], input[type=email], textarea, select {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); min-height: 44px;
}
textarea { resize: vertical; min-height: 88px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-2); outline-offset: 0; border-color: transparent; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px;
  min-height: 40px; padding: 0 14px; cursor: pointer;
}
.chip[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.trow {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; background: var(--bg);
}
.trow-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.trow-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.trow-grid .wide { grid-column: 1 / -1; }
.trow-grid label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 2px; }
.trow-grid input, .trow-grid select { background: var(--card); min-height: 40px; padding: 8px 10px; }

/* fotos */
.photo-actions { display: flex; gap: 8px; margin-bottom: 12px; }
.photo-actions .btn { flex: 1; }
.photo-actions input { display: none; }
.photo {
  display: grid; grid-template-columns: 112px 1fr; gap: 10px;
  padding: 10px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; background: var(--bg);
}
.photo img { width: 112px; height: 112px; object-fit: cover; border-radius: 8px; background: var(--chip); cursor: zoom-in; }
.photo textarea { min-height: 72px; background: var(--card); }
.photo .tools { display: flex; gap: 6px; margin-top: 6px; }
.photo .tools .btn { flex: 1; min-height: 34px; padding: 0 6px; }
.photo .state { font-size: 12px; color: var(--warn); margin-top: 4px; }
.photo.uploading img { opacity: .5; }

.pager {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.pager .btn { flex: 1; }

.viewer {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.92);
  display: grid; place-items: center;
}
.viewer[hidden] { display: none; }
.viewer img { max-width: 100vw; max-height: 100vh; object-fit: contain; }
.viewer .close { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: 8px; color: #fff; }

h2.sec { font-size: 20px; margin: 4px 0 14px; }
h3 { font-size: 15px; margin: 22px 0 10px; }

@media (min-width: 600px) {
  .trow-grid { grid-template-columns: repeat(3, 1fr); }
  .photo { grid-template-columns: 160px 1fr; }
  .photo img { width: 160px; height: 160px; }
}

/* sesión, usuarios y solo lectura */
fieldset.card { min-width: 0; margin: 0 0 12px; }
fieldset:disabled input, fieldset:disabled textarea, fieldset:disabled select { opacity: .85; }
fieldset:disabled .chip { cursor: default; }
textarea[readonly] { background: transparent; }
.notice {
  background: var(--chip); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; font-size: 14px;
}
.badge {
  display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px;
  background: var(--chip); color: var(--muted); font-size: 12px;
}
.error { color: var(--danger); font-size: 14px; margin-bottom: 10px; }
.error:empty, .ok:empty { display: none; }
.ok { color: var(--ok); font-size: 14px; margin-bottom: 10px; }
.userbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 14px;
}
.user-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.user-head select { width: auto; min-height: 40px; }
.card.inactive { opacity: .6; }
input[type=password] {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); min-height: 44px;
}

/* edición de fotos */
.photo .thumb { position: relative; }
.badge.edited { position: absolute; left: 6px; bottom: 6px; margin: 0; background: var(--accent); color: var(--on-accent); }
.photo .tools { flex-wrap: wrap; }
.editor {
  position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column;
  background: #0d1117; color: #e8ecf2;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.editor-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; }
.editor-bar .btn:not(.primary) { background: transparent; color: inherit; border-color: #3a4352; }
.editor-stage { flex: 1; min-height: 0; }
.editor-stage img { display: block; max-width: 100%; }
.editor-tools { padding: 10px 12px 14px; display: grid; gap: 10px; }
.editor .chip { background: #1a202a; border-color: #3a4352; color: inherit; }
.editor .chip[aria-pressed=true] { background: var(--accent); border-color: var(--accent); }
.editor-more { display: flex; flex-wrap: wrap; gap: 8px; }
.editor-more .btn { background: #1a202a; border-color: #3a4352; color: inherit; flex: 1; }
.editor-more .btn.danger { color: #f2766d; }
.editor .hint { color: #9aa5b5; }
.editor-status { text-align: center; font-size: 14px; min-height: 0; }
.editor.busy .editor-tools, .editor.busy .editor-bar { pointer-events: none; opacity: .5; }

/* bloque opcional con casilla */
.group { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 18px; background: var(--bg); }
.group .group-body { display: none; margin-top: 14px; }
.group.on .group-body { display: block; }
.group .group-body .field:last-child { margin-bottom: 0; }
.group input[type=text], .group input[type=tel] { background: var(--card); }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; cursor: pointer; min-height: 32px; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }

/* personal solicitado */
.staff { display: grid; gap: 8px; }
.staff-row { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 4px 10px; }
.staff-row .staff-n { text-align: center; padding: 8px 4px; font-weight: 600; }
.staff-row .staff-obs { grid-column: 2; min-height: 38px; padding: 6px 10px; font-size: 14px; }
.staff-row .staff-obs[hidden] { display: none; }

/* administración de listas */
.cat-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: 0; }
.cat-row.inactive .cat-name { opacity: .6; }
.cat-tools { display: flex; gap: 6px; }
.cat-tools .btn { padding: 0 10px; }
.userbar .row { justify-content: flex-end; }
.btn:disabled { opacity: .4; cursor: default; }

/* listas desplegables en tablas */
.table-actions { margin-top: 2px; }
.table-actions .btn { flex: none; }
.item-form { border: 1px dashed var(--line); border-radius: 10px; padding: 10px; margin-top: 10px; background: var(--card); }
.item-form .row { margin-top: 10px; justify-content: flex-end; }
.item-form .row .btn { flex: none; }
.cat-name { flex: 1; min-width: 50%; }
a.chip { color: var(--text); }
a.chip[aria-pressed=true] { color: var(--on-accent); }
input[type=number].count {
  width: 120px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  min-height: 44px; font-size: 18px; font-weight: 600; text-align: center;
}
