/* ============================================
   HAISE - Centralized Layout Styles
   Header, Sidebar, and Main Content
   Single source of truth for all pages
   ============================================ */

/* CSS Variables are defined in /css/styles.css */

/* ============================================
   APP SHELL - Base Layout Structure
   ============================================ */

body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  min-height: 100vh;
}

.app {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

/* ============================================
   SIDEBAR - Collapsible Navigation
   ============================================ */

/* Sidebar container - maintains layout space */
.sidebar-container {
  width: var(--sidebar-collapsed-width);
  flex-shrink: 0;
  position: relative;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-container.pinned {
  width: var(--sidebar-expanded-width);
}

/* Actual sidebar panel */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-collapsed-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease;
  z-index: 100;
  overflow-x: hidden;
  overflow-y: hidden;
}

.sidebar.hover-expanded {
  width: var(--sidebar-expanded-width);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
}

.sidebar-container.pinned .sidebar {
  width: var(--sidebar-expanded-width);
  box-shadow: none;
}

/* Sidebar header with hamburger */
.sidebar-header {
  display: flex;
  align-items: center;
  padding: 12px;
  min-height: 60px;
  gap: 12px;
  flex-shrink: 0;
}

.hamburger-menu {
  background: transparent;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  min-width: 36px;
  height: 36px;
  transition: all 0.2s;
}

.hamburger-menu:hover {
  background: var(--bg-tertiary);
  transform: scale(1.05);
}

.hamburger-menu svg {
  width: 20px;
  height: 20px;
  transition: transform 0.3s;
}

.sidebar-container.pinned .hamburger-menu svg {
  transform: rotate(90deg);
}

/* Sidebar branding */
.sidebar-branding {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px 12px 12px;
  border-bottom: 1px solid var(--border);
  justify-content: center;
  transition: justify-content 0.3s ease;
}

.sidebar-branding img,
.sidebar-branding svg {
  width: 24px;
  height: 24px;
  color: var(--accent);
  flex-shrink: 0;
  opacity: 1 !important;
}

.sidebar-logo {
  width: 24px;
  height: 24px;
  object-fit: contain;
  flex-shrink: 0;
}

.sidebar-branding-text {
  font-size: 18px;
  font-weight: 600;
  background: linear-gradient(135deg, #1779a1 0%, #40b9c5 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
  opacity: 0;
  width: 0;
  overflow: hidden;
  transition: opacity 0.3s ease 0.1s, width 0.3s ease;
}

.sidebar.hover-expanded .sidebar-branding-text,
.sidebar-container.pinned .sidebar-branding-text {
  opacity: 1;
  width: auto;
}

.sidebar.hover-expanded .sidebar-branding,
.sidebar-container.pinned .sidebar-branding {
  justify-content: flex-start;
}

/* New Chat button */
.new-chat-btn {
  margin: 12px;
  padding: 10px;
  min-height: 40px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.new-chat-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(23, 121, 161, 0.3);
}

.new-chat-btn-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.new-chat-btn-text {
  margin-left: 8px;
  opacity: 0;
  transform: translateX(-10px);
  transition: all 0.3s ease;
  white-space: nowrap;
  position: absolute;
  left: 38px;
}

.sidebar.hover-expanded .new-chat-btn-text,
.sidebar-container.pinned .new-chat-btn-text {
  opacity: 1;
  transform: translateX(0);
  position: relative;
  left: auto;
}

/* Navigation groups */
.sidebar-nav {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.section-label {
  padding: 12px 12px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0;
  transform: translateX(-10px);
  transition: all 0.3s ease 0.15s;
  white-space: nowrap;
  margin-left: 2px;
}

.sidebar.hover-expanded .section-label,
.sidebar-container.pinned .section-label {
  opacity: 1;
  transform: translateX(0);
}

.nav-item {
  display: flex;
  align-items: center;
  position: relative;
  padding: 10px 12px;
  margin: 2px 8px;
  min-height: 44px;
  width: calc(100% - 16px);
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}

.nav-item:hover {
  background: var(--bg-tertiary);
  transform: translateX(2px);
}

.nav-item-icon {
  min-width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-item-icon svg {
  width: 18px;
  height: 18px;
}

.nav-item-text {
  margin-left: 12px;
  white-space: nowrap;
  opacity: 0;
  transform: translateX(-10px);
  transition: all 0.3s ease;
}

.sidebar.hover-expanded .nav-item-text,
.sidebar-container.pinned .nav-item-text {
  opacity: 1;
  transform: translateX(0);
}

/* Tooltip for collapsed state */
.nav-item-tooltip {
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) scale(0.95);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s;
  z-index: 1001;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.sidebar:not(.hover-expanded) .nav-item:hover .nav-item-tooltip {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

.sidebar-container.pinned .nav-item-tooltip {
  display: none;
}

/* Active nav item */
.nav-item.active {
  background: var(--bg-tertiary);
  border-left: 3px solid var(--accent);
}

/* Chat history */
.chat-history {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 8px 8px;
  min-height: 0;
}

.chat-history-item {
  padding: 10px 12px;
  margin-bottom: 4px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.2s;
  position: relative;
}

.chat-history-item:hover {
  background: var(--bg-tertiary);
}

.chat-history-item.active {
  background: var(--bg-tertiary);
  border-left: 3px solid var(--accent);
  padding-left: 9px;
}

.chat-history-item-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.7;
}

.chat-history-item-title {
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translateX(-10px);
  transition: all 0.3s ease 0.1s;
  min-width: 0;
  max-width: 180px;
}

.sidebar.hover-expanded .chat-history-item-title,
.sidebar-container.pinned .chat-history-item-title {
  opacity: 1;
  transform: translateX(0);
}

/* Hide content when sidebar is collapsed */
.sidebar-container:not(.pinned) .sidebar:not(.hover-expanded) .chat-history-item-content {
  display: none !important;
}

.sidebar-container.pinned .chat-history-item-content,
.sidebar.hover-expanded .chat-history-item-content {
  display: flex !important;
  flex-direction: column;
  gap: 2px;
}

.sidebar:not(.hover-expanded):not(.pinned) .chat-history-item {
  justify-content: left;
  padding: 12px;
}

.sidebar:not(.hover-expanded):not(.pinned) .chat-history-item-icon {
  margin: 0;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 8px;
  border-top: 1px solid var(--border);
  margin-top: auto;
  position: relative;
  flex-shrink: 0;
}

.user-button {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 7px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s;
  box-sizing: border-box;
  overflow: hidden;
}

.user-button:hover {
  background: var(--bg-tertiary);
  transform: translateY(-1px);
}

.user-details {
  margin-left: 12px;
  text-align: left;
  overflow: hidden;
  opacity: 0;
  width: 0;
  transform: translateX(-10px);
  transition: all 0.3s ease 0.2s;
  flex: 0;
}

.sidebar.hover-expanded .user-details,
.sidebar-container.pinned .user-details {
  opacity: 1;
  transform: translateX(0);
  flex: 1;
  width: auto;
}

/* Sidebar scrollbars */
.sidebar::-webkit-scrollbar {
  width: 4px;
}

.sidebar {
  scrollbar-width: thin;
}

/* ============================================
   MAIN CONTENT - Primary Content Area
   ============================================ */

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

/* ============================================
   HEADER - Top Navigation Bar
   ============================================ */

.chat-header {
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
  background: var(--bg-primary);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-branding {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-right: 24px;
}

.header-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.header-brand-text {
  font-size: 20px;
  font-weight: 600;
  background: linear-gradient(135deg, #1779a1 0%, #40b9c5 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

/* Hide brand text on mobile */
@media (max-width: 768px) {
  .header-brand-text {
    display: none;
  }
}

/* ============================================
   SIDEBAR TOGGLE (Mobile)
   ============================================ */

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 101;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 20px;
  line-height: 1;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 99;
}

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

/* Mobile sidebar adjustments */
@media (max-width: 768px) {
  .sidebar-toggle {
    display: block;
  }

  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-expanded-width);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }

  .main-content {
    margin-left: 0 !important;
  }
}

/* ============================================
   CONTAINER - Content Width Constraints
   ============================================ */

.container {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 20px;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Main content should handle scrolling */
.main-content {
  overflow-y: auto !important;
  overflow-x: hidden !important;
}

/* Remove nested container constraints */
body.subs-page .container,
body.news-outlets-page .container {
  max-width: none;
  padding: 20px;
  margin: 0;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

/* Tablet */
@media (max-width: 1024px) {
  .container {
    padding: 24px 20px;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .container {
    padding: 20px 16px;
  }

  .chat-header {
    padding: 12px 16px;
  }
}

/* Small Mobile */
@media (max-width: 480px) {
  .container {
    padding: 16px 12px;
  }
}
