/* =============================================================================
 * Ingeniería Civil Tools — hoja de estilo
 * Dirección visual: software técnico premium. Gris mineral, azul profundo,
 * grafito, acento técnico controlado. Nítido, editorial, sin neón ni efectos.
 * ========================================================================== */

:root {
  --bg:        #eef1f4;
  --bg-grid:   #e3e7ec;
  --surface:   #ffffff;
  --surface-2: #f7f9fb;
  --line:      #d7dde4;
  --line-2:    #c3ccd6;

  --ink:       #1a222c;
  --ink-2:     #48555f;
  --ink-3:     #7a8894;

  --primary:   #16324f;   /* azul profundo */
  --primary-2: #1f4e79;
  --accent:    #2b6cb0;   /* acento técnico */
  --accent-soft: #e4eef7;

  --tension:   #0c8599;   /* tracción */
  --compress:  #4c6ef5;   /* compresión */
  --neutral:   #9aa6b2;

  --moment:    #9c36b5;
  --shear:     #2f8f6b;
  --defl:      #b7791f;
  --member:    #1f3a68;   /* barras */
  --member-case: #dfe6f0; /* contorno de perfil */
  --load:      #e8590c;   /* cargas (naranja, como FrameDesign) */
  --react:     #2b8a3e;   /* reacciones */
  --support:   #37506e;
  --support-fill: #e7edf5;

  --ok:        #2f8f6b;
  --warn:      #b7791f;
  --err:       #c2410c;

  --shadow:    0 1px 2px rgba(20,35,50,.06), 0 6px 20px rgba(20,35,50,.06);
  --shadow-sm: 0 1px 2px rgba(20,35,50,.08);
  --radius:    10px;
  --radius-sm: 7px;

  --sans: "Montserrat", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", "Consolas", monospace;
}

:root[data-theme="dark"] {
  --bg:        #0f1620;
  --bg-grid:   #16202c;
  --surface:   #161f2b;
  --surface-2: #1b2634;
  --line:      #263340;
  --line-2:    #33424f;

  --ink:       #e7edf3;
  --ink-2:     #aeb9c4;
  --ink-3:     #7c8894;

  --primary:   #dbe7f2;
  --primary-2: #a9c6e2;
  --accent:    #5fa0da;
  --accent-soft: #1a2c3e;

  --tension:   #3bc9db;
  --compress:  #748ffc;
  --moment:    #da77f2;
  --shear:     #52b48c;
  --defl:      #d9a24a;
  --member:    #b9ccef;
  --member-case: #22314a;
  --load:      #ff922b;
  --react:     #69db7c;
  --support:   #a9c6e2;
  --support-fill: #1c2a3b;

  --shadow:    0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---- Layout general ------------------------------------------------------ */
.app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 0 20px; height: 58px;
  background: var(--primary);
  color: #fff;
  position: sticky; top: 0; z-index: 40;
}
:root[data-theme="dark"] .topbar { background: #0b1219; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; font-weight: 600; letter-spacing: .2px; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 8px;
  display: grid; place-items: center;
  background: linear-gradient(150deg, var(--accent), #163e63);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
}
.brand .mark svg { width: 18px; height: 18px; }
.brand b { font-size: 15px; }
.brand span { font-size: 11px; opacity: .7; font-weight: 400; display:block; margin-top:-2px;}

.tabs { display: flex; gap: 4px; margin-left: 10px; }
.tab {
  appearance: none; border: 0; cursor: pointer;
  background: transparent; color: rgba(255,255,255,.72);
  padding: 8px 15px; border-radius: 8px; font-size: 13.5px; font-weight: 500;
  font-family: inherit; display: flex; align-items: center; gap: 7px;
  transition: background .15s, color .15s;
}
.tab:hover { background: rgba(255,255,255,.08); color: #fff; }
.tab.active { background: rgba(255,255,255,.16); color: #fff; }
.tab svg { width: 16px; height: 16px; opacity: .9; }

.topbar .spacer { flex: 1; }
.icon-btn {
  appearance: none; border: 1px solid rgba(255,255,255,.18); cursor: pointer;
  background: rgba(255,255,255,.06); color: #fff;
  width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center;
  transition: background .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.16); }
.icon-btn svg { width: 18px; height: 18px; }
.unit-pill {
  border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.06);
  color: #fff; padding: 7px 13px; border-radius: 9px; font-size: 12.5px; font-weight:500;
  cursor: pointer;
}

/* ---- Cuerpo de trabajo --------------------------------------------------- */
.workspace {
  display: grid;
  grid-template-columns: 320px 1fr 300px;
  gap: 16px; padding: 16px; flex: 1; align-items: start;
}
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 300px 1fr; }
  .panel-results { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .workspace > * { min-width: 0; max-width: 100%; }
  .btn-row { flex-wrap: wrap; }
}

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.panel-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
}
.panel-hd h2 { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .8px;
  text-transform: uppercase; color: var(--ink-3); }
