.ductos {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --ink: #1f2933;
    --muted: #66788a;
    --line: #d5dde5;
    --accent: #1565c0;
    --accent-soft: #e3f0fd;
    --danger: #c62828;
    --warn-bg: #fff4e0;
    --warn-ink: #8a5300;
    --canvas: #fbfcfd;
    --grid: #e8edf2;
    --grid-major: #d3dbe3;
    --shape: #37474f;
    --duct: #90caf9;
    --duct-edge: #1e5f9e;
    --draft: #e65100;
}

.ductos, .ductos * { box-sizing: border-box; }

.ductos {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    font-size: 15px;
}

.ductos h1, .ductos h2, .ductos h3, .ductos h4 { margin: 0.4em 0; }
.ductos h3 { font-size: 1.05rem; }
.ductos h4 { font-size: 0.95rem; color: var(--muted); }
.ductos .muted { color: var(--muted); }
.ductos .small { font-size: 0.85rem; }
.ductos .error { color: var(--danger); }
.ductos .warn { background: var(--warn-bg); color: var(--warn-ink); padding: 6px 8px; border-radius: 6px; margin: 4px 0; font-size: 0.9rem; }

/* Botones */
.ductos .btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px;
    background: var(--surface); color: var(--ink); font: inherit; cursor: pointer;
    text-decoration: none; white-space: nowrap;
}
.ductos .btn:hover:not(:disabled) { border-color: var(--accent); }
.ductos .btn:disabled { opacity: 0.45; cursor: default; }
.ductos .btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.ductos .btn.ghost { border-color: transparent; background: transparent; }
.ductos .btn.danger { color: var(--danger); margin-top: 12px; }
.ductos .btn.big, .ductos input.big, .ductos select.big { padding: 10px 14px; font-size: 1.05rem; }

.ductos input, .ductos select {
    font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: white; color: var(--ink);
}
.ductos input:focus, .ductos select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.ductos input.bad { border-color: var(--danger); background: #fdecec; }

.ductos .row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.ductos .row.space { justify-content: space-between; align-items: center; }

/* Inicio */
.ductos .home { max-width: 880px; margin: 0 auto; padding: 24px 16px; }
.ductos .home-head h1 { font-size: 2rem; margin-bottom: 0; }
.ductos .home-head p { color: var(--muted); margin-top: 4px; }
.ductos .card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 20px; margin: 16px 0; }
.ductos .card label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; flex: 1 1 220px; }
.ductos .card label.btn { flex: 0 0 auto; flex-direction: row; font-weight: normal; }
.ductos .projects { list-style: none; padding: 0; margin: 0; }
.ductos .projects li { display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); }
.ductos .project { display: flex; flex-direction: column; padding: 12px 4px; color: var(--ink); text-decoration: none; flex: 1; }
.ductos .project:hover strong { color: var(--accent); }

