/**
 * ICF Designer - Design System
 * ============================
 * 
 * PROFESSIONAL DARK THEME
 * Extracted from UI mockups (Nov 2, 2025)
 * 
 * This file defines all design tokens used across the entire application.
 * All pages should import this file for consistent styling.
 */

/* ============================================================================
   COLOR PALETTE
   ============================================================================ */

:root {
  /* Primary Colors */
  --color-primary: #4A9EFF;           /* Blue accent - buttons, links, highlights */
  --color-primary-hover: #3D8AE6;     /* Darker blue for hover states */
  --color-primary-light: #6DB2FF;     /* Lighter blue for subtle accents */
  
  /* Background Colors */
  --color-bg-primary: #1a1d29;        /* Main dark background */
  --color-bg-secondary: #22263a;      /* Card/panel backgrounds */
  --color-bg-tertiary: #2a2f45;       /* Elevated elements (modals, dropdowns) */
  --color-bg-input: #1e2235;          /* Input field backgrounds (slightly lighter for visibility) */
  --color-bg-hover: #2d3248;          /* Hover state for interactive elements */
  
  /* Text Colors */
  --color-text-primary: #ffffff;      /* Primary text (headings, important) */
  --color-text-secondary: #b8bdd0;    /* Secondary text (descriptions, labels) */
  --color-text-tertiary: #8891a8;     /* Tertiary text (placeholders, hints) */
  --color-text-muted: #606680;        /* Very subtle text */
  
  /* Border Colors */
  --color-border-primary: #3a3f5c;    /* Main borders */
  --color-border-secondary: #2d3248;  /* Subtle borders */
  --color-border-input: #5a6585;      /* Input borders (subtle white-ish for visibility) */
  --color-border-focus: #4A9EFF;      /* Focus state borders */
  
  /* Status Colors */
  --color-success: #4CAF50;           /* Success states */
  --color-warning: #FF9800;           /* Warning states */
  --color-error: #F44336;             /* Error states */
  --color-info: #2196F3;              /* Info states */
  
  /* Brand Colors */
  --color-nudura: #7c8b9f;            /* NUDURA brand color */
  
  /* SVG Blueprint Colors - centralized for all thumbnails and wall drawings */
  --svg-bg: #0f172a;                  /* Blueprint dark background (Slate 900) */
  --svg-border: #1e293b;              /* Blueprint border (Slate 800) */
  --svg-wall-line: #38bdf8;           /* Wall lines (Sky 400) */
  --svg-wall-line-highlight: #5eead4; /* Highlighted wall (Teal 300) */
  --svg-inner-line: #64748b;          /* Inner wall lines (Slate 500) */
  --svg-inner-line-alt: #94a3b8;      /* Alt inner lines (Slate 400) */
  --svg-text: #94a3b8;                /* SVG text (Slate 400) */
  --svg-text-highlight: #38bdf8;      /* Highlighted text (Sky 400) */
  
  /* Semantic Colors */
  --color-checkbox-checked: #4A9EFF;
  --color-radio-selected: #4A9EFF;
}

/* ============================================================================
   TYPOGRAPHY
   ============================================================================ */

:root {
  /* Font Families */
  --font-primary: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  
  /* Font Sizes */
  --font-size-xs: 0.75rem;      /* 12px */
  --font-size-sm: 0.875rem;     /* 14px */
  --font-size-base: 1rem;       /* 16px */
  --font-size-lg: 1.125rem;     /* 18px */
  --font-size-xl: 1.25rem;      /* 20px */
  --font-size-2xl: 1.5rem;      /* 24px */
  --font-size-3xl: 2rem;        /* 32px */
  --font-size-4xl: 2.5rem;      /* 40px */
  --font-size-5xl: 3rem;        /* 48px */
  
  /* Line Heights */
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.75;
  
  /* Font Weights */
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
}

