/* ===================================================================
   RESPONSIVE DESIGN & MOBILE NOTEBOOK OPTIMIZATIONS
   Seamless mobile UX: touch targets, thumb-friendly navigation,
   adaptive typography, compact desk header, edge-to-edge notebook
   =================================================================== */

/* Prevent unwanted zoom on focus in iOS WebKit */
@media (max-width: 768px) {
  input, select, textarea {
    font-size: 16px !important;
  }
}

/* -------------------------------------------------------------------
   1. DESK CANVAS & NOTEBOOK BINDER (< 768px)
   ------------------------------------------------------------------- */
@media (max-width: 768px) {
  .desk-canvas {
    padding: 6px 6px 78px 6px !important; /* Bottom clearance for dock */
    min-height: 100vh;
  }

  .notebook-container {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
  }

  .notebook-book {
    border-radius: var(--radius-md) !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06) !important;
    min-height: calc(100vh - 120px) !important;
  }

  .notebook-spiral-strip {
    display: none !important;
  }

  .notebook-page {
    padding: 14px 12px !important;
    background-size: 16px 16px !important;
  }

  /* Page Header */
  .page-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
    margin-bottom: var(--space-md) !important;
    padding-bottom: 8px !important;
  }

  .page-header-title-box {
    flex-wrap: wrap !important;
    gap: 4px !important;
  }

  .page-title {
    font-size: 1.25rem !important;
  }

  .page-subtitle {
    font-size: 0.95rem !important;
  }
}

/* -------------------------------------------------------------------
   2. DESK HEADER & TOP CONTROLS (< 768px & < 480px)
   ------------------------------------------------------------------- */
@media (max-width: 768px) {
  .desk-header {
    padding: 8px 10px !important;
    margin-bottom: 8px !important;
    border-radius: var(--radius-sm) !important;
    gap: 8px !important;
  }

  .brand-section {
    gap: 8px !important;
  }

  .brand-icon {
    width: 32px !important;
    height: 32px !important;
    font-size: 1rem !important;
  }

  .brand-info h1 {
    font-size: 0.95rem !important;
  }

  .brand-info p {
    display: none !important; /* Hide subtitle on mobile to conserve space */
  }

  .header-clock-badge {
    padding: 4px 10px !important;
    font-size: 0.75rem !important;
  }

  .header-actions {
    width: 100% !important;
    justify-content: space-between !important;
    gap: 6px !important;
    padding-top: 6px !important;
    border-top: 1px dashed var(--border-subtle) !important;
  }

  .theme-switch-group {
    padding: 2px !important;
  }

  .theme-pill-btn {
    padding: 4px 8px !important;
    font-size: 0.72rem !important;
  }

  .theme-auto-info {
    display: none !important; /* Hide verbose auto indicator */
  }

  .ink-studio-wrapper {
    padding: 2px 6px !important;
    gap: 4px !important;
  }

  .ink-studio-label {
    display: none !important;
  }

  .ink-bottle-btn {
    width: 16px !important;
    height: 16px !important;
  }

  .icon-action-btn {
    width: 32px !important;
    height: 32px !important;
    font-size: 0.85rem !important;
  }
}

/* -------------------------------------------------------------------
   3. TOP NOTEBOOK TABS BAR (< 768px)
   ------------------------------------------------------------------- */
@media (max-width: 768px) {
  .notebook-tabs-wrapper {
    padding-left: 4px !important;
    padding-right: 4px !important;
    gap: 4px !important;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }

  .notebook-tab {
    padding: 8px 12px !important;
    font-size: 0.78rem !important;
    gap: 5px !important;
    scroll-snap-align: start;
    flex-shrink: 0;
  }

  .notebook-tab .tab-icon svg {
    width: 14px !important;
    height: 14px !important;
  }

  .notebook-tab .tab-badge {
    font-size: 0.65rem !important;
    padding: 0 4px !important;
  }
}

/* -------------------------------------------------------------------
   4. SLEEK MOBILE BOTTOM DOCK NAVIGATION (Thumb ergonomics)
   ------------------------------------------------------------------- */
.mobile-bottom-dock {
  display: none;
}

