:root {
  --primary-color: #00d4ff;
  --primary-hover: #00a3cc;
  --bg-dark: #0f172a;
  --bg-card: rgba(30, 41, 59, 0.7);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: rgba(255, 255, 255, 0.1);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --success: #10b981;
  --warning: #f59e0b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  background-image:
    radial-gradient(at 0% 0%, hsla(253, 16%, 7%, 1) 0, transparent 50%),
    radial-gradient(at 50% 0%, hsla(225, 39%, 30%, 1) 0, transparent 50%),
    radial-gradient(at 100% 0%, hsla(339, 49%, 30%, 1) 0, transparent 50%);
  background-attachment: fixed;
  min-height: 100vh;
}

/* Glassmorphism Utilities */
.glass-panel {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  box-shadow: var(--glass-shadow);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-color), #0066cc);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 212, 255, 0.3);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--primary-color);
  color: var(--primary-color);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-outline:hover {
  background: rgba(0, 212, 255, 0.1);
}

.btn-outline.active-tool {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  box-shadow: 0 0 10px rgba(0, 212, 255, 0.4);
}

/* Layout */
.app-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 260px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  /* Reduced gap slightly */
  border-right: 1px solid var(--border-color);
  height: 100%;
  overflow-y: auto;
  /* Allow scrolling if too tall */
}

/* Custom scrollbar for sidebar */
.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.logo {
  font-size: 1.5rem;
  font-weight: 800;
  background: linear-gradient(to right, #00d4ff, #ffffff);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 20px;
}

.nav-item {
  padding: 12px 16px;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  border-left: 3px solid var(--primary-color);
}

.user-profile {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
  font-size: 0.9rem;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 32px;
  overflow-y: auto;
  position: relative;
}

/* Views (Tab Content) */
.view-section {
  display: none;
  /* Hidden by default */
  animation: fadeIn 0.3s ease-in-out;
  max-width: 1200px;
  margin: 0 auto;
}

.view-section.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Auth Overlay */
.auth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.95);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Main Content Header */
.content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.auth-card {
  width: 400px;
  padding: 40px;
}

.form-group {
  margin-bottom: 24px;
}

.form-group label {
  display: block;
  margin-bottom: 12px;
  color: var(--text-main);
  font-size: 0.95rem;
}

.form-control {
  width: 100%;
  padding: 12px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: white;
  font-size: 1rem;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-color);
}

/* Grid Layouts */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

/* Compact Form Styling */
.form-section {
  background: rgba(255, 255, 255, 0.03);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  margin-bottom: 16px;
}

.form-section h4 {
  font-size: 0.95rem;
  color: var(--primary-color);
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 4px;
}

.form-group {
  margin-bottom: 0;
  /* Let grid gap handle spacing */
}

.form-group label {
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.form-control {
  padding: 8px 12px;
  font-size: 0.9rem;
}

small {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
  line-height: 1.2;
}


/* Enhanced Tabs */
.tabs-container {
  background: rgba(0, 0, 0, 0.2);
  padding: 6px;
  border-radius: 12px;
  display: inline-block;
  width: 100%;
}

.tabs-header {
  display: flex;
  gap: 8px;
}

.tab-item {
  flex: 1;
  text-align: center;
  padding: 10px;
  cursor: pointer;
  border-radius: 8px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.2s;
  border: 1px solid transparent;
}

.tab-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.tab-item.active {
  background: var(--primary-color);
  color: white;
  box-shadow: 0 4px 12px rgba(0, 212, 255, 0.3);
  font-weight: 700;
  border-color: rgba(255, 255, 255, 0.2);
}

/* Stats Cards */
.stat-card {
  padding: 24px;
  text-align: center;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-color);
  margin: 10px 0;
}

/* Table */
table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

th {
  color: var(--text-muted);
  font-weight: 500;
}

/* Region Selector */
.region-select {
  position: absolute;
  top: 32px;
  right: 32px;
  width: 200px;
}

/* Success/Error Toasts */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 24px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: white;
  display: none;
  animation: slideUp 0.3s;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }

  to {
    transform: translateY(0);
  }
}

