/* ==============================================================================
   onesimus.tech User-Facing Mailbox Stylesheet
   Solid Light Theme System (Default) & Responsive Master-Detail Layout
   Benchmarked against Apple Mail (macOS Light Mode) & Superhuman
   ============================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

:root {
  /* Solid Light Mode Palette (Default) */
  --bg-app: #f8f9fa;
  --bg-sidebar: #f4f4f6;
  --bg-surface: #ffffff;
  --bg-subtle: #f4f4f6;
  --bg-hover: #ebecef;
  --bg-active: #e2e4e8;
  
  --border-color: #e4e4e7;
  --border-subtle: #f0f0f2;
  --border-strong: #d4d4d8;
  
  --text-primary: #09090b;
  --text-secondary: #52525b;
  --text-muted: #71717a;
  
  --primary-btn-bg: #18181b;
  --primary-btn-text: #ffffff;
  --primary-btn-hover: #27272a;
  
  /* Subtle Brand Red Accents (.tech #fd2558) */
  --brand-red: #fd2558;
  --brand-red-hover: #e01a4b;
  --brand-red-subtle: rgba(253, 37, 88, 0.08);
  --brand-red-ring: rgba(253, 37, 88, 0.15);
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-modal: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
}

/* Solid Dark Mode Palette (Fallback if toggled) */
html.dark,
body.dark {
  --bg-app: #09090b;
  --bg-sidebar: #0f0f12;
  --bg-surface: #141418;
  --bg-subtle: #18181d;
  --bg-hover: #202026;
  --bg-active: #272730;
  
  --border-color: #27272a;
  --border-subtle: #1e1e24;
  --border-strong: #3f3f46;
  
  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  
  --primary-btn-bg: #f4f4f5;
  --primary-btn-text: #09090b;
  --primary-btn-hover: #e4e4e7;
  
  /* Subtle Brand Red Accents (Dark Mode) */
  --brand-red: #fd2558;
  --brand-red-hover: #ff3d6c;
  --brand-red-subtle: rgba(253, 37, 88, 0.12);
  --brand-red-ring: rgba(253, 37, 88, 0.22);
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
  --shadow-modal: 0 20px 25px -5px rgba(0, 0, 0, 0.7);
}

::selection {
  background: rgba(253, 37, 88, 0.16);
  color: inherit;
}

::-moz-selection {
  background: rgba(253, 37, 88, 0.16);
  color: inherit;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-app);
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Native Dialog Enhancements */
dialog:not([open]) {
  display: none !important;
}

