:root {
  --bg: #1c1f23;
  --panel: #262a2f;
  --panel-2: #2d3238;
  --panel-3: #343a41;
  --ink: #f0f2f4;
  --muted: #a3abb3;
  --muted-2: #7f8892;
  --line: #3b424a;
  --line-soft: #333940;
  --orange: #ef741f;
  --orange-dark: #d96416;
  --danger: #ef7070;
  --success: #68c48b;
  --shadow: 0 18px 48px rgba(0, 0, 0, .24);
  --radius: 20px;
}

* { box-sizing: border-box; }
html { min-width: 320px; color-scheme: dark; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% -10%, rgba(239,116,31,.07), transparent 34%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 26px;
  border-bottom: 1px solid rgba(59,66,74,.9);
  background: rgba(31,35,39,.90);
  backdrop-filter: blur(16px);
}
.brand { text-decoration: none; font-size: 27px; font-weight: 800; letter-spacing: -1.5px; white-space: nowrap; }
.brand-build { color: #eef1f3; }
.brand-tech { color: var(--orange); }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }
.tile-badge { padding: 7px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--muted); font-size: 11px; font-weight: 700; white-space: nowrap; }

.app-shell {
  width: min(1760px, calc(100% - 28px));
  margin: 18px auto 30px;
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}
.panel, .workspace {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}
.controls-panel, .summary-panel { padding: 17px; }
.workspace { padding: 22px; min-width: 0; }
.logo-card { background: #24282d; border: 1px solid var(--line); border-radius: 15px; overflow: hidden; margin-bottom: 16px; }
.logo-card img { display: block; width: 100%; aspect-ratio: 1.65 / 1; object-fit: cover; object-position: center 56%; opacity: .92; }

.control-section { padding: 17px 0; border-top: 1px solid var(--line-soft); }
.control-section:first-of-type { border-top: 0; padding-top: 2px; }
.section-heading, .workspace-toolbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.eyebrow { margin: 0 0 5px; color: var(--orange); font-size: 10px; line-height: 1; font-weight: 800; letter-spacing: 1.35px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(22px, 2.15vw, 33px); line-height: 1.08; letter-spacing: -1px; }
h2 { margin-bottom: 0; font-size: 16px; letter-spacing: -.25px; }
.helper { color: var(--muted-2); font-size: 11px; }
.subtitle { margin-bottom: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

.dimensions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 13px; }
.field { display: grid; gap: 7px; color: #c3c8cd; font-size: 11px; font-weight: 650; }
.field em { font-style: normal; color: var(--muted-2); font-weight: 500; }
.input-wrap {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #202429;
  transition: .16s ease;
}
.input-wrap:focus-within { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(239,116,31,.13); }
.input-wrap input { width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; font-weight: 700; min-width: 0; }
.input-wrap > span { color: var(--muted); font-size: 12px; }
.dimension-note { margin-top: 9px; color: var(--muted-2); font-size: 10px; line-height: 1.45; }

/* Paleta compacta: deja de ser una lista vertical larga. */
.palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 8px;
  margin-top: 13px;
}
.color-option {
  min-width: 0;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 6px;
  min-height: 58px;
  padding: 7px 4px 6px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #202429;
  color: var(--muted);
  text-align: center;
  transition: .14s ease;
}
.color-option:hover { border-color: #59616a; background: #24292e; }
.color-option.active { border-color: var(--orange); background: rgba(239,116,31,.08); box-shadow: 0 0 0 2px rgba(239,116,31,.10); color: var(--ink); }
.swatch { width: 28px; height: 28px; border-radius: 8px; border: 1px solid rgba(255,255,255,.17); box-shadow: inset 0 0 0 1px rgba(0,0,0,.16); }
.color-option span:last-child { width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 9px; font-weight: 650; }
.microcopy { margin: 10px 0 0; color: var(--muted-2); font-size: 9.5px; line-height: 1.5; }
.microcopy.centered { text-align: center; }

.tool-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 7px; margin-top: 13px; }
.tool-btn { min-height: 38px; padding: 7px 5px; border: 1px solid var(--line); border-radius: 10px; background: #202429; color: #cbd0d5; font-size: 10px; font-weight: 700; transition: .14s ease; }
.tool-btn:hover, .tool-btn.active { background: rgba(239,116,31,.10); color: #ff9b57; border-color: #92552e; }
.link-btn { border: 0; background: transparent; padding: 10px 2px 0; font-size: 10px; font-weight: 700; }
.link-btn.danger { color: var(--danger); }

.workspace-toolbar { align-items: center; margin-bottom: 18px; }
.history-actions { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.icon-btn { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 10px; background: #202429; color: #d7dbe0; font-size: 18px; font-weight: 700; }
.icon-btn:hover { background: #2f353b; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.zoom-control { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 11px; overflow: hidden; background: #202429; }
.zoom-control .icon-btn { border: 0; border-radius: 0; }
.zoom-control span { width: 54px; text-align: center; font-size: 10px; font-weight: 700; color: var(--muted); }

.canvas-card {
  position: relative;
  min-height: 570px;
  padding: 34px 26px 22px 48px;
  border-radius: 17px;
  background:
    radial-gradient(circle at 15% 10%, rgba(255,255,255,.035), transparent 34%),
    linear-gradient(145deg, #23272c, #1e2226);
  border: 1px solid var(--line);
  overflow: hidden;
}
.grid-viewport {
  width: 100%;
  height: 510px;
  display: grid;
  place-items: center;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 16px;
  border: 1px dashed #46505a;
  border-radius: 13px;
  background-color: rgba(8,10,12,.20);
  scrollbar-color: #4a525a #252a2f;
}
.floor-canvas {
  display: block;
  flex: 0 0 auto;
  max-width: none;
  max-height: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  cursor: crosshair;
  background: #3b4249;
  box-shadow: 0 20px 38px rgba(0,0,0,.36);
  image-rendering: auto;
}
body.painting, body.painting * { cursor: crosshair !important; }

.measure { position: absolute; color: #8f98a1; font-size: 10px; font-weight: 750; letter-spacing: .2px; pointer-events: none; }
.measure::before, .measure::after { content: ""; position: absolute; background: #5c6670; }
.measure-top { top: 12px; left: 48px; right: 26px; height: 16px; border-top: 1px solid #5c6670; text-align: center; }
.measure-top span { position: relative; top: -7px; padding: 0 8px; background: #23272c; }
.measure-top::before, .measure-top::after { width: 1px; height: 8px; top: -4px; }
.measure-top::before { left: 0; }.measure-top::after { right: 0; }
.measure-left { left: 11px; top: 34px; bottom: 22px; width: 28px; border-left: 1px solid #5c6670; }
.measure-left span { position: absolute; top: 50%; left: -2px; transform: translate(-50%, -50%) rotate(-90deg); white-space: nowrap; padding: 0 8px; background: #22262b; }
.measure-left::before, .measure-left::after { width: 8px; height: 1px; left: -4px; }
.measure-left::before { top: 0; }.measure-left::after { bottom: 0; }
.workspace-hint { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 12px; color: var(--muted); font-size: 10px; text-align: center; }
.status-dot { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: #20252b; box-shadow: 0 0 0 4px rgba(255,255,255,.05); }

.summary-header { padding: 3px 1px 14px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat-card { padding: 11px; border: 1px solid var(--line); border-radius: 12px; background: #202429; }
.stat-card span { display: block; color: var(--muted-2); font-size: 9px; margin-bottom: 5px; }
.stat-card strong { font-size: 14px; letter-spacing: -.3px; }
.materials-list { display: grid; gap: 8px; margin: 13px 0 14px; }
.material-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 9px; font-size: 10px; }
.material-row .swatch { width: 18px; height: 18px; border-radius: 6px; }
.material-row .material-name { color: #c0c6cb; font-weight: 600; }
.material-row strong { font-size: 10px; }
.total-card { padding: 15px; border-radius: 14px; background: #171a1e; border: 1px solid #323940; color: white; }
.total-card span { display: block; color: #9aa3ac; font-size: 9px; margin-bottom: 5px; }
.total-card strong { display: block; font-size: 21px; letter-spacing: -.6px; }
.total-card small { display: block; margin-top: 4px; color: #7f8993; font-size: 9px; }
.price-box { margin: 12px 0; padding: 13px; border: 1px solid var(--line); border-radius: 14px; background: #22262b; }
.price-line { display: flex; align-items: center; justify-content: space-between; font-size: 10px; }
.price-line strong { font-size: 12px; }
.price-total { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 10px; }
.price-total strong { font-size: 15px; }
.summary-actions { display: grid; gap: 8px; }

.btn { min-height: 40px; border-radius: 10px; padding: 0 13px; border: 1px solid transparent; font-size: 10px; font-weight: 800; transition: .14s ease; white-space: nowrap; }
.btn-primary { background: var(--orange); color: white; box-shadow: 0 9px 20px rgba(239,116,31,.16); }
.btn-primary:hover { background: var(--orange-dark); transform: translateY(-1px); }
.btn-secondary, .btn-ghost { background: #202429; border-color: var(--line); color: #d2d7dc; }
.btn-secondary:hover, .btn-ghost:hover { background: #2d3339; }
.admin-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.toast { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); z-index: 80; transform: translate(-50%, 16px); opacity: 0; pointer-events: none; padding: 10px 14px; border: 1px solid #454d55; border-radius: 999px; background: #14171a; color: #f1f3f5; box-shadow: 0 10px 34px rgba(0,0,0,.4); font-size: 10px; transition: .18s ease; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

.textured-swatch {
  background-color: var(--swatch) !important;
  background-image: linear-gradient(145deg, rgba(255,255,255,.12), rgba(0,0,0,.08));
}
.empty-swatch { background: #e8e9e7; }
.money span { font-weight: 700; color: var(--muted); }

/* Admin */
.admin-body { background: var(--bg); }
.admin-shell { width: min(1030px, calc(100% - 28px)); margin: 24px auto 40px; }
.admin-panel { padding: 27px; }
.admin-heading { margin-bottom: 24px; }
.admin-section { padding: 21px 0; border-top: 1px solid var(--line-soft); }
.admin-section h2 { margin-bottom: 11px; }
.admin-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.auth-fields { margin-top: 14px; }
.auth-note { max-width: 680px; }
.color-editor { display: grid; gap: 9px; margin-top: 15px; }
.color-edit-row {
  display: grid;
  grid-template-columns: 52px minmax(150px, 1fr) minmax(125px, .65fr) 40px;
  gap: 9px;
  align-items: end;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #202429;
}
.color-picker { width: 52px; height: 42px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: #171a1e; cursor: pointer; }
.remove-color { width: 40px; height: 42px; color: var(--danger); }
.admin-actions { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 19px; }
.admin-notice { min-height: 18px; margin-top: 13px; color: var(--muted); font-size: 11px; }
.admin-notice.success { color: var(--success); font-weight: 700; }
.admin-notice.error { color: var(--danger); font-weight: 700; }

.login-panel { width: min(430px, 100%); margin: 8vh auto 0; padding: 28px; }
.login-badge { display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; margin-bottom: 16px; border-radius: 999px; background: rgba(239,116,31,.12); color: #ff9951; font-size: 9px; font-weight: 800; letter-spacing: 1.1px; }
.login-panel h1 { font-size: 27px; }
.login-form { display: grid; gap: 14px; margin-top: 22px; }
.login-form .btn { margin-top: 3px; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 272px minmax(0, 1fr); }
  .summary-panel { grid-column: 1 / -1; display: grid; grid-template-columns: 1.1fr 1fr 1fr; gap: 16px; align-items: start; }
  .summary-header { grid-column: 1 / -1; padding-bottom: 0; }
  .summary-panel > .microcopy { grid-column: 1 / -1; }
  .materials-list { margin-top: 0; }
}

@media (max-width: 820px) {
  .topbar { min-height: 62px; padding: 9px 14px; }
  .brand { font-size: 23px; }
  .tile-badge { display: none; }
  .btn { min-height: 36px; padding-inline: 10px; }
  .reset-top { display: none; }

  .app-shell { width: min(100% - 18px, 720px); margin-top: 10px; grid-template-columns: 1fr; gap: 10px; }
  .controls-panel { order: 1; }
  .workspace { order: 2; padding: 14px; }
  .summary-panel { order: 3; display: block; }
  .logo-card { display: none; }
  .control-section:first-of-type { padding-top: 0; }
  .palette { grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); }
  .tool-grid { grid-template-columns: repeat(3, 1fr); }

  .workspace-toolbar { align-items: flex-start; flex-direction: column; gap: 12px; }
  .workspace-toolbar h1 { font-size: 24px; }
  .history-actions { width: 100%; justify-content: flex-start; }
  .canvas-card { min-height: 455px; padding: 32px 12px 18px 38px; }
  .grid-viewport { height: 405px; padding: 9px; }
  .measure-top { left: 38px; right: 12px; }
  .measure-left { left: 7px; }

  .summary-header { padding-bottom: 13px; }
  .materials-list { margin-top: 12px; }

  .admin-shell { width: min(100% - 18px, 720px); margin-top: 10px; }
  .admin-panel { padding: 18px; }
  .admin-fields { grid-template-columns: 1fr; }
  .admin-color-heading { align-items: center; }
  .color-edit-row { grid-template-columns: 46px 1fr 40px; }
  .color-edit-row .field:nth-of-type(2) { grid-column: 2 / 3; }
  .color-edit-row .field:nth-of-type(3) { grid-column: 2 / 3; }
  .color-edit-row .remove-color { grid-column: 3; grid-row: 1 / 3; align-self: center; }
  .login-panel { margin-top: 5vh; }
}

@media (max-width: 520px) {
  .topbar-actions { gap: 6px; }
  .topbar .btn { font-size: 9px; }
  .app-shell { width: calc(100% - 12px); gap: 8px; }
  .controls-panel, .summary-panel, .workspace { border-radius: 16px; }
  .controls-panel, .summary-panel { padding: 14px; }
  .workspace { padding: 12px; }

  .dimensions-grid, .stat-grid { grid-template-columns: 1fr 1fr; }
  .palette { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .color-option { min-height: 54px; padding: 6px 3px 5px; }
  .swatch { width: 26px; height: 26px; }
  .tool-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .tool-btn { min-height: 36px; font-size: 9px; }

  .workspace-toolbar h1 { font-size: 21px; }
  .subtitle { font-size: 11px; }
  .icon-btn { width: 36px; height: 36px; }
  .canvas-card { min-height: 395px; padding-left: 35px; padding-right: 9px; }
  .grid-viewport { height: 350px; padding: 6px; }
  .measure-top { left: 35px; right: 9px; }
  .measure-left { left: 5px; }
  .workspace-hint { font-size: 9px; }

  .admin-shell { width: calc(100% - 12px); }
  .admin-panel, .login-panel { padding: 16px; border-radius: 16px; }
  .login-panel h1 { font-size: 23px; }
  .admin-color-heading { align-items: flex-start; flex-direction: column; }
  .admin-color-heading .btn { width: 100%; }
}

/* V5: productos, precio por m² y 10% extra recomendado */
.product-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 13px; }
.select-wrap {
  min-height: 42px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #202429;
  overflow: hidden;
}
.select-wrap:focus-within { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(239,116,31,.13); }
.select-wrap select {
  width: 100%;
  min-height: 42px;
  padding: 0 34px 0 11px;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: #202429;
  font-size: 10px;
  font-weight: 700;
}
.product-card {
  display: grid;
  gap: 4px;
  margin-top: 10px;
  padding: 11px 12px;
  border: 1px solid #424952;
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(239,116,31,.07), rgba(255,255,255,.02));
}
.product-card .product-kicker { color: var(--orange); font-size: 8px; font-weight: 800; letter-spacing: 1px; }
.product-card strong { font-size: 11px; }
.product-card small { color: var(--muted-2); font-size: 9px; }
.summary-product { margin: 5px 0 0; color: var(--muted); font-size: 10px; }

.extra-toggle-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 13px 0 5px;
  padding: 12px;
  border: 1px solid #4a4740;
  border-radius: 13px;
  background: rgba(239,116,31,.055);
  cursor: pointer;
}
.extra-toggle-card > div { display: grid; gap: 4px; }
.extra-toggle-card strong { font-size: 10px; }
.extra-toggle-card span:not(.switch):not(.switch-track) { color: var(--muted); font-size: 9px; line-height: 1.35; }
.switch { position: relative; flex: 0 0 auto; width: 40px; height: 23px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #3a4148;
  border: 1px solid #505963;
  transition: .16s ease;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #d8dde1;
  transition: .16s ease;
}
.switch input:checked + .switch-track { background: var(--orange); border-color: var(--orange); }
.switch input:checked + .switch-track::after { transform: translateX(17px); background: white; }

.total-split { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 5px; }
.total-card .total-split span { margin: 0; }
.total-card .total-split strong { font-size: 11px; letter-spacing: 0; }
.total-card .extra-line strong { color: #ff9c59; }
.total-card .extra-line.disabled-extra { opacity: .45; }
.total-divider { height: 1px; margin: 10px 0 11px; background: #30363c; }
.subtle-price { margin-top: 7px; color: var(--muted); }
.subtle-price strong { color: #c7ccd1; }

.price-product-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; margin-top: 14px; }
.price-product-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #202429;
}
.price-product-card > span { min-height: 30px; display: flex; align-items: center; line-height: 1.35; }
.single-field { grid-template-columns: minmax(0, 1fr); max-width: 520px; }
.remove-color:disabled { opacity: .25; cursor: not-allowed; }

.material-row { grid-template-columns: auto minmax(70px, 1fr) auto; }
.material-row strong { text-align: right; line-height: 1.3; }

@media (max-width: 820px) {
  .product-grid { grid-template-columns: 1fr 1fr; }
  .price-product-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .product-grid { grid-template-columns: 1fr; }
  .product-card { margin-top: 8px; }
  .select-wrap select { font-size: 11px; }
  .extra-toggle-card { align-items: flex-start; }
  .material-row { grid-template-columns: auto minmax(65px, 1fr) minmax(110px, auto); gap: 7px; }
  .material-row strong { font-size: 9px; }
  .summary-actions .btn { white-space: normal; line-height: 1.2; padding-block: 9px; }
}
