/* ==========================================================================
   Estimador Piura — Studio Architectural UI Stylesheet (Pure CSS)
   Replicates the design system of proyecto-tesis without any JS bundler.
   ========================================================================== */

:root {
  --font-display: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  --font-sans: "DM Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;

  --bg-page: #f8fafc;
  --bg-surface: #ffffff;
  --bg-stage: #fafbfc;
  --bg-subtle: #f1f5f9;
  --bg-table-head: #f8fafc;

  --text-primary: #0f172a;
  --text-strong: #020617;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --border-default: #e2e8f0;
  --border-subtle: #f1f5f9;
  --border-input: #cbd5e1;

  --brand: #1d4ed8;
  --brand-hover: #1e40af;
  --brand-soft: rgba(29, 78, 216, 0.06);
  --brand-ring: rgba(29, 78, 216, 0.16);

  --amber-700: #b45309;
  --emerald-700: #047857;
  --red-700: #b91c1c;
  --red-50: #fef2f2;
  --red-200: #fecaca;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

body {
  margin: 0;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
}

::selection {
  background-color: rgba(29, 78, 216, 0.15);
  color: var(--brand);
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  margin: 0;
}

p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.tabular-nums-mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.text-right {
  text-align: right;
}

.text-strong {
  font-weight: 600;
  color: #334155;
}

/* Icons */
.icon-xs {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.icon-sm {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.spin {
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-result {
  animation: fadeSlideIn 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* Layout Shell */
.app-shell {
  min-height: 100vh;
  background-color: var(--bg-page);
  color: var(--text-primary);
}

.container {
  max-width: 1240px;
  margin-inline: auto;
  padding-inline: 16px;
}

@media (min-width: 640px) {
  .container {
    padding-inline: 24px;
  }
}

@media (min-width: 1024px) {
  .container {
    padding-inline: 32px;
  }
}

/* Sticky 3-Zone Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border-default);
  background-color: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(6px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  padding-block: 14px;
}

.brand-link {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  white-space: nowrap;
  flex-shrink: 0;
}

.main-nav {
  display: none;
  align-items: center;
  gap: 28px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

@media (min-width: 768px) {
  .main-nav {
    display: flex;
  }
}

.nav-link {
  white-space: nowrap;
  transition: color 150ms ease;
}

.nav-link:hover {
  color: var(--text-strong);
}

.header-actions {
  flex-shrink: 0;
}

/* Buttons */
.btn-outline-sm,
.btn-outline-xs {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background-color: var(--bg-surface);
  color: #334155;
  font-size: 12px;
  font-weight: 500;
  transition: background-color 150ms ease, border-color 150ms ease,
    color 150ms ease;
}

.btn-outline-sm {
  padding: 8px 14px;
}

.btn-outline-xs {
  padding: 6px 12px;
}

.btn-outline-sm:hover,
.btn-outline-xs:hover {
  border-color: #cbd5e1;
  background-color: #f8fafc;
  color: var(--text-strong);
}

.btn-outline-sm:focus-visible,
.btn-outline-xs:focus-visible,
.btn-primary-full:focus-visible,
.btn-model-toggle:focus-visible,
.ratio-card:focus-visible,
.segmented-btn:focus-visible,
.stepper-btn:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* Main Content */
.main-content {
  padding-block: 32px;
}

.page-intro {
  margin-bottom: 32px;
}

.page-title {
  max-width: 48rem;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-strong);
  line-height: 1.2;
}

@media (min-width: 640px) {
  .page-title {
    font-size: 30px;
  }
}

.page-subtitle {
  margin-top: 6px;
  font-size: 14px;
  color: var(--text-secondary);
}

.conditions-strip {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  border-top: 1px solid var(--border-default);
  border-bottom: 1px solid var(--border-default);
  padding-block: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}

.conditions-label {
  font-weight: 500;
  color: #1e293b;
}

.strip-sep {
  color: #cbd5e1;
}

/* Studio 5/7 Split Grid */
.studio-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  align-items: stretch;
  scroll-margin-top: 80px;
}

@media (min-width: 1024px) {
  .studio-grid {
    grid-template-columns: repeat(12, minmax(0, 1fr));
  }

  .studio-form-col {
    grid-column: span 5 / span 5;
  }

  .studio-model-col {
    grid-column: span 7 / span 7;
  }
}

/* Cards */
.card {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-default);
  background-color: var(--bg-surface);
}

.form-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  padding: 24px;
}

.form-fields {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.card-header-inner {
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 14px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text-primary);
}

.card-subtitle {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Form Controls */
.field-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.field-label {
  font-size: 14px;
  font-weight: 500;
  color: #1e293b;
}

.field-label-block {
  display: block;
  margin-bottom: 8px;
}

.field-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.area-input-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

input[type="range"].studio-range {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  background: transparent;
  cursor: pointer;
}

input[type="range"].studio-range::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 9999px;
  background: #e2e8f0;
}

input[type="range"].studio-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  height: 18px;
  width: 18px;
  margin-top: -6px;
  border-radius: 9999px;
  background: var(--brand);
  border: 2px solid #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.28);
  transition: transform 150ms cubic-bezier(0.16, 1, 0.3, 1);
}