dialog {
  max-height: 90vh;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

dialog[open] {
  display: flex !important;
  flex-direction: column;
  animation: modal-fade-in 0.16s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes modal-fade-in {
  from {
    opacity: 0;
    transform: scale(0.98) translateY(4px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ==============================================================================
   Solid Non-Glass Surface Utilities (Zero Glassmorphism / Zero Blur)
   ============================================================================== */

/* Master Structural Panels (Sidebars, Message Lists, Readers) */
.glass-panel {
  background: var(--bg-surface);
  border-color: var(--border-color);
}

#mailbox-sidebar.glass-panel {
  background: var(--bg-sidebar);
  border-color: var(--border-color);
}

/* Top Application Header Bar */
.glass-navbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

/* Elevated Cards, Disclosures, Advisor Panels */
.glass-slab {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

/* Interactive Surface Elements (Folder buttons, Toolbar actions) */
.glass-slab-interactive {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  transition: all 140ms ease;
}

.glass-slab-interactive:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

/* Modal Surface (Compose, Login, Settings) */
.glass-modal {
  background: var(--bg-surface) !important;
  border: 1px solid var(--border-color) !important;
  box-shadow: var(--shadow-modal) !important;
}

/* Solid Form Input Fields */
.glass-input {
  background: var(--bg-surface) !important;
  border: 1px solid var(--border-strong) !important;
  color: var(--text-primary) !important;
  box-shadow: var(--shadow-sm);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.glass-input:focus {
  background: var(--bg-surface) !important;
  border-color: #18181b !important;
  box-shadow: 0 0 0 2px rgba(24, 24, 27, 0.08) !important;
  outline: none;
}

html.dark .glass-input:focus {
  border-color: #e4e4e7 !important;
  box-shadow: 0 0 0 2px rgba(228, 228, 231, 0.12) !important;
}

/* Explicit validation error states only */
.glass-input.input-error,
.glass-input:user-invalid {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.15) !important;
}

/* Status Badges & Pills */
.glass-pill {
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

/* Authoritative Primary CTA Button */
.btn-glass-primary {
  background: var(--primary-btn-bg) !important;
  color: var(--primary-btn-text) !important;
  border: 1px solid var(--primary-btn-bg) !important;
  box-shadow: var(--shadow-sm);
  transition: all 140ms cubic-bezier(0.16, 1, 0.3, 1);
  letter-spacing: -0.01em;
  font-weight: 500;
}

.btn-glass-primary:hover {
  background: var(--primary-btn-hover) !important;
  border-color: var(--primary-btn-hover) !important;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-glass-primary:active {
  transform: translateY(0);
}

/* Compose CTA Button subtle brand accent */
#btn-open-compose i {
  color: var(--brand-red);
  transition: transform 140ms ease;
}

#btn-open-compose:hover {
  border-color: rgba(253, 37, 88, 0.3) !important;
  box-shadow: 0 2px 8px rgba(253, 37, 88, 0.12), var(--shadow-md);
}

#btn-open-compose:hover i {
  transform: rotate(-6deg) scale(1.08);
}

/* Captivating Dispatch Button State */
.btn-sending {
  position: relative;
  overflow: hidden;
  cursor: wait !important;
  opacity: 0.92;
}

.btn-sending .icon-plane-fly {
  display: inline-block;
  color: var(--brand-red);
  animation: sendPlaneFly 0.65s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes sendPlaneFly {
  0% {
    transform: translate(0, 0) rotate(0deg) scale(1);
    opacity: 1;
  }
  35% {
    transform: translate(-2px, 2px) rotate(-10deg) scale(0.95);
  }
  100% {
    transform: translate(22px, -22px) rotate(18deg) scale(0.4);
    opacity: 0;
  }
}

/* Floating Dispatch Capsule (Bottom-Center Island) */
#dispatch-capsule-container {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.dispatch-capsule {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 1rem;
  border-radius: 9999px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.06);
  font-size: 0.75rem;
  color: var(--text-primary);
  animation: capsuleSlideUp 0.32s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: 90vw;
}

.dispatch-capsule.dismissing {
  opacity: 0;
  transform: translateY(12px) scale(0.96);
}

@keyframes capsuleSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn-sending .icon-plane-fly,
  .dispatch-capsule {
    animation: none !important;
  }
}

/* Hide native details disclosure triangles */
details > summary {
  list-style: none;
}
details > summary::-webkit-details-marker {
  display: none;
}
details summary::-moz-list-bullet {
  list-style-type: none;
}

/* Smooth details transitions */
details[open] > summary {
  margin-bottom: 0.25rem;
}

/* Solid Navigation Active State */
.folder-nav-btn {
  border-radius: 0.5rem;
  transition: all 140ms ease;
  color: var(--text-secondary);
}

.folder-nav-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.folder-nav-btn.active {
  background: var(--bg-active) !important;
  color: var(--text-primary) !important;
  font-weight: 600 !important;
  border: 1px solid var(--border-color) !important;
}

.folder-nav-btn.active i {
  color: var(--brand-red) !important;
}

/* Quiet Badges: Automatically hide when count is 0 or empty */
.sidebar-badge {
  background: var(--brand-red-subtle);
  color: var(--brand-red);
  border: 1px solid rgba(253, 37, 88, 0.2);
  font-weight: 600;
}

.sidebar-badge:empty,
.sidebar-badge[data-count="0"],
.sidebar-badge-zero {
  display: none !important;
}


/* Desktop Sidebar Collapsed Rail Mode */
.sidebar-collapsed {
  width: 4.5rem !important; /* 72px */
}

.sidebar-collapsed .sidebar-label {
  display: none !important;
}

.sidebar-collapsed #btn-open-compose {
  padding: 0.625rem !important;
  justify-content: center !important;
  width: 2.75rem !important;
  height: 2.75rem !important;
  margin: 0 auto !important;
  border-radius: 0.75rem !important;
}

.sidebar-collapsed #btn-open-compose .sidebar-label {
  display: none !important;
}

.sidebar-collapsed .folder-nav-btn {
  justify-content: center !important;
  padding: 0.625rem 0 !important;
  position: relative !important;
}

