/* Sistema visual "CADMETRY" -- identidad industrial de precision portada
   desde el mockup de referencia del usuario (paleta, tipografia, layout de
   sidebar). Los datos que alimentan cada pantalla siguen siendo reales
   (no se han copiado cifras de ejemplo del mockup). */
@import url('https://fonts.googleapis.com/css2?family=Hanken+Grotesk:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #111316;
  --bg-panel: #171a1e;
  --bg-panel-2: #1b1f24;
  --border: #262b31;
  --tertiary: #273130;
  --primary: #ff2e2e;
  --primary-dim: rgba(255, 46, 46, 0.14);
  --text: #f2f3f4;
  --text-muted: #8a9099;
  --text-faint: #929ba7;
  --card-shadow: 0 10px 26px rgba(0, 0, 0, .08);
  --success: #2fd47a;
  --warning: #ffb020;
  --font-head: 'Hanken Grotesk', system-ui, sans-serif;
  --font-mono: 'Hanken Grotesk', system-ui, sans-serif;
  --font-body: 'Hanken Grotesk', system-ui, sans-serif;
  --sidebar-w: 236px;
  --grid-line: rgba(255,255,255,0.028);
  --grid-line-fine: rgba(255,255,255,0.014);
}

/* --- Tema claro: mismo sistema de marca (rojo/tipografias), fondos claros.
   Se activa con [data-theme="light"] en <html>, guardado por usuario en
   localStorage (ver mountThemeToggle en js/api.js) -- por defecto (sin el
   atributo) la app sigue siendo oscura, como hasta ahora. */
:root[data-theme="light"] {
  --bg: #f3f4f6;
  --bg-panel: #ffffff;
  --bg-panel-2: #eef0f2;
  --border: #dde1e6;
  --tertiary: #e4e8ea;
  --primary-dim: rgba(255, 46, 46, 0.10);
  --text: #171a1e;
  --text-muted: #5b6470;
  --text-faint: #66717e;
  --card-shadow: 0 14px 28px rgba(24, 35, 45, .07);
  --success: #1f9d5c;
  --warning: #a9670a;
  --grid-line: rgba(0,0,0,0.035);
  --grid-line-fine: rgba(0,0,0,0.018);
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
  margin: 0;
  background: var(--bg);
  background-color: var(--bg);
  color: var(--text);
}

/* --- Layout de app: sidebar fija + contenido --- */
.app-shell { display: flex; min-height: 100vh; min-width: 0; }
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 0 14px 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 84px;
  margin: 0 0 12px;
  padding: 20px 12px;
}
.sidebar-logo-img { height: 33px; max-width: 100%; width: auto; display: block; }
.brand-icon-img { display: block; }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  min-height: 42px; padding: 10px 12px; border-radius: 10px;
  color: var(--text-muted); text-decoration: none;
  font-size: 0.9rem; font-weight: 500;
}
.sidebar-nav a svg { width: 18px; height: 18px; flex: none; opacity: .8; }
.sidebar-nav a:hover { background: var(--bg-panel-2); color: var(--text); }
.sidebar-nav a.active { background: #242d35; color: #fff; font-weight: 700; box-shadow: 0 3px 12px rgba(0,0,0,.12); }
.sidebar-nav a.active svg { opacity: 1; color: var(--primary); }
:root[data-theme="light"] .sidebar-nav a.active { background: #edf0f2; color: #202b35; box-shadow: 0 3px 12px rgba(24,35,45,.07); }
.sidebar-nav a .badge {
  margin-left: auto; background: var(--primary); color: #fff;
  font-size: 0.7rem; font-weight: 700; border-radius: 999px;
  padding: 1px 7px;
}

.main { flex: 1; min-width: 0; padding: 22px 28px 60px; }
.skip-link { position: fixed; top: 10px; left: 10px; z-index: 1000; padding: 10px 14px; border-radius: 9px; background: var(--bg-panel); color: var(--text); transform: translateY(-150%); }
.skip-link:focus-visible { transform: translateY(0); outline: 2px solid var(--primary); }
.nav-toggle, .nav-backdrop, .mobile-bottom-nav, .mobile-brand { display: none; }
.table-scroll { max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; }
.table-scroll table { min-width: max-content; }
.table-scroll:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

@media (min-width: 1600px) {
  html { font-size: clamp(16px, 14px + .125vw, 18px); }
  :root { --sidebar-w: clamp(220px, 14vw, 280px); }
  .main { padding-inline: clamp(28px, 2vw, 48px); }
}

/* --- Paginas de detalle sin sidebar (cliente/proyecto/captura) --- */
.page-container { max-width: 1100px; margin: 0 auto; padding: 22px 28px 60px; }

.page-topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 22px; gap: 12px; flex-wrap: wrap;
}
.page-topbar h1 {
  font-family: var(--font-head); font-weight: 700;
  font-size: clamp(1.65rem, 2vw, 2.1rem); line-height: 1.15; letter-spacing: -.025em; margin: 0;
}
.page-topbar .topbar-right { display: flex; align-items: center; gap: 10px; }
h2 {
  font-family: var(--font-head); font-weight: 700; font-size: 1.15rem;
  color: var(--text); margin: 32px 0 14px;
  letter-spacing: -.02em;
}
h3 { font-family: var(--font-head); font-weight: 700; font-size: 1.04rem; color: var(--text); }
a { color: var(--primary); }

/* --- Rejilla de widgets del resumen (overview) --- */
.overview-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .overview-grid { grid-template-columns: 1fr; } }
.widget-heading {
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--font-head); font-weight: 700; font-size: 0.82rem;
  text-transform: uppercase; letter-spacing: 0.03em; color: var(--text); margin-bottom: 10px;
}
.widget-heading a { font-size: 0.72rem; text-transform: none; letter-spacing: 0; font-weight: 500; }
.alert-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--bg-panel-2); border: 1px solid var(--primary-dim); border-radius: 8px;
  padding: 9px 12px; margin-bottom: 8px;
}
/* Flex items no encogen por debajo de su contenido por defecto (min-width:
   auto) -- con un motivo de bloqueo largo (ver admin.html renderFraudWidget)
   eso hacia que el texto se desbordara FUERA de la tarjeta en vez de ajustar
   su columna, porque el hermano de la izquierda (nombre+email) tampoco cedia
   espacio. Con min-width:0 ambos lados pueden encogerse y el text-wrap/
   max-width ya puesto en cada fila (inline) se respeta de verdad. */
.alert-row > div { min-width: 0; }
.alert-row .amount { font-family: var(--font-mono); font-weight: 600; color: var(--primary); }
.mini-list { display: flex; flex-direction: column; gap: 8px; }
.mini-list-row { display: flex; align-items: center; gap: 10px; }
.mini-list-row .avatar-sm {
  width: 26px; height: 26px; border-radius: 50%; background: var(--tertiary); color: var(--text);
  display: flex; align-items: center; justify-content: center; font-size: 0.7rem; font-weight: 700; flex-shrink: 0;
}

