/* layout.css – CSS grid for modular shell layout
   Only active when body.modular-layout is present (added by shellManager).
*/

body.modular-layout {
  height: 100vh;
  margin: 0;
  display: grid;
  grid-template-columns: 260px 1fr 400px; /* sidebar | main | secondary */
  grid-template-rows: auto 1fr;           /* header | content */
  grid-template-areas:
    "sidebar header header"
    "sidebar main secondary";
}

body.modular-layout #universal-sidebar {
  grid-area: sidebar;
  /* ensure sidebar stretches full height */
  height: 100%;
  overflow: hidden;
}

body.modular-layout #app-header {
  grid-area: header;
  width: 100%;
  box-shadow: 0 1px 0 var(--color-border);
  z-index: 10;
}

body.modular-layout #output-area {
  grid-area: main;
  overflow: auto;
}

body.modular-layout #chat-panel-column {
  grid-area: secondary;
  border-left: 1px solid var(--color-border);
  overflow: auto;
}

/* Ensure original flex behaviours disabled under modular layout */
body.modular-layout #app-container,
body.modular-layout #right-column {
  display: contents;
}

/* Fixed 60-40 split for desktop without column resizer */
body.modular-layout #top-content-panel {
  display: flex !important;
  width: 100%;
  height: 100%;
}

body.modular-layout #output-area {
  flex: 0 0 60% !important; /* Fixed 60% width */
  width: 60% !important;
  max-width: 60% !important;
}

body.modular-layout #chat-panel-column {
  flex: 0 0 40% !important; /* Fixed 40% width */
  width: 40% !important;
  max-width: 40% !important;
}

