/*
 * Mobile bottom navigation + phone readability overrides for the Calm Workspace POC.
 * Desktop/tablet Global Rail keeps the existing layered navigation.
 */

@media (max-width: 767px) {
  :root {
    --mobile-nav-height: calc(78px + env(safe-area-inset-bottom));

    /* Phone-first type scale: avoid the previous 8-9px micro text and oversized page title contrast. */
    --type-meta: 12px;
    --type-caption: 13px;
    --type-body: 15px;
    --type-body-lg: 16px;
    --type-section: 18px;
    --type-title: 24px;
    --type-display: 26px;
  }

  .global-rail {
    overflow: visible;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    height: var(--mobile-nav-height);
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    border-top: 1px solid color-mix(in srgb, var(--line) 82%, transparent);
    box-shadow: 0 -10px 30px rgba(35, 39, 33, .07);
    backdrop-filter: blur(16px);
  }

  /* The mobile dock is navigation only: no brand/logo, avatar or utility controls. */
  .global-rail > .rail-brand,
  .global-rail > .rail-spacer,
  .global-rail > .rail-action,
  .global-rail > .rail-avatar {
    display: none !important;
  }

  /* Mobile primary navigation is intentionally limited to five destinations. */
  .global-rail .rail-item[data-global],
  .global-rail .rail-more {
    display: none !important;
  }

  .global-rail .rail-item[data-global="my-work"],
  .global-rail .rail-item[data-global="chat"],
  .global-rail .rail-item[data-global="home"],
  .global-rail .rail-item[data-global="autopilot"],
  .global-rail .rail-item[data-global="settings"] {
    display: flex !important;
    min-width: 0;
  }

  /* Left -> right: My Task | Chat | Home | AI Autopilot | Cài đặt. */
  .global-rail .rail-item[data-global="my-work"] { order: 1; }
  .global-rail .rail-item[data-global="chat"] { order: 2; }
  .global-rail .rail-item[data-global="home"] { order: 3; }
  .global-rail .rail-item[data-global="autopilot"] { order: 4; }
  .global-rail .rail-item[data-global="settings"] { order: 5; }

  .global-rail .rail-item {
    min-height: 60px;
    padding: 4px 1px 1px;
    border-radius: 14px;
    gap: 4px;
    justify-content: flex-start;
    color: var(--muted);
    -webkit-tap-highlight-color: transparent;
  }

  .global-rail .rail-item:hover,
  .global-rail .rail-item.active {
    background: transparent;
  }

  /* Every destination uses the same icon plate, so the row reads as one system. */
  .global-rail .rail-icon {
    width: 38px;
    height: 34px;
    flex: 0 0 34px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    color: currentColor;
    transition: background-color .16s ease, color .16s ease, transform .16s ease;
  }

  .global-rail .rail-icon::before {
    width: 22px;
    height: 22px;
  }

  .global-rail .rail-item:not([data-global="home"]).active {
    color: var(--green);
  }

  .global-rail .rail-item:not([data-global="home"]).active .rail-icon {
    background: var(--green-soft);
    transform: translateY(-1px);
  }

  /* Home remains the center anchor, but the heavy black rounded-square card is replaced by one clean circle. */
  .global-rail .rail-item[data-global="home"] {
    width: auto;
    min-height: 60px;
    height: auto;
    justify-self: stretch;
    align-self: stretch;
    transform: none;
    border-radius: 14px;
    background: transparent;
    color: var(--text);
    box-shadow: none;
  }

  .global-rail .rail-item[data-global="home"]:hover,
  .global-rail .rail-item[data-global="home"].active {
    background: transparent;
    color: var(--text);
  }

  .global-rail .rail-item[data-global="home"] .rail-icon {
    width: 46px;
    height: 46px;
    flex-basis: 46px;
    margin-top: -9px;
    border-radius: 50%;
    background: var(--text);
    color: var(--surface);
    box-shadow: 0 7px 18px rgba(35, 39, 33, .16);
  }

  .global-rail .rail-item[data-global="home"] .rail-icon::before {
    width: 21px;
    height: 21px;
  }

  .global-rail .rail-item[data-global="home"] .rail-label {
    margin-top: -5px;
    font-weight: 700;
    color: var(--text);
  }

  /* Better-balanced Lucide choices for the five phone destinations. */
  @supports ((-webkit-mask-image: url("")) or (mask-image: url(""))) {
    .global-rail .rail-item[data-global="my-work"] .rail-icon {
      --ui-icon: url("https://unpkg.com/lucide-static@1.16.0/icons/circle-check-big.svg");
    }
    .global-rail .rail-item[data-global="chat"] .rail-icon {
      --ui-icon: url("https://unpkg.com/lucide-static@1.16.0/icons/message-circle.svg");
    }
    .global-rail .rail-item[data-global="home"] .rail-icon {
      --ui-icon: url("https://unpkg.com/lucide-static@1.16.0/icons/house.svg");
    }
    .global-rail .rail-item[data-global="autopilot"] .rail-icon {
      --ui-icon: url("https://unpkg.com/lucide-static@1.16.0/icons/sparkles.svg");
    }
    .global-rail .rail-item[data-global="settings"] .rail-icon {
      --ui-icon: url("https://unpkg.com/lucide-static@1.16.0/icons/sliders-horizontal.svg");
    }
  }

  /* Mobile-friendly labels without changing desktop terminology. */
  .global-rail .rail-item[data-global="my-work"] .rail-label,
  .global-rail .rail-item[data-global="autopilot"] .rail-label,
  .global-rail .rail-item[data-global="settings"] .rail-label {
    font-size: 0;
  }

  .global-rail .rail-item[data-global="my-work"] .rail-label::after {
    content: "My Task";
    font-size: 11px;
  }

  .global-rail .rail-item[data-global="autopilot"] .rail-label::after {
    content: "AI Autopilot";
    font-size: 11px;
  }

  .global-rail .rail-item[data-global="settings"] .rail-label::after {
    content: "Cài đặt";
    font-size: 11px;
  }

  .global-rail .rail-item .rail-label {
    display: block;
    max-width: 76px;
    min-height: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    line-height: 1.15;
    font-weight: 560;
    letter-spacing: -.01em;
  }

  .global-rail .rail-item.active .rail-label {
    font-weight: 680;
  }

  /* Phone typography polish for Note/Task/Knowledge surfaces. */
  .app-shell .notion-page-grid,
  .app-shell .knowledge-page .notion-page-grid {
    padding-left: 18px;
    padding-right: 18px;
  }

  .app-shell .notion-page-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    font-size: 19px;
    margin-bottom: 14px;
  }

  .app-shell .notion-page-title {
    font-size: 24px;
    line-height: 1.18;
    letter-spacing: -.02em;
    margin-bottom: 16px;
  }

  .app-shell .notion-note-actions,
  .app-shell .notion-note-meta {
    font-size: 12px;
    line-height: 1.35;
  }

  .app-shell .notion-note-actions {
    min-height: 32px;
    margin-bottom: 22px;
  }

  .app-shell .notion-note-actions small,
  .app-shell .notion-note-meta small {
    font-size: 11px;
  }

  .app-shell .notion-section-label,
  .app-shell .notion-relations-title,
  .app-shell .notion-relations-title b {
    font-size: 11px;
  }

  .app-shell .notion-editor-toolbar button,
  .app-shell .notion-editor-toolbar > span,
  .app-shell .notion-add-block {
    font-size: 12px;
  }

  .app-shell .notion-editor-toolbar button {
    min-height: 34px;
    padding: 0 10px;
  }

  .app-shell .notion-editor-toolbar > span {
    line-height: 1.4;
  }

  .app-shell .block-editable {
    min-height: 34px;
    padding-top: 5px;
    padding-bottom: 5px;
    font-size: 15px;
    line-height: 1.55;
  }

  .app-shell .notion-heading .block-editable {
    font-size: 19px;
  }

  .app-shell .notion-relations section > button {
    min-height: 46px;
  }

  .app-shell .notion-relations section > button strong,
  .app-shell .notion-relations p {
    font-size: 12px;
  }

  .app-shell .notion-relations section > button small {
    font-size: 11px;
  }

  .main-stage {
    padding-bottom: var(--mobile-nav-height);
  }

  .workspace-sidebar,
  .focus-panel,
  .focus-panel.open {
    bottom: var(--mobile-nav-height);
  }

  .drawer-scrim.open {
    inset: 24px 0 var(--mobile-nav-height) 0;
  }

  .toast {
    bottom: calc(var(--mobile-nav-height) + 12px);
  }
}

@media (max-width: 360px) {
  .global-rail {
    padding-left: 4px;
    padding-right: 4px;
  }

  .global-rail .rail-item .rail-label,
  .global-rail .rail-item[data-global="my-work"] .rail-label::after,
  .global-rail .rail-item[data-global="autopilot"] .rail-label::after,
  .global-rail .rail-item[data-global="settings"] .rail-label::after {
    font-size: 10px;
  }

  .global-rail .rail-item[data-global="home"] .rail-icon {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }
}