/* ============================================================================
   SPACING SYSTEM (8px grid)
   ============================================================================ */

:root {
  --space-1: 0.25rem;   /* 4px */
  --space-2: 0.5rem;    /* 8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.25rem;   /* 20px */
  --space-6: 1.5rem;    /* 24px */
  --space-7: 1.75rem;   /* 28px */
  --space-8: 2rem;      /* 32px */
  --space-10: 2.5rem;   /* 40px */
  --space-12: 3rem;     /* 48px */
  --space-16: 4rem;     /* 64px */
  --space-20: 5rem;     /* 80px */
  --space-24: 6rem;     /* 96px */
}

/* ============================================================================
   BORDER RADIUS
   ============================================================================ */

:root {
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;
}

/* ============================================================================
   SHADOWS
   ============================================================================ */

:root {
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
  --shadow-inner: inset 0 2px 4px 0 rgba(0, 0, 0, 0.3);
}

/* ============================================================================
   TRANSITIONS
   ============================================================================ */

:root {
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================================
   Z-INDEX LAYERS
   ============================================================================ */

:root {
  --z-base: 0;
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;
}

/* ============================================================================
   GLOBAL STYLES
   ============================================================================ */

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

body {
  font-family: var(--font-primary);
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  background-color: var(--color-bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================================================
   COMPONENT STYLES
   ============================================================================ */

/* Cards */
.card {
  background-color: var(--color-bg-secondary);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: all var(--transition-base);
}

.card:hover {
  border-color: var(--color-border-primary);
  box-shadow: var(--shadow-md);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled,
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.35);
}

.global-flashes {
  position: fixed;
  top: 104px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  display: grid;
  gap: var(--space-2);
  width: min(1120px, calc(100% - 32px));
  margin: 0;
  pointer-events: none;
}

.global-flash {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: var(--radius-md);
  color: var(--color-text-primary);
  background: rgba(59, 130, 246, 0.12);
  box-shadow: 0 12px 30px rgba(2,6,23,.3);
  pointer-events: auto;
}

.global-flash--success { border-color: rgba(16,185,129,.4); background: rgba(16,185,129,.14); }
.global-flash--warning { border-color: rgba(245,158,11,.42); background: rgba(245,158,11,.14); }
.global-flash--error { border-color: rgba(239,68,68,.42); background: rgba(239,68,68,.14); }
.global-flash__dismiss { flex: 0 0 auto; padding: 0 3px; border: 0; background: transparent; color: inherit; font-size: 22px; line-height: 1; }
@media (max-width: 720px) { .global-flashes { top: 92px; width:calc(100% - 20px); } }

/* Envelope-stage header order: identity, project links, scoped values, then tools. */
.app-header .home-link { order: -1; }
.app-header .app-logo { order: 0; }
.app-header .project-shortcuts,
.app-header .ma-header-link { order: 1; }
.app-header .north-direction-indicator,
.app-header .ma-north-indicator,
.app-header .ma-header-spacer { order: 2; }
.app-header #costTicker { order: 3; }
.app-header #wasteTicker,
.app-header .ma-waste-ticker { order: 4; }
.app-header #saveStatus { order: 5; }
.app-header .brand-logo { order: 6; }

.btn-primary {
  background-color: var(--color-primary);
  color: white;
}

.btn-primary:hover {
  background-color: var(--color-primary-hover);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background-color: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border-primary);
}

.btn-secondary:hover {
  background-color: var(--color-bg-hover);
}

.btn-lg {
  padding: var(--space-4) var(--space-8);
  font-size: var(--font-size-lg);
}

.btn-success {
  background-color: var(--color-success);
  color: white;
  border: none;
}

.btn-success:hover {
  background-color: var(--color-success-hover, #3d8b40);
  box-shadow: var(--shadow-md);
}

.btn-danger {
  background-color: var(--color-danger, #ef4444);
  color: white;
  border: none;
}

.btn-danger:hover {
  background-color: var(--color-danger-hover, #dc2626);
  box-shadow: var(--shadow-md);
}

.btn-ghost-success {
  background-color: rgba(76, 175, 80, 0.1);
  color: var(--color-success);
  border: 1px solid var(--color-success);
}

.btn-ghost-success:hover {
  background-color: rgba(76, 175, 80, 0.2);
}

/* Inputs */
.input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-size: var(--font-size-base);
  color: var(--color-text-primary);
  background-color: var(--color-bg-input);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.input:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.1);
}

/* Compact inline input — for sidebar dimension fields where width is constrained */
.input-sm {
  padding: var(--space-1) var(--space-2);
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  background-color: var(--color-bg-input);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-sm);
  text-align: center;
  transition: border-color var(--transition-fast);
}

.input-sm:focus {
  outline: none;
  border-color: var(--color-border-focus);
}

.input::placeholder {
  color: var(--color-text-tertiary);
}

/* Select Dropdowns */
.select {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-size: var(--font-size-base);
  color: var(--color-text-primary);
  background-color: var(--color-bg-input);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-md);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238891a8' d='M1.41 0L6 4.58 10.59 0 12 1.41l-6 6-6-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-4) center;
  padding-right: var(--space-10);
  transition: all var(--transition-fast);
}