.sidebar-collapsed .folder-nav-btn .sidebar-badge {
  position: absolute !important;
  top: 4px !important;
  right: 10px !important;
  font-size: 0 !important;
  width: 8px !important;
  height: 8px !important;
  min-width: 8px !important;
  padding: 0 !important;
  border-radius: 9999px !important;
  background: var(--brand-red) !important;
  border: 1px solid var(--brand-red) !important;
}

.sidebar-collapsed details summary {
  justify-content: center !important;
}

.sidebar-collapsed details summary .sidebar-label {
  display: none !important;
}

.sidebar-collapsed #quota-bar {
  display: none !important;
}

/* Mobile Off-Canvas Drawer Styles */
@media (max-width: 767px) {
  #mailbox-sidebar.drawer-open {
    transform: translateX(0) !important;
  }

  #sidebar-backdrop.active {
    display: block !important;
    opacity: 1 !important;
  }
}

/* Desktop Reader Focus / Full-Width Mode */
.reader-focused #pane-message-list {
  display: none !important;
}

.reader-focused #mailbox-sidebar {
  display: none !important;
}

/* Message List items with Solid Clean Styling */
.message-list-item {
  transition: background-color 0.12s ease;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  position: relative;
}

.message-list-item:hover {
  background-color: var(--bg-hover);
}

.message-list-item.active {
  background-color: var(--bg-subtle) !important;
  border: 1px solid var(--border-color) !important;
}

.message-list-item .item-sender {
  color: var(--text-primary);
}

.message-list-item .item-subject {
  color: var(--text-primary);
}

.message-list-item.unread .item-subject,
.message-list-item.unread .item-sender {
  font-weight: 600;
  color: var(--text-primary);
}

/* Prose for email viewing */
.prose {
  color: var(--text-primary);
}

.prose p {
  margin-top: 0.75em;
  margin-bottom: 0.75em;
}

.prose code {
  color: var(--brand-red);
  background: var(--brand-red-subtle);
  border: 1px solid rgba(253, 37, 88, 0.12);
  padding: 0.15em 0.35em;
  border-radius: 0.25rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85em;
}

/* Toast animations */
.toast-notice {
  animation: toast-in 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Mobile Touch Target and Viewport optimizations */
@media (max-width: 640px) {
  button, input, select, textarea {
    font-size: 16px; /* Prevents auto-zoom on iOS Safari when tapping inputs */
  }

  .folder-nav-btn {
    min-height: 40px;
  }
}

/* ==============================================================================
   Engineer Metrics & Telemetry (Off by default for clean user experience)
   Toggleable via DevTools console: enableMetrics() / disableMetrics() / toggleMetrics()
   ============================================================================== */
html:not(.show-metrics) .engineer-metric,
body:not(.show-metrics) .engineer-metric {
  display: none !important;
}

.show-metrics .engineer-metric {
  animation: metricFadeIn 0.22s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes metricFadeIn {
  from {
    opacity: 0;
    transform: translateY(-2px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==============================================================================
   Email Viewer Formatted Body Styles
   ============================================================================== */
#view-message-body {
  word-break: break-word;
  overflow-wrap: anywhere;
  color: var(--text-primary);
}

#view-message-body [style*="color:#e4e4e7"],
#view-message-body [style*="color: #e4e4e7"],
#view-message-body [style*="color: rgb(228, 228, 231)"],
#view-message-body [style*="color:rgb(228,228,231)"] {
  color: var(--text-primary) !important;
}

#view-message-body img {
  max-width: 100% !important;
  height: auto !important;
  border-radius: 8px;
  display: inline-block;
  margin: 8px 0;
}

#view-message-body blockquote {
  border: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 10px 0;
  color: var(--text-secondary);
  font-style: italic;
}

#view-message-body a {
  color: #2563eb;
  text-decoration: underline;
  text-underline-offset: 2px;
}

#view-message-body table {
  max-width: 100%;
  border-collapse: collapse;
}

.mail-body-plain {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ==============================================================================
   Conversational Chat Interface Styles
   Strict adherence to AGENTS.md: No left vertical colored accent bars, no emojis
   ============================================================================== */

/* View Mode Switcher */
#view-mode-switcher button.active {
  background-color: var(--bg-surface) !important;
  color: var(--text-primary) !important;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

#view-mode-switcher button:not(.active) {
  color: var(--text-secondary);
}