/* Mobile responsive layout */
@media (max-width: 768px) {
  /* Ensure proper mobile viewport */
  html, body {
    overflow-x: hidden !important; /* Prevent horizontal scroll */
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  /* Mobile viewport height fix */
  @supports (height: 100dvh) {
    html, body {
      height: 100dvh !important;
    }
  }
  
  body.modular-layout {
    display: block !important; /* Remove grid from body */
    overflow: hidden !important; /* Prevent body scroll */
  }
  
  /* Fix header overflow */
  #app-header, .app-header {
    width: 100vw !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
    padding-left: 8px !important;
    padding-right: 8px !important;
  }
  
  /* Ensure header content doesn't overflow */
  .app-header h1 {
    font-size: 1.2rem !important; /* Smaller on mobile */
    margin: 0 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  
  .header-actions {
    flex-shrink: 0 !important;
  }
  #top-content-panel {
    display: flex !important;
    flex-direction: column !important;
    width: 100vw;
    height: 100vh; /* Fallback for browsers without dvh support */
    height: 100dvh; /* Use dynamic viewport height for mobile */
    margin: 0;
    padding: 0;
    overflow: hidden; /* Prevent container overflow */
    position: relative !important;
  }
  #output-area {
    flex: 1 1 50% !important;
    width: 100vw !important;
    max-width: 100vw !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overflow: auto !important;
  }
  #output-center-column, .output-column {
    width: 100vw !important;
    max-width: 100vw !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  #chat-panel-column {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 50% !important;
    min-height: 0 !important;
    overflow: hidden !important;
    position: relative !important;
    background: #fff;
    width: 100vw !important; /* Ensure full width */
    max-width: 100vw !important; /* Prevent overflow */
  }
  .chat-messages-container {
    flex: 1 1 auto !important; /* take remaining space */
    overflow-y: auto !important;
    min-height: 0 !important;
  }
  .chat-input-section {
    flex: 0 0 auto !important; /* auto height based on content */
    width: 100% !important;
    max-width: 100vw !important; /* Prevent overflow */
    padding-bottom: 4px !important; /* Reduced padding */
    background: var(--chat-input-bg, var(--color-primary)); /* Match header dark blue on mobile */
    color: var(--on-primary, #ffffff);
    position: relative !important;
    z-index: 10 !important;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.03);
    overflow: hidden !important; /* Prevent content overflow */
  }
  
  /* Ensure the chat interface content fits properly */
  .chat-input-section .chat-interface-content {
    padding: 4px !important; /* Reduced padding */
    width: 100% !important;
    max-width: 100vw !important; /* Prevent overflow */
    box-sizing: border-box !important;
  }
  
  /* Adjust prompt input for mobile */
  .chat-input-section .prompt-input-div {
    min-height: 50px !important; /* Further reduced height */
    max-height: 100px !important; /* Reduced max height */
    margin-bottom: 4px !important; /* Reduced margin */
  }
  
  #output-image-container {
    flex: 0 0 65% !important;
    min-height: 0 !important;
    height: 65% !important;
    max-height: none !important;
    overflow: auto !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
  }
  #chat-images-section,
  .chat-images-section-horizontal {
    flex: 0 0 20% !important;
    min-height: 40px !important; /* Reduced for smaller section */
    height: 20% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    width: 100% !important;
    background: inherit;
    position: static !important;
    display: block !important;
    z-index: auto !important;
  }
  #column-resizer {
    display: none !important;
  }

  /* Single horizontal row for all controls */
  .chat-input-section .controls-row {
    display: flex !important;
    flex-direction: row !important; /* Single horizontal row */
    align-items: center !important;
    justify-content: space-between !important;
    gap: 4px !important;
    padding: 4px !important;
    flex-wrap: nowrap !important; /* No wrapping */
    width: 100% !important;
    max-width: 100vw !important; /* Prevent overflow */
    box-sizing: border-box !important;
    overflow: hidden !important; /* Prevent horizontal scroll */
  }
  
  .chat-input-section .controls-left {
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
    flex: 0 0 auto !important;
  }
  
  .chat-input-section .controls-right {
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
    flex: 1 1 auto !important;
    justify-content: flex-end !important;
  }
  
  /* Compact buttons */
  .chat-input-section .icon-button {
    min-width: 32px !important;
    min-height: 32px !important;
    padding: 6px !important;
    font-size: 14px !important;
  }
  
  /* Compact dropdowns */
  .chat-input-section select {
    flex: 0 0 auto !important;
    min-width: 0 !important;
    padding: 4px 6px !important;
    font-size: 12px !important;
    height: 32px !important;
    border-radius: 4px !important;
  }
  
  /* Generation mode select now moved to chat header - remove specific width constraint */
  
  #image-dimension-select {
    width: 80px !important; /* Compact width */
  }
  
  #generate-button {
    flex: 0 0 auto !important;
    min-width: 50px !important;
    max-width: 60px !important; /* Prevent button from being too wide */
    height: 32px !important;
    padding: 6px 8px !important; /* Reduced padding */
    font-size: 14px !important; /* Smaller font */
    margin-left: 4px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
  }
  
  /* Ensure prompt input doesn't overflow */
  .chat-input-section .prompt-input-div {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  
  /* Make sure all mobile elements fit properly */
  .controls-left, .controls-right {
    min-width: 0 !important; /* Allow flex items to shrink */
  }
  
  .controls-left {
    max-width: 30% !important; /* Limit left controls width */
  }
  
  .controls-right {
    max-width: 70% !important; /* Limit right controls width */
  }
}

/* === Main Header Bar (section title) === */
#main-header-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  height: 22px;
  border-bottom: 1px solid var(--color-border, #e1e5e9);
  background: var(--color-bg, #fff);
  position: relative;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  width: 100%;
  box-sizing: border-box;
  flex-shrink: 0;
  margin: 0;
}

#main-header-bar .back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: none;
  background: var(--color-bg-hover, #f8f9fa);
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s ease;
  color: var(--color-text-secondary, #6c757d);
}

#main-header-bar .back-btn:hover {
  background: var(--color-bg-active, #e9ecef);
  color: var(--color-text, #212529);
  transform: translateX(-1px);
}

#main-header-bar .back-btn:active {
  transform: translateX(-2px);
}

#main-header-bar .toggle-icon {
  font-size: 16px;
  line-height: 1;
}

#main-header-bar .main-header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text, #212529);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

@media (max-width: 768px) {
  #main-header-bar {
    padding: 8px 12px;
    height: 22px;
    gap: 8px;
  }
  
  #main-header-bar .back-btn {
    width: 18px;
    height: 18px;
  }
  
  #main-header-bar .main-header-title {
    font-size: 14px;
  }
} 
