/* App shell. Phone: top bar, bottom tab bar and a "More" sheet. Desktop (900px and up):
   a navy sidebar with the whole menu. Both render the same menu (see navigation.py). */

.app { min-height: 100vh; }
.sidebar { display: none; }

/* Logos: the dark-on-light one on light surfaces, the light one on dark surfaces. */
.logo-for-dark { display: none; }
:root[data-theme="dark"] .logo-for-light { display: none; }
:root[data-theme="dark"] .logo-for-dark { display: inline; }

.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--navy); color: #fff;
  font-size: .9rem; font-weight: 700;
  text-decoration: none;
}
:root[data-theme="dark"] .avatar { background: var(--primary); color: var(--on-primary); }
.avatar--small { width: 26px; height: 26px; font-size: .75rem; }

/* --- top bar (phone) -------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: var(--topbar-height);
  padding: 8px 14px;
  padding-top: max(8px, var(--safe-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-brand { display: block; line-height: 0; }
.topbar-brand img { height: 34px; width: auto; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }

.workspace { min-width: 0; }
.page {
  width: 100%; max-width: var(--page-width);
  margin: 0 auto;
  padding: 20px 16px calc(var(--tabbar-height) + var(--safe-bottom) + 28px);
}
.no-tabbar .page { padding-bottom: 28px; }

/* --- tab bar (phone) -------------------------------------------------- */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; align-items: end;
  height: calc(var(--tabbar-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  /* Solid, with no blur: a backdrop-filter makes the bar the containing block of
     `fixed` children and the "More" sheet would end up trapped inside it. */
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.no-tabbar .tabbar { display: none; }
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px;
  height: var(--tabbar-height); padding: 0 0 9px;
  background: none; border: 0;
  color: var(--muted);
  font: inherit; font-size: .72rem; font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.tab .icon { width: 24px; height: 24px; }
.tab.is-active, .tab[aria-expanded="true"] { color: var(--primary); }
/* "New sheet": the big red button that pops out of the bar. */
.tab--primary .tab-bubble {
  display: grid; place-items: center;
  width: 56px; height: 56px; margin-top: -26px;
  border-radius: 50%;
  background: var(--red); color: #fff;
  box-shadow: 0 6px 16px rgba(226, 49, 42, .38), 0 0 0 5px var(--bg);
  transition: transform .12s ease;
}
.tab--primary .tab-bubble .icon { width: 28px; height: 28px; stroke-width: 2.2; }
.tab--primary:active .tab-bubble { transform: scale(.94); }
.tab--primary.is-active { color: var(--red); }

/* --- "More" sheet (phone) --------------------------------------------- */

.sheet-backdrop { position: fixed; inset: 0; z-index: 25; background: rgba(10, 12, 24, .42); }
.sheet {
  position: fixed; z-index: 26;
  left: 8px; right: 8px; bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 8px);
  max-height: 72vh; overflow-y: auto;
  padding: 6px 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: sheet-in .18s ease-out;
}
@keyframes sheet-in { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 38px; height: 4px; margin: 6px auto 10px; border-radius: 99px; background: var(--border-strong); }
.sheet-user { display: flex; align-items: center; gap: 10px; margin: 0 8px 4px; font-weight: 650; }
.sheet-user small { display: block; color: var(--muted); font-weight: 500; }
.sheet-theme {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 46px; padding: 10px 12px;
  background: none; border: 0; border-radius: var(--radius-sm);
  color: var(--text); font: inherit; text-align: left; cursor: pointer;
}

.menu-title {
  margin: 14px 12px 4px;
  font-size: .72rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted);
}
.menu-link {
  display: flex; align-items: center; gap: 12px;
  min-height: 46px; padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-weight: 550;
}
.menu-link .icon { color: var(--muted); }
.menu-link:hover { background: var(--surface-muted); }
.menu-link.is-active { background: var(--primary-soft); color: var(--primary); }
.menu-link.is-active .icon { color: var(--primary); }
.menu-link--danger, .menu-link--danger .icon { color: var(--danger-text); }

/* Icon-only theme toggle: the moon in light mode (go dark), the sun in dark mode (go light). */
.theme-icon-sun { display: none; }
:root[data-theme="dark"] .theme-icon-sun { display: block; }
:root[data-theme="dark"] .theme-icon-moon { display: none; }

/* --- desktop ---------------------------------------------------------- */

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
  .topbar, .tabbar, .sheet, .sheet-backdrop { display: none; }
  .page { padding: 38px 44px 64px; }
  .no-tabbar .page { padding-bottom: 64px; }

  .sidebar {
    position: sticky; top: 0;
    display: flex; flex-direction: column; gap: 6px;
    height: 100vh;
    padding: 22px 14px 14px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    overflow-y: auto;
  }
  .sidebar-brand { display: block; padding: 2px 10px 18px; line-height: 0; }
  .sidebar-brand img { height: 42px; width: auto; }
  .sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
  .sidebar .menu-title { color: rgba(201, 198, 230, .6); margin-top: 20px; }
  .sidebar .menu-title:first-child { margin-top: 4px; }
  .sidebar .menu-link {
    position: relative;
    min-height: 42px;
    color: var(--sidebar-text);
    font-size: .95rem;
  }
  .sidebar .menu-link .icon { color: rgba(201, 198, 230, .75); }
  .sidebar .menu-link:hover { background: var(--sidebar-hover); color: var(--sidebar-text-strong); }
  .sidebar .menu-link:hover .icon { color: var(--sidebar-text-strong); }
  .sidebar .menu-link.is-active { background: var(--sidebar-active); color: var(--sidebar-text-strong); }
  .sidebar .menu-link.is-active .icon { color: var(--sidebar-text-strong); }
  .sidebar .menu-link.is-active::before {
    content: ""; position: absolute; left: -14px; top: 9px; bottom: 9px;
    width: 4px; border-radius: 0 4px 4px 0;
    background: var(--red);
  }
  .sidebar .menu-link--cta {
    margin: 2px 0 6px;
    background: var(--red); color: #fff;
    box-shadow: 0 6px 16px rgba(226, 49, 42, .3);
  }
  .sidebar .menu-link--cta .icon { color: #fff; }
  .sidebar .menu-link--cta:hover { background: var(--red-deep); color: #fff; }

  .sidebar-user {
    display: flex; align-items: center; gap: 10px;
    margin-top: 10px; padding: 12px 8px 4px 6px;
    border-top: 1px solid rgba(255, 255, 255, .1);
  }
  .sidebar-user .avatar { background: rgba(255, 255, 255, .16); }
  .sidebar-user-text { flex: 1; min-width: 0; line-height: 1.25; }
  .sidebar-user-text a {
    display: block; overflow: hidden;
    color: var(--sidebar-text-strong); font-weight: 650; font-size: .92rem;
    text-decoration: none; text-overflow: ellipsis; white-space: nowrap;
  }
  .sidebar-user-text small { color: rgba(201, 198, 230, .7); font-size: .76rem; }
}

@media (max-width: 420px) {
  .page { padding-left: 12px; padding-right: 12px; }
  .topbar { padding-left: 12px; padding-right: 12px; }
}