.select:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.1);
}

/* Labels */
.label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}

/* Checkboxes */
.checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
}

.checkbox {
  appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border-primary);
  border-radius: var(--radius-sm);
  background-color: var(--color-bg-input);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.checkbox:checked {
  background-color: var(--color-checkbox-checked);
  border-color: var(--color-checkbox-checked);
}

.checkbox:checked::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 14px;
  font-weight: bold;
}

/* Radio Buttons */
.radio-wrapper {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
}

.radio {
  appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border-primary);
  border-radius: var(--radius-full);
  background-color: var(--color-bg-input);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.radio:checked {
  border-color: var(--color-radio-selected);
}

.radio:checked::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background-color: var(--color-radio-selected);
}

/* Icons */
.icon {
  width: 20px;
  height: 20px;
  display: inline-block;
}

.icon-lg {
  width: 24px;
  height: 24px;
}

/* Module Cards (from Welcome page) */
.module-card {
  background-color: var(--color-bg-secondary);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  transition: all var(--transition-base);
  cursor: pointer;
}

.module-card:hover {
  border-color: var(--color-primary);
  background-color: var(--color-bg-tertiary);
}

.module-card.active {
  border-color: var(--color-primary);
  background-color: rgba(74, 158, 255, 0.05);
}

.module-icon {
  width: 40px;
  height: 40px;
  background-color: var(--color-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.module-content {
  flex: 1;
}

.module-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin-bottom: var(--space-1);
}

.module-description {
  font-size: var(--font-size-sm);
  color: var(--color-text-tertiary);
}

/* Checkmark Badge */
.checkmark {
  width: 24px;
  height: 24px;
  background-color: var(--color-success);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
  font-weight: bold;
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */

/* Text Utilities */
.text-primary { color: var(--color-text-primary); }
.text-secondary { color: var(--color-text-secondary); }
.text-tertiary { color: var(--color-text-tertiary); }
.text-muted { color: var(--color-text-muted); }

/* Background Utilities */
.bg-primary { background-color: var(--color-bg-primary); }
.bg-secondary { background-color: var(--color-bg-secondary); }
.bg-tertiary { background-color: var(--color-bg-tertiary); }

/* Spacing Utilities */
.m-0 { margin: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }

.p-0 { padding: 0; }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.p-8 { padding: var(--space-8); }

/* Display Utilities */
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }
.block { display: block; }
.inline-block { display: inline-block; }
.hidden { display: none; }

/* Flexbox Utilities */
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-start { justify-content: flex-start; }
.justify-end { justify-content: flex-end; }
.flex-col { flex-direction: column; }
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }

/* Border Utilities */
.rounded-sm { border-radius: var(--radius-sm); }
.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }
.rounded-full { border-radius: var(--radius-full); }

/* Width Utilities */
.w-full { width: 100%; }
.h-full { height: 100%; }

/* Text Alignment */
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* Font Weight */
.font-normal { font-weight: var(--font-weight-normal); }
.font-medium { font-weight: var(--font-weight-medium); }
.font-semibold { font-weight: var(--font-weight-semibold); }
.font-bold { font-weight: var(--font-weight-bold); }

/* ============================================================================
   GLOBAL FORM INPUT STYLING (IMPROVED VISIBILITY)
   ============================================================================ */

/* Input fields - better visibility with stronger borders and shadows */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="url"],
textarea,
select {
  background: var(--color-bg-input);
  border: 2px solid var(--color-border-input); /* Thicker border for better visibility */
  border-radius: var(--radius-md);
  color: var(--color-text-primary);
  font-size: var(--font-size-base);
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-primary);
  transition: all var(--transition-fast);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3); /* Subtle inner shadow */
}

/* Placeholder text - more visible */
input::placeholder,
textarea::placeholder {
  color: var(--color-text-tertiary);
  opacity: 0.8; /* Slightly more visible */
}

/* Focus state - clear visual feedback */
input[type="text"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.15), inset 0 1px 3px rgba(0, 0, 0, 0.2);
  background: var(--color-bg-input);
}

/* Disabled state */
input:disabled,
textarea:disabled,
select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--color-bg-tertiary);
}

/* Hide number input spinners by default */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* ============================================================================
   ONBOARDING TOOLTIPS
   ============================================================================ */