#view-mode-switcher button:not(.active):hover {
  color: var(--text-primary);
}

/* Chat Stream Container */
#chat-messages-stream {
  scroll-behavior: smooth;
}

/* Chat Message Bubbles */
.chat-bubble-row {
  display: flex;
  margin-bottom: 1rem;
  width: 100%;
}

.chat-bubble-row.incoming {
  justify-content: flex-start;
}

.chat-bubble-row.outgoing {
  justify-content: flex-end;
}

.chat-bubble {
  max-width: 82%;
  position: relative;
  word-break: break-word;
  overflow-wrap: anywhere;
}

@media (min-width: 768px) {
  .chat-bubble {
    max-width: 72%;
  }
}

.chat-bubble.incoming {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  border-top-left-radius: 0.25rem;
  padding: 0.75rem 1rem;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.03);
}

.chat-bubble.outgoing {
  background: #18181b;
  color: #ffffff;
  border: 1px solid #27272a;
  border-radius: 1rem;
  border-top-right-radius: 0.25rem;
  padding: 0.75rem 1rem;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.08);
}

.dark .chat-bubble.incoming {
  background: #18181b;
  color: #f4f4f5;
  border-color: #27272a;
}

.dark .chat-bubble.outgoing {
  background: #f4f4f5;
  color: #09090b;
  border-color: #e4e4e7;
}

/* Clean Quoted Email Box in Chat (Enclosed Card, NO vertical accent bar) */
.chat-quote-card {
  margin-top: 0.625rem;
  padding: 0.625rem 0.75rem;
  border-radius: 0.5rem;
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--border-subtle);
  font-size: 0.725rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.dark .chat-quote-card {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.08);
}

/* Chat Thread List Item (Conversations View) */
.chat-thread-item {
  cursor: pointer;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  transition: background-color 0.15s ease;
}

.chat-thread-item:hover {
  background-color: var(--bg-hover);
}

.chat-thread-item.active {
  background-color: var(--bg-subtle) !important;
  border-color: var(--border-color) !important;
}

/* Auto-resizing inline composer */
#chat-reply-input {
  min-height: 24px;
}

/* Full-Screen Settings View */
#settings-view {
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.settings-nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.875rem;
  border-radius: 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.15s ease;
  cursor: pointer;
  border: 1px solid transparent;
  width: 100%;
  text-align: left;
}

.settings-nav-item:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.settings-nav-item.active {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-color);
  box-shadow: var(--shadow-sm);
}

.settings-mobile-pill {
  padding: 0.4rem 0.875rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text-secondary);
  background-color: var(--bg-hover);
  border: 1px solid var(--border-color);
  transition: all 0.15s ease;
}

.settings-mobile-pill.active {
  background-color: var(--primary-btn-bg);
  color: var(--primary-btn-text);
  border-color: var(--primary-btn-bg);
}

.hidden {
  display: none !important;
}

@media (min-width: 768px) {
  .settings-desktop-nav {
    display: flex !important;
    flex-direction: column !important;
  }
  .settings-mobile-nav {
    display: none !important;
  }
}

@media (max-width: 767px) {
  .settings-desktop-nav {
    display: none !important;
  }
  .settings-mobile-nav {
    display: flex !important;
  }
}




/* =========================================================================
   Email Marquee — header-user-email scrolling ticker for long addresses
   Only scrolls when inner text overflows the 130px clip track.
   Class `.is-overflowing` is applied by JS after measuring offsetWidth.
   ========================================================================= */
@keyframes email-marquee-scroll {
  0%   { transform: translateX(0); }
  /* Pause at start */
  10%  { transform: translateX(0); }
  /* Scroll all the way left so the full text is visible */
  85%  { transform: translateX(var(--marquee-offset, -60px)); }
  /* Pause at end */
  95%  { transform: translateX(var(--marquee-offset, -60px)); }
  /* Snap back without visible gap */
  100% { transform: translateX(0); }
}

.email-marquee-track {
  width: 130px;
  overflow: hidden;
  position: relative;
  white-space: nowrap;
}

/* When NOT overflowing just show the text, no animation */
.email-marquee-track #header-user-email {
  display: inline-block;
  white-space: nowrap;
}

/* When overflowing, animate */
.email-marquee-track.is-overflowing #header-user-email {
  animation: email-marquee-scroll 6s ease-in-out infinite;
}
