@import url("../Buda Gateway Design System/tokens/colors.css");
@import url("../Buda Gateway Design System/tokens/typography.css");
@import url("../Buda Gateway Design System/tokens/spacing.css");
@import url("../Buda Gateway Design System/tokens/fonts.css");

:root {
  --calc-bay-available: rgba(188, 81, 42, 0.72);
  --calc-bay-hover: rgba(207, 160, 76, 0.52);
  --calc-bay-selected: var(--color-olive);
  --calc-bay-leased: var(--color-tan);
  --calc-bay-stroke: #f6f0e6;
}

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

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background: var(--surface-page);
  -webkit-font-smoothing: antialiased;
}

.calc-root {
  max-width: 1120px;
  margin: 0 auto;
  background: var(--surface-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* ----- Building toolbar ----- */
.building-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  border-bottom: var(--border-width) solid var(--border-subtle);
}

.refresh-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-1);
  margin-left: auto;
  padding-bottom: var(--space-2);
}

.status-line {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-size: 10px;
  line-height: 1.3;
  color: var(--text-muted);
  max-width: 220px;
  text-align: right;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-gold);
  flex-shrink: 0;
}

.status-dot.error {
  background: var(--color-red-light);
}

.refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--surface-card);
  border: var(--border-width) solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  cursor: pointer;
  transition: background-color 0.15s ease-out, border-color 0.15s ease-out;
}

.refresh-btn:hover {
  background: var(--surface-sunken);
  border-color: var(--border-strong);
}

.refresh-btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.refresh-btn svg {
  width: 14px;
  height: 14px;
  transition: transform 0.5s ease-out;
}

.refresh-btn.spinning svg {
  transform: rotate(360deg);
}

/* ----- Main ----- */
.main {
  padding: var(--space-6);
  background: var(--surface-page);
}

.is-hidden {
  display: none !important;
}

.loading-state,
.error-state {
  text-align: center;
  padding: var(--space-8) var(--space-5);
  color: var(--text-secondary);
  font-size: var(--text-base);
}

