/* Mobile Specific Layout & Bottom Sheet Drawer */

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  background: var(--bg-base);
}

/* App Header */
.app-header {
  padding: 10px 16px 8px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
  position: sticky;
  top: 0;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.header-actions .action-btn {
  padding: 5px 9px;
  font-size: 0.78rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  white-space: nowrap;
}

.header-actions .btn-icon {
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}

.profile-pills-bar {
  width: 100%;
}

.profile-pills-scroll, .filter-chips-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 4px 0;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}
.profile-pills-scroll::-webkit-scrollbar, .filter-chips-scroll::-webkit-scrollbar {
  display: none;
}

.profile-pill, .filter-chip {
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.profile-pill.active, .filter-chip.active {
  background: var(--emerald-glow);
  color: var(--emerald-500);
  border-color: var(--emerald-500);
}

/* Main View Container */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 100px; /* Space for bottom nav & floating chat */
  -webkit-overflow-scrolling: touch;
}

.tab-pane {
  display: none;
}
.tab-pane.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Bottom Navigation Bar */
.bottom-nav {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-around;
  padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 50;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease;
}

.nav-item.active {
  color: var(--emerald-500);
}

.nav-icon {
  font-size: 1.25rem;
}

/* Floating AI Chat Trigger */
.floating-ai-trigger {
  position: absolute;
  bottom: 70px;
  right: 16px;
  background: linear-gradient(135deg, #10b981, #06b6d4);
  color: #020617;
  border: none;
  border-radius: var(--radius-full);
  padding: 10px 16px;
  font-weight: 700;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 14px rgba(6, 182, 212, 0.4);
  cursor: pointer;
  z-index: 40;
  transition: transform 0.15s ease;
}

.floating-ai-trigger:active {
  transform: scale(0.95);
}

/* Body scroll lock when drawer is open */
body.drawer-open {
  overflow: hidden !important;
}

/* AI Assistant Bottom Sheet Drawer & Responsive Modal */
.chat-drawer {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  justify-content: flex-end;
  align-items: center;
  flex-direction: column;
}

.chat-drawer.open {
  display: flex;
}

.chat-drawer-content {
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  height: 85vh;
  max-height: 85vh;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease-out;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

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

@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.drawer-handle-bar {
  width: 40px;
  height: 4px;
  background: var(--border-subtle);
  border-radius: var(--radius-full);
  margin: 10px auto 4px auto;
  flex-shrink: 0;
}

.chat-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-cost-header-btn {
  background: rgba(16, 185, 129, 0.1);
  color: var(--emerald-500);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: var(--radius-full);
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all var(--transition-fast);
}

.chat-cost-header-btn:hover {
  background: rgba(16, 185, 129, 0.2);
  border-color: rgba(16, 185, 129, 0.4);
}

.chat-usage-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed rgba(255, 255, 255, 0.08);
  font-family: var(--font-mono, monospace);
}

.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 0.88rem;
  line-height: 1.45;
  word-break: break-word;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--emerald-500);
  color: #020617;
  border-bottom-right-radius: var(--radius-sm);
  font-weight: 500;
}

.chat-msg.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-bottom-left-radius: var(--radius-sm);
  max-width: 94%;
}

/* Markdown Rendering Inside Assistant Messages */
.chat-msg.assistant h3,
.chat-msg.assistant h4,
.chat-msg.assistant h5 {
  color: #ffffff;
  font-weight: 700;
  margin-top: 10px;
  margin-bottom: 4px;
  font-size: 0.95rem;
}
.chat-msg.assistant h3:first-child,
.chat-msg.assistant h4:first-child,
.chat-msg.assistant h5:first-child {
  margin-top: 0;
}

.chat-msg.assistant p {
  margin: 6px 0;
  font-size: 0.88rem;
  color: var(--text-primary);
  line-height: 1.5;
}
.chat-msg.assistant p:first-child {
  margin-top: 0;
}
.chat-msg.assistant p:last-child {
  margin-bottom: 0;
}

.chat-msg.assistant strong {
  color: #ffffff;
  font-weight: 600;
}

.chat-msg.assistant em {
  color: var(--text-secondary);
  font-style: italic;
}

.chat-msg.assistant .chat-list {
  margin: 6px 0 8px 18px;
  padding: 0;
}
.chat-msg.assistant .chat-list li {
  margin-bottom: 4px;
  line-height: 1.45;
  color: var(--text-primary);
}
.chat-msg.assistant ul.chat-list li::marker {
  color: var(--emerald-500);
}
.chat-msg.assistant ol.chat-list li::marker {
  color: var(--cyan-500);
}

.chat-msg.assistant .chat-table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 10px 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  touch-action: pan-x pan-y;
  overscroll-behavior-x: contain;
}

