/* ==========================================================================
   DESIGN TOKENS & SYSTEM (Polestar Edition with Copy & Dynamic URL Support)
   ========================================================================== */
:root {
  --bg-app: #F6F6F6;
  --bg-surface: #FFFFFF;
  --bg-track: #E8E8E8;
  --bg-subtle: #F0F0F0;
  --bg-overlay: rgba(17, 17, 17, 0.45);
  
  --color-ink: #111111;
  --color-ink-muted: #575A5E;
  --color-ink-faint: #63666A;
  
  --color-border: #E0E0E0;
  --color-border-hover: #B0B0B0;
  --color-border-active: #111111;

  --color-accent: #EA580C;
  --color-accent-hover: #C2410C;

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", "Consolas", Menlo, monospace;

  --fs-2xs: clamp(0.68rem, 0.65rem + 0.12vw, 0.74rem);
  --fs-xs: clamp(0.78rem, 0.74rem + 0.18vw, 0.84rem);
  --fs-sm: clamp(0.88rem, 0.84rem + 0.22vw, 0.94rem);
  --fs-base: clamp(0.96rem, 0.90rem + 0.28vw, 1.04rem);
  --fs-md: clamp(1.15rem, 1.05rem + 0.35vw, 1.25rem);
  --fs-lg: clamp(1.35rem, 1.22rem + 0.65vw, 1.60rem);
  --fs-hero: clamp(1.65rem, 1.45rem + 1.0vw, 2.05rem);

  --space-2xs: 0.25rem;
  --space-xs: 0.5rem;
  --space-sm: 0.75rem;
  --space-md: 1.0rem;
  --space-lg: 1.5rem;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-card: 10px;
  --radius-sheet: 16px;
  --radius-pill: 9999px;
  
  --shadow-subtle: 0 1px 3px rgba(0, 0, 0, 0.03);
  --shadow-bar: 0 -2px 12px rgba(0, 0, 0, 0.05);
  --shadow-sheet: 0 -8px 32px rgba(0, 0, 0, 0.18);

  --max-w-app: 460px;
  --max-w-header: 1200px;
}

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

body {
  background-color: var(--bg-app);
  color: var(--color-ink);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.015em;
}

/* Header */
.global-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--color-border);
  width: 100%;
}

.header-inner {
  max-width: var(--max-w-header);
  margin: 0 auto;
  padding: 0.75rem var(--space-md);
  display: flex;
  justify-content: center;
  align-items: center;
}

.brand-logo-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  text-decoration: none;
  color: var(--color-ink);
}

.brand-badge {
  background: var(--color-ink);
  color: #FFFFFF;
  font-weight: 700;
  font-size: var(--fs-xs);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  letter-spacing: -0.02em;
}

.brand-name {
  font-weight: 700;
  font-size: var(--fs-base);
  letter-spacing: -0.02em;
  color: var(--color-ink);
}

/* App Wrapper */
.app-wrapper {
  max-width: var(--max-w-app);
  margin: var(--space-xs) auto calc(88px + env(safe-area-inset-bottom, 0px)) auto;
  padding: 0 var(--space-xs);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

/* Tabs */
.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: #EAEAEA;
  padding: 2px;
  border-radius: var(--radius-md);
  gap: 2px;
}