.panel-bd { padding: 16px; }
.panel-inputs { position: sticky; top: 74px; }

/* ---- Controles de formulario -------------------------------------------- */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  margin-bottom: 6px; }
.field .hint { font-size: 11px; color: var(--ink-3); font-weight: 400; }
.control {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink); font-family: inherit; font-size: 13.5px;
  transition: border-color .15s, box-shadow .15s;
}
.control:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select.control { cursor: pointer; }

.row { display: flex; gap: 10px; }
.row .field { flex: 1; }

.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line-2);
  border-radius: var(--radius-sm); padding: 3px; gap: 3px; }
.seg button {
  flex: 1; appearance: none; border: 0; background: transparent; cursor: pointer;
  padding: 7px 6px; border-radius: 5px; font-family: inherit; font-size: 12.5px; font-weight: 500;
  color: var(--ink-2); transition: background .12s, color .12s;
}
.seg.wrap { flex-wrap: wrap; }
.seg.wrap button { flex: 1 0 28%; }
.seg button.active { background: var(--surface); color: var(--primary-2); box-shadow: var(--shadow-sm); font-weight: 600; }
:root[data-theme="dark"] .seg button.active { color: var(--accent); }

.slider-wrap { display: flex; align-items: center; gap: 12px; }
.slider-wrap input[type=range] { flex: 1; accent-color: var(--accent); }
.slider-wrap .val { min-width: 62px; text-align: right; font-family: var(--mono); font-size: 13px; color: var(--ink); }

.btn {
  appearance: none; cursor: pointer; font-family: inherit; font-weight: 600; font-size: 13px;
  padding: 9px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line-2);
  background: var(--surface-2); color: var(--ink); transition: background .15s, border-color .15s;
  display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn.ghost { background: transparent; }
.btn svg { width: 15px; height: 15px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.subhead { font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: var(--ink-3); margin: 18px 0 10px; display: flex; align-items: center; gap: 8px; }
.subhead::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---- Lista de cargas ----------------------------------------------------- */
.load-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; margin-bottom: 7px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 12.5px;
}
.load-item .tag { font-family: var(--mono); font-weight: 600; color: var(--accent); }
.load-item .desc { flex: 1; color: var(--ink-2); }
.load-item .del { appearance: none; border: 0; background: transparent; cursor: pointer;
  color: var(--ink-3); padding: 3px; border-radius: 4px; }
.load-item .del:hover { color: var(--err); background: var(--surface); }
.empty-note { font-size: 12px; color: var(--ink-3); font-style: italic; padding: 4px 0; }

/* ---- Centro: lienzo y diagramas ----------------------------------------- */
.stage { display: flex; flex-direction: column; gap: 16px; }
.viewer {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.viewer-hd { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.viewer-hd .title { font-size: 13px; font-weight: 700; color: var(--ink); }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  appearance: none; cursor: pointer; font-family: inherit; font-size: 11.5px; font-weight: 500;
  padding: 5px 10px; border-radius: 20px; border: 1px solid var(--line-2);
  background: var(--surface-2); color: var(--ink-2);
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--primary-2); }
:root[data-theme="dark"] .chip.active { color: var(--accent); }

.svg-holder { width: 100%; background:
  linear-gradient(var(--bg-grid) 1px, transparent 1px) 0 0 / 24px 24px,
  linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px) 0 0 / 24px 24px,
  var(--surface);
}
.svg-holder svg { display: block; width: 100%; height: auto; }

.diagrams { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .diagrams { grid-template-columns: 1fr; } }
.diagram { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); overflow: hidden; }
.diagram .dg-hd { padding: 9px 13px; border-bottom: 1px solid var(--line);
  font-size: 12px; font-weight: 700; display: flex; justify-content: space-between; align-items:center;}
.diagram .dg-hd .mx { font-family: var(--mono); font-weight: 500; color: var(--ink-2); font-size: 11.5px; }
.diagram .dg-hd .swatch { width: 10px; height: 10px; border-radius: 3px; display:inline-block; margin-right:6px; }

/* ---- Panel de resultados ------------------------------------------------- */
.result-tabs { display: flex; gap: 4px; padding: 10px 12px 0; border-bottom: 1px solid var(--line); }
.result-tabs button { appearance: none; border: 0; background: transparent; cursor: pointer;
  font-family: inherit; font-size: 12.5px; font-weight: 600; color: var(--ink-3);
  padding: 8px 10px; border-bottom: 2px solid transparent; }
.result-tabs button.active { color: var(--primary-2); border-bottom-color: var(--accent); }
:root[data-theme="dark"] .result-tabs button.active { color: var(--accent); }