.onboarding-tooltip {
  position: absolute;
  z-index: 10000;
  max-width: 300px;
  background: linear-gradient(135deg, #1e3a5f 0%, #2d4a6f 100%);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4), 0 0 15px rgba(74, 158, 255, 0.2);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.onboarding-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

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

.onboarding-message {
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  line-height: 1.5;
  margin-bottom: var(--space-3);
}

.onboarding-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.onboarding-actions button {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-xs);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.onboarding-got-it {
  background: var(--color-primary);
  color: white;
  border: none;
}

.onboarding-got-it:hover {
  background: var(--color-primary-hover);
}

.onboarding-dont-show {
  background: transparent;
  color: var(--color-text-tertiary);
  border: 1px solid var(--color-border-secondary);
}

.onboarding-dont-show:hover {
  color: var(--color-text-primary);
  border-color: var(--color-border-primary);
}

/* Arrow positioning */
.onboarding-arrow {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #1e3a5f;
  border: 1px solid var(--color-primary);
  transform: rotate(45deg);
}

.onboarding-tooltip.position-right .onboarding-arrow {
  left: -7px;
  top: 50%;
  margin-top: -6px;
  border-right: none;
  border-top: none;
}

.onboarding-tooltip.position-left .onboarding-arrow {
  right: -7px;
  top: 50%;
  margin-top: -6px;
  border-left: none;
  border-bottom: none;
}

.onboarding-tooltip.position-top .onboarding-arrow {
  bottom: -7px;
  left: 50%;
  margin-left: -6px;
  border-top: none;
  border-left: none;
}

.onboarding-tooltip.position-bottom .onboarding-arrow {
  top: -7px;
  left: 50%;
  margin-left: -6px;
  border-bottom: none;
  border-right: none;
}

/* ============================================================================
   COLLAPSIBLE SIDEBAR SYSTEM
   ============================================================================
   Used across architectural design pages to maximize the building plan view.
   - Toggle button to collapse/expand sidebar
   - Smooth CSS transitions
   - Remembers state via localStorage
   - Override option per-page via data attributes
   ============================================================================ */

/* Main layout container for pages with collapsible sidebar */
.layout-with-sidebar {
  display: flex;
  gap: var(--space-4);
  max-width: 1800px;
  margin: 0 auto;
  padding: var(--space-4);
  min-height: calc(100vh - 120px);
}

/* Sidebar panel - collapsible */
.sidebar-panel {
  width: 360px;
  min-width: 360px;
  flex-shrink: 0;
  transition: width 0.3s ease, min-width 0.3s ease, opacity 0.3s ease;
  overflow: hidden;
  position: relative;
}

.sidebar-panel.collapsed {
  width: 48px;
  min-width: 48px;
}

/* Hide sidebar content when collapsed */
.sidebar-panel.collapsed .sidebar-content {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

/* Sidebar content wrapper */
.sidebar-content {
  transition: opacity 0.2s ease;
  opacity: 1;
}

/* Main content panel - expands when sidebar collapses */
.main-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  transition: flex 0.3s ease;
}

/* Toggle button */
.sidebar-toggle {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: 32px;
  height: 32px;
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: all 0.2s ease;
  color: var(--color-text-secondary);
}

.sidebar-toggle:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
  border-color: var(--color-border-primary);
}

/* Toggle icon - chevron */
.sidebar-toggle svg {
  width: 16px;
  height: 16px;
  transition: transform 0.3s ease;
}

.sidebar-panel.collapsed .sidebar-toggle {
  right: 8px;
}

.sidebar-panel.collapsed .sidebar-toggle svg {
  transform: rotate(180deg);
}

/* Collapsed state indicator bar */
.sidebar-collapsed-bar {
  display: none;
  flex-direction: column;
  align-items: center;
  padding-top: 60px;
  gap: var(--space-4);
}

.sidebar-panel.collapsed .sidebar-collapsed-bar {
  display: flex;
}

.sidebar-collapsed-bar .collapsed-icon {
  width: 24px;
  height: 24px;
  color: var(--color-text-tertiary);
}

.sidebar-collapsed-bar .collapsed-label {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* Building plan container - takes full height */
.building-plan-container {
  flex: 1;
  min-height: 500px;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Shared floor-plan capture surface.
   Used by plan thumbnails/full-plan views so screenshots have a consistent scale. */
.icf-plan-shot {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  height: min(760px, calc(100vh - 170px));
  max-height: min(760px, calc(100vh - 170px));
  width: 100%;
  overflow: hidden;
  background: var(--svg-bg, #0f172a);
  border: 1px solid var(--svg-border, #1e293b);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
}

.icf-plan-shot-title {
  flex: 0 0 auto;
  margin: 0 0 var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  text-align: center;
}

.pdf-underlay-visibility-controls {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--color-text-secondary);
  font-size: 11px;
  font-weight: 600;
}

.pdf-underlay-visibility-controls label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0;
  color: inherit;
  font-size: inherit;
  white-space: nowrap;
}

.pdf-underlay-visibility-controls input[type="range"] {
  width: 92px;
  margin: 0;
  accent-color: #22c55e;
}

.pdf-underlay-visibility-controls button {
  padding: 5px 9px;
  border: 1px solid rgba(34, 197, 94, 0.45);
  border-radius: 6px;
  background: rgba(34, 197, 94, 0.10);
  color: #bbf7d0;
  cursor: pointer;
  font-size: 11px;
  font-weight: 750;
}

.pdf-underlay-visibility-controls button[aria-pressed="true"] {
  background: #22c55e;
  color: #052e16;
}

.pdf-underlay-visibility-controls__locked {
  color: var(--color-text-tertiary);
  font-weight: 500;
  white-space: nowrap;
}

.building-overview-svg .pdf-plan-underlay {
  opacity: var(--pdf-underlay-page-opacity, 0.78) !important;
}

/* PDF Focus is an inspection mode: keep the raster in its original colours
   and reduce the app drawing to context without making it interactive. */
.building-overview-svg.pdf-underlay-focus svg {
  filter: none !important;
}

.building-overview-svg.pdf-underlay-focus .icf-plan-drawing {
  opacity: 0.48;
}

@media (max-width: 700px) {
  .pdf-underlay-visibility-controls {
    width: 100%;
  }
}

.icf-plan-shot-body {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icf-plan-shot-body svg,
.icf-plan-shot svg.icf-plan-svg {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
}

@media (max-width: 900px) {
  .icf-plan-shot {
    height: 65vh;
    min-height: 520px;
  }
}

@media (max-width: 640px) {
  .icf-plan-shot {
    height: 58vh;
    min-height: 420px;
  }
}

.building-plan-container .plan-header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.building-plan-container .plan-title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
}

.building-plan-container .plan-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  overflow: auto;
}

/* Wall elevation strip at bottom */
.wall-elevation-strip {
  height: 180px;
  min-height: 180px;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
  .layout-with-sidebar {
    flex-direction: column;
  }
  
  .sidebar-panel {
    width: 100% !important;
    min-width: 100% !important;
  }
  
  .sidebar-panel.collapsed {
    width: 100% !important;
    min-width: 100% !important;
    height: 48px;
  }
  
  .sidebar-panel.collapsed .sidebar-content {
    display: none;
  }
  
  .sidebar-toggle {
    display: none;
  }
}

/* ── Shared confirm modal ────────────────────────────────────────────────────
   Replaces browser confirm() with a consistent styled dialog.
   JS API: icfConfirm(message, onOk, { title, okLabel, okClass })
   HTML trigger: add data-confirm="Your message" to any button/submit.
   ────────────────────────────────────────────────────────────────────────── */
.icf-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  backdrop-filter: blur(4px);
}

.icf-confirm-box {
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 420px;
  width: 100%;
  padding: var(--space-6);
}

.icf-confirm-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin: 0 0 var(--space-3);
}