input[type="range"].studio-range::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

input[type="range"].studio-range::-moz-range-track {
  height: 6px;
  border-radius: 9999px;
  background: #e2e8f0;
}

input[type="range"].studio-range::-moz-range-thumb {
  height: 18px;
  width: 18px;
  border-radius: 9999px;
  background: var(--brand);
  border: 2px solid #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.28);
}

.area-number-wrap {
  position: relative;
  width: 96px;
  flex-shrink: 0;
}

.area-number-input {
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-input);
  background-color: var(--bg-surface);
  padding: 8px 32px 8px 12px;
  text-align: right;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.area-number-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}

.area-unit {
  pointer-events: none;
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--text-muted);
}

/* Ratio Cards */
.ratio-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.ratio-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background-color: var(--bg-surface);
  padding: 10px 8px;
  text-align: center;
  color: #334155;
  transition: border-color 150ms ease, background-color 150ms ease,
    color 150ms ease;
}

.ratio-card:hover {
  border-color: #cbd5e1;
  background-color: #f8fafc;
}

.ratio-card.is-active {
  border-color: var(--brand);
  background-color: var(--brand-soft);
  color: var(--brand);
}

.ratio-preview {
  display: block;
  height: 16px;
  border-radius: 2px;
  border: 2px solid #94a3b8;
  background-color: #f1f5f9;
}

.ratio-card.is-active .ratio-preview {
  border-color: var(--brand);
  background-color: rgba(29, 78, 216, 0.15);
}

.ratio-preview-sq {
  width: 16px;
}

.ratio-preview-rect {
  width: 24px;
}

.ratio-preview-long {
  width: 32px;
}

.ratio-name {
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
}

.ratio-tag {
  font-size: 11px;
  color: var(--text-muted);
}

/* Segmented Controls */
.segmented {
  display: grid;
  gap: 6px;
  border-radius: var(--radius-md);
  background-color: var(--bg-subtle);
  padding: 4px;
}

.segmented-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segmented-compact {
  gap: 4px;
}

.segmented-btn {
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  padding: 8px 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: background-color 150ms ease, color 150ms ease,
    box-shadow 150ms ease;
}

.segmented-compact .segmented-btn {
  padding: 6px 4px;
}

.segmented-btn:hover {
  color: var(--text-primary);
}

.segmented-btn.is-active {
  background-color: var(--bg-surface);
  color: var(--text-strong);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

/* Ambientes & Baños Row */
.two-col-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 640px) {
  .two-col-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background-color: var(--bg-surface);
  padding: 4px 6px;
}

.stepper-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #334155;
  transition: background-color 150ms ease;
}

.stepper-btn:hover:not(:disabled) {
  background-color: var(--bg-subtle);
}

.stepper-btn:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.stepper-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Submit Footer */
.form-footer {
  margin-top: 24px;
  border-top: 1px solid var(--border-subtle);
  padding-top: 20px;
}

.btn-primary-full {
  display: inline-flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-md);
  background-color: var(--brand);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  white-space: nowrap;
  transition: background-color 150ms ease, opacity 150ms ease;
}

.btn-primary-full:hover:not(:disabled) {
  background-color: var(--brand-hover);
}

.btn-primary-full:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.error-banner {
  margin-top: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--red-200);
  background-color: var(--red-50);
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--red-700);
}

/* 2.5D Model Card */
.model-card {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.model-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border-default);
  padding: 14px 20px;
}

.model-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-model-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background-color: var(--bg-surface);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: #334155;
  transition: border-color 150ms ease, background-color 150ms ease,
    color 150ms ease;
}

.btn-model-toggle:hover {
  border-color: #cbd5e1;
  background-color: #f8fafc;
}

.btn-model-toggle.is-cutaway {
  border-color: var(--brand);
  background-color: var(--brand-soft);
  color: var(--brand);
}

.model-stage {
  position: relative;
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background-color: var(--bg-stage);
  padding: 16px 12px;
}