/* Editor */
.ductos .editor {
    display: grid; height: 100vh;
    grid-template-columns: 92px 1fr 380px;
    grid-template-rows: auto 1fr;
    grid-template-areas: "top top top" "tools work panel";
}
.ductos .topbar {
    grid-area: top; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.ductos .topbar .title { font-size: 1.1rem; margin-right: 8px; }
.ductos .topbar .spacer { flex: 1; }
.ductos .topbar .saved { color: var(--muted); font-size: 0.85rem; }
.ductos .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.ductos .seg button { border: 0; background: white; padding: 7px 12px; font: inherit; cursor: pointer; }
.ductos .seg button.on { background: var(--accent); color: white; }

.ductos .tools {
    grid-area: tools; display: flex; flex-direction: column; gap: 6px; padding: 8px 6px;
    background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto;
}
.ductos .tools hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.ductos .tool {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 8px 2px; border: 1px solid transparent; border-radius: 10px; background: transparent;
    font: inherit; font-size: 0.8rem; cursor: pointer; color: var(--ink);
}
.ductos .tool .ico { font-size: 1.5rem; line-height: 1.1; }
.ductos .tool:hover { background: var(--bg); }
.ductos .tool.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.ductos .tool-opt { font-size: 0.78rem; display: flex; flex-direction: column; gap: 2px; padding: 0 2px; }
.ductos .tool-opt select { font-size: 0.78rem; padding: 3px; }
.ductos .tool-opt:has(input[type=checkbox]) { flex-direction: row; align-items: center; gap: 4px; }

.ductos .work { grid-area: work; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ductos .canvas { flex: 1; min-height: 0; background: var(--canvas); position: relative; touch-action: none; user-select: none; }
.ductos .canvas svg { display: block; }

.ductos .drawbar { background: var(--surface); border-top: 1px solid var(--line); padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; }
.ductos .drawbar-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.ductos .drawbar-row.small { font-size: 0.88rem; min-height: 1.3em; }
.ductos .drawbar .group { display: inline-flex; align-items: center; gap: 6px; }
.ductos .drawbar .largo { width: 9em; font-size: 1.1rem; padding: 7px 10px; border: 2px solid var(--accent); }
.ductos .drawbar .live { color: var(--draft); }
.ductos .drawbar .msg { color: var(--muted); }
.ductos .len-input { display: inline-flex; align-items: center; gap: 3px; }
.ductos .len-input input { width: 5.5em; }
.ductos .unit { color: var(--muted); font-size: 0.85rem; }

.ductos .panel { grid-area: panel; display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-left: 1px solid var(--line); }
.ductos .tabs { display: flex; border-bottom: 1px solid var(--line); }
.ductos .tabs button { flex: 1; border: 0; background: transparent; padding: 10px 2px; font: inherit; font-size: 0.85rem; cursor: pointer; border-bottom: 3px solid transparent; }
.ductos .tabs button.on { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }
.ductos .badge { background: var(--danger); color: white; border-radius: 9px; padding: 0 6px; font-size: 0.72rem; margin-left: 3px; }
.ductos .panel-body { overflow-y: auto; padding: 10px 14px 24px; }

.ductos .form { display: flex; flex-direction: column; gap: 8px; }
.ductos .form label { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 0.9rem; }
.ductos .form label > input:not([type=checkbox]), .ductos .form label > select { width: 12em; }
.ductos .form label.check { justify-content: flex-start; }

.ductos table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
.ductos th { text-align: left; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); padding: 4px; }
.ductos td { border-bottom: 1px solid #eef1f4; padding: 4px; vertical-align: middle; }
.ductos table.pieces tr, .ductos .mini-list li { cursor: pointer; }
.ductos table.pieces tr:hover td, .ductos .mini-list li:hover { background: var(--bg); }
.ductos tr.on td, .ductos .mini-list li.on { background: var(--accent-soft); }
.ductos .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.ductos .mini-list { list-style: none; padding: 0; margin: 0; font-size: 0.88rem; }
.ductos .mini-list li { padding: 4px; border-radius: 6px; }

.ductos .pattern, .ductos .sheet { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 10px; background: white; }
.ductos .pattern svg, .ductos .sheet svg { width: 100%; height: auto; display: block; }
.ductos .piece-detail { border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.ductos .ok { color: #2e7d32; }
.ductos .steps { padding-left: 1.3em; margin: 4px 0 10px; }
.ductos .steps li { margin-bottom: 3px; }
.ductos .view3d { flex: 1; min-height: 0; position: relative; background: #f7f9fb; }
.ductos .view3d canvas { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.ductos .view3d-legend { position: absolute; right: 12px; top: 10px; background: rgba(255,255,255,0.9); padding: 6px 10px; border-radius: 8px; display: flex; gap: 10px; }
.ductos .view3d-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -2px; }
.ductos .modal-back { position: fixed; inset: 0; background: rgba(20, 30, 40, 0.45); z-index: 50; display: flex; align-items: center; justify-content: center; }
.ductos .modal { background: var(--surface); border-radius: 12px; padding: 14px 18px; box-shadow: 0 10px 40px rgba(0,0,0,0.25); }
.ductos .modal.fold { width: min(1000px, 94vw); }
.ductos .fold-canvas { width: 100%; height: min(62vh, 560px); display: block; border: 1px solid var(--line); border-radius: 8px; cursor: grab; touch-action: none; }
.ductos .fold-controls { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.ductos .fold-controls input[type=range] { flex: 1; min-width: 160px; }
.ductos .effects { background: var(--accent-soft); padding: 8px 12px; border-radius: 8px; font-size: 0.9rem; margin: 8px 0 12px; }
.ductos .effects ul { margin: 4px 0 0; padding-left: 1.2em; }
.ductos .effects li { margin-bottom: 3px; }
.ductos .shop-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.ductos .home-head.row { align-items: center; }
.ductos .home .card .form label { flex-direction: row; font-weight: normal; flex: none; }
.ductos .help { background: var(--bg); padding: 8px 12px; border-radius: 8px; font-size: 0.9rem; margin-top: 12px; }
.ductos .help ol { padding-left: 1.2em; margin: 6px 0; }
.ductos .help li { margin-bottom: 6px; }

/* Lienzo */
.ductos .grid { stroke: var(--grid); stroke-width: 1; }
.ductos .grid.major { stroke: var(--grid-major); }
.ductos .shape { fill: rgba(55, 71, 79, 0.04); stroke: var(--shape); stroke-width: 3; stroke-linejoin: round; }
.ductos polyline.shape { fill: none; }
.ductos .shape.selected { stroke: var(--accent); }
.ductos .duct-edge { fill: none; stroke: var(--duct-edge); stroke-linejoin: miter; stroke-opacity: 0.8; }
.ductos .duct { fill: none; stroke: var(--duct); stroke-linejoin: miter; }
.ductos .duct.selected { stroke: #64b5f6; }
.ductos .duct.draft { stroke: #ffcc80; stroke-opacity: 0.6; }
.ductos .pc { stroke-width: 1.5; stroke-linejoin: miter; }
.ductos .pc-straight { fill: #bbdefb; stroke: #1e5f9e; }
.ductos .pc-elbow { fill: #ffe0b2; stroke: #e65100; }
.ductos .pc-transition { fill: #e1bee7; stroke: #7b1fa2; }
.ductos .pc-tee { fill: #c8e6c9; stroke: #2e7d32; }
.ductos .pc-cap { fill: #8d6e63; stroke: #4e342e; }
.ductos .pc.sel { stroke-width: 2.5; filter: brightness(0.95); }
.ductos .pc.selpiece { stroke: #d50000; stroke-width: 3; }
.ductos .nowrap { white-space: nowrap; }
.ductos .nowrap .len-input input { width: 4.2em; }
.ductos .branch-box { background: #e8f5e9; border-radius: 8px; padding: 8px 10px; margin: 8px 0; }
.ductos .hint { font-size: 12px; font-weight: 600; fill: #2e7d32; paint-order: stroke; stroke: white; stroke-width: 4px; }
.ductos .duct-axis { fill: none; stroke: var(--duct-edge); stroke-width: 1; stroke-dasharray: 8 5; opacity: 0.6; }
.ductos .dim { font-size: 12px; fill: var(--shape); paint-order: stroke; stroke: var(--canvas); stroke-width: 4px; }
.ductos .duct-dim { fill: var(--duct-edge); }
.ductos .draft-line { fill: none; stroke: var(--draft); stroke-width: 2; stroke-dasharray: 6 4; }
.ductos .draft-dim { fill: var(--draft); font-weight: 600; font-size: 13px; }
.ductos .draft-pt { fill: var(--draft); }
.ductos .handle { fill: white; stroke: var(--accent); stroke-width: 2; }
.ductos .cursor { fill: none; stroke: var(--draft); stroke-width: 2; }
.ductos .cursor.snapped { stroke: #2e7d32; stroke-width: 3; }
.ductos .piece-num { font-size: 11px; font-weight: 700; fill: var(--ink); pointer-events: none; }
.ductos .hanger { fill: #6d4c41; }
.ductos .scalebar { stroke: var(--ink); stroke-width: 3; }
.ductos .scale-text { font-size: 12px; fill: var(--ink); }

/* Aviso de error de Blazor: lo pone el anfitrion fuera de .ductos; en GCCERP lo define su propio CSS. */
.ductos-anfitrion #blazor-error-ui {
    background: #fff3cd; bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none; left: 0; padding: 0.6rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}

/* ===== Convivencia con Bootstrap (GCCERP lo usa) =====
   Bootstrap tambien define .row, .card, .btn, .badge y .modal; aqui se anulan sus efectos. */
.ductos .row { margin: 0; --bs-gutter-x: 0; --bs-gutter-y: 0; }
.ductos .row > * { width: auto; max-width: none; padding: 0; margin-top: 0; flex-shrink: 1; }
.ductos .card { display: block; min-width: 0; word-wrap: normal; }
.ductos .btn { line-height: 1.3; font-weight: 400; text-align: left; vertical-align: middle; }
.ductos .btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.ductos .badge { display: inline; font-weight: 600; line-height: 1.4; }
.ductos .modal { display: block; position: static; width: auto; height: auto; overflow: visible; z-index: auto; outline: 0; }
.ductos label { margin-bottom: 0; }
.ductos a { text-decoration: none; }
.ductos table { caption-side: bottom; }

/* ===== Pantallas medianas ===== */
@media (max-width: 1200px) {
    .ductos .editor { grid-template-columns: 84px 1fr 320px; }
}

/* ===== Celular y tableta vertical: el editor en una sola columna =====
   Arriba la barra, luego las herramientas en fila (se deslizan), el plano y debajo el panel. */
@media (max-width: 900px) {
    .ductos { font-size: 15px; }
    .ductos .home { padding: 16px 12px; }
    .ductos .home-head h1 { font-size: 1.6rem; }
    .ductos .card { padding: 12px 14px; }
    .ductos .row { gap: 10px; }
    .ductos .row > button, .ductos .row > .btn { flex: 1 1 auto; justify-content: center; }
    .ductos .projects li { flex-wrap: wrap; }

    .ductos .editor { display: flex; flex-direction: column; height: auto; min-height: 100dvh; }
    /* Barra superior en una sola fila que se desliza de lado. */
    .ductos .topbar { gap: 6px; padding: 6px 8px; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .ductos .topbar > * { flex: 0 0 auto; }
    .ductos .topbar .title { max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 0 4px 0 0; }
    .ductos .topbar .spacer { display: none; }
    .ductos .topbar .btn { padding: 6px 9px; font-size: 0.88rem; }

    .ductos .tools {
        flex-direction: row; align-items: stretch; overflow-x: auto; overflow-y: hidden;
        border-right: 0; border-bottom: 1px solid var(--line); padding: 6px; gap: 4px;
        -webkit-overflow-scrolling: touch;
    }
    .ductos .tools hr { width: auto; height: auto; border-top: 0; border-left: 1px solid var(--line); margin: 0 2px; }
    .ductos .tool { flex: 0 0 auto; min-width: 68px; padding: 6px 4px; }
    .ductos .tool .ico { font-size: 1.3rem; }
    .ductos .tool-opt { flex: 0 0 auto; justify-content: center; }

    .ductos .work { height: auto; flex: none; }
    .ductos .canvas { height: 58dvh; min-height: 320px; flex: none; }
    .ductos .drawbar { padding: 8px; }
    .ductos .drawbar .largo { width: 7em; }
    .ductos .drawbar-row { gap: 8px; }
    .ductos .drawbar .group { flex-wrap: wrap; }
    .ductos .drawbar .arrows { display: inline-flex; gap: 4px; }
    .ductos .drawbar .arrows .btn { padding: 6px 12px; font-size: 1.05rem; }
    /* En celular no hay mouse: "Hacia el mouse" no aplica. */
    .ductos .drawbar .arrows + .btn { display: none; }

    .ductos .panel { border-left: 0; border-top: 1px solid var(--line); }
    .ductos .tabs { position: sticky; top: 0; background: var(--surface); z-index: 1; overflow-x: auto; }
    .ductos .tabs button { flex: 1 0 auto; padding: 10px 8px; }
    .ductos .panel-body { overflow: visible; }

    .ductos .form label { flex-wrap: wrap; }
    .ductos .form label > input:not([type=checkbox]), .ductos .form label > select { width: 100%; max-width: 14em; }
    .ductos table { font-size: 0.82rem; }
    .ductos .modal { padding: 10px; }
    .ductos .modal.fold { width: 96vw; }
    .ductos .fold-canvas { height: 50vh; }
    .ductos .view3d { min-height: 340px; }
}