/* Update: Split View and Drag Drop Styles */
.split-view {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  gap: 30px;
  height: calc(100vh - 120px);
  /** Reduced overhead to give more space */
  min-height: 600px;
}

.left-column-wrapper {
  height: 100%;
  overflow-y: auto;
  /** Allow scrolling if inputs overflow */
}

.upload-zone {
  border: 2px dashed var(--border-color);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  transition: all 0.3s ease;
  background: rgba(255, 255, 255, 0.02);
  height: 100%;
  min-height: 400px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary-color);
  background: rgba(0, 212, 255, 0.05);
}

#upload-prompt i {
  font-size: 3rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.preview-container {
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 0;
  left: 0;
  background: var(--bg-card);
  padding: 10px;
  /** Add padding inside container */
  box-sizing: border-box;
}

.preview-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  /** Ensure image fits within container without crop */
  border-radius: 8px;
}

.results-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.price-display {
  font-size: 3rem;
  font-weight: 800;
  background: linear-gradient(to right, #00d4ff, #10b981);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 20px;
}

.hidden-file-input {
  display: none;
}

/* Breakdown Category Hover */
.breakdown-category {
  transition: background 0.2s;
}

.breakdown-category:hover {
  background: rgba(255, 255, 255, 0.05) !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
}

/* =============================================================================
   📱 MOBILE RESPONSIVE STYLES
   ============================================================================= */

/* Mobile Menu Toggle Button */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  color: var(--text-main);
  cursor: pointer;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.mobile-menu-toggle i {
  font-size: 1.2rem;
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

.sidebar-overlay.active {
  display: block;
}

/* =============================================================================
   TABLET BREAKPOINT (max-width: 1024px)
   ============================================================================= */
@media (max-width: 1024px) {
  .sidebar {
    width: 220px;
    padding: 20px;
  }

  .main-content {
    padding: 24px;
  }

  .split-view {
    gap: 20px;
    height: auto;
    min-height: auto;
  }

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

  .stat-value {
    font-size: 1.6rem;
  }

  .auth-card {
    width: 360px;
    padding: 32px;
  }
}

/* =============================================================================
   MOBILE BREAKPOINT (max-width: 768px)
   ============================================================================= */
@media (max-width: 768px) {

  /* Show Mobile Menu Toggle */
  .mobile-menu-toggle {
    display: block;
  }

  /* Sidebar becomes slide-out drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    z-index: 100;
    border-radius: 0;
    border-right: 1px solid var(--border-color);
    transition: left 0.3s ease;
  }

  .sidebar.open {
    left: 0;
  }

  /* Main Content takes full width */
  .app-container {
    flex-direction: column;
  }

  .main-content {
    padding: 70px 16px 24px;
    /* Top padding for mobile menu button */
    width: 100%;
  }

  /* Page Title adjustments */
  #page-title {
    font-size: 1.4rem;
  }

  /* Context Bar stacks vertically */
  .main-content>div:first-child {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  #region-selector {
    width: 100% !important;
  }

  /* Split View becomes stacked */
  .split-view {
    grid-template-columns: 1fr;
    gap: 16px;
    height: auto;
    min-height: auto;
  }

  .left-column-wrapper {
    height: auto;
    overflow: visible;
  }

  .upload-zone {
    min-height: 300px;
    padding: 24px;
  }

  .results-panel {
    padding: 20px !important;
  }

  /* Grid Layouts stack on mobile */
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Form Groups */
  .form-group {
    margin-bottom: 16px;
  }

  .form-control {
    padding: 14px;
    font-size: 16px;
    /* Prevents iOS zoom on focus */
  }

  /* Buttons - Touch friendly */
  .btn-primary,
  .btn-outline {
    padding: 14px 20px;
    min-height: 48px;
    font-size: 1rem;
  }

  /* Stat Cards */
  .stat-card {
    padding: 20px;
  }

  .stat-value {
    font-size: 1.8rem;
  }

  /* Tables - Horizontal scroll */
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  th,
  td {
    padding: 10px 8px;
    font-size: 0.9rem;
  }

  /* Auth Card */
  .auth-card {
    width: 90%;
    max-width: 400px;
    padding: 24px;
    margin: 16px;
  }

  /* Metric boxes in results */
  .metric-box {
    padding: 12px;
  }

  .metric-val {
    font-size: 1.2rem !important;
  }

  /* Toast positioning */
  .toast {
    left: 16px;
    right: 16px;
    bottom: 16px;
    width: auto;
  }

  /* Sketch Tool Canvas Container */
  #sketch-container {
    height: 400px !important;
  }

  /* Package Settings */
  .content-header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start !important;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions button {
    width: 100%;
  }

  /* Tabs */
  .tabs-header {
    flex-wrap: wrap;
  }

  .tab-item {
    flex: 1 1 30%;
    min-width: 80px;
    padding: 8px;
    font-size: 0.85rem;
  }

  /* Action buttons in results */
  #upload-result>div:last-of-type {
    flex-direction: column;
  }

  #upload-result button {
    width: 100%;
    min-width: auto !important;
  }

  /* AI Architect Section */
  #ai-architect-section {
    padding: 16px !important;
  }

  #ai-architect-section>div {
    flex-direction: column;
    gap: 12px;
  }

  /* User Profile in Sidebar */
  .user-profile {
    padding-top: 16px;
  }

  /* Nav items touch-friendly */
  .nav-item {
    padding: 14px 16px;
    font-size: 1rem;
  }

  /* Logo */
  .logo {
    font-size: 1.3rem;
    margin-bottom: 24px;
  }
}