.model-svg {
  width: 100%;
  height: auto;
  max-height: 440px;
  user-select: none;
  display: block;
}

.slab-group {
  pointer-events: none;
  transition: opacity 200ms cubic-bezier(0.16, 1, 0.3, 1),
    transform 200ms cubic-bezier(0.16, 1, 0.3, 1);
}

.slab-group.is-hidden {
  opacity: 0;
  transform: translateY(-14px);
}

.model-footer {
  border-top: 1px solid var(--border-default);
  background-color: var(--bg-surface);
  padding: 14px 20px;
}

.geometry-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
}

@media (min-width: 640px) {
  .geometry-strip {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.geo-label {
  font-size: 12px;
  color: var(--text-muted);
}

.geo-val {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.geo-val-text {
  font-weight: 500;
}

.model-legend {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 20px;
  border-top: 1px solid var(--border-subtle);
  padding-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid rgba(148, 163, 184, 0.5);
}

.legend-swatch-bath {
  border-color: rgba(59, 130, 246, 0.6);
  background-color: #dbeafe;
}

.legend-swatch-slab {
  border-color: rgba(100, 116, 139, 0.6);
  background-color: rgba(226, 232, 240, 0.7);
}

.legend-mono {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Results & History Sections */
.section-block {
  margin-top: 40px;
  scroll-margin-top: 80px;
}

.section-header-row {
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.section-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-strong);
}

.section-subtitle {
  margin-top: 2px;
  font-size: 14px;
  color: var(--text-muted);
}

.stale-banner {
  font-size: 12px;
  font-weight: 500;
  color: var(--amber-700);
}

.empty-card {
  border-radius: var(--radius-lg);
  border: 1px dashed #cbd5e1;
  background-color: var(--bg-surface);
  padding: 40px 24px;
  text-align: center;
}

.empty-title {
  font-size: 14px;
  font-weight: 500;
  color: #1e293b;
}

.empty-subtitle {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 14px;
}

.data-table thead tr {
  border-bottom: 1px solid var(--border-default);
  background-color: var(--bg-table-head);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.data-table th {
  padding: 12px 20px;
  font-weight: 600;
}

.data-table td {
  padding: 12px 20px;
  border-top: 1px solid var(--border-subtle);
}

.data-table tbody tr:first-child td {
  border-top: none;
}

.data-table tbody tr {
  transition: background-color 120ms ease;
}

.data-table tbody tr:hover {
  background-color: rgba(248, 250, 252, 0.75);
}

.data-table-sm {
  font-size: 12px;
}

.data-table-sm th,
.data-table-sm td {
  padding: 10px 20px;
}

.cell-material {
  font-weight: 500;
  color: var(--text-primary);
}

.cell-teorico {
  color: var(--text-secondary);
}

.cell-unit {
  font-size: 12px;
  color: var(--text-faint);
}

.cell-final {
  font-weight: 600;
  color: var(--text-strong);
}

.cell-final .cell-unit {
  font-weight: 400;
  color: var(--text-muted);
}

.pct-pos {
  font-weight: 500;
  color: var(--amber-700);
}

.pct-neg {
  font-weight: 500;
  color: var(--emerald-700);
}

.pct-neutral {
  color: var(--text-muted);
}

/* Disclosure */
.disclosure-bar {
  border-top: 1px solid var(--border-default);
  padding: 12px 20px;
}

.disclosure-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  padding: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color 150ms ease;
}

.disclosure-trigger:hover {
  color: var(--text-strong);
}

.chevron {
  transition: transform 150ms ease;
}

.chevron.is-open {
  transform: rotate(180deg);
}

.detalles-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  border-top: 1px solid var(--border-subtle);
  padding-top: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

@media (min-width: 640px) {
  .detalles-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .detalle-note {
    grid-column: span 3 / span 3;
  }
}

.detalle-label {
  display: block;
  color: var(--text-faint);
}

.detalle-val {
  font-weight: 600;
  color: var(--text-primary);
}

.detalle-note {
  color: var(--text-muted);
}

/* History Panel */
.registros-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
}

.registros-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  background: transparent;
  padding: 0;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  transition: color 150ms ease;
}

.registros-trigger:hover {
  color: var(--brand);
}

.registros-count {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

.registros-panel {
  border-top: 1px solid var(--border-default);
}

.registros-empty {
  padding: 24px 20px;
  font-size: 14px;
  color: var(--text-muted);
}

/* Footer */
.site-footer {
  margin-top: 48px;
  border-top: 1px solid var(--border-default);
  padding-top: 20px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