/* --- Tarjetas KPI --- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi-card {
  position: relative;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 18px; box-shadow: var(--card-shadow);
}
.kpi-card:has(> .kpi-icon) { display: grid; grid-template-columns: 44px minmax(0, 1fr); column-gap: 14px; align-content: start; }
.kpi-card:has(> .kpi-icon) .kpi-label { grid-column: 2; grid-row: 1; }
.kpi-card:has(> .kpi-icon) .kpi-value { grid-column: 2; grid-row: 2; }
.kpi-card .kpi-icon { grid-column: 1; grid-row: 1 / span 2; align-self: start; width: 44px; height: 44px; padding: 10px; margin-top: 6px; border-radius: 11px; color: #c1ced9; background: #252e36; pointer-events: none; }
:root[data-theme="light"] .kpi-card .kpi-icon { color: #4b6175; background: #edf1f4; }
.workspace-page .kpi-card:has(> .kpi-icon) .kpi-label { color: color-mix(in srgb, var(--text-muted) 85%, var(--text)); font-weight: 500; margin-bottom: 10px; line-height: 1.35; }
.workspace-page .kpi-card:has(> .kpi-icon) .kpi-value { font-weight: 600; letter-spacing: -.025em; }
.kpi-card.alert .kpi-icon { color: #ff7777; background: #3a2328; }
:root[data-theme="light"] .kpi-card.alert .kpi-icon { color: #d52d3a; background: #ffedef; }
.kpi-card:has(#statEnTramite) .kpi-icon { color: #e5b66c; background: #342d23; }
.kpi-card:has(#statEntregado) .kpi-icon { color: #81c9ab; background: #22352e; }
:root[data-theme="light"] .kpi-card:has(#statEnTramite) .kpi-icon { color: #946115; background: #fbf1df; }
:root[data-theme="light"] .kpi-card:has(#statEntregado) .kpi-icon { color: #287354; background: #e8f4ed; }
@media (max-width: 600px) {
  .workspace-page .kpi-card:has(> .kpi-icon) { grid-template-columns: minmax(0, 1fr); align-content: start; min-height: 156px; }
  .kpi-card .kpi-icon { grid-column: 1; grid-row: 1; width: 36px; height: 36px; padding: 7px; margin: 0 0 10px; border-radius: 9px; }
  .kpi-card:has(> .kpi-icon) .kpi-label { grid-column: 1; grid-row: 2; }
  .workspace-page .kpi-card:has(> .kpi-icon) .kpi-label { min-height: 2.7em; margin-bottom: 8px; }
  .kpi-card:has(> .kpi-icon) .kpi-value { grid-column: 1; grid-row: 3; }
}
.kpi-card .kpi-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); font-weight: 600; margin-bottom: 8px;
}
.kpi-card .kpi-value {
  font-family: var(--font-body); font-size: 1.8rem; font-weight: 700; color: var(--text);
}
.kpi-card .kpi-sub { font-size: 0.72rem; color: var(--text-faint); margin-top: 4px; }
.kpi-card.alert .kpi-value { color: var(--primary); }
.kpi-card #kpiPlan { font-family: var(--font-body); font-size: clamp(1.2rem, 1.6vw, 1.6rem); font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.kpi-card #kpiPlan small { display: block; margin-top: 5px; color: var(--text-muted); font-size: .75rem; font-weight: 500; }
.workspace-page.workspace-dashboard .kpi-row { gap: 0; overflow: hidden; border: 1px solid var(--border); border-radius: 16px; background: var(--bg-panel); box-shadow: var(--card-shadow); }
.workspace-page.workspace-dashboard .kpi-card { min-height: 124px; border: 0; border-radius: 0; box-shadow: none; }
.workspace-page.workspace-dashboard .kpi-card + .kpi-card { border-left: 1px solid var(--border); }
@media (max-width: 600px) {
  .workspace-page.workspace-dashboard .kpi-card:nth-child(odd) { border-left: 0; }
  .workspace-page.workspace-dashboard .kpi-card:nth-child(n+3) { border-top: 1px solid var(--border); }
}

button, .btn {
  font-family: var(--font-body);
  font-size: 0.88rem; font-weight: 600;
  min-height: 40px; padding: 9px 16px; margin: 4px 6px 4px 0;
  border-radius: 10px; border: 1px solid transparent;
  cursor: pointer; display: inline-block; text-decoration: none;
}
button:disabled { opacity: 0.35; cursor: not-allowed; }
.primary { background: var(--primary); color: #fff; }
.danger { background: transparent; color: var(--primary); border-color: var(--primary); }
.neutral { background: var(--bg-panel-2); color: var(--text); border-color: var(--border); }
/* Controles compartidos: marca sobria, estados perceptibles y foco accesible. */
.app-shell :is(button, .btn) { transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease; }
.app-shell .primary:hover:not(:disabled) { background: #e92323; box-shadow: 0 4px 12px rgba(255,46,46,.15); }
.app-shell .neutral:hover:not(:disabled) { background: color-mix(in srgb, var(--bg-panel-2) 88%, var(--text)); border-color: color-mix(in srgb, var(--border) 65%, var(--text-muted)); }
.app-shell button:disabled { opacity: .55; }
.app-shell .error:empty { display: none; }
.app-shell .error:not(:empty) { line-height: 1.5; }
.app-shell .muted { line-height: 1.5; }
.app-shell input::placeholder, .app-shell textarea::placeholder { color: var(--text-faint); opacity: 1; }
.app-shell input:focus, .app-shell select:focus, .app-shell textarea:focus { border-color: var(--text-muted); }
.app-shell :is(input, select, textarea):focus-visible { outline: 2px solid color-mix(in srgb, var(--text-muted) 65%, transparent); outline-offset: 2px; }
.app-shell td[colspan].muted, .app-shell td.empty-cell { padding: 28px 16px; text-align: center; color: var(--text-muted); line-height: 1.5; }
.app-shell :is(.widget-heading, .card-head) a { color: var(--text-muted); text-decoration: none; font-weight: 600; }
.app-shell :is(.widget-heading, .card-head) a:hover { color: var(--text); text-decoration: underline; text-underline-offset: 4px; }

input, select, textarea {
  font-family: var(--font-body); font-size: 0.9rem;
  min-height: 42px; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); width: 100%; box-sizing: border-box;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
input:is([type="date"], [type="time"], [type="datetime-local"]) { color-scheme: dark; }
:root[data-theme="light"] input:is([type="date"], [type="time"], [type="datetime-local"]) { color-scheme: light; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
label { display: block; margin: 10px 0 6px; color: var(--text-muted); font-size: 0.84rem; font-weight: 600; }

.box {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 20px; margin: 14px 0; box-shadow: var(--card-shadow);
}
.dimension-style-layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(340px, .85fr); gap: 24px; margin-top: 14px; }
.dimension-style-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; align-content: start; }
.dimension-style-controls > div { min-width: 0; }
.dimension-group-heading { grid-column: 1 / -1; margin: 0; padding: 2px 0 10px; border-bottom: 1px solid var(--border); color: var(--text); font: 700 .84rem var(--font-head); }
.dimension-group-heading:not(:first-child) { margin-top: 10px; }
.dimension-style-controls > div > label:first-child:not(.dimension-switch) { margin: 0 0 8px; font-size: .8rem; font-weight: 600; }
.dimension-style-controls input[type="number"], .dimension-style-controls select { width: 100% !important; min-height: 44px; padding: 10px 12px; border-radius: 10px; background-color: var(--bg-panel-2); font-size: .86rem; }
.dimension-segmented { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--border); border-radius: 11px; background: var(--bg-panel-2); }
.dimension-segmented button { flex: 1; min-width: 0; min-height: 42px; margin: 0; padding: 7px 8px; border-radius: 8px; color: var(--text-muted); background: transparent; font-size: .75rem; line-height: 1.2; }
.dimension-segmented button[aria-pressed="true"] { color: var(--text); background: var(--bg-panel); border-color: var(--border); box-shadow: 0 2px 7px rgba(0,0,0,.1); }
.dimension-segmented button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.dimension-color-picker { display: grid; gap: 10px; }
.custom-color-trigger { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 44px; margin: 0; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-panel-2); color: var(--text); font-size: .8rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.custom-color-trigger:hover, .custom-color-choice[data-selected="true"] .custom-color-trigger { border-color: var(--primary); }
.custom-color-trigger:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.custom-color-dot { width: 20px; height: 20px; flex: none; border: 1px solid rgba(128,128,128,.45); border-radius: 50%; background: var(--chosen-color, #fff); }
.dimension-color-presets { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; min-width: 0; }
.dimension-color-presets .color-swatch { width: 32px; height: 32px; min-height: 32px; margin: 0; padding: 0; border: 2px solid var(--bg-panel); border-radius: 50%; background: var(--swatch); box-shadow: 0 0 0 1px var(--border); cursor: pointer; transition: transform .15s ease, box-shadow .15s ease; }
.dimension-color-presets .color-swatch:hover { transform: scale(1.1); }
.dimension-color-presets .color-swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--bg-panel), 0 0 0 4px var(--primary); }
.dimension-color-presets .color-swatch:focus-visible { outline: 2px solid var(--text); outline-offset: 4px; }
@media (prefers-reduced-motion: reduce) { .dimension-color-presets .color-swatch { transition: none; } }
.dimension-switch { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; min-height: 60px; margin: 0; padding: 0 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-panel-2); color: var(--text); font-size: .85rem; font-weight: 600; cursor: pointer; }
.dimension-switch-row { grid-column: 1 / -1; }
.dimension-switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dimension-switch-track { position: relative; width: 46px; height: 27px; flex: none; border-radius: 99px; background: var(--border); transition: background .2s ease; }
.dimension-switch-track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s ease; }
.dimension-switch input:checked + .dimension-switch-track { background: var(--primary); }
.dimension-switch input:checked + .dimension-switch-track::after { transform: translateX(19px); }
.dimension-switch input:focus-visible + .dimension-switch-track { outline: 2px solid var(--primary); outline-offset: 3px; }
.dimension-color-dialog { box-sizing: border-box; width: min(420px, calc(100vw - 28px)); max-width: none; max-height: calc(100dvh - 28px); overflow-y: auto; padding: 20px; border: 1px solid var(--border); border-radius: 18px; background: var(--bg-panel); color: var(--text); box-shadow: 0 22px 70px rgba(0,0,0,.35); }
.dimension-color-dialog::backdrop { background: rgba(0,0,0,.65); backdrop-filter: blur(3px); }
.dimension-dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.dimension-dialog-heading p { margin: 0 0 4px; color: var(--text-muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }
.dimension-dialog-heading h3 { margin: 0; font: 700 1.15rem var(--font-head); }
.dimension-dialog-close { width: 40px; height: 40px; margin: -6px -6px 0 0; padding: 0; border-radius: 50%; background: var(--bg-panel-2); color: var(--text); font-size: 1.5rem; line-height: 1; }
.dimension-color-area { position: relative; width: 100%; height: 220px; border-radius: 12px; background: linear-gradient(to top,#000,transparent), linear-gradient(to right,#fff,transparent), hsl(var(--hue,0) 100% 50%); cursor: crosshair; touch-action: none; }
.dimension-color-area:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
.dimension-color-point { position: absolute; left: 100%; top: 0; width: 18px; height: 18px; border: 3px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px #222, 0 2px 5px rgba(0,0,0,.45); transform: translate(-50%,-50%); pointer-events: none; }
.dimension-hue-label { display: block; margin: 16px 0 8px; color: var(--text); font-size: .8rem; font-weight: 600; }
.dimension-color-dialog .dimension-hue-input { display: block; width: 100%; height: 24px; margin: 0 0 20px; padding: 0; border: 0; border-radius: 99px; background: linear-gradient(to right,#f00,#ff0,#0f0,#0ff,#00f,#f0f,#f00); appearance: none; cursor: pointer; }
.dimension-color-dialog .dimension-hue-input::-webkit-slider-thumb { width: 24px; height: 24px; border: 3px solid #fff; border-radius: 50%; background: transparent; box-shadow: 0 0 0 1px #333; appearance: none; }
.dimension-color-dialog .dimension-hue-input::-moz-range-thumb { width: 18px; height: 18px; border: 3px solid #fff; border-radius: 50%; background: transparent; box-shadow: 0 0 0 1px #333; }
.dimension-color-bottom { display: flex; align-items: center; gap: 10px; }
.dimension-color-sample { width: 44px; height: 44px; flex: none; border: 1px solid var(--border); border-radius: 10px; background: var(--chosen-color); }
.dimension-color-bottom label { margin: 0; font: 600 .75rem var(--font-mono); }
.dimension-color-bottom input { flex: 1; min-width: 0; min-height: 44px; font: 600 .95rem var(--font-mono); text-transform: uppercase; }
.dimension-color-bottom input:invalid { border-color: var(--primary); }
.dimension-dialog-actions { display: flex; gap: 10px; margin-top: 22px; }
.dimension-dialog-actions button { flex: 1; min-height: 46px; margin: 0; }
.dimension-style-preview { min-width: 0; align-self: start; position: sticky; top: 20px; overflow: hidden; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-panel-2); }
.dimension-preview-title { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: .75rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
#dimensionPreview { display: block; width: 100%; height: 320px; }
@media (max-width: 1100px) {
  .dimension-style-layout { grid-template-columns: 1fr; }
  .dimension-style-preview { order: -1; position: static; }
}
@media (max-width: 600px) {
  .dimension-style-controls { grid-template-columns: 1fr; }
  .custom-color-trigger { min-height: 48px; }
  .dimension-color-presets { flex-wrap: nowrap; overflow-x: auto; padding: 5px 4px; scrollbar-width: thin; }
  .dimension-color-presets .color-swatch { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
  #dimensionPreview { height: 240px; }
  .dimension-color-dialog { position: fixed; inset: auto 0 0; width: 100%; max-height: min(90dvh, 680px); margin: 0; padding: 22px 18px max(20px, env(safe-area-inset-bottom)); border-radius: 20px 20px 0 0; }
  .dimension-color-area { height: min(32dvh, 250px); }
}
@media (prefers-reduced-motion: reduce) { .dimension-switch-track, .dimension-switch-track::after { transition: none; } }
.error { color: var(--primary); margin-top: 10px; font-size: 0.85rem; }
.muted { color: var(--text-muted); font-size: 0.85rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-faint); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
td.mono, .mono { font-family: var(--font-mono); }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--bg-panel-2); }

/* Fila de filtros bajo la cabecera de una tabla, ver js/column-search.js --
   un input por columna, del mismo alto/estilo compacto que la propia
   cabecera para que no rompa el ritmo visual de la tabla. */
tr.col-search-row th { padding: 4px 8px 8px; border-bottom: 1px solid var(--border); }
.col-search-input {
  width: 100%; margin: 0; padding: 5px 8px; font-size: 0.8rem;
  font-weight: 400; text-transform: none; letter-spacing: normal;
  background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 6px; color: var(--text);
}
.col-search-input:focus { border-color: var(--primary); outline: none; }
.list-search-tools { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.list-search-tools input { flex: 1; min-width: 0; max-width: 520px; min-height: 44px; }
.list-search-tools button { margin: 0; min-height: 44px; }
.list-feedback { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: .85rem; color: var(--text-muted); }
.list-feedback:has(span:empty):has(button[hidden]) { display: none; }
.list-feedback button[hidden] { display: none; }
.form-save-status { color: var(--success); font-size: .85rem; margin: 0 22px 16px; }
.form-save-status:empty { display: none; }
.date-control { position: relative; min-width: 0; width: 100%; }
.date-control > input[data-date-enhanced] { position: absolute; width: 1px !important; height: 1px !important; min-height: 0 !important; padding: 0 !important; opacity: 0; pointer-events: none; }
.date-trigger { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 44px; margin: 0; padding: 9px 12px; background: var(--bg); border: 1px solid var(--border); color: var(--text); font-weight: 500; text-align: left; }
.date-trigger.date-empty { color: var(--text-muted); }
.date-trigger svg { width: 20px; height: 20px; flex: none; color: var(--text-muted); }
.date-dialog { width: min(380px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 22px; color: var(--text); background: var(--bg-panel); border: 1px solid var(--border); border-radius: 20px; box-shadow: 0 24px 80px #0005; overflow-y: auto; }
.date-dialog::backdrop { background: #0007; }
.date-dialog-head { display: flex; align-items: center; gap: 12px; justify-content: space-between; margin-bottom: 16px; }
.date-dialog-head h2 { font-size: 1.05rem; margin: 0; letter-spacing: -.01em; }
.date-dialog button { margin: 0; }
.date-close { min-width: 44px; min-height: 44px; padding: 0; background: var(--bg-panel-2); color: var(--text-muted); font-size: 1.4rem; }
.date-shortcuts { display: flex; gap: 6px; margin-bottom: 18px; }
.date-shortcuts button { flex: 1; padding: 8px 6px; min-height: 44px; font-size: .78rem; background: var(--bg-panel-2); color: var(--text); border-color: var(--border); }
.date-navigation { display: grid; grid-template-columns: 40px minmax(0,1fr) 76px 40px; gap: 6px; align-items: center; margin-bottom: 14px; }
.date-navigation button { padding: 0; min-height: 44px; font-size: 1.5rem; background: transparent; color: var(--text); }
.date-navigation select, .date-navigation input { min-width: 0; font-size: .9rem; padding: 8px; background: var(--bg-panel-2); }
.date-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.date-weekday { text-align: center; font-size: .7rem; color: var(--text-muted); padding: 8px 0; overflow: hidden; }
.date-day { min-height: 42px; min-width: 0; padding: 0; font-size: .88rem; background: transparent; color: var(--text); border-radius: 10px; }
.date-day.outside { color: var(--text-muted); opacity: .6; }
.date-day.today { box-shadow: inset 0 0 0 1px var(--border); }
.date-day:hover:not(:disabled) { background: var(--bg-panel-2); }
.date-day.selected, .date-day.selected:hover { background: var(--primary); color: #fff; opacity: 1; font-weight: 700; }
.date-clear { width: 100%; min-height: 44px; margin-top: 16px !important; color: var(--text-muted); background: var(--bg-panel-2); }
.date-clear[hidden] { display: none; }
.date-time { display: flex; gap: 14px; align-items: center; margin: 16px 0 0; }
.date-time input { flex: 1; min-width: 0; }
.date-confirm { width: 100%; margin-top: 16px !important; }
.date-time[hidden], .date-confirm[hidden] { display: none; }
.date-dialog button:disabled { opacity: .3; cursor: not-allowed; }
@media (max-width: 600px) {
  .date-dialog { width: 100%; max-width: none; margin: auto 0 0; padding: 20px 16px max(20px, env(safe-area-inset-bottom)); border-radius: 22px 22px 0 0; max-height: 90dvh; }
  .date-day { min-height: 44px; }
  .workspace-projects .workspace-data-table tbody td > .date-control { flex: 1; max-width: 58%; }
}
tbody[aria-busy="true"] { opacity: .55; }
@media (max-width: 600px) { .list-search-tools { flex-wrap: wrap; } .list-search-tools input { flex-basis: 100%; } }

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.pill {
  display: inline-block; background: var(--tertiary); color: var(--text);
  border-radius: 999px; padding: 3px 11px; font-size: 0.72rem; margin-right: 6px;
  font-weight: 500;
}
.pill.stage-red { background: var(--primary-dim); color: var(--primary); }
.pill.stage-green { background: rgba(47,212,122,0.12); color: var(--success); }
.pill.stage-amber { background: rgba(255,176,32,0.12); color: var(--warning); }
.pill[data-state="en_tramite"] { background: rgba(255,176,32,.12); color: var(--warning); }
.pill[data-state="fabricado"] { background: var(--bg-panel-2); color: var(--text); }
.pill[data-state="entregado"] { background: rgba(47,212,122,.12); color: var(--success); }
.pill { line-height: 1.4; font-weight: 600; }
.project-status[data-state="en_tramite"] { border-color: color-mix(in srgb, var(--warning) 35%, var(--border)); }
.project-status[data-state="entregado"] { border-color: color-mix(in srgb, var(--success) 35%, var(--border)); }

/* --- Facturacion: tarjetas de Plan/Metodo de pago + historial visual --- */
.billing-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 16px; margin: 14px 0; align-items: stretch; }
.billing-card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; }
.billing-card-top { display: flex; justify-content: space-between; align-items: flex-start; }
.billing-card-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: 600; }
.billing-plan-name { font-size: 1.2rem; font-weight: 700; margin: 12px 0 2px; }
.billing-price { font-family: var(--font-mono); font-size: 2.1rem; font-weight: 700; }
.billing-price .unit { font-size: 0.85rem; font-weight: 500; color: var(--text-muted); margin-left: 4px; }
.billing-meta { color: var(--text-muted); font-size: 0.85rem; margin: 10px 0 16px; }
.billing-notice { color: var(--text-faint); font-size: 0.78rem; margin: -6px 0 14px; }
.card-tile { display: flex; align-items: center; gap: 12px; background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin: 4px 0 16px; }
.card-tile .card-brand { font-family: var(--font-mono); font-weight: 700; font-style: italic; background: var(--tertiary); padding: 4px 9px; border-radius: 6px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; }
.card-tile .card-number { font-family: var(--font-mono); letter-spacing: 0.04em; }
.card-tile .card-expiry { color: var(--text-muted); font-size: 0.78rem; margin-top: 2px; }
.billing-card .btn-block { width: 100%; text-align: center; margin: auto 0 0; }
.invoice-row { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.invoice-row:last-child { border-bottom: none; }
.invoice-icon { width: 34px; height: 34px; border-radius: 8px; background: var(--bg-panel-2); display: flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0; }
.invoice-info { flex: 1; min-width: 0; }
.invoice-number { font-weight: 600; }
.invoice-date { color: var(--text-faint); font-size: 0.78rem; }
.invoice-amount { font-family: var(--font-mono); font-weight: 600; min-width: 90px; text-align: right; }
.invoice-download { width: 34px; height: 34px; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--text-muted); text-decoration: none; border: 1px solid var(--border); flex-shrink: 0; font-size: 1.1rem; line-height: 1; }
.invoice-download:hover { color: var(--primary); border-color: var(--primary); }
.page-topbar-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--primary-dim); color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; }
.page-topbar-heading { display: flex; align-items: center; gap: 12px; }
.page-topbar-heading .subtitle { color: var(--text-muted); font-size: 0.85rem; font-weight: 400; margin-top: 2px; }

form.narrow { max-width: 400px; }
.session-dot { display:inline-block; width:8px; height:8px; border-radius:50%; margin-right:6px; }
.session-dot.active { background: var(--success); }
.session-dot.inactive { background: var(--text-faint); }

/* --- Paginas sin sidebar (login/registro/suspendido) --- */
.centered-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.brand-hero {
  max-width: 960px; width: 100%; display: grid; grid-template-columns: 1fr 1fr;
  gap: 0; border: 1px solid var(--border); border-radius: 16px; overflow: hidden;
}
.brand-hero .brand-side { background: var(--bg-panel); padding: 40px; display: flex; flex-direction: column; justify-content: center; }
.brand-hero .form-side { background: var(--bg-panel-2); padding: 40px; }
@media (max-width: 720px) { .brand-hero { grid-template-columns: 1fr; } }

/* --- Franja superior: ubicación, idioma, tema y cuenta --- */
.topbar-strip {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; margin-bottom: 16px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.breadcrumb {
  font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.04em;
  color: var(--text-faint); text-transform: uppercase; display: flex; align-items: center; gap: 6px;
}
.breadcrumb .sep { color: var(--text-faint); opacity: 0.5; }
.breadcrumb .current { color: var(--text-muted); }
.topbar-strip .topbar-right { display: flex; align-items: center; gap: 16px; margin-left: auto; }

/* En las pantallas principales el título ya aparece en el contenido.
   Conservamos la ruta de navegación cuando contiene enlaces de vuelta. */
@media (min-width: 601px) {
  .topbar-strip:has(> .breadcrumb:not(:has(a))) { margin-bottom: 8px; padding-bottom: 0; border-bottom: 0; }
  .topbar-strip .breadcrumb:not(:has(a)) { display: none; }
}

/* --- Cuenta: disparador y acciones en un solo desplegable --- */
.user-block { position: relative; min-width: 0; }
.user-trigger {
  display: flex; align-items: center; gap: 8px; max-width: 230px; min-height: 40px;
  padding: 4px 10px 4px 5px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--bg-panel-2); color: var(--text); cursor: pointer;
}
.user-trigger:hover, .user-trigger[aria-expanded="true"] { border-color: var(--primary); }
.user-trigger:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--tertiary);
  color: var(--text); display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-avatar svg { width: 18px; height: 18px; }
.user-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .78rem; font-weight: 600; }
.user-caret { color: var(--text-muted); font-size: .7rem; }

.user-block-panel {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 30;
  width: min(280px, calc(100vw - 24px));
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.3);
}
.user-block-panel[hidden], .user-block-panel form[hidden] { display: none; }
.app-shell #logoutBtn { display: none; }
.user-menu-action, .user-block-panel #logoutBtn {
  display: block; width: 100%; min-height: 42px; margin: 0; padding: 9px 10px;
  border: 0; border-radius: 8px; background: transparent; color: var(--text);
  text-align: left; font: 600 .84rem var(--font-body); cursor: pointer;
}
.user-menu-action[hidden] { display: none; }
.user-menu-sep[hidden] { display: none; }
.user-menu-action:hover, .user-block-panel #logoutBtn:hover { background: var(--bg-panel-2); }
.user-block-panel #logoutBtn { color: var(--primary); }
.user-menu-sep { height: 1px; margin: 5px 4px; background: var(--border); }
.user-block-panel form { padding: 12px 6px; }
.user-block-panel label { text-align: left; }

.auth-country-combo { position: relative; }
.auth-country-combo input { padding-right: 36px; }
.auth-country-combo::after { content: '⌄'; position: absolute; top: 10px; right: 14px; color: var(--text-muted); pointer-events: none; font-size: 1.2rem; }
.auth-country-options { position: absolute; z-index: 30; top: calc(100% + 5px); right: 0; left: 0; max-height: 240px; margin: 0; padding: 5px; overflow-y: auto; list-style: none; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-panel); box-shadow: 0 16px 36px rgba(0,0,0,.22); }
.auth-country-options[hidden] { display: none; }
.auth-country-options li { margin: 0; padding: 0; }
.auth-country-options button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; margin: 0; padding: 7px 9px; border: 0; border-radius: 7px; background: transparent; color: var(--text); text-align: left; font-size: .85rem; }
.auth-country-options button:hover, .auth-country-options button:focus-visible { background: var(--primary-dim); }
.auth-country-options button:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.auth-country-flag { display: grid; place-items: center; flex: none; width: 25px; height: 19px; color: var(--text-muted); font: 700 .66rem var(--font-mono); }
.auth-country-flag img { display: block; width: 23px; height: 16px; object-fit: cover; border-radius: 2px; }
.auth-country-code { margin-left: auto; color: var(--text-muted); font: 600 .7rem var(--font-mono); }
.auth-phone-combo { display: flex; gap: 8px; }
.auth-phone-combo > input { flex: 1; min-width: 0; width: 100%; }
.auth-phone-prefix { position: relative; flex: none; }
.auth-phone-prefix-btn { display: flex; align-items: center; gap: 6px; min-height: 48px; margin: 0; padding: 0 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-panel-2); color: var(--text); white-space: nowrap; cursor: pointer; }
.auth-phone-prefix-btn:hover, .auth-phone-prefix-btn:focus-visible { border-color: var(--primary); }
.auth-phone-prefix-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.auth-phone-prefix-panel { position: fixed; z-index: 1000; width: min(320px, calc(100vw - 16px)); padding: 8px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-panel); box-shadow: 0 16px 36px rgba(0,0,0,.22); }
.auth-phone-prefix-panel[hidden] { display: none; }
.auth-phone-prefix-panel > input { width: 100%; min-height: 42px; }
.auth-phone-prefix-panel .auth-country-options { position: static; max-height: 220px; margin-top: 4px; padding: 0; border: 0; box-shadow: none; }
/* Idioma y tema comparten los controles del acceso. */
.dropdown-select { position: relative; font-family: var(--font-body); }
.dropdown-select-btn {
  display: flex; align-items: center; gap: 6px; background: var(--bg-panel-2);
  min-height: 38px; border: 1px solid var(--border); border-radius: 999px; padding: 6px 11px;
  color: var(--text); font-size: 0.78rem; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.dropdown-select-btn:hover { border-color: var(--primary); }
.dropdown-select-btn:focus-visible, .auth-theme-button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.dropdown-select-btn .ds-icon { font-size: 0.95rem; line-height: 1; }
.ds-icon.flag-icon { display: inline-flex; width: 18px; height: 13px; border-radius: 2px; overflow: hidden; box-shadow: 0 0 0 1px rgba(0,0,0,0.15); flex-shrink: 0; }
.ds-icon.flag-icon img { width: 100%; height: 100%; display: block; object-fit: cover; }
.dropdown-select-btn .ds-chevron { display: none; }
.dropdown-select-panel {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 170px;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3); z-index: 100; padding: 4px; display: none;
}
.dropdown-select.open .dropdown-select-panel { display: block; }
.dropdown-select-option {
  display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: none;
  min-height: 40px; padding: 8px 10px; border-radius: 8px; color: var(--text-muted); font-size: 0.8rem; text-align: left; cursor: pointer;
}
.dropdown-select-option:hover { background: var(--bg-panel-2); color: var(--text); }
.dropdown-select-option.active { color: var(--primary); font-weight: 600; }
.auth-theme-button {
  display: grid; place-items: center; width: 40px; height: 40px; padding: 0;
  border: 1px solid var(--border); border-radius: 50%; color: var(--text-muted);
  background: var(--bg-panel-2); cursor: pointer;
}
.auth-theme-button:hover { border-color: var(--primary); color: var(--primary); }
.auth-theme-button .theme-icon { display: grid; place-items: center; }
.auth-theme-button svg { display: block; width: 19px; height: 19px; }
@keyframes auth-theme-switch { from { opacity: 0; transform: rotate(-75deg) scale(.55); } }
@media (prefers-reduced-motion: no-preference) {
  .auth-theme-button svg { animation: auth-theme-switch .38s cubic-bezier(.16,1,.3,1) both; }
}