/* =============================================================================
   SMALL MOBILE BREAKPOINT (max-width: 480px)
   ============================================================================= */
@media (max-width: 480px) {
  .main-content {
    padding: 60px 12px 16px;
  }

  #page-title {
    font-size: 1.2rem;
  }

  .glass-panel {
    border-radius: 16px;
  }

  .upload-zone {
    min-height: 250px;
    padding: 16px;
  }

  #upload-prompt i {
    font-size: 2rem;
    margin-bottom: 12px;
  }

  #upload-prompt h3 {
    font-size: 1.1rem;
  }

  .stat-value {
    font-size: 1.5rem;
  }

  .price-display {
    font-size: 2rem;
  }

  /* Smaller total cost display */
  #total-cost-display {
    font-size: 1.2rem !important;
  }

  /* Compact form section headers */
  .form-section h4 {
    font-size: 0.85rem;
  }

  /* Sketch Tool adjustments */
  #sketch-container {
    height: 300px !important;
  }

  /* Toolbar wraps nicely */
  #view-sketch-tool .glass-panel>div:first-child {
    padding: 8px 12px !important;
    gap: 6px !important;
  }

  #view-sketch-tool .btn-outline {
    padding: 8px 10px;
    min-height: auto;
  }
}

/* =============================================================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================================================= */
@media (hover: none) and (pointer: coarse) {

  /* Remove hover states that don't work on touch */
  .btn-primary:hover {
    transform: none;
  }

  .btn-outline:hover {
    background: transparent;
  }

  /* Make interactive elements more obvious */
  .nav-item.active {
    background: rgba(0, 212, 255, 0.15);
  }

  /* Larger tap targets */
  input[type="checkbox"] {
    width: 20px;
    height: 20px;
  }

  /* Better scrolling */
  .main-content {
    -webkit-overflow-scrolling: touch;
  }
}

/* =============================================================================
   LANDSCAPE MOBILE
   ============================================================================= */
@media (max-height: 500px) and (orientation: landscape) {
  .auth-card {
    max-height: 90vh;
    overflow-y: auto;
  }

  .auth-overlay {
    align-items: flex-start;
    padding-top: 10px;
  }

  #sketch-container {
    height: 250px !important;
  }
}

/* =============================================================================
   PRINT STYLES (for reports)
   ============================================================================= */
@media print {

  .sidebar,
  .mobile-menu-toggle,
  .auth-overlay,
  .toast,
  #analyze-controls,
  .btn-primary,
  .btn-outline {
    display: none !important;
  }

  .main-content {
    padding: 0;
    width: 100%;
  }

  .glass-panel {
    background: white;
    border: 1px solid #ccc;
    box-shadow: none;
  }

  body {
    background: white;
    color: black;
  }
}