:root {
  --navy: #14324a;
  --navy-2: #1d4668;
  --amber: #f0a300;
  --amber-ink: #5a3d00;
  --ok: #1f8a4c;
  --ok-bg: #e5f5ec;
  --bad: #c0392b;
  --bad-bg: #fdeceb;
  --warn: #9a6700;
  --warn-bg: #fff4d6;
  --bg: #f3f5f7;
  --card: #ffffff;
  --line: #d3dae1;
  --ink: #17212b;
  --ink-2: #566472;
  --radius: 14px;
  --tap: 52px;
  font-size: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }

/* ---------- barra superior ---------- */
#top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  min-height: 64px; padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--c-strong, var(--navy)); color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}
#top .back {
  flex: none; width: var(--tap); height: var(--tap); border: 0; border-radius: 12px;
  background: rgba(255, 255, 255, .16); color: #fff; font-size: 26px; line-height: 1;
}
#top .titles { flex: 1; min-width: 0; }
#top .t1 { font-size: 1.15rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#top .t2 { font-size: .8rem; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#top .right { display: flex; align-items: center; gap: 8px; flex: none; }
.chip-sync {
  border: 0; border-radius: 999px; padding: 8px 14px; min-height: 40px; max-width: 46vw;
  font-size: .78rem; font-weight: 600; background: #fff; color: var(--ink);
  display: inline-flex; align-items: center; gap: 8px; text-align: left;
}
.chip-sync .dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: #8a97a3; }
.chip-sync.ok .dot { background: var(--ok); }
.chip-sync.warn .dot { background: var(--amber); }
.chip-sync.bad .dot { background: var(--bad); }
.chip-sync.busy .dot { background: #2f80ed; animation: pulse 1s infinite; }
.chip-sync .txt { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
@keyframes pulse { 50% { opacity: .3; } }
.icon-btn {
  flex: none; width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: rgba(255, 255, 255, .16); color: #fff; font-size: 22px;
}

/* ---------- contenedores ---------- */
#view { padding: 16px; max-width: 1280px; margin: 0 auto; }
.page-title { font-size: 1.3rem; font-weight: 800; margin: 4px 0 2px; }
.muted { color: var(--ink-2); }
.small { font-size: .82rem; }

.btn {
  min-height: var(--tap); padding: 0 22px; border-radius: 12px; border: 2px solid var(--navy);
  background: #fff; color: var(--navy); font-weight: 700;
}
.btn.primary { background: var(--amber); border-color: var(--amber); color: #2b1d00; }
.btn.ghost { border-color: var(--line); color: var(--ink); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.sm { min-height: 40px; padding: 0 14px; font-size: .85rem; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; }

/* ---------- inicio ---------- */
.summary {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; display: grid; gap: 10px; margin-bottom: 14px;
}
.summary .big { font-size: 1.5rem; font-weight: 800; }
.bar { height: 12px; background: #e3e8ed; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 99px; transition: width .3s; }
.bar.amber > i { background: var(--amber); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.search {
  flex: 1; min-width: 200px; min-height: var(--tap); padding: 0 16px; border-radius: 12px;
  border: 2px solid var(--line); background: #fff;
}
.toggle { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 0 14px; border-radius: 12px; border: 2px solid var(--line); background: #fff; font-weight: 600; }
.toggle input { width: 22px; height: 22px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.card-ub {
  position: relative; text-align: left; padding: 16px 18px 16px 22px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); display: grid; gap: 8px; min-height: 140px;
  color: inherit; text-decoration: none; overflow: hidden;
}
.card-ub::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 8px; background: #b9c4cf; }
.card-ub.done::before { background: var(--ok); }
.card-ub.part::before { background: var(--amber); }
.card-ub .name { font-size: 1.12rem; font-weight: 800; }
.card-ub .sub { font-size: .85rem; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-ub .nums { display: flex; justify-content: space-between; font-size: .85rem; font-weight: 600; }
.card-ub .check { position: absolute; right: 14px; top: 12px; color: var(--ok); font-size: 1.4rem; font-weight: 900; }

/* ---------- ubicación ---------- */
.notes { background: var(--warn-bg); border: 1px solid #ecd48a; border-radius: 12px; padding: 10px 14px; margin: 10px 0 14px; font-size: .85rem; color: var(--amber-ink); }
.list { display: grid; gap: 12px; }
.card-cu {
  --cs: #14324a; --ct: #eef2f6;
  position: relative; display: grid; grid-template-columns: 56px 1fr auto; gap: 14px; align-items: center;
  text-align: left; padding: 14px 16px; border-radius: var(--radius);
  background: var(--ct); border: 2px solid var(--cs); color: inherit; min-height: 84px;
}
.card-cu .num { width: 44px; height: 44px; border-radius: 12px; background: var(--cs); color: #fff; font-weight: 800; display: grid; place-items: center; font-size: 1.1rem; }
.card-cu .name { font-weight: 800; }
.card-cu .sub { font-size: .85rem; color: var(--ink-2); margin-top: 2px; }
.card-cu .mini { height: 8px; background: rgba(255, 255, 255, .8); border-radius: 99px; margin-top: 8px; overflow: hidden; border: 1px solid rgba(0,0,0,.08); }
.card-cu .mini > i { display: block; height: 100%; background: var(--cs); }

.tag { display: inline-block; padding: 6px 12px; border-radius: 99px; font-size: .78rem; font-weight: 800; white-space: nowrap; background: #e6ebf0; color: var(--ink-2); }
.tag.curso { background: var(--warn-bg); color: var(--warn); }
.tag.guardado { background: var(--ok-bg); color: var(--ok); }
.tag.modificado { background: #ffe9d2; color: #a14b00; }
.tag.nuevo-d { background: #e3efff; color: #1b5cb8; margin-left: 6px; }

/* ---------- cuadro ---------- */
.cuadro-head {
  background: var(--ct); border: 2px solid var(--cs); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
}
.cuadro-head .num { width: 44px; height: 44px; border-radius: 12px; background: var(--cs); color: #fff; font-weight: 800; display: grid; place-items: center; }
.cuadro-head .name { font-weight: 800; font-size: 1.05rem; flex: 1; min-width: 200px; }
.rows { display: grid; gap: 12px; padding-bottom: 110px; }
.row {
  display: grid; grid-template-columns: minmax(220px, 1fr) minmax(0, 2.1fr); gap: 14px;
  padding: 14px 16px; background: var(--card); border-radius: var(--radius);
  border: 1px solid var(--line); border-left: 10px solid var(--cs);
}
.row.filled { background: #fbfefc; }
.row.bad { border-color: #e7b3ae; border-left-color: var(--bad); background: #fffafa; }
.row .code { font-weight: 800; font-size: 1.05rem; overflow-wrap: anywhere; }
.row .desc { color: var(--ink-2); font-size: .9rem; overflow-wrap: anywhere; }
.row .tipo { display: inline-block; margin-top: 4px; padding: 2px 8px; border-radius: 6px; background: #eef2f6; font-size: .75rem; font-weight: 700; }
.prev {
  margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: #eceff2; color: #4c5966;
  font-size: .82rem; display: flex; gap: 6px 12px; flex-wrap: wrap; align-items: baseline;
}
.prev b { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: #6b7886; }
.fields { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 10px; align-content: start; align-items: start; }
.f { display: grid; gap: 4px; }
.f .lab { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }
.in {
  width: 100%; min-height: var(--tap); padding: 8px 12px; border: 2px solid #aeb9c4; border-radius: 10px;
  background: #fff; font-size: 1.1rem;
}
.in:focus { outline: none; border-color: var(--cs); box-shadow: 0 0 0 3px var(--ct); }
textarea.in { min-height: var(--tap); resize: vertical; font-size: 1rem; }
.f-obs26 { grid-column: 1 / -1; }
.quick { display: flex; gap: 8px; margin-top: 2px; }
.quick button { flex: 1; min-height: 40px; border-radius: 10px; border: 2px solid; font-weight: 800; background: #fff; }
.quick .q-ok { border-color: var(--ok); color: var(--ok); }
.quick .q-mal { border-color: var(--bad); color: var(--bad); }
.rowtools { display: flex; justify-content: flex-end; grid-column: 1 / -1; }

.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 14px rgba(0, 0, 0, .1);
}
.dock .cnt { font-weight: 800; }
.dock .sp { flex: 1; }

/* ---------- ajustes ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; display: grid; gap: 12px; }
.panel h2 { font-size: 1.05rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: .9rem; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; }

.welcome { max-width: 640px; margin: 8vh auto; text-align: center; display: grid; gap: 16px; }
.welcome h1 { font-size: 1.6rem; }

/* ---------- avisos ---------- */
#toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #1c2833; color: #fff; padding: 12px 20px; border-radius: 12px; z-index: 50; transition: .25s;
  max-width: 90vw; font-weight: 600;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--bad); }
#modal:empty { display: none; }
#modal { position: fixed; inset: 0; z-index: 60; background: rgba(10, 20, 30, .55); display: grid; place-items: center; padding: 16px; }
.dlg { background: #fff; border-radius: 16px; padding: 22px; width: min(520px, 100%); display: grid; gap: 14px; max-height: 90vh; overflow: auto; }
.dlg h2 { font-size: 1.15rem; }
.dlg .btns { justify-content: flex-end; }

/* ---------- pantallas estrechas ---------- */
@media (max-width: 860px) {
  .row { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .fields { grid-template-columns: 1fr 1fr; }
  .f-est26 { grid-column: 1 / -1; }
  .chip-sync { max-width: 40vw; }
}
@media print { #top, .dock { display: none; } }