.icf-confirm-message {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  line-height: var(--line-height-relaxed);
  margin: 0 0 var(--space-5);
}

.icf-confirm-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
}

/* ── iPad / touch-screen overrides ─────────────────────────────────────────
   Uses (pointer: coarse) so these ONLY apply on touch screens (iPad, phone).
   Desktop mouse users (pointer: fine) are completely unaffected.
   ────────────────────────────────────────────────────────────────────────── */
@media (pointer: coarse) {

  /* 44px minimum tap targets (Apple HIG / WCAG 2.5.5) */
  .btn, button {
    min-height: 44px;
    padding: var(--space-3) var(--space-5);
  }
  .btn-lg {
    min-height: 52px;
  }

  /* Prevent iOS auto-zoom when focusing any input (requires font-size ≥ 16px) */
  input, select, textarea, .input {
    font-size: 16px !important;
    min-height: 44px;
  }

  /* Sidebar toggle: bigger hit area */
  .sidebar-toggle {
    width: 44px;
    height: 44px;
    display: flex; /* override the max-width:1200px rule that hides it */
  }

  /* Suppress double-tap zoom on interactive elements without disabling pinch-zoom */
  button, a, input, select, textarea, label, .btn {
    touch-action: manipulation;
  }

  /* iPad landscape (≥1024px wide) keeps side-by-side layout.
     Overrides the max-width:1200px stack rule above. */
  @media (min-width: 1024px) {
    .layout-with-sidebar {
      flex-direction: row !important;
    }
    .sidebar-panel {
      width: auto !important;
      min-width: auto !important;
    }
    .sidebar-panel.collapsed {
      width: auto !important;
      min-width: auto !important;
      height: auto;
    }
    .sidebar-panel.collapsed .sidebar-content {
      display: block;
    }
  }

  /* Safe-area insets for iPad notch / home indicator */
  .app-header {
    padding-left: max(var(--space-6), env(safe-area-inset-left));
    padding-right: max(var(--space-6), env(safe-area-inset-right));
  }
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ── Shared SVG canvas controls ─────────────────────────────────────────────
   Floating zoom / pan toolbar that sits over any SVG drawing canvas.
   Used by internal_walls, and available to any other page that needs it.
   ────────────────────────────────────────────────────────────────────────── */
.plan-control-bar {
  position: relative;
  z-index: 40;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.9);
}