/* --- Control segmentado (p.ej. perfil de canto activo) --- */
.segmented { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button {
  margin: 0; border-radius: 0; border: none; border-right: 1px solid var(--border);
  background: var(--bg-panel-2); color: var(--text-muted); font-size: 0.76rem; font-weight: 600; padding: 8px 12px;
}
.segmented button:last-child { border-right: none; }
.segmented button.active { background: var(--primary-dim); color: var(--primary); }

/* --- Lista compacta de puntos capturados (Medicion) --- */
.point-log-list { display: flex; flex-direction: column; gap: 5px; max-height: 280px; overflow-y: auto; }
.point-log-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 7px;
  padding: 7px 10px; font-family: var(--font-mono); font-size: 0.74rem; color: var(--text-muted);
}
.point-log-row .idx { color: var(--primary); font-weight: 700; }
.point-log-row select { width: auto; padding: 3px 6px; font-size: 0.7rem; }

/* --- Layout de captura: un unico lienzo con todo flotando encima ---
   No hay columna lateral: el rail de iconos abre paneles SOBRE el dibujo
   (uno cada vez), asi el lienzo se queda con todo el ancho y la mano no
   viaja entre dos zonas distintas para una sola accion. */
.capture-shell { display: block; }
.capture-stage {
  position: relative; height: 72vh; min-height: 460px;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
}
.capture-stage > canvas { position: absolute; inset: 0; }

