/* =========================================================================
   PIXEL FOLD & RESPONSIVE SPLIT-SCREEN BREAKPOINTS
   - Inner Unfolded Display (~884px - 1120px width, ~6:5 landscape square ratio)
   - Outer Cover Display (~360px - 640px width, tall portrait)
   ========================================================================= */
@media (max-width: 1180px) {
  .highlights-levels-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 960px) {
  .left-sidebar {
    width: 158px;
    min-width: 158px;
    max-width: 158px;
    padding: 10px 5px;
  }
  .nav-tab {
    padding: 7px 5px;
    font-size: 0.82rem;
  }
}

@media (max-width: 820px) {
  .highlights-levels-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .pool-two-parts {
    grid-template-columns: 1fr;
  }
  .week-strip-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .month-cal-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .year-months-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .form-row-3,
  .form-row-2,
  .writing-meta-row {
    grid-template-columns: 1fr;
  }
  .book-chunks-grid {
    grid-template-columns: 1fr;
  }
  .horizon-tabs {
    width: 100%;
    overflow-x: auto;
  }
  .horizon-tab {
    flex: 1;
    text-align: center;
    padding: 7px 10px;
  }
}

/* Pixel Fold Folded Cover Screen (<= 640px) */
@media (max-width: 640px) {
  .app-shell.app-layout-container {
    padding: 4px 6px;
    gap: 6px;
  }
  .left-sidebar {
    width: 58px !important;
    min-width: 58px !important;
    max-width: 58px !important;
    padding: 8px 4px;
    align-items: center;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }
  .sidebar-brand-text,
  .nav-tab-label,
  .sidebar-btn-text,
  .sidebar-sys-info,
  .btn-sidebar-collapse {
    display: none !important;
  }
  .sidebar-header {
    justify-content: center;
    padding-bottom: 6px;
    margin-bottom: 6px;
  }
  .sidebar-brand {
    justify-content: center;
  }
  .sidebar-body,
  .sidebar-nav {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }
  .nav-tab {
    justify-content: center;
    padding: 9px 2px;
    flex-direction: column;
    gap: 2px;
    min-height: 48px;
    border-left-width: 1px;
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }
  .nav-tab.active {
    border-left-width: 3px;
  }
  .nav-tab-icon {
    font-size: 1.3rem;
    width: auto;
    margin: 0 auto !important;
    display: inline-flex !important;
  }
  /* Time Logger tab in folded/mobile icon mode */
  .left-sidebar .nav-tab-pill.pill-mini-timer,
  .left-sidebar .nav-tab-pill.pill-recording,
  .left-sidebar #badge-nav-timer {
    display: none !important;
  }
  .left-sidebar .nav-tab.is-recording .nav-tab-icon,
  .left-sidebar .nav-tab.is-recording .nav-tab-icon-timer,
  .left-sidebar .nav-tab.is-recording .dynamic-timer-icon {
    display: inline-flex !important;
  }
  .dynamic-cal-icon {
    width: 24px;
    height: 24px;
  }
  .dynamic-cal-day {
    height: 8px;
    font-size: 7px;
  }
  .dynamic-cal-date {
    font-size: 12px;
  }
  .nav-tab-pill {
    margin: 0;
    font-size: 0.55rem;
    padding: 1px 3px;
  }
  .btn-sidebar-action {
    justify-content: center;
    padding: 6px 2px;
  }
  .topbar {
    padding: 7px 9px;
    margin-bottom: 6px;
    gap: 6px;
  }
  .active-tab-headline h1 {
    font-size: 1rem;
  }
  .topbar-subtitle {
    display: none;
  }
  .topbar-sep {
    display: none;
  }
  .titlebar-actions {
    gap: 6px;
  }
  .gdrive-group {
    display: none;
  }
  .highlights-levels-grid {
    display: flex !important;
    overflow-x: auto;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    gap: 6px !important;
    padding-bottom: 4px;
  }
  .highlights-levels-grid .hl-level-card {
    flex: 0 0 150px;
    min-width: 150px;
  }
}

/* User-toggled Collapsed Sidebar Mode (Any screen size) */
.left-sidebar.collapsed {
  width: 58px !important;
  min-width: 58px !important;
  max-width: 58px !important;
  padding: 8px 4px !important;
  align-items: center !important;
  overflow-x: hidden !important;
  box-sizing: border-box !important;
}
.left-sidebar.collapsed .sidebar-brand-text,
.left-sidebar.collapsed .nav-tab-label,
.left-sidebar.collapsed .sidebar-btn-text,
.left-sidebar.collapsed .sidebar-sys-info {
  display: none !important;
}
.left-sidebar.collapsed .sidebar-header {
  justify-content: center;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding-bottom: 8px;
  width: 100%;
}
.left-sidebar.collapsed .sidebar-header-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}
.left-sidebar.collapsed #btn-brand-fullscreen,
.left-sidebar.collapsed .btn-fullscreen-toggle {
  display: none !important;
}
.left-sidebar.collapsed .sidebar-brand {
  justify-content: center;
  width: 100%;
}
.left-sidebar.collapsed .sidebar-body,
.left-sidebar.collapsed .sidebar-nav {
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: hidden !important;
  box-sizing: border-box !important;
}
.left-sidebar.collapsed .nav-tab {
  justify-content: center !important;
  align-items: center !important;
  padding: 9px 0 !important;
  gap: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}