.plan-control-bar__primary {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.plan-control-bar__hint {
  min-width: 120px;
  flex: 1 1 auto;
  color: var(--color-text-secondary);
  font-size: 12px;
  line-height: 1.35;
}

/* Page templates historically position each of these controls absolutely.
   Inside the shared bar they participate in normal flow, so controls cannot
   occupy or obscure one another. */
.plan-control-bar > .svg-style-toggle,
.plan-control-bar > .draw-viewport-controls,
.plan-control-bar > .draw-camera-hint,
.plan-control-bar > .plan-north-indicator,
.plan-control-bar > .ma-plan-north-indicator {
  position: static !important;
  inset: auto !important;
  transform: none !important;
  margin: 0 !important;
}

.plan-control-bar > .svg-style-toggle {
  flex: 0 0 auto;
  margin-left: auto !important;
}

.plan-control-bar > .draw-viewport-controls,
.plan-control-bar > .draw-camera-hint {
  max-width: none;
}

.plan-control-bar > .draw-camera-hint {
  flex: 1 1 auto;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  pointer-events: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.draw-camera-controls {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.86);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.draw-camera-controls button {
  min-width: 42px;
  height: 34px;
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-sm);
  background: var(--color-bg-tertiary);
  color: var(--color-text-accent, #dbeafe);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.draw-camera-controls button:hover {
  border-color: var(--color-primary);
  background: rgba(37, 99, 235, 0.38);
  color: white;
}

.draw-camera-controls .draw-camera-follow {
  min-width: 72px;
  color: var(--color-success);
}

.draw-camera-controls .draw-camera-follow.off {
  color: var(--color-text-secondary);
}

.draw-camera-hint {
  position: absolute;
  left: 14px;
  top: 14px;
  z-index: 24;
  max-width: min(520px, calc(100% - 220px));
  padding: 8px 11px;
  border: 1px solid rgba(56, 189, 248, 0.22);
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.82);
  color: var(--color-text-secondary);
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Zoom % badge injected dynamically by JS (plan_viewport.js, internal_walls) */
.svg-zoom-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 11px;
  color: var(--color-text-secondary);
}

.svg-zoom-badge button {
  background: none;
  border: 1px solid var(--color-border-secondary);
  color: var(--color-primary);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.svg-zoom-badge button:hover {
  background: var(--color-primary);
  color: white;
}

@media (max-width: 800px) {
  .plan-control-bar {
    align-items: stretch;
    flex-wrap: wrap;
  }
  .plan-control-bar__hint,
  .plan-control-bar > .draw-camera-hint {
    order: 3;
    flex-basis: 100%;
  }
  .plan-control-bar > .svg-style-toggle {
    margin-left: 0 !important;
  }
  .draw-camera-hint {
    top: auto;
    bottom: 62px;
    max-width: calc(100% - 28px);
  }
  .draw-camera-controls {
    right: 14px;
    justify-content: center;
  }
}

@media (pointer: coarse) {
  body {
    overflow-x: hidden;
  }
  .wall-delete-btn {
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 10px 12px !important;
  }
  .draw-camera-controls button {
    min-width: 44px;
    height: 44px;
  }
  .svg-zoom-badge button {
    min-height: 32px;
    padding: 4px 10px;
  }
}

/*
 * Dark presentation for engineering SVGs whose source renderer intentionally
 * remains light for PDF/export use. Keeping this at the display layer preserves
 * one authoritative path for geometry, reinforcement and annotations.
 */
.dark-technical-canvas,
.dark-technical-drawing {
  background: var(--svg-bg, #0f172a) !important;
  border-color: var(--svg-border, #1e293b) !important;
}

.dark-technical-drawing > svg {
  display: block;
  filter: invert(1) hue-rotate(180deg) brightness(1.2);
}

/* Delayed feedback for page transitions and long-running calculations. */
.icf-delayed-loading {
  position: fixed;
  inset: 0;
  z-index: 2147483647;
  display: grid;
  place-items: center;
  padding: 20px;
  pointer-events: none;
}

.icf-delayed-loading[hidden] {
  display: none;
}

.icf-delayed-loading__card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  width: min(390px, calc(100vw - 40px));
  padding: 16px 18px;
  overflow: hidden;
  border: 1px solid rgba(103, 232, 249, 0.48);
  border-radius: 16px;
  background: rgba(7, 19, 36, 0.96);
  color: #e7f8ff;
  box-shadow: 0 24px 80px rgba(2, 6, 23, 0.68), 0 0 30px rgba(14, 165, 233, 0.16);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.icf-delayed-loading__card::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, #22d3ee, #fbbf24, transparent);
  background-size: 180% 100%;
  content: "";
  animation: icf-wait-progress 1.4s ease-in-out infinite;
}

.icf-delayed-loading__builder {
  position: relative;
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(251, 191, 36, 0.38);
  border-radius: 50%;
  background: rgba(251, 191, 36, 0.1);
  filter: drop-shadow(0 0 8px rgba(251, 191, 36, 0.34));
}

.icf-delayed-loading__builder-emoji {
  font-size: 24px;
  line-height: 1;
  transform-origin: 50% 90%;
  animation: icf-builder-consider 1.6s ease-in-out infinite;
}

.icf-delayed-loading__thoughts {
  position: absolute;
  top: -4px;
  right: -6px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
}

.icf-delayed-loading__thoughts i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #e0f2fe;
  box-shadow: 0 0 6px rgba(103, 232, 249, 0.7);
  opacity: 0.25;
  animation: icf-builder-thought 1.25s ease-in-out infinite;
}

.icf-delayed-loading__thoughts i:nth-child(2) {
  width: 6px;
  height: 6px;
  animation-delay: 0.16s;
}

.icf-delayed-loading__thoughts i:nth-child(3) {
  width: 8px;
  height: 8px;
  animation-delay: 0.32s;
}

.icf-delayed-loading__copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.icf-delayed-loading__copy strong {
  color: #f8fbff;
  font-size: 14px;
  letter-spacing: 0.02em;
}

.icf-delayed-loading__copy > span {
  color: #a8bad0;
  font-size: 12px;
  line-height: 1.45;
}

.icf-delayed-loading__cancel {
  justify-self: start;
  margin-top: 8px;
  padding: 7px 12px;
  border: 1px solid rgba(248, 113, 113, 0.68);
  border-radius: 8px;
  background: rgba(127, 29, 29, 0.42);
  color: #fecaca;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  pointer-events: auto;
}

.icf-delayed-loading__cancel:hover,
.icf-delayed-loading__cancel:focus-visible {
  border-color: #fca5a5;
  background: rgba(153, 27, 27, 0.68);
  color: #fff;
  outline: none;
}

@keyframes icf-builder-consider {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  45% { transform: translateY(-2px) rotate(-4deg); }
  70% { transform: translateY(-1px) rotate(3deg); }
}

@keyframes icf-builder-thought {
  0%, 100% { opacity: 0.2; transform: translateY(2px) scale(0.72); }
  50% { opacity: 1; transform: translateY(-1px) scale(1); }
}

@keyframes icf-wait-progress {
  from { background-position: 180% 0; }
  to { background-position: -180% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .icf-delayed-loading__builder-emoji,
  .icf-delayed-loading__thoughts i,
  .icf-delayed-loading__card::after {
    animation: none;
  }
}