.category-card {
  background: transparent;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.25rem;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.category-card.is-active {
  background: var(--bg-surface);
  border-color: var(--color-accent);
  box-shadow: var(--shadow-subtle);
}

.category-icon {
  width: 16px;
  height: 16px;
  stroke: var(--color-ink-muted);
  fill: none;
  stroke-width: 1.8;
}

.category-card.is-active .category-icon {
  stroke: var(--color-ink);
}

.category-name {
  font-size: var(--fs-2xs);
  font-weight: 600;
  color: var(--color-ink-muted);
}

.category-card.is-active .category-name {
  color: var(--color-ink);
  font-weight: 700;
}

/* Ingress */
.scenario-intro-card {
  background: var(--bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  padding: 0.75rem var(--space-md);
  box-shadow: var(--shadow-subtle);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.scenario-intro-title {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--color-ink);
}

.scenario-intro-text {
  font-size: var(--fs-2xs);
  color: var(--color-ink-muted);
  line-height: 1.4;
}

/* Controls */
.unified-controls-card {
  background: var(--bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-subtle);
  padding: 0.2rem var(--space-md);
  display: flex;
  flex-direction: column;
}

.unified-field-row {
  padding: 0.7rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.unified-field-row:not(:last-child) {
  border-bottom: 1px solid var(--color-border);
}

.field-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.field-label-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-caption {
  font-size: var(--fs-2xs);
  font-weight: 700;
  color: var(--color-ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
}

.info-help-btn {
  position: relative;
  background: var(--bg-track);
  border: none;
  color: var(--color-ink-muted);
  width: 18px;
  height: 18px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.info-help-btn::after {
  content: '';
  position: absolute;
  inset: -13px;
}

.info-help-btn:hover {
  background: var(--color-border);
  color: var(--color-ink);
}

.field-sub-hint {
  font-size: var(--fs-2xs);
  color: var(--color-ink-faint);
  line-height: 1.35;
}

.toggle-subtle {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-2xs);
  font-weight: 600;
  color: var(--color-ink-muted);
  cursor: pointer;
  min-height: 32px;
}

.toggle-subtle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.val-display-wrap {
  display: flex;
  align-items: center;
  margin: 0.1rem 0;
}

.editable-input-box {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  width: 100%;
}

.currency-input {
  font-family: var(--font-sans);
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--color-ink);
  font-variant-numeric: tabular-nums;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  padding: 0.15rem 0.2rem;
  width: 100%;
  max-width: 220px;
  outline: none;
  transition: all 0.15s ease;
}

.currency-input:hover {
  background: #F0F0F0;
}

.currency-input:focus {
  background: #FFFFFF;
  border-color: var(--color-accent);
}

.val-unit {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--color-ink-muted);
}

.subtle-notice-card {
  background: #FAFAFA;
  border-left: 2px solid var(--color-accent);
  border-radius: 2px;
  padding: 0.55rem 0.7rem;
  margin-top: 0.3rem;
  font-size: var(--fs-2xs);
  color: var(--color-ink-muted);
  line-height: 1.4;
}

/* Slider Track */
.slider-container {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.app-slider {
  width: 100%;
  height: 6px;
  border-radius: var(--radius-pill);
  outline: none;
  -webkit-appearance: none;
  cursor: pointer;
  background: linear-gradient(to right, var(--color-accent) 0%, var(--color-accent) 50%, var(--bg-track) 50%, var(--bg-track) 100%);
}

.app-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #FFFFFF;
  border: 1.5px solid var(--color-ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  cursor: grab;
  transition: transform 0.1s ease, border-color 0.1s ease;
}

.app-slider::-webkit-slider-thumb:hover {
  border-color: var(--color-accent);
}

.app-slider::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.15);
  border-color: var(--color-accent);
}

.slider-limits {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--color-ink-faint);
}

/* Bostadsrätt Panel */
.brf-panel-card {
  background: var(--bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  padding: var(--space-md);
  box-shadow: var(--shadow-subtle);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.brf-header-box h2 {
  font-size: var(--fs-sm);
  font-weight: 700;
}

.brf-header-box p {
  font-size: var(--fs-xs);
  color: var(--color-ink-muted);
}

.brf-section-block {
  border-top: 1px solid var(--color-border);
  padding-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brf-section-title {
  font-size: var(--fs-2xs);
  font-weight: 700;
  text-transform: uppercase;
  color: var(--color-ink-muted);
  letter-spacing: 0.04em;
}

.brf-fee-row {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-xs);
}

.brf-disclaimer {
  font-size: var(--fs-2xs);
  color: var(--color-ink-faint);
  line-height: 1.35;
}

/* Sticky Tesla Bar */
.sticky-tesla-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 90;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--color-border);
  box-shadow: var(--shadow-bar);
  padding: 0.65rem 1rem max(0.65rem, env(safe-area-inset-bottom, 0px));
}

