/* Mobile Shell — overrides for hub.next-gen-flows.at pages with sidebar layout.
   Activates at <=768px. Hides desktop sidebar, adds top-bar + bottom-nav,
   stacks rails, full-bleed cards. Pair with mobile-shell.js for nav injection. */

@media (max-width: 768px) {

  /* ── HIDE DESKTOP CHROME ────────────────────────────────────────────── */
  .sidebar { display: none !important; }

  /* ── APP SHELL: stack vertically + enable body-level scroll ──────────── */
  html, body {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    height: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  body { -webkit-text-size-adjust: 100%; }
  .app { display: block !important; height: auto !important; min-height: 100vh; overflow: visible !important; }
  .main {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
    padding-top: 56px !important;     /* room for fixed top-bar */
    padding-bottom: 80px !important;  /* room for fixed bottom-nav */
  }

  /* ── MAIN GRID: single column ───────────────────────────────────────── */
  .main-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
    padding: 16px 16px 16px !important;
  }
  .rail, .rail-left, .rail-right {
    position: static !important;
    top: auto !important;
  }
  .rail-right { order: 3; }
  .rail-left  { order: 2; }
  .center     { order: 1; }

  /* ── MOBILE TOP-BAR (injected by mobile-shell.js) ────────────────────── */
  .m-topbar {
    position: fixed; top: 0; left: 0; right: 0;
    height: 56px;
    display: flex; align-items: center; gap: 10px;
    padding: 0 14px;
    background: rgba(255,255,255,.92);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--card-border, #ebebeb);
    z-index: 90;
  }
  .m-topbar-brand {
    font-size: 11px; font-weight: 800;
    letter-spacing: .14em; text-transform: uppercase;
    color: var(--muted-foreground, #717171);
    flex-shrink: 0;
  }
  .m-topbar-title {
    flex: 1;
    font-size: 15px; font-weight: 700;
    letter-spacing: -.01em;
    color: var(--foreground, #222);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .m-topbar-btn {
    width: 38px; height: 38px;
    border-radius: 10px;
    background: var(--muted, #f7f7f7);
    border: 1px solid var(--card-border, #ebebeb);
    color: var(--foreground, #222);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
  }
  .m-topbar-btn:active { background: var(--card-border, #ebebeb); }
  .m-topbar-btn svg { width: 18px; height: 18px; stroke-width: 2; }

  /* ── MOBILE BOTTOM-NAV (injected by mobile-shell.js) ─────────────────── */
  .m-bottomnav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: 64px;
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255,255,255,.96);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--card-border, #ebebeb);
    display: grid; grid-template-columns: repeat(5, 1fr);
    z-index: 90;
  }
  .m-bottomnav a {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 3px;
    font-size: 10px; font-weight: 600;
    color: var(--muted-foreground, #717171);
    text-decoration: none;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
  }
  .m-bottomnav a svg {
    width: 22px; height: 22px;
    stroke-width: 1.8;
    transition: transform .15s;
  }
  .m-bottomnav a.here {
    color: var(--primary, #14b8a6);
    font-weight: 700;
  }
  .m-bottomnav a.here::before {
    content: '';
    position: absolute; top: 0; left: 28%; right: 28%;
    height: 3px;
    background: var(--primary, #14b8a6);
    border-radius: 0 0 4px 4px;
  }
  .m-bottomnav a:active svg { transform: scale(.92); }

  /* ── DRAWER for sidebar content (Notiz etc) ──────────────────────────── */
  .m-sidedrawer-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.32);
    z-index: 95;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
  }
  .m-sidedrawer-backdrop.on { opacity: 1; pointer-events: auto; }
  .m-sidedrawer {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: 84vw; max-width: 320px;
    background: #fff;
    z-index: 96;
    padding: 20px 18px;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform .25s ease-out;
    display: flex; flex-direction: column; gap: 18px;
  }
  .m-sidedrawer.on { transform: translateX(0); }
  .m-sidedrawer .m-sd-brand { font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--muted-foreground, #717171); }
  .m-sidedrawer .m-sd-date { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted-foreground, #717171); margin-top: 6px; }
  .m-sidedrawer .m-sd-hello { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; margin-bottom: 4px; }
  .m-sidedrawer textarea {
    width: 100%;
    background: var(--muted, #f7f7f7);
    border: 1px solid var(--card-border, #ebebeb);
    border-radius: 12px;
    padding: 10px 12px;
    font-family: inherit; font-size: 13px;
    color: var(--foreground, #222);
    resize: none; min-height: 80px; line-height: 1.5;
  }
  .m-sidedrawer button {
    padding: 10px 18px;
    border-radius: 10px;
    background: var(--primary, #14b8a6);
    color: #fff; border: none;
    font-family: inherit; font-size: 13px; font-weight: 600;
    cursor: pointer; align-self: flex-end;
  }

  /* ── PAGE HEAD on mobile: tighter, wraps actions ─────────────────────── */
  .page-head {
    margin-bottom: 16px !important;
    gap: 10px !important;
  }
  .page-title {
    font-size: 22px !important;
    line-height: 1.1 !important;
  }
  .page-sub { font-size: 12px !important; }
  .page-actions {
    flex-wrap: wrap !important;
    width: 100%;
  }
  .page-actions .page-count {
    flex: 0 0 auto;
    font-size: 11px !important;
    padding: 5px 10px !important;
  }
  .page-actions .page-btn {
    min-height: 40px;
    padding: 8px 12px !important;
    font-size: 12px !important;
    flex: 1;
    min-width: 0;
    justify-content: center;
  }

  /* ── BRIEFING CARD: tighter padding ─────────────────────────────────── */
  .briefing-card { padding: 16px 16px !important; margin-bottom: 16px !important; }
  .briefing-card .br-content { font-size: 13px !important; line-height: 1.55 !important; }
  .briefing-card .br-content h2 { font-size: 11px !important; margin: 10px 0 4px !important; }
  .briefing-card .br-foot { flex-direction: column; align-items: stretch; gap: 8px; }
  .briefing-card .br-stats { justify-content: flex-start; }

  /* ── MINI CALENDAR on index: horizontal scroll if any ──────────────── */
  .mini-cal { padding: 12px !important; }
  .mini-cal-grid { gap: 4px !important; }
  .mini-day { min-height: 80px !important; padding: 6px !important; }
  .mini-day-num { font-size: 13px !important; }
  .mini-item { font-size: 9.5px !important; padding: 2px 5px !important; }

  /* ── ACT GRID (active projects) ──────────────────────────────────────── */
  .act-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  /* ── PRIORITY GRID: stack columns ────────────────────────────────────── */
  .pr-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .pr-col { border-radius: 14px; }
  .pr-head { padding: 14px 14px 10px !important; }
  .pr-body { padding: 0 8px 10px !important; }

  /* ── MODAL on mobile: full-bleed, comfortable ──────────────────────── */
  .modal-back { padding: 0 !important; align-items: flex-end !important; }
  .modal {
    width: 100% !important; max-width: 100% !important;
    border-radius: 18px 18px 0 0 !important;
    max-height: 90vh !important;
  }
  .modal-head { padding: 18px 18px 14px !important; }
  .modal-title { font-size: 18px !important; }
  .modal-body { padding: 16px 18px !important; }
  .modal-foot { padding: 14px 18px 18px !important; }
  .field input, .field select, .field textarea { font-size: 16px !important; }  /* prevents iOS zoom */

  /* ── CALENDAR-page specific: shrink cells ─────────────────────────── */
  .cal-grid, .cal-week, .cal-day {
    /* Calendar.html uses its own classes; ensure overflow-x-auto wrapper exists */
  }
  .cal-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .cal-grid { min-width: 700px; }  /* let it scroll horizontally inside its wrapper */

  /* ── PROJECTS-page specific: cards full-width ──────────────────────── */
  .proj-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .proj-card { padding: 14px !important; }

  /* ── PRIORITIES rail cards in line ────────────────────────────────── */
  .rail-card { padding: 14px !important; }
  .focus-card { padding: 14px !important; }

  /* ── PRIORITIES.html top-pill-nav: hide on mobile (bottom-nav has same links) ── */
  .topbar { padding: 8px 14px !important; }
  .topbar .pill-nav, .pill-nav { display: none !important; }
  .topbar #topbarDate { font-size: 11px !important; }

  /* ── INDEX page-actions: cleaner row ─────────────────────────────── */
  .page-actions .page-count { order: -1; flex-basis: 100%; text-align: center; }
}

/* ── EXTRA SMALL (iPhone SE etc.) ────────────────────────────────────── */
@media (max-width: 380px) {
  .m-bottomnav a { font-size: 9.5px; }
  .m-topbar-title { font-size: 14px; }
  .page-title { font-size: 20px !important; }
  .page-actions .page-btn { font-size: 11px !important; padding: 7px 10px !important; }
}

/* ── DARK-THEME VARIANT (auto-applied by mobile-shell.js when body bg is dark) ── */
@media (max-width: 768px) {
  body.m-dark .m-topbar {
    background: rgba(8, 12, 18, .88);
    border-bottom-color: rgba(255, 255, 255, .08);
  }
  body.m-dark .m-topbar-brand { color: rgba(255, 255, 255, .55); }
  body.m-dark .m-topbar-title { color: #e8edf5; }
  body.m-dark .m-topbar-btn {
    background: rgba(255, 255, 255, .06);
    border: 1px solid rgba(255, 255, 255, .1);
    color: #e8edf5;
  }
  body.m-dark .m-bottomnav {
    background: rgba(8, 12, 18, .94);
    border-top-color: rgba(255, 255, 255, .08);
  }
  body.m-dark .m-bottomnav a { color: rgba(255, 255, 255, .45); }
  body.m-dark .m-bottomnav a.here { color: #4a9eff; }
  body.m-dark .m-bottomnav a.here::before { background: #4a9eff; }
  body.m-dark .m-sidedrawer { background: #0e1520; color: #e8edf5; }
  body.m-dark .m-sidedrawer textarea {
    background: rgba(255, 255, 255, .05);
    border-color: rgba(255, 255, 255, .1);
    color: #e8edf5;
  }
  body.m-dark .m-sidedrawer .m-sd-brand,
  body.m-dark .m-sidedrawer .m-sd-date { color: rgba(255, 255, 255, .55); }
  body.m-dark .m-sidedrawer .m-sd-hello { color: #fff; }
  body.m-dark .m-sidedrawer button { background: #4a9eff; }

  /* Body padding for pages without sidebar/main but with their own topbar (project.html) */
  body.m-has-own-topbar { padding-top: 0 !important; padding-bottom: 80px !important; }
}

/* ── REDUCED MOTION ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .m-sidedrawer, .m-sidedrawer-backdrop, .m-bottomnav a svg { transition: none !important; }
}