.spinner {
  width: 32px;
  height: 32px;
  margin: 0 auto var(--space-4);
  border: 2px solid var(--border-subtle);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.error-state h3 {
  font-family: var(--font-display);
  color: var(--text-primary);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  margin: 0 0 var(--space-3);
}

/* ----- Tabs (design system pattern) ----- */
.tab-list {
  display: flex;
  flex-wrap: wrap;
  flex: 1;
  gap: 0;
  min-width: 0;
}

.tab-btn {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 500;
  letter-spacing: var(--tracking-normal);
  text-transform: none;
  padding: 10px 18px;
  margin-bottom: -1px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.15s ease-out, border-color 0.15s ease-out;
}

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

.tab-btn.is-active {
  font-weight: 700;
  color: var(--brand-primary);
  border-bottom-color: var(--brand-primary);
  background: none;
}

.tab-btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* ----- Layout & cards ----- */
.layout-stack {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: var(--space-5);
}

.floor-section {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.results-section {
  flex: 0 0 260px;
  width: 260px;
  display: flex;
  flex-direction: column;
}

.results-section,
.floor-section {
  background: var(--surface-card);
  border: var(--border-width) solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.panel-heading-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.empty-prompt {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  margin: 0;
  white-space: nowrap;
}

.empty-prompt.is-hidden {
  display: none;
}

.btn-clear {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  color: var(--color-white);
  background: var(--brand-primary);
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
  transition: background-color 0.15s ease-out;
}

.btn-clear:hover,
.btn-clear:focus-visible {
  background: var(--color-red-dark);
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.btn-clear:disabled {
  display: none;
}

/* ----- Metrics ----- */
.metrics-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: var(--border-width) solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-card);
}

.metric-cell {
  padding: var(--space-4);
  border-bottom: var(--border-width) solid var(--border-subtle);
  min-height: 72px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.metric-cell:nth-child(even) {
  background: var(--surface-sunken);
}

.metric-cell:last-child {
  border-bottom: none;
}

.metric-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.metrics-grid .metric-value {
  font-family: var(--font-body);
  font-size: clamp(var(--text-lg), 3.5vw, var(--text-xl));
  font-weight: 700;
  color: var(--brand-tertiary);
  line-height: var(--leading-tight);
  text-align: left;
}

.metric-value.is-deep {
  color: var(--text-primary);
}

.metric-value.metric-empty {
  color: var(--text-muted);
  font-size: var(--text-xl);
}

/* ----- Floor plan ----- */
.svg-wrap {
  position: relative;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: var(--border-width) solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
}

.floor-bg {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

.floor-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.floor-overlay .suite-hit {
  pointer-events: auto;
}

.suite-hit {
  stroke: var(--calc-bay-stroke);
  stroke-width: 1;
  cursor: pointer;
  transition: fill 0.18s ease-out;
  fill: var(--calc-bay-available);
}

.suite-hit[data-status="available"][data-selected="false"] {
  fill: var(--calc-bay-available);
  stroke: var(--calc-bay-stroke);
}

.suite-hit[data-status="available"][data-selected="true"] {
  fill: var(--calc-bay-selected);
  stroke: var(--color-olive-dark);
}

.suite-hit[data-status="leased"] {
  fill: var(--calc-bay-leased);
  opacity: 0.75;
  cursor: not-allowed;
  pointer-events: none;
  stroke: var(--color-tan-dark);
}

.suite-hit:focus {
  outline: none;
}

.suite-hit:focus-visible {
  stroke: var(--brand-primary);
  stroke-width: 2;
}

@media (hover: hover) {
  .suite-hit[data-status="available"][data-selected="false"]:hover {
    fill: var(--calc-bay-hover);
    stroke: var(--color-gold-dark);
  }
}

.suite-label-num {
  font-family: var(--font-body);
  font-weight: 700;
  fill: var(--color-olive-dark);
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: middle;
}

.suite-label-sf {
  font-family: var(--font-body);
  font-weight: 500;
  fill: var(--text-secondary);
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: middle;
}

.suite-label-status {
  font-family: var(--font-body);
  font-weight: 700;
  fill: var(--text-muted);
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: middle;
  letter-spacing: 0.04em;
}

.suite-label-group.is-selected .suite-label-num,
.suite-label-group.is-selected .suite-label-sf,
.suite-label-group.is-selected .suite-label-status {
  fill: var(--color-cream);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-items: center;
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: var(--border-width) solid var(--border-subtle);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.swatch {
  width: 24px;
  height: 14px;
  border: var(--border-width) solid var(--border-strong);
  border-radius: var(--radius-sm);
}

.swatch-default {
  background: var(--color-red-light);
  border-color: var(--calc-bay-stroke);
}

.swatch-hover-hint {
  background: var(--color-gold-light);
  border-color: var(--color-gold-dark);
}

.swatch-selected {
  background: var(--calc-bay-selected);
}

.swatch-leased {
  background: var(--calc-bay-leased);
}

/* ----- Footer ----- */
.footer {
  margin-top: auto;
  padding-top: var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  border-top: var(--border-width) solid var(--border-subtle);
}

.footer-specs {
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 var(--space-2);
  line-height: var(--leading-relaxed);
}

.footer-disc {
  margin: 0;
  color: var(--text-muted);
  max-width: 65ch;
  line-height: var(--leading-relaxed);
}

@media (max-width: 860px) {
  .layout-stack {
    flex-direction: column;
  }

  .results-section {
    flex: none;
    width: auto;
  }
}

@media (max-width: 640px) {
  .calc-root {
    margin: 0;
    border-radius: 0;
  }

  .building-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .refresh-block {
    align-items: flex-end;
    margin-left: 0;
    padding-bottom: var(--space-3);
  }

  .main {
    padding: var(--space-4);
  }
}