@media (max-width: 768px) {
  .mobile-bottom-dock {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-strong);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
    z-index: 990;
    align-items: center;
    justify-content: space-around;
  }

  .mobile-dock-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 100%;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    padding: 4px 2px;
    position: relative;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-dock-btn .mobile-dock-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: currentColor;
    transition: transform var(--transition-fast);
  }

  .mobile-dock-btn .mobile-dock-icon svg {
    width: 18px;
    height: 18px;
  }

  .mobile-dock-btn .mobile-dock-label {
    font-family: var(--font-display);
    font-size: 0.62rem;
    font-weight: 600;
    color: currentColor;
    line-height: 1;
    letter-spacing: -0.01em;
  }

  .mobile-dock-btn.active {
    color: var(--primary);
  }

  .mobile-dock-btn.active .mobile-dock-icon {
    transform: translateY(-2px);
  }

  .mobile-dock-btn.active::after {
    content: '';
    position: absolute;
    bottom: calc(3px + env(safe-area-inset-bottom, 0px));
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--primary);
  }
}

/* -------------------------------------------------------------------
   5. PAGE 1: TODOS (Mobile Forms, Filters & Cards)
   ------------------------------------------------------------------- */
@media (max-width: 768px) {
  .todo-toolbar {
    padding: 10px !important;
    gap: 10px !important;
    margin-bottom: 12px !important;
  }

  .quick-add-form {
    flex-direction: column !important;
    gap: 8px !important;
  }

  .quick-add-input {
    width: 100% !important;
    min-width: 100% !important;
  }

  .quick-add-options-row {
    display: flex;
    gap: 6px;
    width: 100%;
  }

  .quick-add-options-row select,
  .quick-add-options-row input {
    flex: 1;
    min-width: 0;
  }

  .quick-add-form .btn-primary {
    width: 100% !important;
    justify-content: center !important;
    padding: 10px !important;
  }

  .filter-row {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }

  .filter-pills {
    width: 100% !important;
    display: flex !important;
    justify-content: stretch !important;
  }

  .filter-btn {
    flex: 1 !important;
    text-align: center !important;
    padding: 6px 4px !important;
    font-size: 0.78rem !important;
  }

  .search-box {
    width: 100% !important;
    min-width: 100% !important;
  }

  .search-box input {
    width: 100% !important;
  }

  /* Todo Cards on Mobile */
  .todo-item-card {
    padding: 10px 10px !important;
    gap: 8px !important;
  }

  .todo-left {
    align-items: flex-start !important;
    gap: 8px !important;
  }

  .todo-checkbox {
    margin-top: 2px !important;
    flex-shrink: 0 !important;
  }

  .todo-title {
    font-size: 0.94rem !important;
    line-height: 1.35 !important;
  }

  .todo-meta {
    gap: 4px !important;
    font-size: 0.72rem !important;
  }

  .todo-actions {
    opacity: 1 !important;
    align-self: flex-start !important;
    flex-shrink: 0 !important;
  }

  .todo-action-btn {
    padding: 4px 6px !important;
  }

  .subtasks-container {
    padding-left: 20px !important;
  }
}

/* -------------------------------------------------------------------
   6. PAGE 2: NOT-DO HABIT LIST (< 768px)
   ------------------------------------------------------------------- */
@media (max-width: 768px) {
  .notdo-banner {
    flex-direction: column !important;
    align-items: flex-start !important;
    padding: 12px !important;
    gap: 8px !important;
    margin-bottom: var(--space-md) !important;
  }

  .notdo-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .notdo-card {
    padding: 12px !important;
  }

  .notdo-bad-habit {
    font-size: 1rem !important;
  }

  .notdo-consequence,
  .notdo-alternative {
    font-size: 0.82rem !important;
    padding: 6px 10px !important;
  }
}

/* -------------------------------------------------------------------
   7. PAGE 3: DAILY LEDGER & TIMEBLOCKING (< 768px)
   ------------------------------------------------------------------- */