.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 6px; }
.metric { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 11px 12px; }
.metric .k { font-size: 10.5px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  color: var(--ink-3); }
.metric .v { font-family: var(--mono); font-size: 17px; font-weight: 600; color: var(--ink); margin-top: 3px; }
.metric .u { font-size: 11px; color: var(--ink-3); font-weight: 500; }

table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data th { text-align: right; font-weight: 700; color: var(--ink-3); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .4px; padding: 7px 8px; border-bottom: 1.5px solid var(--line-2); }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data td { padding: 7px 8px; border-bottom: 1px solid var(--line); font-family: var(--mono); }
table.data tr:last-child td { border-bottom: 0; }
.pos { color: var(--tension); } /* tracción */
.neg { color: var(--compress); } /* compresión */

/* ---- Matrices ------------------------------------------------------------ */
.matrix-block { margin-bottom: 18px; }
.matrix-block h4 { margin: 0 0 8px; font-size: 12.5px; color: var(--ink); font-weight: 700; }
.matrix-block .cap { font-size: 11.5px; color: var(--ink-3); margin: -4px 0 8px; }
.matrix-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table.matrix { border-collapse: collapse; font-family: var(--mono); font-size: 11px; white-space: nowrap; }
table.matrix td { padding: 5px 9px; text-align: right; border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line); color: var(--ink-2); }
table.matrix td.diag { background: var(--accent-soft); color: var(--primary-2); font-weight: 600; }
:root[data-theme="dark"] table.matrix td.diag { color: var(--accent); }
table.matrix .hdr { background: var(--surface-2); color: var(--ink-3); font-weight: 700; position: sticky; }

.callout { display: flex; gap: 10px; padding: 11px 13px; border-radius: var(--radius-sm);
  font-size: 12.5px; margin-bottom: 12px; border: 1px solid; }
.callout.ok  { background: color-mix(in srgb, var(--ok) 8%, var(--surface)); border-color: color-mix(in srgb, var(--ok) 30%, var(--line)); color: var(--ink); }
.callout.warn{ background: color-mix(in srgb, var(--warn) 10%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 35%, var(--line)); }
.callout.err { background: color-mix(in srgb, var(--err) 10%, var(--surface)); border-color: color-mix(in srgb, var(--err) 35%, var(--line)); }
.callout svg { width: 17px; height: 17px; flex-shrink: 0; margin-top: 1px; }