/* Fila superior del lienzo: logo (solo en pantalla completa) + fases +
   acciones. Al ser una fila real y no tres islas absolutas, en tablet se
   reparten el ancho o bajan de linea en vez de pisarse. */
.stage-top {
  /* Una sola barra continua de borde a borde, no islas sueltas de distinto
     tamano: dentro van el logo/menu, el estado del metro, las fases y las
     acciones, todos a la misma altura y alineados. */
  /* Por encima del rail y de los paneles (z-index 3 y 2): el desplegable
     del logo cuelga de esta barra y tiene que abrirse SOBRE ellos, no por
     debajo -- la navegacion manda sobre las herramientas. */
  position: absolute; top: 0; left: 0; right: 0; z-index: 6;
  display: flex; align-items: center; gap: 12px;
  padding: 7px 12px;
  background: var(--bg-panel-2); border-bottom: 1px solid var(--border);
}
.stage-top > * { pointer-events: auto; }
.stage-top > .stage-top-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stage-top > .phase-steps { position: absolute; left: 50%; top: 0; transform: translateX(-50%); }

/* Cerrar (salir al proyecto), al otro extremo de la fila superior */
.stage-close:hover:not(:disabled) { color: var(--primary); }

/* Dialogo de cambios sin guardar */
.stage-modal {
  display: none; position: absolute; inset: 0; z-index: 10;
  align-items: center; justify-content: center; padding: 20px;
  background: rgba(0,0,0,0.55);
}
.stage-modal.open { display: flex; }
.stage-modal-card {
  width: 100%; max-width: 420px; padding: 20px;
  background: var(--bg-panel-2); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.stage-modal-card h3 { margin: 0 0 8px; font-size: 1.05rem; }
.help-card { max-width: 440px; }
/* El dibujo manda: ocupa la mayor parte de la tarjeta y el texto es una
   sola frase debajo. */
.help-visual { width: 100%; height: auto; margin: 6px 0 12px; }
.help-visual .cv-piece { fill: var(--bg-panel); stroke: var(--border); stroke-width: 1.5; }
.help-text { min-height: 2.6em; margin: 0 0 12px; color: var(--text); font-size: 0.95rem; }
.help-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 16px; }
.help-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
.help-dot.on { background: var(--primary); }
.stage-modal-card p { margin: 0 0 18px; color: var(--text-muted); font-size: 0.9rem; }
.stage-modal-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stage-modal-actions button { margin: 0; min-height: 44px; flex: 1; min-width: 130px; }