@media (max-width: 768px) {
  .daily-planner-grid {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }

  .mood-picker-bar {
    padding: 6px 8px !important;
    gap: 6px !important;
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .mood-picker-bar::-webkit-scrollbar { display: none; }

  .mood-stamp-btn {
    padding: 4px 10px !important;
    font-size: 0.75rem !important;
    flex-shrink: 0 !important;
  }

  .rule-of-three-item {
    padding: 8px 10px !important;
  }

  .timeblock-slot {
    padding: 6px 8px !important;
    gap: 6px !important;
  }

  .timeblock-hour {
    width: 48px !important;
    font-size: 0.75rem !important;
  }
}

/* -------------------------------------------------------------------
   8. PAGE 4: CALENDAR & EVENTS (< 768px)
   ------------------------------------------------------------------- */
@media (max-width: 768px) {
  .calendar-layout {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .calendar-main-card {
    padding: 10px !important;
  }

  .calendar-controls {
    margin-bottom: 8px !important;
  }

  .calendar-month-title {
    font-size: 1.1rem !important;
  }

  .calendar-weekday {
    font-size: 0.68rem !important;
    padding: 3px 0 !important;
  }

  .calendar-day-cell {
    min-height: 44px !important;
    padding: 2px !important;
    border-radius: 2px !important;
  }

  .cal-day-num {
    font-size: 0.72rem !important;
  }

  .cal-event-pill {
    font-size: 0.65rem !important;
    padding: 1px 3px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
}

/* -------------------------------------------------------------------
   9. PAGE 5: POMODORO STATION (< 768px)
   ------------------------------------------------------------------- */
@media (max-width: 768px) {
  .pomodoro-dial-container {
    width: min(230px, 68vw) !important;
    height: min(230px, 68vw) !important;
  }

  .pomodoro-time-display {
    font-size: clamp(2.2rem, 9vw, 3rem) !important;
  }

  .pomo-mode-selector {
    gap: 3px !important;
    padding: 2px !important;
  }

  .pomo-mode-btn {
    padding: 5px 10px !important;
    font-size: 0.75rem !important;
  }

  .btn-pomo-main {
    padding: 10px 24px !important;
    font-size: 1rem !important;
  }

  .ambient-bar {
    flex-direction: column !important;
    align-items: flex-start !important;
    padding: 10px !important;
    gap: 8px !important;
  }

  .ambient-options {
    width: 100% !important;
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 4px !important;
  }

  .ambient-btn {
    padding: 6px 4px !important;
    font-size: 0.68rem !important;
    justify-content: center !important;
  }
}

/* -------------------------------------------------------------------
   10. PAGE 6: STICKY BOARD (< 768px)
   ------------------------------------------------------------------- */
@media (max-width: 768px) {
  .stickies-board {
    padding: 10px !important;
    gap: 12px !important;
    justify-content: center !important;
  }

  .sticky-note {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 140px !important;
  }
}

/* -------------------------------------------------------------------
   11. PAGE 7: BULLET JOURNAL & HABIT STUDIO (< 768px)
   ------------------------------------------------------------------- */
@media (max-width: 768px) {
  .bujo-matrix-card,
  .bujo-habits-card,
  .bujo-rapid-card {
    padding: 12px 10px !important;
  }

  .bujo-matrix-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
  }

  .bujo-matrix-controls {
    width: 100% !important;
    justify-content: space-between !important;
  }

  .matrix-view-toggle {
    flex: 1 !important;
    justify-content: center !important;
  }

  .matrix-view-btn {
    padding: 3px 7px !important;
    font-size: 0.68rem !important;
  }

  /* Grid Layout: 1 column on mobile */
  .year-matrix-grid-layout {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  /* Habit Table Sticky First Column on Mobile */
  .habit-col-name {
    position: sticky !important;
    left: 0 !important;
    background: var(--bg-card) !important;
    z-index: 5 !important;
    min-width: 130px !important;
  }

  .habit-name-cell {
    position: sticky !important;
    left: 0 !important;
    background: var(--bg-card) !important;
    z-index: 4 !important;
    min-width: 130px !important;
    box-shadow: 2px 0 6px rgba(0, 0, 0, 0.06) !important;
  }
}

/* -------------------------------------------------------------------
   12. MODALS & DIALOGS (< 768px)
   ------------------------------------------------------------------- */
@media (max-width: 768px) {
  .modal-overlay {
    padding: 12px !important;
    align-items: flex-end !important; /* Bottom-sheet appearance on mobile */
  }

  .modal-card {
    max-width: 100% !important;
    width: 100% !important;
    padding: 16px 14px !important;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
    max-height: 88vh !important;
    transform: translateY(20px) !important;
  }

  .modal-overlay.active .modal-card {
    transform: translateY(0) !important;
  }

  .modal-footer {
    display: flex !important;
    gap: 8px !important;
  }

  .modal-footer .btn {
    flex: 1 !important;
    justify-content: center !important;
    padding: 10px !important;
  }

  /* In-app notification banner on mobile */
  .in-app-notif-banner {
    top: 8px !important;
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
  }

  .notif-banner-card {
    padding: 10px 12px !important;
    gap: 8px !important;
  }
}