.sticky-bar-inner {
  max-width: var(--max-w-app);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sticky-bar-sum-block {
  display: flex;
  flex-direction: column;
}

.sticky-bar-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sticky-bar-sum {
  font-size: var(--fs-md);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--color-ink);
  font-variant-numeric: tabular-nums;
}

.btn-open-breakdown {
  background: #F0F0F0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 0.6rem 1.05rem;
  min-height: 44px;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--color-ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.btn-open-breakdown:hover {
  background: #E5E5E5;
  border-color: var(--color-border-hover);
}

/* Bottom Sheet */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.sheet-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.sheet-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 201;
  background: var(--bg-surface);
  border-top-left-radius: var(--radius-sheet);
  border-top-right-radius: var(--radius-sheet);
  box-shadow: var(--shadow-sheet);
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
}

.sheet-panel.is-visible {
  transform: translateY(0);
}

.sheet-header {
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  padding: 1rem var(--space-md) 0.75rem var(--space-md);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--color-border);
}

.sheet-title {
  font-size: var(--fs-base);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sheet-close-btn {
  background: #F0F0F0;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  color: var(--color-ink-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sheet-close-btn:hover {
  background: #E0E0E0;
}

.sheet-content {
  max-width: var(--max-w-app);
  margin: 0 auto;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.sheet-total-box {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: var(--space-sm);
}

.sheet-total-hero {
  font-size: var(--fs-hero);
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--color-ink);
  font-variant-numeric: tabular-nums;
}

.sheet-breakdown-row {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-xs);
  color: var(--color-ink-muted);
}

.sheet-breakdown-row strong {
  color: var(--color-ink);
  font-variant-numeric: tabular-nums;
}

.sheet-narrative-block {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sheet-block-title {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--color-ink);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sheet-block-desc {
  font-size: var(--fs-xs);
  color: var(--color-ink-muted);
  line-height: 1.45;
}

.sheet-formula {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--color-ink);
  background: #F4F4F4;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  margin-top: 3px;
  display: inline-block;
}

.sheet-footer-legal {
  font-size: var(--fs-2xs);
  color: var(--color-ink-faint);
  line-height: 1.35;
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-xs);
}

/* Action button i Bottom Sheet */
.sheet-action-wrap {
  margin-top: var(--space-2xs);
}

.btn-copy-calc {
  width: 100%;
  background: var(--color-ink);
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.75rem var(--space-md);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: -0.01em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-copy-calc:hover {
  background: #2B2E33;
}

.btn-copy-calc:active {
  transform: scale(0.98);
}

.btn-copy-calc.is-copied {
  background: var(--color-accent);
}

.copy-icon {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* FAQ */
.faq-section {
  background: var(--bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  padding: var(--space-md);
  box-shadow: var(--shadow-subtle);
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
  margin-top: var(--space-xs);
}

.faq-title {
  font-size: var(--fs-sm);
  font-weight: 700;
  margin-bottom: var(--space-2xs);
}

.faq-item {
  border-top: 1px solid var(--color-border);
}

.faq-item summary {
  padding: 0.65rem 0;
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.faq-item summary span {
  font-size: 14px;
  font-family: var(--font-mono);
  color: var(--color-ink-muted);
  transition: transform 0.15s ease;
}

.faq-item[open] summary span {
  transform: rotate(45deg);
}

.faq-item summary::-webkit-details-marker {
  display: none;
}

.faq-body {
  padding-bottom: 0.65rem;
  font-size: var(--fs-2xs);
  color: var(--color-ink-muted);
  line-height: 1.45;
}

.app-footer {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--color-ink-faint);
  padding: 0 var(--space-xs);
  margin-top: var(--space-2xs);
}