/* Indicador de conexion del metro, visible en toda la pantalla de medicion */
.stage-conn {
  display: inline-flex; align-items: center; gap: 7px; height: 40px;
  margin: 0; padding: 0 10px; cursor: pointer;
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  font-size: 0.78rem; color: var(--text-muted); white-space: nowrap;
}
.stage-conn:hover { background: var(--bg-panel); }
.stage-conn .conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); flex-shrink: 0; }
.stage-conn.ok .conn-dot { background: var(--success); }
.stage-conn.sim .conn-dot { background: var(--warning); }
.stage-conn.err .conn-dot { background: var(--primary); }
.stage-conn.err { color: var(--primary); }

/* --- Fase 1: pantalla de conexion --- */
.connect-hero {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; display: none;
  top: var(--stage-top-h, 54px);
  flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; padding: 24px; text-align: center;
  background: var(--bg-panel);
}
.connect-hero.on { display: flex; }
.disto-svg { width: 180px; max-width: 60%; height: auto; margin-bottom: 6px; }
.disto-body { fill: var(--bg-panel-2); stroke: var(--text-muted); stroke-width: 2; }
.disto-screen { fill: var(--bg); stroke: var(--text-faint); stroke-width: 1.5; }
.disto-line { stroke: var(--text-faint); stroke-width: 2; stroke-linecap: round; }
.disto-key { fill: var(--primary); }
.disto-beam {
  stroke: var(--primary); stroke-width: 2.5; stroke-dasharray: 8 6;
  animation: cv-flow 0.7s linear infinite;
}
.disto-target { fill: var(--primary); animation: hero-ping 1.4s ease-out infinite; }
@keyframes hero-ping { 0% { r: 4; opacity: 1; } 70% { r: 11; opacity: 0; } 100% { opacity: 0; } }
.bt-waves path { fill: none; stroke: var(--text-muted); stroke-width: 2.5; stroke-linecap: round; }
.bt-waves path:nth-child(1) { animation: bt-pulse 1.6s ease-in-out infinite; }
.bt-waves path:nth-child(2) { animation: bt-pulse 1.6s ease-in-out 0.2s infinite; }
.bt-waves path:nth-child(3) { animation: bt-pulse 1.6s ease-in-out 0.4s infinite; }
@keyframes bt-pulse { 0%, 100% { opacity: 0.15; } 50% { opacity: 0.9; } }
.connect-hero-title { font-family: var(--font-head); font-size: 1.25rem; margin: 0; border: none; padding: 0; text-transform: none; letter-spacing: 0; }
.connect-hero-sub { color: var(--text-muted); font-size: 0.88rem; margin: 6px 0 16px; max-width: 380px; }
.connect-hero-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.connect-hero-btn { min-height: 52px; padding: 0 26px; font-size: 1rem; margin: 0; }
.connect-hero-actions .neutral { min-height: 52px; padding: 0 20px; margin: 0; }
.connect-hero-status { font-size: 0.84rem; color: var(--text-muted); min-height: 1.2em; margin: 14px 0 0; }
@media (prefers-reduced-motion: reduce) {
  .disto-beam, .disto-target, .bt-waves path { animation: none; }
  .bt-waves path { opacity: 0.5; }
}

/* Rail vertical de herramientas, bajo la fila superior (su alto real lo
   mide el JS en --stage-top-h, ver trackStageTopHeight). */
.stage-rail {
  position: absolute; top: calc(var(--stage-top-h, 54px) + 64px); left: 12px; z-index: 3;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--bg-panel-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.28);
}
/* Icono + etiqueta corta: un simbolo suelto no dice de que va cada
   herramienta, y esta pantalla la usa gente de taller que entra a medir sin
   tiempo de aprenderse iconos. */
.stage-rail-btn {
  width: 58px; min-height: 48px; margin: 0; padding: 6px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  line-height: 1;
  background: transparent; color: var(--text-muted);
  border: 1px solid transparent; border-radius: 8px; cursor: pointer;
}
.stage-rail-btn .rail-icon { font-size: 1.15rem; }
.stage-rail-btn .rail-label { font-size: 0.62rem; letter-spacing: 0.02em; }
.stage-rail-btn:hover { background: var(--bg-panel); color: var(--text); }
.stage-rail-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Acciones sueltas sobre el lienzo (deshacer/rehacer/pantalla completa) */
.stage-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.stage-actions > span { display: inline-flex; gap: 6px; }
.stage-action-btn {
  width: 40px; height: 40px; margin: 0; padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem; line-height: 1;
  background: transparent; color: var(--text-muted);
  border: 1px solid transparent; border-radius: 8px; cursor: pointer;
}
.stage-action-btn:hover:not(:disabled) { background: var(--bg-panel); color: var(--text); }
.stage-action-btn:disabled { opacity: 0.35; cursor: default; }
/* Pulso de atencion del "?" al entrar en una fase nueva: tres latidos y
   para (ver flashHelp). */
.stage-action-btn.pulse { color: var(--primary); animation: help-pulse 1.4s ease-out 3; }
@keyframes help-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,46,46,0.55); }
  70% { box-shadow: 0 0 0 12px rgba(255,46,46,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,46,46,0); }
}
@media (prefers-reduced-motion: reduce) { .stage-action-btn.pulse { animation: none; } }

/* Logo: oculto mientras se ve el menu lateral (que ya lo lleva), visible solo
   en pantalla completa, donde no queda ninguna otra marca en pantalla. */
/* El logo ES el menu de la app: esta pantalla va siempre a pantalla completa
   y no tiene barra lateral, asi que la navegacion cuelga de aqui. Va sobre
   chapa propia porque el lienzo se pinta claro incluso en tema oscuro y el
   logo blanco encima del dibujo no se leeria. */
