@keyframes rise-in { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }
.mobile-nav, .more-menu { display: none; }

@media (min-width: 1500px) {
  .metric-grid { gap: 1.2rem; }
  .content-grid { gap: 1.2rem; }
}

/* Tablet: use the same compact navigation as phones; do not squeeze a desktop sidebar beside the content. */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 1.2rem 1.25rem calc(92px + env(safe-area-inset-bottom)); }
  .mobile-nav {
    position: fixed; inset: auto 0 0; z-index: 30;
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
    min-height: 70px; padding: .4rem .45rem calc(.4rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border); background: #0e141df5;
    backdrop-filter: blur(18px);
  }
  .mobile-nav-item {
    display: flex; min-width: 0; align-items: center; justify-content: center;
    flex-direction: column; gap: .22rem; padding: .25rem .1rem;
    border: 1px solid transparent; border-radius: 10px;
    color: var(--muted); background: transparent; cursor: pointer;
  }
  .mobile-nav-item span { font-size: 1.05rem; line-height: 1.1; }
  /* iPhone: icon-only navigation avoids label collisions on narrow screens. */
  .mobile-nav-item small { display: none; }
  .mobile-nav-item span { display: grid; width: 100%; min-height: 42px; place-items: center; font-size: 1.35rem; line-height: 1; }
  .mobile-nav-item { min-height: 48px; padding: .15rem; }
  .mobile-nav-item.active { color: #fff; background: #1b2b45; border-color: #2c4c78; }
  .mobile-nav-item.active span { color: #60a5fa; }
  .more-menu:not([hidden]) {
    position: fixed; right: .6rem; bottom: calc(78px + env(safe-area-inset-bottom));
    z-index: 31; display: grid; width: min(245px, calc(100vw - 1.2rem)); gap: .25rem;
    padding: .5rem; border: 1px solid var(--border); border-radius: 15px;
    background: var(--elevated); box-shadow: var(--shadow);
  }
  .more-menu button { min-height: 44px; padding: .7rem .8rem; border: 0; border-radius: 9px; color: var(--text); background: transparent; text-align: left; cursor: pointer; }
  .more-menu button:hover { background: #2a394d; }
  .welcome-row { align-items: flex-start; flex-direction: column; }
}
@media (max-width: 760px) {
  .main-content { padding: 1.1rem .9rem calc(88px + env(safe-area-inset-bottom)); }
  .topbar { align-items: center; padding-bottom: 1rem; }
  .topbar .eyebrow { font-size: .58rem; }
  .top-actions { gap: .4rem; }
  .date-control input { width: 132px; min-height: 40px; font-size: .78rem; }
  .avatar { width: 39px; height: 39px; }
  .welcome-row { padding: 1.25rem 0; }
  .preview-pill { font-size: .66rem; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
  .metric-card { padding: .9rem; border-radius: 15px; }
  .metric-heading { font-size: .7rem; }
  .metric-value { margin-top: .9rem; font-size: 1.12rem; }
  .metric-foot { font-size: .65rem; }
  .content-grid { grid-template-columns: minmax(0, 1fr); gap: .75rem; margin-top: .75rem; }
  .panel { padding: 1rem; border-radius: 15px; }
  .priorities-panel, .progress-panel, .trend-panel, .quick-panel { min-height: 0; }
  .page-footer { flex-direction: column; gap: .25rem; padding-bottom: .4rem; }
}
@media (max-width: 370px) {
  .mobile-nav-item span { font-size: 1.25rem; }
  .mobile-nav-item { min-height: 46px; }
  .date-control input { width: 115px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}


/* FINAL SAFETY OVERRIDE: mobile navigation is icon-only and desktop sidebar is hidden on phone/tablet. */
@media screen and (max-width: 900px) {
  body .sidebar {
    display: none !important;
  }
  body nav.mobile-nav .mobile-nav-item > small {
    display: none !important;
    visibility: hidden !important;
  }
  body nav.mobile-nav .mobile-nav-item {
    display: flex !important;
    flex-direction: column !important;
    min-width: 0 !important;
    overflow: hidden !important;
  }
  body nav.mobile-nav .mobile-nav-item > span {
    display: grid !important;
    width: 100% !important;
    min-height: 42px !important;
    place-items: center !important;
  }
}


/* Mobile layout repair: keep page titles readable and give controls their own row. */
@media screen and (max-width: 600px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: .8rem;
  }
  .topbar > div:first-child {
    width: 100%;
    min-width: 0;
  }
  .topbar #page-title {
    width: 100%;
    overflow-wrap: normal !important;
    word-break: normal !important;
    hyphens: none;
    font-size: clamp(1.55rem, 7vw, 2rem);
    line-height: 1.15;
  }
  .top-actions {
    display: flex;
    width: 100%;
    min-width: 0;
    align-items: center;
    justify-content: flex-start;
    gap: .5rem;
  }
  .date-control {
    min-width: 0;
    flex: 1 1 auto;
  }
  .date-control input {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    font-size: .78rem;
  }
  .live-clock {
    flex: 0 0 auto;
  }
  .avatar {
    flex: 0 0 39px;
  }
}

@media (max-width: 520px) {
  .refresh-button { min-height: 34px; padding: .45rem .55rem; font-size: .78rem; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
}
