/* =========================================
   MOBILE-FIRST DIARY REDESIGN
   ========================================= */

/* --- Base: Diary Page Wrapper --- */
.diary-page-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* --- Diary Header: more compact on small screens --- */
@media (max-width: 768px) {
  .diary-container-fluid {
    padding-top: var(--dashboard-content-top-gap);
    padding-bottom: 0.25rem !important;
  }

  .diary-header {
    margin-top: 0 !important;
    margin-bottom: 0.5rem !important;
    text-align: left;
  }

  .diary-title {
    margin-top: 0 !important;
    font-size: 1.4rem !important;
    margin-bottom: 0 !important;
  }

  .diary-subtitle {
    display: none !important;
  }
}

/* --- Grid: single column on mobile --- */
@media (max-width: 1024px) {
  .diary-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .diary-sidebar {
    padding: 0 1rem 2rem;
  }
}

/* --- Notebook page: tighter padding on mobile --- */
@media (max-width: 768px) {
  .diary-notebook-page {
    padding: 1rem 0.75rem 1rem 1.25rem;
    border-radius: 0;
    border-left: none;
    border-right: none;
    margin-bottom: 0;
    box-shadow: none;
  }

  .diary-notebook-page::before {
    left: 0.75rem;
  }

  .diary-form {
    padding-bottom: 0 !important;
  }
}