.stage-menu-wrap { position: relative; }
.stage-logo {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  margin: 0; padding: 0 8px; height: 40px;
  background: transparent; border: 1px solid transparent; border-radius: 8px;
}
.stage-logo:hover { background: var(--bg-panel); }
.stage-logo img { height: 20px; width: auto; display: block; }
.stage-menu-caret { color: var(--text-muted); font-size: 0.7rem; }
.stage-menu {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; z-index: 5;
  min-width: 220px; padding: 8px;
  background: var(--bg-panel-2); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.stage-menu.open { display: block; }
.stage-menu a {
  display: block; padding: 10px 10px; border-radius: 8px;
  color: var(--text-muted); text-decoration: none; font-size: 0.88rem;
}
.stage-menu a:hover { background: var(--bg-panel); color: var(--text); }
.stage-menu a.active { background: var(--primary-dim); color: var(--primary); }
.stage-menu-sep { height: 1px; background: var(--border); margin: 8px 0; }
.stage-menu-row { display: flex; gap: 8px; flex-wrap: wrap; }
.stage-menu .user-block { margin: 4px 0 8px; }
.stage-menu #logoutBtn { width: 100%; margin: 0; }

/* Paneles flotantes: solo uno abierto a la vez (lo controla el rail). Se
   apoyan a la derecha del rail para no taparlo, y nunca ocupan mas de lo
   que queda de lienzo (scroll interno si la herramienta es larga). */
.stage-panel {
  position: absolute; top: calc(var(--stage-top-h, 54px) + 64px); left: 84px; z-index: 2;
  display: none; flex-direction: column;
  width: 300px; max-height: calc(100% - 108px); /* deja libre la barra de abajo */
  background: var(--bg-panel-2); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
.stage-panel.open { display: flex; }
.stage-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px 10px 8px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 0.85rem;
}
.stage-panel-close {
  margin: 0; padding: 0; width: 24px; height: 24px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 0.9rem;
}
.stage-panel-close:hover { color: var(--text); }
.stage-panel-body { overflow-y: auto; padding: 10px 12px 12px; }
/* Las cajas de dentro ya no son tarjetas propias: el panel ES la tarjeta. */
.stage-panel-body .box {
  background: none; border: none; border-radius: 0;
  padding: 0; margin: 0 0 12px;
}
.stage-panel-body .box:last-child { margin-bottom: 0; }
.stage-panel-body .box + .box { border-top: 1px solid var(--border); padding-top: 12px; }

/* Pantalla completa: el lienzo se come la ventana entera (menu, cabeceras y
   secciones de abajo se ocultan) -- es como se mide de verdad en tablet. */
body.capture-max .sidebar,
body.capture-max .topbar-strip,
body.capture-max .page-topbar,
body.capture-max #captureIntro,
body.capture-max .main > h2,
body.capture-max .main > .box,
body.capture-max .main > .muted,
body.capture-max .main > #log { display: none; }
body.capture-max .main { padding: 0; }
body.capture-max .capture-stage {
  position: fixed; inset: 0; z-index: 50;
  height: auto; border-radius: 0; border: none;
}

/* Con el lienzo estrecho no caben pildora + 3 nombres de fase + acciones en
   la misma fila: se deja solo el numero, salvo en la fase actual. */
@media (max-width: 1200px) {
  .phase-step span { display: none; }
  .phase-step.current span { display: inline; }
}
@media (max-width: 900px) {
  .capture-stage { height: 78vh; }
  /* En tablet/movil el panel pasa a ocupar el ancho completo por debajo del
     rail: a 300px fijos taparia casi todo el dibujo en horizontal. */
  .stage-rail { flex-direction: row; }
  .stage-panel { left: 12px; right: 12px; top: calc(var(--stage-top-h, 54px) + 72px); width: auto; max-height: 45%; }
  /* Estrecho: el asistente deja de flotar centrado y ocupa su propia linea
     dentro de la misma barra, con los lados debajo. */
  .stage-top { flex-wrap: wrap; }
  .stage-top > .phase-steps { position: static; transform: none; order: -1; flex-basis: 100%; }
  .phase-steps { justify-content: space-between; }
}
@media (max-width: 600px) {
  /* En movil el logo se encoge (es el menu, no puede desaparecer) y el
     indicador del metro se queda en el punto de color, para que volver,
     menu, estado y acciones quepan en la misma fila en vez de comerse
     cuatro lineas de alto antes de empezar el dibujo. */
  .stage-logo img { height: 16px; }
  .stage-logo { padding: 7px 9px; }
  .stage-conn { padding: 11px; }
  .stage-conn #stageConnText { display: none; }
  /* (el apilado ya lo hace la rejilla de .stage-top a partir de 900px) */
}

/* --- Tutorial visual de calibracion/captura ---
   Sustituye al parrafo de instrucciones: en obra nadie lee tres lineas de
   texto, pero un dibujo con "estas aqui / apunta ahi" se entiende de un
   vistazo. Los estados los pone el JS (data-step + clases .done/.active). */
.calib-visual { display: block; width: 100%; height: auto; margin: 2px 0 6px; }
/* En la barra de abajo el diagrama es pequeno: es un vistazo de "el metro
   esta puesto, apunto ahi", no el tutorial (ese esta en el "?"). */
.phase-visual { width: 132px; height: 52px; flex-shrink: 0; margin: 0; }
@media (max-width: 700px) { .phase-visual { width: 104px; height: 44px; } }
.calib-visual .cv-piece { fill: var(--bg-panel); stroke: var(--border); stroke-width: 1.5; }
.calib-visual .cv-piece-label { fill: var(--text-faint); font-size: 16px; text-anchor: middle; }
.calib-visual .cv-leg { stroke: var(--border); stroke-width: 2; fill: none; opacity: 0.45; }
.calib-visual .cv-leg.done { stroke: var(--success); opacity: 1; }
.calib-visual .cv-leg.active {
  stroke: var(--primary); opacity: 1; stroke-dasharray: 7 5;
  animation: cv-flow 0.7s linear infinite;
}
@keyframes cv-flow { to { stroke-dashoffset: -12; } }
.calib-visual .cv-target { fill: var(--primary); }
/* El tripode del aparato: lo unico fijo del dibujo. */
.calib-visual .cv-tripod { stroke: var(--border); stroke-width: 2; stroke-linecap: round; }
.calib-visual .cv-station.from .cv-tripod { stroke: var(--primary); }
/* La lente, para que se lea como un aparato y no como una pelota. */
.calib-visual .cv-lens { fill: var(--bg-panel); stroke: none; }
.calib-visual .cv-station.from .cv-lens { fill: #fff; }
.calib-visual .cv-station circle { fill: var(--bg-panel-2); stroke: var(--border); stroke-width: 2; }
.calib-visual .cv-station text { fill: var(--text-muted); font-size: 11px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }
/* El aparato ya montado: es el origen de todas las medidas */
.calib-visual .cv-station.from circle { fill: var(--primary); stroke: var(--primary); }
.calib-visual .cv-station.from text { fill: #fff; }
/* Donde hay que ponerlo: anillo que late hacia fuera */
.calib-visual .cv-halo { fill: none; stroke: var(--primary); stroke-width: 2; opacity: 0; }
.calib-visual .cv-station.to .cv-halo { animation: cv-ping 1.3s ease-out infinite; }
.calib-visual .cv-station.to circle:not(.cv-halo) { stroke: var(--primary); }
@keyframes cv-ping { 0% { opacity: 0.85; r: 11; } 100% { opacity: 0; r: 20; } }
/* Las tres coordenadas del punto simulado caben en una fila: se teclean
   juntas y se leen como un punto, no como tres campos sueltos. */
.sim-coords { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.sim-coords input { margin: 0; text-align: center; }

/* Herramientas de la fase de ajustar. Van en la barra de abajo, en el sitio
   que deja libre el boton de capturar: es la zona del pulgar al sujetar la
   tablet con las dos manos. */
.adjust-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.adjust-tool {
  min-height: 44px; padding: 0 16px; border-radius: 10px;
  background: var(--bg-panel-2); color: var(--text); border: 1px solid var(--border);
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
}
.adjust-tool:hover { border-color: var(--primary); }
/* Armada: se esta esperando a que toques un canto del dibujo. */
.adjust-tool.armed {
  background: var(--primary); border-color: var(--primary); color: #fff;
}

/* El dialogo de la medida se pega abajo en vez de centrarse: asi la vista
   previa sobre la pieza queda a la vista mientras se teclea. */
.stage-modal.sheet { align-items: flex-end; padding-bottom: 96px; }
.stage-modal.sheet .stage-modal-card { width: min(420px, calc(100% - 24px)); }
.tool-dialog-row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.tool-dialog-row input { margin: 0; flex: 1; min-width: 0; font-size: 1.1rem; text-align: center; }
.tool-dialog-unit { color: var(--text-muted); font-size: 0.9rem; }

.calib-caption { margin: 0 0 8px; font-size: 0.84rem; color: var(--text); font-weight: 600; }
@media (prefers-reduced-motion: reduce) {
  .calib-visual .cv-leg.active, .calib-visual .cv-station.to .cv-halo { animation: none; }
  .calib-visual .cv-station.to .cv-halo { opacity: 0.7; }
}

/* Cabeceras plegables de las herramientas de geometria/huecos -- para que la
   barra lateral no crezca sin limite cada vez que se anade una herramienta
   nueva, cada bloque se puede cerrar cuando no se esta usando. */
.collapsible-header { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 0.85rem; cursor: pointer; user-select: none; }
.collapsible-header .collapse-arrow { display: inline-block; width: 1em; color: var(--text-muted); }
.collapsible-header label { cursor: pointer; }

/* --- Toolbar inferior del canvas (area/perimetro/acciones) ---
   Flota sobre el propio lienzo, pegada al borde inferior: asi el dibujo
   ocupa el alto completo y las acciones estan siempre en el mismo sitio. */
/* --- Asistente por fases (medir una pieza nueva) --- */
.phase-steps { display: none; align-items: center; gap: 4px; }
.phase-steps.on { display: flex; }
.phase-step {
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
  margin: 0; padding: 0 12px; height: 40px;
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  color: var(--text-faint); font-size: 0.8rem; cursor: default;
}
.phase-step b {
  display: flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--border); color: var(--text-muted); font-size: 0.7rem;
}
/* Una fase ya superada se puede volver a tocar; las futuras no. */
.phase-step.done { color: var(--text-muted); cursor: pointer; }
.phase-step.done b { background: var(--success); color: #fff; }
.phase-step.current { color: var(--text); background: var(--bg-panel); }
.phase-step.current b { background: var(--primary); color: #fff; }

/* Barra de la fase: pista + boton grande de capturar + continuar */
.phase-bar {
  width: 100%; box-sizing: border-box;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--bg-panel-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.28);
}
.phase-bar.off { display: none; }
.phase-hint { flex: 1; min-width: 130px; display: flex; flex-direction: column; gap: 2px; }
.phase-hint-text { font-size: 0.9rem; font-weight: 600; }
.phase-hint-sub { font-size: 0.78rem; color: var(--text-muted); font-family: var(--font-mono); }
/* Boton de capturar: el mas grande de la pantalla a proposito -- se pulsa
   con el pulgar, sin mirar, entre disparo y disparo. */
.capture-fab {
  margin: 0; padding: 8px 22px; min-height: 62px; min-width: 150px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--primary); color: #fff; border: none; border-radius: 12px;
  cursor: pointer;
}
.capture-fab:disabled { opacity: 0.4; cursor: default; }
/* Deshacer ultimo punto, pegado a Capturar y con su misma altura: se pulsa
   con el dedo justo despues de un disparo malo. */
.capture-undo {
  margin: 0; min-height: 62px; min-width: 52px; padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.6rem; line-height: 1;
  background: var(--bg-panel); color: var(--text); border: 1px solid var(--border); border-radius: 12px;
  cursor: pointer;
}
.capture-undo:disabled { opacity: 0.35; cursor: default; }
body.capture-integrated .capture-undo { min-height: 52px; border-radius: 9px; }
.capture-fab-dist { font-family: var(--font-mono); font-size: 1.25rem; font-weight: 700; line-height: 1.1; }
.capture-fab-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.9; }
.capture-fab.hit { animation: capture-hit 0.25s ease-out; }
@keyframes capture-hit { 50% { transform: scale(0.94); } }
/* Secundario a proposito: mientras se mide, el unico boton rojo debe ser el
   de capturar. Dos rojos del mismo tamano compiten y se pulsa el que no es. */
/* Chip del acabado de canto, dentro de la barra de fase */
.edge-chip-wrap { position: relative; }
.edge-chip {
  display: flex; align-items: center; gap: 6px;
  margin: 0; padding: 0 12px; min-height: 62px;
  background: var(--bg-panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; cursor: pointer;
  font-size: 0.86rem;
}
.edge-chip .edge-chip-label { color: var(--text-muted); font-weight: 500; }
.edge-chip b { color: var(--primary); }
.edge-chip-caret { color: var(--text-muted); font-size: 0.7rem; }
.edge-picker {
  display: none; position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 5;
  padding: 8px; min-width: 220px;
  background: var(--bg-panel-2); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.edge-picker.open { display: block; }
.edge-picker .segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.edge-picker .edge-profile-btn { min-height: 44px; }

.phase-next {
  margin: 0; min-height: 62px; padding: 0 20px;
  background: var(--bg-panel); color: var(--text); border: 1px solid var(--border);
}
.phase-next:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.phase-next:disabled { opacity: 0.4; }

@media (max-width: 700px) {
  /* En movil la barra se apila: la pista arriba y las acciones a lo ancho,
     para que el boton de capturar no se quede en una esquina diminuta. */
  .phase-hint { flex-basis: 100%; }
  .capture-fab { flex: 1; }
  /* Chip del acabado de canto, dentro de la barra de fase */
.edge-chip-wrap { position: relative; }
.edge-chip {
  display: flex; align-items: center; gap: 6px;
  margin: 0; padding: 0 12px; min-height: 62px;
  background: var(--bg-panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; cursor: pointer;
  font-size: 0.86rem;
}
.edge-chip .edge-chip-label { color: var(--text-muted); font-weight: 500; }
.edge-chip b { color: var(--primary); }
.edge-chip-caret { color: var(--text-muted); font-size: 0.7rem; }
.edge-picker {
  display: none; position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 5;
  padding: 8px; min-width: 220px;
  background: var(--bg-panel-2); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.edge-picker.open { display: block; }
.edge-picker .segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.edge-picker .edge-profile-btn { min-height: 44px; }

.phase-next { flex: 1; }
}

/* Columna anclada al borde inferior del lienzo: aviso de guardado arriba,
   barra debajo (ver .stage-toast). */
.stage-bottom {
  position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 3;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
}
.canvas-toolbar {
  width: 100%; box-sizing: border-box;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--bg-panel-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.28);
}
/* Aviso de guardado, justo encima de la barra inferior. Vacio = invisible
   (:empty), para no dejar un hueco flotando cuando no hay nada que decir. */
.stage-toast {
  margin: 0; max-width: 100%; padding: 6px 10px;
  background: var(--bg-panel-2); border: 1px solid var(--border);
  border-radius: 8px; font-size: 0.82rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.28);
}
.stage-toast:empty { display: none; }
.capture-sync-status { display: flex; justify-content: space-between; gap: 12px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-panel); color: var(--text-muted); font-size: .72rem; line-height: 1.4; }
.capture-sync-status button { color: var(--text-muted); background: transparent; border: 0; padding: 0; margin: 0; min-height: 24px; font-size: inherit; text-align: right; }
.capture-sync-status button.pending, .capture-sync-status .offline { color: var(--warning); }
.capture-sync-status button:hover { text-decoration: underline; }
@media (max-width: 600px) { .capture-sync-status button { min-height: 44px; } }
#pendingSyncBox { scroll-margin-top: 80px; }
.canvas-toolbar .metric { font-family: var(--font-mono); font-size: 0.78rem; color: var(--text-muted); }
.canvas-toolbar .metric b { color: var(--text); }
.canvas-toolbar .spacer { flex: 1; }

/* --- Slider (p.ej. angulo de veta) --- */
input[type=range] {
  -webkit-appearance: none; appearance: none; height: 4px; background: var(--border);
  border-radius: 2px; padding: 0; margin: 6px 0;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--primary); cursor: pointer; border: 2px solid var(--bg-panel-2);
}
input[type=range]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; background: var(--primary); border: 2px solid var(--bg-panel-2); cursor: pointer;
}


/* --- Acciones por fila (listado de proyectos) ---
   Abrir es la fila entera; duplicar/archivar/borrar se esconden tras el
   "..." para que no se pulsen por error al ir a abrir, y el destructivo va
   separado y en rojo al final. */
/* Los controles de una fila forman un grupo: misma altura (40px), mismo
   radio y mismo peso. El "..." es cuadrado, del mismo alto que el resto --
   antes era mas bajo y la fila quedaba desalineada. */
.row-actions { display: inline-flex; align-items: center; gap: 6px; justify-content: flex-end; }
.row-actions > *, .row-actions .row-menu-btn {
  height: 40px; min-height: 40px; margin: 0; border-radius: 8px;
}
.row-open-btn { padding: 0 18px; display: inline-flex; align-items: center; }
.row-menu-wrap { position: relative; display: inline-flex; }
.row-menu-btn {
  width: 40px; height: 40px; min-height: 40px; margin: 0;
  padding: 0; line-height: 1; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.05rem;
}
.row-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 4px); z-index: 20;
  min-width: 190px; padding: 6px; text-align: left;
  background: var(--bg-panel-2); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.row-menu.open { display: block; }
