/* --------------------------------------------------------------------------
   15. RESPONSIVE BREAKPOINTS
   -------------------------------------------------------------------------- */
/* Laptop / Narrow Desktop (< 1350px) */
@media (max-width: 1349px) {
  .workspace-grid {
    display: block;
  }
  .desktop-rail-only {
    display: none;
  }
  .main-scrollable {
    width: min(100% - 2.5rem, 1150px);
  }
}

/* Small Laptop & Tablet Landscape (900px–1199px) */
@media (max-width: 1199px) {
  :root {
    --sidebar-w: 240px;
  }
  .main-scrollable {
    padding: 1.8rem 1.4rem 5rem;
  }
  .composer-options-row {
    flex-wrap: wrap;
  }
  .option-field-priority,
  .option-field-date,
  .option-field-time,
  .option-field-project {
    flex: 1 1 140px;
  }
  .option-field-tags {
    flex: 1 1 100%;
  }
}

/* Tablet Portrait (768px–899px) */
@media (max-width: 899px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .composer-options-row {
    flex-wrap: wrap;
  }
}

/* Mobile Screens (320px–767px) */
@media (max-width: 767px) {
  body.sidebar-open {
    overflow: hidden;
  }

  .mobile-only {
    display: flex;
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(84vw, 320px);
    max-width: 320px;
    height: 100vh;
    height: 100dvh;
    z-index: 100;
    transform: translateX(-100%);
    box-shadow: 8px 0 36px rgba(0, 0, 0, 0.55);
    background: var(--sidebar-bg);
    transition: transform 280ms cubic-bezier(0.16, 1, 0.3, 1), background-color 300ms ease;
  }

  .app-sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: block;
    z-index: 90;
  }

  .sidebar-header {
    padding-top: calc(1.2rem + env(safe-area-inset-top, 0px));
  }

  .sidebar-footer {
    padding-bottom: calc(1.1rem + env(safe-area-inset-bottom, 0px));
  }

  .mobile-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.95rem 1.3rem;
    background: var(--sidebar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
  }

  .mobile-brand .brand-name {
    font-size: 1.35rem;
  }

  .mobile-top-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .main-scrollable {
    width: 100%;
    padding: 1.4rem 1.1rem 6.5rem;
  }

  .hero-section {
    margin-bottom: 1.6rem;
  }

  .hero-title {
    font-size: clamp(2.1rem, 7vw, 2.7rem);
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.8rem;
  }

  .composer-panel {
    display: none; /* Mobile uses the dedicated bottom sheet composer via + button */
  }

  .list-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
  }

  .todo-item {
    grid-template-columns: auto 1fr;
    gap: 0.85rem;
    padding: 1rem;
  }

  .todo-actions {
    grid-column: span 2;
    justify-content: flex-end;
    border-top: 1px solid var(--border-light);
    padding-top: 0.5rem;
    margin-top: 0.25rem;
  }

  /* Mobile 5-Button Bottom Nav */
  .mobile-bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--sidebar-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-top: 1px solid var(--border);
    padding: 0.45rem 0.3rem calc(0.45rem + env(safe-area-inset-bottom, 0px));
    z-index: 30;
  }

  .mobile-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.4rem 0.2rem;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 10px;
    transition: color 150ms ease;
  }

  .mobile-nav-btn.active {
    color: var(--accent);
  }

  .mobile-nav-btn.active svg {
    stroke: var(--accent);
  }

  /* Center Floating + Action Button */
  .mobile-add-action-btn {
    position: relative;
    top: -0.8rem;
  }

  .mobile-add-circle {
    width: 2.85rem;
    height: 2.85rem;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
    color: white;
    display: grid;
    place-items: center;
    box-shadow: 0 6px 18px var(--accent-glow);
    transition: transform 180ms var(--ease-smooth);
  }

  .mobile-add-action-btn:active .mobile-add-circle {
    transform: scale(0.92);
  }
}

/* Accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

/* --------------------------------------------------------------------------
   15B. PHONE: COMPACT STAT STRIP
   Four compact tiles in one row so the task list starts above the fold.
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
  .hero-ai-actions-bar {
    margin-bottom: 1rem;
  }

  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.5rem;
  }

  .stat-card {
    padding: 0.75rem 0.4rem 0.7rem;
    gap: 0.35rem;
    align-items: center;
    text-align: center;
  }

  .stat-card-header {
    justify-content: center;
  }

  .stat-card-icon {
    display: none;
  }

  .stat-label {
    font-size: 0.66rem;
    letter-spacing: 0.08em;
  }

  .stat-value-wrap {
    justify-content: center;
  }

  .stat-number {
    font-size: 1.65rem;
  }

  .stat-subtext {
    display: none;
  }

  .controls-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
  }
}

/* --------------------------------------------------------------------------
   15C. PHONE: TASKS FIRST
   Filters, search, sort and "Clear completed" live in one sheet behind the
   search button in the list header. The controls panel itself becomes the sheet.
   -------------------------------------------------------------------------- */
.filter-sheet-header,
.mobile-filter-btn,
.filter-sheet-backdrop {
  display: none;
}

@media (max-width: 767px) {
  .list-header {
    position: relative;
    padding-right: 3.2rem;
  }

  .mobile-filter-btn {
    display: inline-grid;
    place-items: center;
    position: absolute;
    top: 0;
    right: 0;
    width: var(--tap-min);
    height: var(--tap-min);
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--panel-subtle);
    color: var(--text);
  }

  .mobile-filter-dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 2px var(--panel-strong);
    display: none;
  }

  .mobile-filter-btn.has-active .mobile-filter-dot {
    display: block;
  }

  .filter-sheet-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 110;
    background: rgba(0, 0, 0, 0.45);
    animation: fadeIn var(--dur-fast) ease;
  }

  .controls-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 120;
    flex-direction: column;
    align-items: stretch;
    gap: 0.9rem;
    margin: 0;
    padding: 1rem 1.1rem calc(1.4rem + env(safe-area-inset-bottom, 0px));
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    background: var(--panel-strong);
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.35);
    transform: translateY(105%);
    visibility: hidden;
    transition: transform var(--dur-base) var(--ease-out), visibility 0s linear var(--dur-base);
  }

  .controls-panel.is-open {
    transform: none;
    visibility: visible;
    transition: transform var(--dur-base) var(--ease-out), visibility 0s;
  }

  .filter-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .filter-sheet-title {
    margin: 0;
    font-family: var(--font-serif);
    font-size: 1.3rem;
    color: var(--text);
  }

  .controls-panel .filters {
    width: 100%;
  }

  .controls-panel .filter-chip {
    flex: 1;
  }

  .controls-panel .search-wrap {
    flex: none;
    width: 100%;
  }

  .controls-panel #searchInput {
    min-height: var(--tap-min);
    font-size: 1rem; /* 16px stops iOS zooming on focus */
  }

  .controls-panel .controls-actions {
    justify-content: space-between;
  }

  .controls-panel .sort-control-wrap {
    flex: 1;
  }

  .controls-panel .sort-select {
    width: 100%;
  }
}
