/**
 * SaaS Admin Layout & Dashboard Styling
 */

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  margin: 0;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* App Layout Wrapper */
.app-wrapper {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* Sidebar Navigation */
.app-sidebar {
  width: 260px;
  background-color: var(--bg-sidebar);
  color: var(--text-sidebar);
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
  z-index: 1040;
}

.sidebar-header {
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.brand-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-accent));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  font-weight: 700;
  font-size: 1.1rem;
}

.brand-title {
  font-size: 1rem;
  font-weight: 700;
  color: #FFFFFF;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  padding: 1rem 0.75rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-sidebar);
  padding: 0.75rem 0.75rem 0.25rem 0.75rem;
  opacity: 0.6;
}

.nav-link-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  color: var(--text-sidebar);
  text-decoration: none;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.nav-link-item:hover {
  background-color: var(--bg-sidebar-hover);
  color: #FFFFFF;
}

.nav-link-item.active {
  background-color: var(--brand-primary);
  color: #FFFFFF;
  font-weight: 600;
}

/* Main Content Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Top Header Bar */
.top-header {
  height: 64px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  z-index: 1020;
  transition: background-color 0.3s ease;
}

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

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.sidebar-toggle-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
}

.sidebar-toggle-btn:hover {
  background-color: var(--bg-app);
}

/* Theme Toggle Button */
.theme-toggle-btn {
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
  border-color: var(--brand-primary);
}

/* Page Workspace Container */
.page-workspace {
  padding: 1.75rem 1.5rem;
  flex: 1;
}

/* Dashboard Module Cards */
.module-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.module-card:hover {
  transform: translateY(-2px);
  border-color: var(--brand-primary);
  box-shadow: 0 8px 16px -2px rgba(0, 0, 0, 0.08);
}

.card-icon-wrapper {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.card-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
  flex: 1;
  margin-bottom: 1.25rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  width: fit-content;
}

.badge-placeholder {
  background-color: rgba(100, 116, 139, 0.1);
  color: var(--text-muted);
}

/* Responsive Collapsed Sidebar & Mobile Drawer */
@media (max-width: 991.98px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: -260px;
  }
  .app-sidebar.show-mobile {
    left: 0;
  }
}

/* =========================================================================
   COMMERCIAL AI WORKSPACE LAYOUT & COMPONENTS
   ========================================================================= */

.extra-small {
  font-size: 0.75rem !important;
}

.ai-workspace-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 100px);
  min-height: 550px;
}

.workspace-main-container {
  display: flex;
  flex: 1;
  gap: 1rem;
  overflow: hidden;
  position: relative;
}

/* Left Workspace History Panel */
.workspace-history-panel {
  width: 300px;
  min-width: 300px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  z-index: 1020;
}

@media (max-width: 767.98px) {
  .workspace-history-panel {
    width: 85%;
    max-width: 320px;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    border-radius: 0;
  }
}

/* History List Item Styling */
.workspace-history-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.history-item-btn {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.65rem 0.85rem;
  background-color: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  width: 100%;
  color: var(--text-main);
  text-decoration: none;
}

.history-item-btn:hover {
  background-color: var(--bg-app);
  border-color: var(--border-color);
}

.history-item-btn.active {
  background-color: rgba(79, 70, 229, 0.08);
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 1px var(--brand-primary);
}

.history-item-btn .history-title {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-btn .history-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Main Workspace Chat Area */
.workspace-chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  min-width: 0; /* Prevents flex flex-grow overflow issues */
}

.chat-header {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
}

.chat-stream-window {
  flex: 1;
  background-color: var(--bg-app);
  overflow-y: auto;
  scroll-behavior: smooth;
}

/* Chat Message Bubbles */
.chat-bubble-user {
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-hover, var(--brand-primary)));
  color: #FFFFFF;
  border-radius: 1rem 1rem 0.25rem 1rem;
  padding: 0.85rem 1.15rem;
  max-width: 80%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  word-break: break-word;
  white-space: pre-wrap;
}

.chat-bubble-assistant {
  background-color: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 1rem 1rem 1rem 0.25rem;
  padding: 0.85rem 1.15rem;
  max-width: 85%;
  box-shadow: var(--shadow-sm);
  word-break: break-word;
  white-space: pre-wrap;
}

/* Composer Input Styling */
.chat-textarea {
  border-color: var(--border-color);
  border-radius: var(--radius-md);
  resize: none;
  font-size: 0.92rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-textarea:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

/* Skeleton Loading State */
.skeleton-item {
  height: 48px;
  background: linear-gradient(90deg, #f0f3f6 25%, #e6ebf0 50%, #f0f3f6 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: var(--radius-md);
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Dropdown Menu Contrast & Visibility Fixes */
.dropdown-menu {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  padding: 0.35rem;
}

.dropdown-item {
  color: var(--text-main);
  border-radius: var(--radius-md);
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.dropdown-item:hover,
.dropdown-item:focus {
  background-color: var(--bg-app);
  color: var(--text-main);
}

.dropdown-item.text-danger {
  color: #dc3545 !important;
}

.dropdown-item.text-danger:hover,
.dropdown-item.text-danger:focus {
  background-color: rgba(220, 53, 69, 0.08) !important;
  color: #dc3545 !important;
}