/* Botones y enlaces del menu se pintan igual: que una entrada sea un <a>
   (descargar un fichero) es un detalle tecnico, no debe notarse. */
.row-menu button, .row-menu a {
  display: block; width: 100%; margin: 0; text-align: left;
  background: transparent; border: none; color: var(--text);
  padding: 9px 10px; border-radius: 7px;
  font-family: var(--font-body); font-size: 0.86rem; font-weight: 600;
  text-decoration: none; box-sizing: border-box;
}
.row-menu button:hover, .row-menu a:hover { background: var(--bg-panel); color: var(--text); }
.row-menu .danger { color: var(--primary); }
.row-menu-sep { height: 1px; background: var(--border); margin: 6px 0; }

/* Aviso con deshacer tras archivar */
.undo-bar {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--bg-panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 6px 6px 12px; font-size: 0.85rem;
}
.undo-bar button { margin: 0; padding: 5px 12px; }

/* Dialogo modal generico (borrado de proyecto) */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(0,0,0,0.55);
}
.modal-card {
  width: 100%; max-width: 440px; padding: 20px;
  background: var(--bg-panel-2); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}


/* --- Pestanas con contador (Activos / Archivados) ---
   Sustituyen a una casilla "ver archivados": se lee de un vistazo cuantos
   hay de cada, y se cambia de vista con un toque, que en tablet importa. */
.seg-tabs {
  display: inline-flex; gap: 4px; padding: 4px;
  background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 10px;
}
.seg-tab {
  display: inline-flex; align-items: center; gap: 8px;
  margin: 0; padding: 8px 14px; min-height: 40px;
  background: transparent; border: none; border-radius: 8px;
  color: var(--text-muted); font-size: 0.86rem; cursor: pointer;
}
.seg-tab:hover { color: var(--text); }
.seg-tab.active { background: var(--bg-panel); color: var(--text); }
.seg-count {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; flex: 0 0 20px; padding: 0; border-radius: 50%;
  background: var(--border); color: var(--text-muted);
  font-family: var(--font-body); font-size: 0.7rem; line-height: 1; text-align: center;
}
.seg-tab.active .seg-count { background: var(--primary); color: #fff; }
.workspace-page #importProjectBtn { background: transparent; border-color: var(--text-muted); color: var(--text); }
.workspace-page #importProjectBtn:hover { background: var(--bg-panel-2); }
.empty-cell { color: var(--text-faint); text-align: center; padding: 28px 10px; }


/* --- Dialogo de borrado ---
   Centrado, con icono de aviso y lo que se pierde en fichas: se entiende
   sin leer un parrafo. El boton destructivo va a la derecha (el sitio del
   "siguiente") y en rojo; cancelar queda a mano y sin peso visual. */
.danger-card { max-width: 400px; text-align: center; }
.danger-icon {
  width: 52px; height: 52px; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--primary-dim); color: var(--primary);
}
.danger-card h3 { margin: 0 0 6px; font-size: 1.1rem; }
.danger-target {
  margin: 0 0 12px; font-family: var(--font-mono); font-size: 1rem;
  font-weight: 600; color: var(--text); word-break: break-word;
}
.danger-chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 14px; }
.chip-loss, .chip-empty {
  padding: 6px 12px; border-radius: 999px; font-size: 0.8rem;
  border: 1px solid var(--border); background: var(--bg-panel);
}
.chip-loss { color: var(--primary); border-color: var(--primary-dim); }
.chip-empty { color: var(--text-muted); }
.danger-note { margin: 0 0 20px; font-size: 0.84rem; color: var(--text-muted); }
.danger-actions { display: flex; gap: 10px; }
.danger-actions button { flex: 1; margin: 0; min-height: 46px; }
.danger-go { background: var(--primary); color: #fff; }


/* Cabecera de tarjeta con su propia accion (p.ej. "Editar" sobre la tarjeta
   de datos del proyecto): la accion vive pegada a lo que modifica, no
   suelta arriba del todo entre otras que no tienen nada que ver. */
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px;
}
.card-head-title {
  font-family: var(--font-head); font-weight: 700; font-size: 0.8rem;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted);
}
.card-head-action { margin: 0; padding: 0 16px; height: 40px; min-height: 40px; border-radius: 8px; }


/* Miniatura del contorno en la lista de piezas: identifica la pieza por su
   forma, que es como se reconocen de verdad en un proyecto con varias. */
.piece-name-cell { display: flex; align-items: center; gap: 10px; }
.piece-thumb {
  width: 40px; height: 40px; flex-shrink: 0;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
}
.piece-thumb path { fill: var(--primary-dim); stroke: var(--primary); stroke-width: 1.5; }


/* --- Galeria de piezas recientes (pantalla de Medicion) ---
   Tarjetas con la silueta real de cada pieza: se busca "la encimera en L de
   ayer", y esa se reconoce por la forma, no leyendo una tabla. */
