/* Premium Mobile UI Overhaul */

:root {
  --bg: #09090b;
  --bg-alt: #18181b;
  --panel: rgba(24, 24, 27, 0.45);
  --panel-strong: rgba(24, 24, 27, 0.85);
  --accent: #10b981;
  --accent-soft: rgba(16, 185, 129, 0.15);
  --accent-strong: #059669;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --shadow: 0 32px 64px rgba(0, 0, 0, 0.6);
  --shadow-soft: 0 16px 32px rgba(0, 0, 0, 0.4);
}

body::before { background: radial-gradient(circle, rgba(16, 185, 129, 0.25) 0%, transparent 60%); }
body::after { background: radial-gradient(circle, rgba(59, 130, 246, 0.2) 0%, transparent 60%); }

/* Glassmorphism Panels */
.auth-card, .panel, .dialog-card {
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  background: linear-gradient(145deg, rgba(255,255,255,0.06) 0%, rgba(255,255,255,0.01) 100%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.3s ease, border-color 0.3s ease;
}

/* Micro-animations */
.button, .workspace-card, .thread-card {
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}
.workspace-card:hover, .thread-card:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 12px 24px rgba(0,0,0,0.3);
  border-color: rgba(16, 185, 129, 0.3);
  background: rgba(255, 255, 255, 0.08);
}
.button:hover { transform: translateY(-2px) scale(1.02); }
.button:active { transform: translateY(0) scale(0.98); }

.button.primary {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #fff;
  border: none;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
}
.button.primary:hover {
  background: linear-gradient(135deg, #34d399 0%, #10b981 100%);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.6);
}

/* Enhancing inputs */
input, textarea, select {
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-strong);
}
input:focus, textarea:focus, select:focus {
  border-color: #10b981;
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.15);
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-1px);
}

/* Custom fade-in for popups */
@keyframes fadeScaleIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.dialog[open] {
  animation: fadeScaleIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Mobile Sticky Bottom Tab Bar */
@media (max-width: 960px) {
  .mobile-nav {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    overflow: hidden;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(9, 9, 11, 0.85) 0%, rgba(9, 9, 11, 0.95) 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    border-radius: 24px 24px 0 0;
    z-index: 50;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.5);
    display: flex;
    justify-content: space-around;
    gap: 8px;
  }

  .panel {
    padding-bottom: 74px; /* Space for the bottom nav without breaking grid logic */
  }
  .mobile-nav-button {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 0.95rem;
    padding: 10px 0;
    font-weight: 600;
  }
  .mobile-nav-button.active {
    color: #10b981;
    background: rgba(16, 185, 129, 0.1);
    border-radius: 16px;
  }
  
  /* Make sure buttons are easily tappable */
  .button, input:not([type="checkbox"]):not([type="radio"]), select {
    min-height: 48px;
  }
  
  /* Hamburger dropdown */
  .brand-block .meta { display: none !important; }
  .topbar {
    position: relative !important;
    display: flex !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    justify-content: space-between !important;
    margin-bottom: 0 !important;
    padding-bottom: 12px;
  }
  .brand-block {
    flex: 1 1 auto;
    min-width: 0;
  }
  .mobile-menu-toggle {
    display: block !important;
    font-size: 1.5rem !important;
    padding: 8px 12px !important;
    width: auto !important;
    flex: 0 0 auto !important;
  }
  .topbar-actions {
    display: none !important;
    position: absolute !important;
    top: calc(100% - 10px) !important;
    right: 16px !important;
    flex-direction: column !important;
    background: var(--panel-strong) !important;
    padding: 16px !important;
    border-radius: var(--radius-md) !important;
    border: 1px solid var(--border) !important;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5) !important;
    z-index: 100 !important;
    min-width: 200px !important;
    gap: 8px !important;
  }
  .topbar-actions.open {
    display: flex !important;
  }
  .topbar-actions .button {
    width: 100% !important;
  }

  /* Structural UI fixes */
  .panel {
    padding-bottom: 84px !important; /* Space for the bottom nav */
  }
  .rail-panel {
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
  }
  .rail-list {
    max-height: none !important;
    flex: 1 1 0 !important;
    overflow-y: auto !important;
  }

  /* Pinned Chat Composer UX */
  .conversation-panel {
    overflow-y: hidden !important; 
    display: flex !important;
    flex-direction: column !important;
  }
  .history-shell {
    flex: 1 1 0 !important; 
    min-height: 0 !important;
    height: auto !important;
  }
  .message-list {
    overflow-y: auto !important;
    height: 100% !important;
  }
  .composer-shell {
    position: static !important;
    flex: 0 0 auto !important;
    z-index: 10 !important;
    background: transparent !important;
    border-top: 1px solid var(--border) !important;
    padding-top: 10px !important;
    margin-bottom: 4px !important;
  }

  .composer-actions {
    flex-direction: row !important;
  }
  .composer-actions .button {
    width: auto !important;
  }

  /* Toast adjustment */
  .toast {
    bottom: calc(85px + env(safe-area-inset-bottom));
  }

  /* Settings Dialog Form alignment bugs */
  .settings-group label {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 12px !important;
    width: auto !important;
    background: transparent !important;
    padding: 0 !important;
  }
  .settings-group input[type="checkbox"] {
    flex: 0 0 auto !important;
    width: auto !important;
    min-height: 24px !important;
    margin: 0 !important;
  }

  /* Ensure JS visibility toggles actually execute */
  .mobile-hidden {
    display: none !important;
  }
}

@media (min-width: 961px) {
  .mobile-menu-toggle {
    display: none !important;
  }
}