/* ---- Procedimiento ------------------------------------------------------- */
.steps { counter-reset: step; }
.step { position: relative; padding: 0 0 16px 34px; border-left: 2px solid var(--line); margin-left: 8px; }
.step:last-child { border-left-color: transparent; }
.step::before { counter-increment: step; content: counter(step);
  position: absolute; left: -13px; top: -2px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.step h5 { margin: 0 0 4px; font-size: 13px; color: var(--ink); }
.step p { margin: 0; font-size: 12.5px; color: var(--ink-2); }
.step .eq { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; margin-top: 6px; display:inline-block; }

/* ---- Pie ----------------------------------------------------------------- */
.foot { padding: 14px 20px; color: var(--ink-3); font-size: 11.5px; text-align: center; }
.foot b { color: var(--ink-2); }

/* ---- SVG estructura ------------------------------------------------------ */
.s-member { stroke: var(--ink); stroke-width: 3; fill: none; }
.s-member-truss { stroke-width: 2.5; }
.s-node { fill: var(--surface); stroke: var(--ink); stroke-width: 1.5; }
.s-load { stroke: var(--accent); stroke-width: 2; fill: var(--accent); }
.s-load-udl { fill: color-mix(in srgb, var(--accent) 16%, transparent); stroke: var(--accent); stroke-width: 1; }
.s-dim { stroke: var(--ink-3); stroke-width: 1; }
.s-label { fill: var(--ink-2); font-family: var(--mono); font-size: 11px; font-weight: 600; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.s-label.load-lbl { fill: var(--load); }
.halo { paint-order: stroke; stroke: var(--surface); stroke-width: 3.2px; stroke-linejoin: round; }
.s-node-lbl { fill: var(--ink-3); font-family: var(--mono); font-size: 10px; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.s-support { stroke: var(--primary-2); stroke-width: 2; fill: none; }
.s-deflect { stroke: var(--defl); stroke-width: 2; fill: none; stroke-dasharray: 5 4; }

/* ---- Editor interactivo ------------------------------------------------- */
.toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.toolbar .tool {
  appearance: none; cursor: pointer; font-family: inherit; font-size: 12.5px; font-weight: 600;
  padding: 9px 8px; border-radius: var(--radius-sm); border: 1px solid var(--line-2);
  background: var(--surface-2); color: var(--ink-2); transition: all .12s; text-align: left;
}
.toolbar .tool:first-child { grid-column: 1 / -1; }
.toolbar .tool:hover { border-color: var(--accent); }
.toolbar .tool.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.toolbar .tool { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.toolbar kbd { font-family: var(--mono); font-size: 10px; padding: 1px 5px; border-radius: 4px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-3); font-weight: 600; }
.toolbar .tool.active kbd { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.35); color: #fff; }

.editor-holder { height: 460px; position: relative; cursor: crosshair; }
.editor-holder.mode-select { cursor: default; }
.editor-svg { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; }
.editor-svg text { user-select: none; }
.hintbar { font-size: 11.5px; color: var(--ink-3); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 7px 10px; margin-bottom: 10px; }

.prop-row { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.prop-row label { font-size: 12px; color: var(--ink-2); min-width: 62px; }
.prop-row .control { flex: 1; padding: 7px 9px; }
.badge { display: inline-block; font-family: var(--mono); font-size: 11px; padding: 2px 8px; border-radius: 5px;
  background: var(--accent-soft); color: var(--primary-2); font-weight: 600; margin-bottom: 8px; }
:root[data-theme="dark"] .badge { color: var(--accent); }

.s-label.sel { fill: var(--accent); font-weight: 700; }

/* ---- Celular / tablet: lienzo primero, herramientas compactas encima ------ */
.mtoolbar, .msub { display: none; }
@media (max-width: 820px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 10px; gap: 8px; }
  .brand span { display: none; }
  .brand b { font-size: 13px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; margin-left: 0; scrollbar-width: none; }
  .tab { padding: 6px 10px; font-size: 12.5px; white-space: nowrap; }
  .icon-btn { width: 32px; height: 32px; }
  .unit-pill { padding: 5px 8px; font-size: 12px; }
  .workspace { padding: 8px; gap: 10px; }
  .stage { order: 1; min-width: 0; }
  .panel-inputs { order: 2; position: static; }
  .panel-results { order: 3; }
  .panel-inputs #toolbar, .panel-inputs #subtools { display: none; }
  .editor-holder { height: 62vh; }
  .viewer-hd { padding: 7px 8px; gap: 6px; }
  .chip { padding: 4px 8px; font-size: 11px; }
  .mtoolbar { display: flex; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .mtool { flex: 1 0 auto; appearance: none; border: 1px solid var(--line-2); background: var(--surface-2); color: var(--ink-2);
    border-radius: 8px; padding: 6px 8px; font-family: inherit; font-size: 15px; display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 50px; }
  .mtool span { font-size: 10px; font-weight: 600; }
  .mtool.active { background: var(--accent); border-color: var(--accent); color: #fff; }
  .msub { display: block; padding: 6px 8px; border-bottom: 1px solid var(--line); }
  .msub .hintbar { margin-bottom: 6px; font-size: 11px; padding: 5px 8px; }
  .diagrams { grid-template-columns: 1fr; }
}
@media (max-width: 480px) { .brand div { display: none; } }

/* ---- Menú contextual ----------------------------------------------------- */
.ctx-menu { position: fixed; z-index: 90; min-width: 210px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); padding: 5px; }
.ctx-menu button { display: block; width: 100%; text-align: left; appearance: none; border: 0; background: transparent;
  padding: 7px 10px; border-radius: 6px; font-family: inherit; font-size: 12.5px; color: var(--ink); cursor: pointer; }
.ctx-menu button:hover { background: var(--accent-soft); }
.ctx-menu button.danger { color: var(--err); }
.ctx-sep { height: 1px; background: var(--line); margin: 4px 6px; }
.chip:disabled { opacity: .4; cursor: default; }
.dir-row button { font-size: 13px; }

/* ---- Modal (pop-up al crear) -------------------------------------------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,22,32,.45); display: grid; place-items: center; z-index: 80; }
.modal-overlay[hidden] { display: none; }
.modal-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); width: min(360px, 92vw); padding: 18px; }
.modal-card h3 { margin: 0 0 3px; font-size: 16px; color: var(--ink); }
.modal-card .sub { font-size: 12px; color: var(--ink-3); margin-bottom: 14px; }
.dir-row { display: flex; gap: 6px; margin: 4px 0 12px; }
.dir-row button { flex: 1; padding: 9px; border: 1px solid var(--line-2); background: var(--surface-2);
  border-radius: 8px; cursor: pointer; font-size: 17px; color: var(--ink); }
.dir-row button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ---- Impresión (formato reporte) ---------------------------------------- */
.print-only { display: none; }
@media print {
  @page { margin: 14mm; }
  .topbar, .panel-inputs, .result-tabs, .chip-row, .viewer-hd .chip-row,
  .no-print, .foot { display: none !important; }
  body { background: #fff; font-size: 11px; }
  .workspace { display: block; padding: 0; }
  .panel, .viewer, .diagram { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; margin-bottom: 12px; }
  .print-only { display: block; }
  .print-head { display: flex; justify-content: space-between; align-items: baseline;
    border-bottom: 2px solid #16324f; padding-bottom: 8px; margin-bottom: 14px; }
  .print-head h1 { font-size: 18px; margin: 0; color: #16324f; }
  .print-head .meta { font-size: 11px; color: #555; text-align: right; }
  .diagrams { display: block; }
  .matrix-scroll { overflow: visible; }
  .stage, .panel-results { break-inside: auto; }
}
.print-report { display: none; }
@media print {
  body.printing-report .app > *:not(#printReport) { display: none !important; }
  body.printing-report .print-report { display: block; color: #1a2330; font-family: Montserrat, system-ui, sans-serif; }
  @page { size: letter portrait; margin: 12mm; }
  .rp-head { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 3px solid #16324f; padding-bottom: 8px; margin-bottom: 10px; }
  .rp-kicker { font-size: 9px; letter-spacing: .12em; text-transform: uppercase; color: #6b7a8c; font-weight: 700; }
  .rp-head h1 { margin: 2px 0 0; font-size: 20px; color: #16324f; }
  .rp-meta { font-size: 10px; color: #4a5868; text-align: right; line-height: 1.5; }
  .rp-plano svg { width: 100%; height: auto; display: block; }
  .rp-break { break-before: page; }
  .rp-sec h2 { font-size: 16px; color: #16324f; margin: 0 0 4px; }
  .rp-sec h3 { font-size: 12px; color: #16324f; background: #e4eef7; padding: 4px 8px; border-left: 4px solid #1f4e79; margin: 12px 0 6px; break-after: avoid; }
  .rp-note { font-size: 9.5px; color: #6b7a8c; font-style: italic; margin: 2px 0; }
  .rp-tbl { border-collapse: collapse; width: 100%; font-size: 9.5px; margin: 4px 0 8px; break-inside: auto; }
  .rp-tbl tr { break-inside: avoid; }
  .rp-tbl th { background: #1f4e79; color: #fff; font-weight: 700; padding: 4px 5px; border: 1px solid #c3ccd6; text-align: center; }
  .rp-tbl td { padding: 3px 5px; border: 1px solid #d5dce4; }
  .rp-tbl td.n { text-align: right; font-family: 'JetBrains Mono', monospace; }
  .rp-tbl tr:nth-child(even) td { background: #f6f8fb; }
  .rp-tbl td.dg { background: #e4eef7 !important; font-weight: 700; }
  .rp-mat .rp-tbl { font-size: 8.5px; }
  .rp-tbl td.n { white-space: nowrap; }
  .rp-mat .rp-tbl td, .rp-mat .rp-tbl th { padding: 2px 3px; }
  .rp-foot { margin-top: 14px; border-top: 1px solid #c3ccd6; padding-top: 6px; font-size: 9px; color: #6b7a8c; }
}
.ic { width: 17px; height: 17px; flex: 0 0 auto; vertical-align: -3px; }
.tool { display: flex; align-items: center; gap: 7px; }
.tool kbd { margin-left: auto; }
.chip .ic { width: 15px; height: 15px; vertical-align: -3px; }
.mtool .ic { width: 20px; height: 20px; }
.fold { border-top: 1px solid var(--line); margin-top: 12px; }
.fold > summary { cursor: pointer; list-style: none; padding: 10px 0 8px; font-size: 11px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--ink-3); display: flex; align-items: center; justify-content: space-between; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after { content: "▸"; font-size: 12px; transition: transform .15s; }
.fold[open] > summary::after { transform: rotate(90deg); }
.fold > summary:hover { color: var(--accent); }
.view-toggle { display: none; margin-left: auto; }
@media (max-width: 820px) {
  .view-toggle { display: inline-flex; align-items: center; gap: 4px; }
  #viewChips, .viewer-hd2 { display: none; }
  body.show-view #viewChips, body.show-view .viewer-hd2 { display: flex; }
  .viewer-hd .title { font-size: 13px; }
  .panel-results .result-tabs button { padding: 7px 9px; font-size: 12px; }
  .export-box .btn-row { display: grid; grid-template-columns: 1fr 1fr; }
  .editor-holder { height: 58vh; }
  .footer, .foot { display: none; }
}
.modal-card.wide { width: min(640px, 94vw); max-height: 88vh; overflow: auto; }
.lx-steps { padding-left: 20px; margin: 8px 0 12px; font-size: 12.5px; color: var(--ink-2); }
.lx-steps li { margin-bottom: 10px; }
.lx-steps .row { margin-top: 6px; gap: 8px; flex-wrap: wrap; }
.lx-steps label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; font-weight: 600; flex: 1 1 110px; }
/* ---- Distribución tipo Canva: barra de íconos + panel deslizable + resultados en paralelo ---- */
@media (min-width: 821px) {
  .workspace { grid-template-columns: 52px var(--dw, 290px) minmax(0, 1fr) var(--rw, 400px) !important; gap: 12px; padding: 12px; align-items: stretch; transition: grid-template-columns .18s ease; }
  body.drawer-closed .workspace { grid-template-columns: 52px 0 minmax(0, 1fr) var(--rw, 400px) !important; }
  body.right-closed .workspace { grid-template-columns: 52px var(--dw, 290px) minmax(0, 1fr) 0 !important; }
  body.drawer-closed.right-closed .workspace { grid-template-columns: 52px 0 minmax(0, 1fr) 0 !important; }
  body.drawer-closed .panel-inputs, body.right-closed .panel-results { visibility: hidden; overflow: hidden; border: 0; padding: 0; min-width: 0; }
  .panel-inputs { position: sticky; top: 70px; max-height: calc(100vh - 84px); overflow: auto; min-width: 0; }
  .panel-results { grid-column: auto !important; position: sticky; top: 70px; max-height: calc(100vh - 84px); overflow: auto; min-width: 0; }
  .panel-inputs .pane { display: none; } .panel-inputs .pane.on { display: block; }
  .panel-inputs .pane-title { display: none; }
  .panel-inputs #toolbar { display: none; }
  .editor-holder { height: calc(100vh - 250px); min-height: 380px; }
  .foot { display: none; }
}
.rail { display: none; }
@media (min-width: 821px) {
  .rail { display: flex; flex-direction: column; gap: 4px; align-items: center; padding: 8px 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); position: sticky; top: 70px; height: calc(100vh - 84px); }
}
.rbtn { appearance: none; border: 0; background: transparent; color: var(--ink-2); width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; }
.rbtn .ic { width: 21px; height: 21px; }
.rbtn:hover { background: var(--surface-2); color: var(--accent); }
.rbtn.active { background: var(--accent); color: #fff; }
.rbtn.open { background: var(--accent-soft); color: var(--accent); }
.rsep { width: 26px; height: 1px; background: var(--line); margin: 6px 0; }
.rgrow { flex: 1; }
.pane-close { width: 28px; height: 28px; font-size: 13px; }
.pane-title { font-size: 11px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--ink-3); margin: 14px 0 8px; }
.panel-results { position: relative; }
.rs-handle { position: absolute; left: -7px; top: 0; bottom: 0; width: 10px; cursor: col-resize; z-index: 5; }
.rs-handle:hover, .rs-handle.drag { background: linear-gradient(90deg, transparent 4px, var(--accent) 4px, var(--accent) 6px, transparent 6px); }
.rt-wide { margin-left: auto; }
/* ---- Procedimiento con fórmulas ---- */
.pz { display: flex; flex-direction: column; gap: 14px; }
.pz-step { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--surface); }
.pz-step h5 { margin: 0 0 8px; font-size: 13px; color: var(--primary); display: flex; gap: 8px; align-items: center; }
.pz-step h5 .n { background: var(--accent); color: #fff; border-radius: 50%; width: 22px; height: 22px; display: grid; place-items: center; font-size: 11px; flex: 0 0 auto; }
.pz-step p { margin: 6px 0; font-size: 12.5px; color: var(--ink-2); line-height: 1.55; }
.fx { font-family: "Cambria Math", "STIX Two Math", "Times New Roman", serif; font-size: 16px; color: var(--ink); display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 8px 0; overflow-x: auto; }
.fx i { font-style: italic; }
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; margin: 0 2px; line-height: 1.1; }
.frac > span:first-child { border-bottom: 1px solid currentColor; padding: 0 3px 1px; }
.frac > span:last-child { padding: 1px 3px 0; }
.bm { display: inline-table; border-collapse: collapse; position: relative; margin: 0 6px; font-family: var(--mono); font-size: 11px; vertical-align: middle; }
.bm td { padding: 2px 7px; text-align: right; white-space: nowrap; }
.bm.sym td { font-family: "Cambria Math", "Times New Roman", serif; font-size: 14px; text-align: center; }
.bm-wrap { display: inline-flex; align-items: stretch; vertical-align: middle; }
.bm-wrap::before, .bm-wrap::after { content: ""; width: 6px; border: 1.6px solid var(--ink); }
.bm-wrap::before { border-right: 0; } .bm-wrap::after { border-left: 0; }
.bm-wrap.vec::before, .bm-wrap.vec::after { border-radius: 6px; }
.bm .lb { color: var(--ink-3); font-size: 10px; text-align: left; padding-right: 10px; }
.bm .dg { font-weight: 700; color: var(--primary); }
.pz details summary { cursor: pointer; font-size: 12px; color: var(--accent); margin: 6px 0; }
.rt-sp { flex: 1; }
.rt-ic { appearance: none; border: 0; background: transparent; color: var(--ink-3); cursor: pointer; font-size: 14px; padding: 6px 8px; border-radius: 6px; }
.rt-ic:hover { background: var(--surface-2); color: var(--accent); }
@media (min-width: 821px) { .panel-results .result-tabs { position: sticky; top: 0; z-index: 4; background: var(--surface); } }
/* tipografía más humana */
body { letter-spacing: -0.005em; }
h1, h2, h3, h4, h5, .brand b, .panel-hd h2, .pane-title, .subhead { letter-spacing: 0; }
.brand b { font-weight: 800; }
.btn, .chip, .tab { font-weight: 600; }
/* fórmulas KaTeX */
.pz .katex { font-size: 1.08em; }
.pz .katex-display { margin: 8px 0; overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.kx-block { overflow-x: auto; }
/* tablas y matrices en celular: se desplazan, no se aplastan */
.matrix-scroll, .kx-block, .pz-step { max-width: 100%; }
#resultPanel table.data { display: block; overflow-x: auto; max-width: 100%; }
@media (max-width: 820px) {
  .pz-step { padding: 10px; }
  .pz .katex { font-size: .95em; }
  .matrix td { padding: 3px 5px; font-size: 10.5px; }
}
.result-tabs { flex-wrap: wrap; } .tbl-in { padding: 4px 6px; font-size: 12px; }
.export-box { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.export-box .btn { padding: 7px 11px; font-size: 12.5px; }

/* ---- Inicio rápido sobre el lienzo ---------------------------------------- */
.canvas-wrap { position: relative; }
.quickstart { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.quickstart[hidden] { display: none; }
.qs-card { pointer-events: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 18px 20px; width: min(460px, 92%); }
.qs-card h3 { margin: 0 0 2px; font-size: 16px; }
.qs-card .sub { font-size: 12px; color: var(--ink-3); margin-bottom: 12px; }
.qs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; margin-bottom: 10px; }
.qs-grid label { font-size: 11.5px; color: var(--ink-2); font-weight: 600; display: flex; flex-direction: column; gap: 4px; }
.qs-grid .control { padding: 7px 9px; font-size: 13px; }
.qs-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.qs-or { font-size: 11.5px; color: var(--ink-3); margin: 12px 0 6px; display: flex; align-items: center; gap: 8px; }
.qs-or::before, .qs-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.qs-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.qs-draw { font-size: 12px; color: var(--ink-2); background: var(--surface-2); border: 1px dashed var(--line-2); border-radius: 8px; padding: 8px 10px; margin-top: 10px; }

/* ---- Barra de estado ----------------------------------------------------- */
.statusbar { display: flex; align-items: center; gap: 12px; padding: 7px 12px; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--ink-2); background: var(--surface-2); flex-wrap: wrap; border-radius: 0 0 var(--radius) var(--radius); }
.statusbar .st-mode { font-weight: 700; color: var(--primary-2); }
.statusbar .st-count { color: var(--ink-3); font-family: var(--mono); font-size: 11.5px; }
.statusbar .st-msg { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.statusbar .st-ok { color: var(--ok); font-weight: 600; }
.statusbar .st-warn { color: var(--warn); font-weight: 600; }
.statusbar .btn { padding: 4px 10px; font-size: 11.5px; }

/* ---- Miniaturas de diagramas (clic = mostrar en el lienzo) --------------- */
.thumbs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; grid-column: 1 / -1; }
.thumb { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; overflow: hidden; transition: border-color .12s, box-shadow .12s; }
.thumb:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.thumb.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.thumb .th-hd { display: flex; justify-content: space-between; padding: 7px 11px; font-size: 12px; font-weight: 700; border-bottom: 1px solid var(--line); }
.thumb .th-hd span:last-child { font-family: var(--mono); font-weight: 500; color: var(--ink-3); font-size: 11px; }
.thumb svg { display: block; width: 100%; height: auto; }
@media (max-width: 720px) { .thumbs { grid-template-columns: 1fr; } }
.signs-img svg { width: 100%; height: auto; display: block; border-radius: 10px; margin-bottom: 12px; }
.flex-pick { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.flex-pick label { display: flex; align-items: center; gap: 6px; font-size: 12px; border: 1px solid var(--line-2); border-radius: 8px; padding: 5px 9px; cursor: pointer; }
.flex-pick label.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.learn-btn.on { background: var(--accent); color: #fff; }
.learn { background: var(--accent-soft); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 12.5px; }
.learn ul { margin: 6px 0 0; padding-left: 18px; } .learn li { margin: 3px 0; color: var(--ink-2); }

.result-tabs { flex-wrap: nowrap !important; overflow-x: auto; scrollbar-width: none; }
.result-tabs::-webkit-scrollbar { display: none; }
.result-tabs button { white-space: nowrap; padding: 13px 8px 11px; font-size: 12.5px; }

/* ===================== Reporte impreso · diseño 2 ===================== */
@page { size: letter portrait; margin: 14mm 12mm 16mm; @bottom-right { content: "Página " counter(page) " de " counter(pages); font: 8pt Montserrat, sans-serif; color: #6b7a8c; } @bottom-left { content: "Ingeniería Civil Tools"; font: 8pt Montserrat, sans-serif; color: #6b7a8c; } }
@media print {
  body.printing-report .print-report { font-size: 10pt; }
  .rp-cover { display: flex; gap: 16px; align-items: center; padding: 18px 20px; border-radius: 14px; background: #16324f; color: #fff; margin-bottom: 14px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rp-brand { width: 54px; height: 54px; border-radius: 14px; background: #2b6cb0; display: grid; place-items: center; flex: 0 0 auto; }
  .rp-brand svg { width: 32px; height: 32px; }
  .rp-cover .rp-kicker { color: #a9c6e2; font-size: 8pt; letter-spacing: .12em; text-transform: uppercase; font-weight: 700; }
  .rp-cover h1 { margin: 3px 0 8px; font-size: 20pt; color: #fff; letter-spacing: -.01em; }
  .rp-meta-row { display: flex; flex-wrap: wrap; gap: 6px; }
  .rp-meta-row span { background: rgba(255,255,255,.12); border-radius: 999px; padding: 3px 10px; font-size: 8pt; }
  .rp-note-box { border-left: 4px solid #2b6cb0; background: #eef4fb; padding: 10px 14px; border-radius: 0 10px 10px 0; font-size: 9.5pt; margin-bottom: 12px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rp-kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 6px; }
  .rp-kpi { border: 1px solid #d6e2ef; border-radius: 12px; padding: 9px 11px; background: #f3f7fc; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rp-kpi .l { font-size: 7.5pt; color: #6b7a8c; font-weight: 600; }
  .rp-kpi .v { font-size: 15pt; font-weight: 800; color: #16324f; letter-spacing: -.02em; margin-top: 2px; }
  .rp-kpi .v small { font-size: 8pt; color: #6b7a8c; font-weight: 600; }
  .rp-h2 { display: flex; align-items: center; gap: 10px; font-size: 13pt; color: #16324f; margin: 16px 0 8px; padding-bottom: 6px; border-bottom: 2px solid #2b6cb0; break-after: avoid; }
  .rp-h2 span { width: 24px; height: 24px; border-radius: 50%; background: #2b6cb0; color: #fff; display: grid; place-items: center; font-size: 10pt; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rp-fig svg { width: 100%; height: auto; display: block; border: 1px solid #e3e6ea; border-radius: 12px; }
  .rp-dg { break-inside: avoid; margin-bottom: 12px; }
  .rp-dg-hd { display: flex; justify-content: space-between; align-items: baseline; font-size: 10.5pt; margin: 4px 2px 5px; color: #16324f; }
  .rp-dg-hd span { font-size: 8.5pt; color: #6b7a8c; font-family: 'JetBrains Mono', monospace; }
  .rp-dg svg { width: 100%; height: auto; display: block; border: 1px solid #e3e6ea; border-radius: 12px 12px 0 0; }
  .rp-st { margin-top: 0; font-size: 8pt; } .rp-st td, .rp-st th { text-align: center; padding: 3px 2px; }
  .rp-react { width: 70%; }
  .rp-cap { font-size: 8.5pt; color: #6b7a8c; margin: 4px 0 8px; }
  .rp-tbl th { background: #1f4e79 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rp-tbl tr:nth-child(even) td { background: #f3f7fc !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rp-foot { display: flex; justify-content: space-between; gap: 12px; }
}
@media (min-width: 821px) and (max-width: 1199px) { .workspace { --dw: 250px; } .viewer-hd .chip { padding: 4px 8px; font-size: 11px; } }
@media (min-width: 821px) and (max-width: 1150px) { .topbar { gap: 8px; padding: 0 12px; } .brand span { display: none; } .brand b { font-size: 14px; } .tab { padding: 0 9px; font-size: 13px; } .icon-btn { width: 32px; height: 32px; } .unit-pill { padding: 6px 8px; } }
.topbar { min-width: 0; overflow: hidden; }

.pane[data-pane="lat"] { display: none !important; }
@media (max-width: 820px) {
  .panel-inputs .pane-title { display: flex; justify-content: space-between; align-items: center; cursor: pointer; padding: 12px 2px; margin: 0; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink); text-transform: none; letter-spacing: 0; }
  .panel-inputs .pane-title::after { content: "▸"; transition: transform .15s; color: var(--ink-3); }
  .panel-inputs .pane.m-open .pane-title::after { transform: rotate(90deg); }
  .panel-inputs .pane:not(.m-open) > *:not(.pane-title) { display: none !important; }
  .panel-inputs .pane[data-pane="tools"] > .subhead:first-of-type { display: none; }
  .panel-inputs .panel-hd { display: none; }
  .msub .hintbar { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
}

/* Modo analisis: sin casos de carga a la vista mientras el modelo tenga un solo grupo */
.cases-simple .case-lbl, .cases-simple #caseSel { display: none; }
