:root {
  --brand: #04508f;
  --brand-ink: #033a68;
  --brand-soft: #e6eff7;
  --accent: #f08a24;
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1d2733;
  --muted: #667383;
  --line: #dfe4ea;
  --ok: #1e8e5a;
  --warn: #c77700;
  --edit: #2f6fd6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
code { background: var(--brand-soft); color: var(--brand-ink); padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.muted { color: var(--muted); margin: 2px 0 0; }
.hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 0; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; border-radius: 9px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { border-color: #c5ced8; background: #fafbfc; }
.btn:focus-visible, .tool:focus-visible, .seg button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(4, 80, 143, .07); }
.btn.small { height: 32px; padding: 0 12px; font-size: 13.5px; }
.btn.block { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn em, .tag { font-style: normal; font-size: 11px; font-weight: 600; text-transform: uppercase; background: var(--accent); color: #fff; padding: 1px 6px; border-radius: 99px; }
.icon-btn { width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--line); background: #fff; font-size: 20px; line-height: 1; cursor: pointer; color: var(--ink); }
.icon-btn:hover { background: #f2f4f7; }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 20px;
  padding: 10px 24px; background: #fff; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { height: 34px; max-width: 150px; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 16px; }
.brand-text span { font-size: 12.5px; color: var(--muted); }
.patient { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.patient span { font-size: 13px; color: var(--muted); }
.patient input { height: 36px; width: 240px; }
.actions { display: flex; gap: 4px; }

input:not([type]), input[type=text], select, textarea {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; height: 36px; width: 100%;
}
textarea { height: auto; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(4, 80, 143, .25); border-color: var(--brand); }
input[type=color] { width: 100%; height: 36px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: #fff; }
input[type=range] { accent-color: var(--brand); width: 100%; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.check input { accent-color: var(--brand); width: 16px; height: 16px; }

main { padding: 28px 24px 60px; max-width: 1400px; margin: 0 auto; }

/* ---------- Paso 1 ---------- */
.drop-view { max-width: 820px; margin: 4vh auto 0; }
.dropzone {
  background: #fff; border: 2px dashed #c4d3e2; border-radius: 18px;
  padding: 48px 32px; text-align: center; transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--brand); background: var(--brand-soft); }
.drop-icon svg { fill: none; stroke: var(--brand); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.dropzone h1 { font-size: 24px; margin: 10px 0 8px; }
.dropzone p { color: var(--muted); margin: 0 auto; max-width: 520px; }
.drop-buttons { display: flex; gap: 10px; justify-content: center; margin: 22px 0 18px; flex-wrap: wrap; }
.privacy { font-size: 13px; }
.steps { list-style: none; padding: 0; margin: 28px 0 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; background: #fff; border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); font-size: 14px; }
.steps b { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }

/* ---------- Pasos 2 y 3 ---------- */
.gridbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.gridbar h2 { font-size: 22px; }
.gridbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.warnings { background: #fff7e8; border: 1px solid #f3d9a4; color: #7a4c00; border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-size: 14px; }
.warnings ul { margin: 4px 0 0; padding-left: 18px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px; }
.card {
  position: relative; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; display: flex; flex-direction: column; border: 2px solid transparent; transition: border-color .15s, transform .15s;
}
.card:hover { border-color: #c9d7e6; }
.card.excluded .thumb { opacity: .35; }
.thumb { display: block; width: 100%; aspect-ratio: 4 / 5; background: #e9edf1; cursor: zoom-in; }
.card-body { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
.card-title { flex: 1; min-width: 0; }
.card-title b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 99px; margin-top: 3px; }
.chip.ok { background: #e3f4ec; color: var(--ok); }
.chip.revisar { background: #fff1db; color: var(--warn); }
.chip.editada { background: #e5eefc; color: var(--edit); }
.chip.incompleta { background: #f1f2f4; color: var(--muted); }
.chip.pendiente { background: #f1f2f4; color: var(--muted); }
.card-actions { display: flex; gap: 4px; }
.card-actions button { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 15px; }
.card-actions button:hover { background: #f2f4f7; }
.card .pick { position: absolute; top: 10px; left: 10px; width: 22px; height: 22px; accent-color: var(--brand); cursor: pointer; }
.card-note { font-size: 12px; color: var(--warn); padding: 0 12px 10px; margin-top: -4px; }

/* ---------- Progreso y avisos ---------- */
.progress { position: fixed; inset: 0; background: rgba(244, 246, 249, .75); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 50; }
.progress-card { background: #fff; padding: 22px 26px; border-radius: 14px; box-shadow: var(--shadow); width: min(420px, 90vw); }
.progress-card p { margin: 0 0 12px; font-weight: 500; }
.bar { height: 8px; border-radius: 99px; background: #e8edf2; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  background: #1d2733; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; z-index: 60;
  transition: opacity .2s, transform .2s; pointer-events: none; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Editor ---------- */
dialog { border: 0; padding: 0; color: var(--ink); }
dialog::backdrop { background: rgba(15, 22, 32, .55); }
.editor[open] { width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; display: flex; background: #20262e; }
.editor-stage { flex: 1; display: grid; place-items: center; padding: 20px; min-width: 0; }
.editor-stage canvas { box-shadow: 0 10px 40px rgba(0, 0, 0, .45); cursor: grab; touch-action: none; border-radius: 4px; }
.editor-stage canvas.dragging { cursor: grabbing; }
.editor-side { width: 330px; flex: none; background: #fff; display: flex; flex-direction: column; overflow-y: auto; }
.ed-head { display: flex; align-items: center; gap: 10px; padding: 16px; border-bottom: 1px solid var(--line); }
.ed-head > div { flex: 1; min-width: 0; text-align: center; }
.ed-head small { color: var(--muted); font-size: 12px; }
.ed-head h2 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-block { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.ed-label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 8px; }
.seg { display: flex; background: #eef1f4; border-radius: 9px; padding: 3px; gap: 3px; }
.seg + .seg { margin-top: 8px; }
.seg button { flex: 1; height: 32px; border: 0; border-radius: 7px; background: transparent; font: inherit; font-size: 14px; cursor: pointer; color: var(--ink); }
.seg button.on { background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); font-weight: 600; color: var(--brand); }
.seg.small button { height: 28px; font-size: 13px; }
.seg.disabled { opacity: .45; pointer-events: none; }
.tools { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.tool { height: 38px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 16px; cursor: pointer; color: var(--ink); }
.tool:hover { background: #f2f4f7; }
.range-row { display: grid; grid-template-columns: auto 1fr 46px; align-items: center; gap: 10px; margin-top: 12px; font-size: 14px; }
.range-row output { font-variant-numeric: tabular-nums; text-align: right; color: var(--muted); font-size: 13px; }
.switch { display: flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; margin-top: 10px; }
.switch:first-child { margin-top: 0; }
.switch input { position: absolute; opacity: 0; }
.switch span { flex: none; width: 36px; height: 20px; border-radius: 99px; background: #cfd6de; position: relative; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.switch + .hint { margin: 2px 0 6px 46px; }
.ed-foot { margin-top: auto; padding: 14px 16px; }
.ed-foot-btns { display: flex; gap: 8px; margin-top: 10px; }
.ed-foot-btns .btn { flex: 1; }

/* ---------- Modales ---------- */
.modal[open] { width: min(860px, 94vw); max-height: 92vh; border-radius: 16px; display: flex; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal-body { display: flex; flex-direction: column; width: 100%; max-height: 92vh; margin: 0; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 19px; display: flex; align-items: center; gap: 8px; }
.modal-scroll { overflow-y: auto; padding: 8px 22px 18px; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--line); }
.spacer { flex: 1; }
fieldset { border: 0; padding: 0; margin: 16px 0 6px; }
legend { font-weight: 600; font-size: 15px; margin-bottom: 10px; padding: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.form-grid.one { grid-template-columns: 1fr; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.form-grid label.check { flex-direction: row; color: var(--ink); align-self: end; }
.asset-row { display: grid; grid-template-columns: 200px 1fr; gap: 16px; align-items: center; padding: 10px 0; }
.asset-row + .asset-row { border-top: 1px solid var(--line); }
.asset-row .btn { margin: 8px 10px 0 0; }
.asset-preview { height: 90px; border-radius: 10px; display: grid; place-items: center; padding: 10px;
  background: repeating-conic-gradient(#eef1f4 0 25%, #fff 0 50%) 0 0 / 16px 16px; border: 1px solid var(--line); }
.asset-preview img { max-width: 100%; max-height: 70px; }
.seq-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 14px; }
.seq-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px 6px; }
.seq-table td { padding: 3px 6px; }
.seq-table td:first-child { width: 32px; color: var(--muted); text-align: center; }
.seq-table select, .seq-table input { height: 32px; padding: 4px 8px; }
.seq-table .zoom-in { width: 72px; font: inherit; border: 1px solid var(--line); border-radius: 8px; }

.video-grid { display: grid; grid-template-columns: 1fr 300px; gap: 22px; padding-top: 16px; }
.video-grid output { font-size: 12px; }
.video-preview { background: #111; border-radius: 12px; display: grid; place-items: center; min-height: 375px; overflow: hidden; }
.video-preview video, .video-preview canvas { width: 100%; height: auto; display: block; }
.video-empty { color: #8a96a3; font-size: 13px; padding: 20px; text-align: center; }

@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .patient { margin-left: 0; order: 3; width: 100%; }
  .patient input { width: 100%; }
  main { padding: 20px 16px 48px; }
  .steps { grid-template-columns: 1fr; }
  .editor[open] { flex-direction: column; }
  .editor-side { width: 100%; max-height: 45vh; }
  .video-grid { grid-template-columns: 1fr; }
  .asset-row { grid-template-columns: 1fr; }
}