.chat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  min-width: 280px;
}
.chat-table th {
  background: rgba(30, 41, 59, 0.9);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.chat-table td {
  padding: 6px 10px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.5);
  color: var(--text-primary);
}
.chat-table tr:last-child td {
  border-bottom: none;
}
.chat-table tr:nth-child(even) {
  background: rgba(15, 23, 42, 0.4);
}

.chat-inline-code {
  background: rgba(15, 23, 42, 0.8);
  color: var(--cyan-500);
  border: 1px solid rgba(6, 182, 212, 0.25);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82em;
}

.chat-code-block {
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin: 8px 0;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8rem;
  color: var(--cyan-500);
}

.chat-blockquote {
  border-left: 3px solid var(--emerald-500);
  padding: 4px 10px;
  margin: 8px 0;
  background: rgba(16, 185, 129, 0.06);
  color: var(--text-secondary);
  font-size: 0.85rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.chat-hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 10px 0;
}

.chat-link {
  color: var(--cyan-500);
  text-decoration: underline;
}

.chat-msg.tool-badge {
  align-self: center;
  font-size: 0.72rem;
  background: rgba(6, 182, 212, 0.1);
  color: var(--cyan-500);
  border: 1px solid rgba(6, 182, 212, 0.25);
  border-radius: var(--radius-full);
  padding: 4px 10px;
}

/* Suggestion Chips Container */
.chat-suggestions {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border-subtle) transparent;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  scroll-snap-type: x proximity;
  flex-shrink: 0;
  width: 100%;
}

.chat-suggestions::-webkit-scrollbar {
  height: 4px;
}
.chat-suggestions::-webkit-scrollbar-track {
  background: transparent;
}
.chat-suggestions::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: var(--radius-full);
}

.suggestion-chip {
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 500;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  scroll-snap-align: start;
  transition: all 0.15s ease;
  user-select: none;
  line-height: 1.3;
}

.suggestion-chip:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: rgba(16, 185, 129, 0.4);
}

.suggestion-chip:active {
  transform: scale(0.96);
  background: var(--emerald-glow);
  color: var(--emerald-500);
}

/* Chat Input Bar */
.chat-input-container {
  padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 10px 16px;
  color: var(--text-primary);
  font-size: 0.9rem;
}
.chat-input:focus {
  outline: none;
  border-color: var(--emerald-500);
}

/* -------------------------------------------------------------------------
   Responsive Adaptations Across Screen Sizes
   ------------------------------------------------------------------------- */

/* Small Devices / Phones (< 360px) */
@media (max-width: 359px) {
  .chat-suggestions {
    padding: 6px 10px;
    gap: 6px;
  }
  .suggestion-chip {
    padding: 5px 9px;
    font-size: 0.72rem;
  }
}

/* Tablet & Moderate Widths (>= 481px): Allow suggestions to wrap into rows */
@media (min-width: 481px) {
  .chat-suggestions {
    flex-wrap: wrap;
    overflow-x: visible;
    overflow-y: auto;
    max-height: 105px;
    gap: 6px 8px;
    padding: 8px 16px;
  }
  .suggestion-chip {
    flex-shrink: 1;
    font-size: 0.8rem;
    padding: 6px 12px;
  }
}

/* Desktop Viewports (>= 768px): Centered Floating Assistant Modal */
@media (min-width: 768px) {
  .chat-drawer {
    justify-content: center;
    align-items: center;
    padding: 24px;
  }
  .chat-drawer-content {
    max-width: 580px;
    height: 76vh;
    max-height: 720px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    animation: fadeInScale 0.2s ease-out;
  }
  .drawer-handle-bar {
    display: none;
  }
  .chat-header {
    padding: 14px 20px;
  }
  .chat-messages {
    padding: 20px;
  }
  .chat-suggestions {
    padding: 10px 20px;
    max-height: 115px;
    gap: 8px;
  }
  .suggestion-chip {
    font-size: 0.82rem;
    padding: 7px 14px;
  }
  .chat-input-container {
    padding: 12px 20px;
  }
}

/* Compact Landscape Viewports (height <= 500px): Protect Chat Scroll Area */
@media (max-height: 500px) {
  .chat-drawer-content {
    height: 94vh;
  }
  .chat-suggestions {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 4px 12px;
    max-height: 38px;
    gap: 6px;
  }
  .suggestion-chip {
    padding: 4px 8px;
    font-size: 0.72rem;
  }
  .chat-header {
    padding: 6px 12px;
  }
  .chat-messages {
    padding: 8px 12px;
    gap: 8px;
  }
  .chat-input-container {
    padding: 6px 12px;
  }
}