/* --- Context Bar (mobile: split evenly by default, collapse others when focused) --- */
@media (max-width: 768px) {
  .diary-context-bar {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.4rem;
    margin-bottom: 1.25rem;
    width: 100%;
  }

  .context-pill {
    flex: 1 1 33.333%;
    min-width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 8px !important; /* Square button with rounded corners */
    justify-content: center;
    overflow: hidden;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Hide placeholders entirely */
  .context-pill .context-input::placeholder {
    color: transparent !important;
  }

  /* Show input values if populated, hide if empty (so they fit centered icon) */
  .context-pill .context-input {
    width: 0;
    opacity: 0;
    padding: 0;
    font-size: 0.85rem;
    transition: width 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
  }

  .context-pill:has(input:not(:placeholder-shown)) .context-input,
  .context-pill:has(.user-tag-pill) .context-input {
    width: 100%;
    opacity: 1;
    padding: 0 0.4rem;
    justify-content: flex-start;
  }

  /* Expand the focused pill and collapse the other non-focused ones */
  .diary-context-bar:has(.context-pill:focus-within) .context-pill:not(:focus-within) {
    flex: 0 0 36px !important;
    width: 36px !important;
  }

  .diary-context-bar:has(.context-pill:focus-within) .context-pill:not(:focus-within) .context-input {
    width: 0 !important;
    opacity: 0 !important;
    padding: 0 !important;
  }

  .context-pill:focus-within {
    flex: 1 1 auto !important;
    border-radius: 8px !important;
    padding: 0 0.4rem 0 0.2rem;
    justify-content: flex-start;
  }

  .context-pill:focus-within .context-input {
    width: 100% !important;
    opacity: 1 !important;
    padding: 0 0.4rem;
  }

  .context-icon, .context-icon-btn {
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.95rem;
  }
  
  /* Make dropdown lists fit mobile screen context */
  .user-dropdown {
    position: absolute;
    top: 40px;
    left: 0;
    width: 220px;
    z-index: 100;
  }
}


/* --- Emotion picker grid: horizontal scroll on mobile --- */
@media (max-width: 768px) {
  .emotion-picker-container {
    margin-bottom: 1rem;
  }

  .emotion-picker-grid {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.5rem;
    gap: 0.4rem;
  }

  .emotion-picker-grid::-webkit-scrollbar {
    display: none;
  }

  .emotion-pill {
    flex-shrink: 0;
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
  }
}

/* --- Mood slider: more touch-friendly --- */
@media (max-width: 768px) {
  .diary-form-group {
    margin-bottom: 1rem;
  }

  .handmade-label {
    font-size: 0.9rem !important;
    margin-bottom: 0.3rem !important;
  }

  .mood-slider-container {
    padding: 0.35rem 0;
  }

  .mood-slider {
    height: 5px;
  }

  .mood-slider::-webkit-slider-thumb {
    width: 20px;
    height: 20px;
    border-width: 2px;
  }

  .mood-slider-labels {
    font-size: 0.7rem;
    margin-top: 0.35rem;
  }
}

/* --- THE WRITING AREA: the star of the show --- */
@media (max-width: 768px) {
  /* Textarea "Dear Diary" — make it feel like a real page */
  .diary-textarea.lined-paper {
    font-size: 1rem;
    line-height: 1.5rem;
    background-size: 100% 1.5rem;
    min-height: 6rem;  /* Exactly 4 lines: 4 * 1.5rem */
    height: 6rem;
    padding: 0.2rem 0.4rem;
    resize: vertical;
  }

  /* Focused state: subtle highlight */
  .diary-textarea.lined-paper:focus {
    background-color: rgba(255, 255, 255, 0.5);
    outline: none;
    box-shadow: none;
  }
}

/* On very small screens: maintain 4 lines height */
@media (max-width: 480px) {
  .diary-textarea.lined-paper {
    min-height: 6rem;
    height: 6rem;
  }
}


/* --- Photo attachment area --- */
@media (max-width: 768px) {
  .attachment-polaroid-btn {
    padding: 0.75rem;
    border-radius: 8px;
  }

  .attachment-icon {
    font-size: 1.25rem;
    margin-bottom: 0.2rem;
  }

  .attachment-title {
    font-size: 0.85rem;
  }

  .attachment-preview-grid {
    gap: 0.4rem;
  }

  .polaroid-preview {
    width: 90px;
  }
}

/* --- Submit button: static at bottom of form on mobile --- */
@media (max-width: 768px) {
  .diary-submit {
    position: static !important;
    background: transparent !important;
    padding: 1.25rem 0 0 !important;
    margin: 0 !important;
    text-align: center;
  }

  .wax-seal-btn {
    width: 100%;
    padding: 0.6rem 1rem !important;
    font-size: 0.9rem;
    border-radius: 8px !important;
    text-align: center;
    display: block;
  }
}


/* --- Diary auto-scroll section: smaller on mobile --- */
@media (max-width: 768px) {
  .diary-auto-scroll-container {
    padding: 1.5rem 0;
  }

  .auto-scroll-title {
    font-size: 1.5rem;
    margin-bottom: 1.25rem;
  }

  .auto-scroll-item {
    width: 280px;
  }
}

/* --- Sidebar sections: compact on mobile --- */
@media (max-width: 1024px) {
  .sidebar-section {
    padding: 1rem 0;
    border-top: 1px dashed rgba(0, 0, 0, 0.08);
  }

  .sidebar-title {
    font-size: 1.25rem;
    margin-bottom: 1rem;
  }

  /* Recent photos: smaller polaroids */
  .recent-photos-grid {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  }

  .mini-polaroid {
    padding: 4px 4px 14px !important;
  }

  /* Mood heatmap: smaller cells */
  .mood-heatmap {
    padding: 1rem;
    gap: 6px;
  }

  .mood-day {
    width: 32px;
    height: 32px;
    font-size: 0.65rem;
    border-radius: 6px;
  }
}

/* --- Earlier today feed: compact cards --- */
@media (max-width: 768px) {
  .diary-entry-card {
    padding: 1rem 1rem 1rem 2rem;
  }

  .diary-entry-header {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
  }

  .diary-note-preview {
    margin-top: 0.75rem;
    padding: 0.75rem;
    font-size: 0.9rem;
  }
}

/* --- Prevent horizontal overflow --- */
@media (max-width: 768px) {
  .diary-page-wrapper {
    overflow-x: hidden;
  }

  .diary-context-bar {
    overflow-x: hidden;
  }
}

/* --- Focus mode: when textarea is focused, dim surrounding elements for a zen-like writing experience --- */
@media (max-width: 768px) {
  /* Transitions for dimming */
  .diary-header,
  .diary-form > *:not(.diary-submit) {
    transition: opacity 0.25s ease, filter 0.25s ease;
  }

  /* Fade and blur all other content when textarea is focused */
  .diary-page-wrapper:has(.diary-textarea:focus) .diary-header {
    opacity: 0.08;
    filter: blur(1.5px);
  }

  .diary-form:has(.diary-textarea:focus) > *:not(:has(.diary-textarea)):not(.diary-submit) {
    opacity: 0.08;
    filter: blur(1.5px);
    pointer-events: none;
  }

  /* Keep active textarea and submit button fully visible */
  .diary-form:has(.diary-textarea:focus) .diary-form-group:has(.diary-textarea),
  .diary-form:has(.diary-textarea:focus) .diary-submit {
    opacity: 1;
    filter: none;
    pointer-events: auto;
  }

  .diary-form .diary-textarea.lined-paper:focus {
    border-bottom: 2px solid var(--action-primary);
  }
}


/* =========================================
   DIARY CRUD — MOBILE RESPONSIVE (new)
   ========================================= */

/* Entry cards: tighter on small screens */
@media (max-width: 768px) {
  .diary-section-heading {
    font-size: 1.2rem;
  }

  /* Heatmap section: less top padding on mobile */
  .diary-heatmap-section {
    padding-top: 0.75rem;
  }
}