.left-sidebar.collapsed .nav-tab-icon {
  margin: 0 auto !important;
  flex-shrink: 0 !important;
}
.left-sidebar.collapsed .dynamic-cal-icon {
  width: 24px;
  height: 24px;
}
.left-sidebar.collapsed .dynamic-cal-day {
  height: 8px;
  font-size: 7px;
}
.left-sidebar.collapsed .dynamic-cal-date {
  font-size: 12px;
}
.left-sidebar.collapsed .nav-tab-pill,
.left-sidebar.collapsed .nav-tab-pill.pill-recording,
.left-sidebar.collapsed .nav-tab-pill.pill-mini-timer,
.left-sidebar.collapsed #badge-nav-timer,
.left-sidebar.collapsed .planner-weather-icon {
  display: none !important;
}
.left-sidebar.collapsed .btn-sidebar-action {
  justify-content: center;
  padding: 6px 2px;
}
.left-sidebar.collapsed .sidebar-highlights-section,
.left-sidebar.collapsed .sidebar-perks-vault-section {
  display: none !important;
}
.left-sidebar.collapsed .visual-edit-bar {
  display: flex !important;
  justify-content: center;
  width: 100%;
}
.left-sidebar.collapsed .visual-edit-bar .btn-visual-edit,
.left-sidebar.collapsed .visual-edit-bar .btn-save-edit,
.left-sidebar.collapsed .visual-edit-bar .btn-cancel-edit,
.left-sidebar.collapsed .visual-edit-bar .btn-undo-edit {
  justify-content: center;
  padding: 6px 2px;
}
.left-sidebar.collapsed .visual-edit-actions {
  flex-direction: column;
  gap: 4px;
}


/* =========================================================================
   BUILT-IN AI CHAT DRAWER & FLOATING CHAT BUBBLE (Pixel Fold Friendly)
   ========================================================================= */
.chat-fab-btn {
  position: fixed;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom, 18px));
  z-index: 1090;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-emerald));
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 11px 18px;
  font-size: 0.86rem;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(88, 102, 201, 0.35);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.chat-fab-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 11px 28px rgba(47, 158, 119, 0.40);
}

.chat-fab-btn.dragging {
  cursor: grabbing !important;
  opacity: 0.94;
  transform: scale(1.04);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
  transition: none !important;
}

.chat-fab-icon {
  font-size: 1rem;
}

.chat-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 35, 42, 0.28);
  backdrop-filter: blur(2px);
  z-index: 1100;
  transition: opacity 0.2s ease;
}

.chat-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(440px, 100vw);
  height: 100vh;
  height: 100dvh;
  background: var(--bg-card);
  border-left: 1px solid var(--border-subtle);
  box-shadow: -8px 0 32px rgba(45, 52, 54, 0.14);
  z-index: 1110;
  display: flex;
  flex-direction: column;
  transform: translateX(102%);
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}

.chat-drawer.open {
  transform: translateX(0);
}

.chat-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-card-elevated);
}

.chat-header-eyebrow {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--accent-emerald);
  letter-spacing: 0.04em;
}

.chat-header-title-group h3 {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 2px;
}

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

.chat-close-btn {
  font-weight: 700;
  padding: 4px 9px;
}

.chat-capabilities-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 8px 14px;
  background: var(--bg-subcard);
  border-bottom: 1px solid var(--border-subtle);
}

.chat-cap-pill {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  color: #5866c9;
  background: rgba(108, 122, 224, 0.10);
  border: 1px solid rgba(108, 122, 224, 0.22);
  padding: 2px 7px;
  border-radius: 999px;
}

.chat-quick-prompts {
  display: flex;
  gap: 6px;
  padding: 8px 14px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-card);
  scrollbar-width: thin;
}

.chat-quick-prompts .chip-btn {
  white-space: nowrap;
  flex-shrink: 0;
}

.chat-messages-list {
  flex: 1;
  overflow-y: auto;
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  background: var(--bg-main);
}

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 92%;
}

.chat-msg-user {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-msg-ai {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-msg-meta {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  color: var(--text-muted);
}

.chat-msg-bubble {
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.81rem;
  line-height: 1.5;
  word-break: break-word;
}

.chat-msg-user .chat-msg-bubble {
  background: var(--accent-indigo);
  color: #ffffff;
  border-bottom-right-radius: 3px;
}

.chat-msg-ai .chat-msg-bubble {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: 3px;
  box-shadow: 0 2px 8px rgba(80, 70, 50, 0.04);
}

.chat-action-card {
  margin-top: 7px;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(47, 158, 119, 0.10);
  border: 1px solid rgba(47, 158, 119, 0.32);
  color: #1f5f4a;
  font-size: 0.74rem;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chat-citations-wrap {
  margin-top: 7px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chat-citation-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.67rem;
  font-family: var(--font-mono);
  color: #3b7dd8;
  background: rgba(59, 125, 216, 0.10);
  border: 1px solid rgba(59, 125, 216, 0.25);
  padding: 2px 8px;
  border-radius: 999px;
  text-decoration: none;
}

.chat-citation-pill:hover {
  background: rgba(59, 125, 216, 0.18);
}

.chat-input-form {
  padding: 11px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-card);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.chat-input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Pixel Fold Inner Screen (~700-960px) & Outer Cover Screen (<=600px) */
@media (max-width: 920px) {
  .chat-drawer {
    width: min(410px, 92vw);
  }
}

@media (max-width: 560px) {
  .chat-drawer {
    width: 100vw;
    border-left: none;
  }
  .chat-fab-btn {
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom, 12px));
    padding: 10px 15px;
    font-size: 0.8rem;
  }
}