.piece-gallery {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.piece-card {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px;
}
.piece-card-art {
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; margin-bottom: 12px;
}
.piece-card-art .piece-thumb { width: 120px; height: 120px; background: none; border: none; }
.piece-card-name { font-weight: 600; font-size: 0.95rem; margin-bottom: 2px; }
.piece-card-sub { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 8px; }
.piece-card-meta {
  display: flex; gap: 10px; margin-bottom: 12px;
  font-family: var(--font-mono); font-size: 0.74rem; color: var(--text-faint);
}
.piece-card-actions { display: flex; gap: 6px; }
.piece-card-actions .row-open-btn { flex: 1; justify-content: center; padding: 0 10px; }


/* Dialogo de vista previa del plano (compartido por la ficha del proyecto y
   la galeria de Medicion) */
.pdf-card { max-width: 560px; }
.pdf-preview-body { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-start; }
.pdf-preview-body canvas { border: 1px solid var(--border); background: #fff; flex-shrink: 0; }
.pdf-preview-side { flex: 1; min-width: 180px; }


/* Puntos capturados: desplegable en la barra superior, no un panel sobre el
   dibujo. Se mira de reojo (cuantos llevo) y se abre solo para corregir. */
.points-menu-wrap {
  position: absolute; top: calc(var(--stage-top-h, 54px) + 12px); left: 12px; z-index: 4;
}
.points-btn {
  display: flex; align-items: center; gap: 8px; height: 40px; margin: 0;
  padding: 0 12px; border-radius: 8px; cursor: pointer;
  background: var(--bg-panel-2); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.78rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.28);
}
.points-btn:hover { color: var(--text); background: var(--bg-panel); }
.points-btn b {
  min-width: 22px; padding: 1px 7px; border-radius: 999px;
  background: var(--border); color: var(--text);
  font-family: var(--font-mono); font-size: 0.72rem; text-align: center;
}
.points-caret { font-size: 0.7rem; }
.points-menu {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; z-index: 6;
  width: 300px; max-height: 60vh; overflow-y: auto; padding: 10px;
  background: var(--bg-panel-2); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.points-menu.open { display: block; }
@media (max-width: 700px) {
  .points-btn span:first-child { display: none; }  /* solo el contador */
  .points-menu { width: min(300px, 80vw); }
}

/* La app conserva la barra lateral en escritorio y la convierte en un
   cajón accesible cuando el contenido necesita todo el ancho disponible. */
@media (max-width: 900px) {
  .app-shell { display: block; }
  .main { width: 100%; padding: 16px clamp(14px, 3vw, 24px) 48px; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 102;
    width: min(290px, 84vw); height: 100dvh;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 16px 0 40px rgba(0,0,0,.35);
  }
  .nav-open .sidebar { transform: translateX(0); }
  .nav-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 101; background: rgba(0,0,0,.6); }
  .nav-toggle { display: inline-flex; align-items: center; gap: 8px; flex: none; min-height: 44px; margin: 0; }
  .sidebar-nav a { min-height: 48px; font-size: .95rem; }
  .topbar-strip { flex-wrap: nowrap; }
  .topbar-strip .breadcrumb { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-strip .topbar-right { margin-left: auto; min-width: 0; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
  .page-topbar .topbar-right { flex-wrap: wrap; }
  .box, .kpi-card, .billing-card { min-width: 0; }
  .kpi-row { grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }
  .stage-rail { top: calc(var(--stage-top-h, 54px) + 8px); }
  .stage-panel { top: calc(var(--stage-top-h, 54px) + 68px); max-height: min(45%, 45dvh); }
}

@media (max-width: 600px) {
  .main, .page-container { padding: 12px 12px 40px; }
  .has-mobile-nav .main { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
  .topbar-strip {
    position: sticky; top: 0; z-index: 50; flex-wrap: nowrap;
    margin: -12px -12px 18px; padding: 10px 12px;
    background: var(--bg); border-bottom: 1px solid var(--border);
  }
  .nav-toggle { width: 44px; height: 44px; justify-content: center; padding: 0; font-size: 1.2rem; }
  .nav-toggle [data-i18n] { display: none; }
  .topbar-strip .breadcrumb { display: none; }
  .mobile-brand { display: flex; align-items: center; min-width: 0; flex: 0 1 128px; }
  .mobile-brand img { display: block; width: 100%; max-height: 29px; }
  .topbar-strip .topbar-right { width: auto; flex: 0 1 auto; flex-basis: auto; margin-left: auto; flex-wrap: nowrap; }
  .topbar-strip .user-trigger { max-width: min(38vw, 150px); min-height: 44px; }
  .topbar-strip .user-block { min-width: 0; }
  .sidebar { display: flex; flex-direction: column; width: min(320px, 86vw); padding-bottom: max(18px, env(safe-area-inset-bottom)); }
  .sidebar-preferences { display: flex; gap: 10px; align-items: center; margin-top: auto; padding: 18px 8px 4px; border-top: 1px solid var(--border); }
  .sidebar-preferences .dropdown-select-btn, .sidebar-preferences .auth-theme-switch button { min-height: 44px; }
  .sidebar-preferences .auth-theme-button { width: 44px; height: 44px; }
  .sidebar-preferences .dropdown-select-panel { top: auto; bottom: calc(100% + 6px); left: 0; right: auto; }
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi-card { padding: 14px; }
  .page-topbar h1 { font-size: clamp(1.15rem, 5vw, 1.5rem); }
  .page-topbar .topbar-right { width: 100%; }
  .page-topbar .topbar-right > .btn, .page-topbar .topbar-right > button { flex: 1; justify-content: center; text-align: center; min-height: 44px; }
  .box { padding: 14px; }
  .brand-hero .brand-side { padding: 24px 20px; }
  .brand-hero .form-side { padding: 24px 20px; }
  .centered-shell { padding: 12px; align-items: flex-start; }
  .main form[style*="display:flex"] > div[style*="min-width"],
  .main form [style*="display:flex"][style*="flex-wrap:wrap"] > div[style*="min-width"],
  .main .box > [style*="display:flex"][style*="flex-wrap:wrap"] > div[style*="min-width"],
  .main .tenant-details .field {
    min-width: 0 !important; flex: 1 1 100% !important;
  }
  .main form[style*="display:flex"] > div:has(> button[type="submit"]) { width: 100%; }
  .main form[style*="display:flex"] > div > button[type="submit"] { width: 100%; min-height: 46px; }
  .main input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
  .main select, .main textarea { min-height: 46px; font-size: 16px; }
  .material-row { flex-wrap: wrap; }
  .material-row .material-name { flex: 1 1 100% !important; min-width: 0; }
  .material-row .material-thickness { flex: 1 1 0; width: auto !important; min-width: 0; }
  .material-row .remove-material-row { min-width: 46px; min-height: 46px; }
  .row-menu-btn { width: 44px; height: 44px; }
  .seg-tab, .card-head-action, .points-btn { min-height: 44px; }
  .table-scroll { scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
  .table-scroll th, .table-scroll td { padding-block: 13px; }
  .mobile-bottom-nav {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
    position: fixed; inset: auto 0 0; z-index: 60;
    padding: 6px 6px max(6px, env(safe-area-inset-bottom));
    background: var(--bg-panel); border-top: 1px solid var(--border);
    box-shadow: 0 -8px 24px rgba(0,0,0,.12);
  }
  .mobile-bottom-nav a {
    min-width: 0; min-height: 54px; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px;
    border-radius: 10px; color: var(--text-muted); text-decoration: none;
    font-size: .64rem; font-weight: 600; white-space: nowrap;
  }
  .mobile-bottom-nav a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .mobile-bottom-nav a.active { color: var(--text); font-weight: 700; }
  .mobile-bottom-nav a.active svg { color: var(--primary); }
  .mobile-bottom-nav svg { width: 21px; height: 21px; flex: none; }
  .modal-card, .stage-modal-card { max-height: calc(100dvh - 24px); overflow-y: auto; }
  .modal-backdrop { padding: 12px; }
  .pdf-preview-body canvas { max-width: 100%; height: auto; }
  .capture-stage { min-height: 0; height: min(78dvh, 800px); }
  .stage-bottom { left: 8px; right: 8px; bottom: 8px; }
  .phase-bar, .canvas-toolbar { gap: 6px; padding: 6px; }
  .phase-visual { display: none; }
}

@media (max-width: 360px) {
  .topbar-strip .user-trigger { max-width: 100px; }
}

@media (max-width: 900px) and (orientation: landscape) {
  .mobile-bottom-nav { display: none; }
  .has-mobile-nav .main { padding-bottom: 40px; }
}

@media (orientation: landscape) and (max-width: 900px) and (max-height: 600px) {
  .capture-stage { height: max(440px, 100dvh); }
  body.capture-max .capture-stage { height: auto; }
  .stage-top { gap: 4px; padding: 4px 8px; }
  .stage-bottom { max-height: 38dvh; overflow-y: auto; }
  .stage-rail { top: calc(var(--stage-top-h, 54px) + 6px); }
  .stage-panel { top: calc(var(--stage-top-h, 54px) + 62px); max-height: calc(100% - var(--stage-top-h, 54px) - 70px); }
  .stage-modal { align-items: flex-start; overflow-y: auto; padding: 8px; }
  .stage-modal-card { max-height: none; }
  .connect-hero { justify-content: flex-start; overflow-y: auto; padding: 8px 16px 16px; }
  .connect-hero .disto-svg { width: 78px; margin: 0; }
  .connect-hero-title { font-size: 1.05rem; }
  .connect-hero-sub { margin: 2px 0 8px; }
  .connect-hero-actions .connect-hero-btn,
  .connect-hero-actions .neutral { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .app-shell :is(button, .btn) { transition: none; }
}

/* Prueba finalizada: solo facturacion hasta activar la suscripcion. */
.subscription-locked .sidebar-nav > a:not([href="facturacion.html"]),
.subscription-locked .mobile-bottom-nav {
  display: none !important;
}

.mobile-client .auth-create,
.mobile-client a[href*="register.html"],
.mobile-client a[href*="facturacion.html"] {
  display: none !important;
}
.mobile-access-dialog { box-sizing: border-box; width: min(440px, calc(100vw - 32px)); padding: 30px 24px; color: var(--text); background: var(--bg-panel); border: 1px solid var(--border); border-radius: 20px; box-shadow: 0 24px 80px #0006; text-align: center; }
.mobile-access-dialog::backdrop { background: #000b; backdrop-filter: blur(6px); }
.mobile-access-dialog > svg { width: 48px; height: 48px; padding: 12px; box-sizing: content-box; color: var(--primary); background: var(--primary-dim); border-radius: 18px; }
.mobile-access-dialog h2 { margin: 20px 0 12px; font-size: 1.4rem; }
.mobile-access-dialog p { color: var(--text-muted); line-height: 1.6; }
.mobile-access-actions { display: grid; gap: 10px; margin-top: 24px; }
.mobile-access-actions button { margin: 0; min-height: 48px; width: 100%; }
@media (max-width: 600px) {
  .subscription-locked.has-mobile-nav .main {
    padding-bottom: calc(40px + env(safe-area-inset-bottom));
  }
}
.mobile-reminders[hidden] { display: none; }
.mobile-reminder-controls { display: flex; gap: 16px; align-items: end; flex-wrap: wrap; }
.mobile-reminder-controls label { display: grid; gap: 8px; flex: 1; min-width: 180px; }
.mobile-reminder-controls select, .mobile-reminder-controls button { min-height: 48px; }
.mobile-reminders h2 { margin-bottom: 12px; }
.mobile-reminders p { line-height: 1.5; }
