/* Reset, type, and the frame the pages sit in: a top bar, a sidebar on a wide
 * screen and a tab bar along the bottom of a narrow one. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; }
body { min-height: 100vh; min-height: 100dvh; overscroll-behavior-y: none; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); }
h1, h2, h3 { margin: 0; font-weight: 650; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------ top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(var(--gap-4), env(safe-area-inset-right)) 0 max(var(--gap-4), env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: var(--gap-3);
  background: rgba(14, 20, 34, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: var(--gap-2); min-width: 0; }
.brand-logo {
  width: 34px; height: 34px; flex: none;
  border-radius: 9px;
  background: var(--accent-grad);
  color: var(--on-accent);
  display: grid; place-items: center;
  font-weight: 800; font-size: 17px;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-title { font-weight: 650; font-size: 15px; white-space: nowrap; }
.brand-sub { font-size: 11.5px; color: var(--text-faint); white-space: nowrap; }
.topbar-spacer { flex: 1; }

.app-switch {
  display: flex;
  padding: 3px;
  gap: 2px;
  border-radius: 999px;
  background: var(--input);
  border: 1px solid var(--line);
}
.app-switch button {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 7px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  min-height: 34px;
  white-space: nowrap;
}
.app-switch button[aria-pressed="true"] { background: var(--accent-grad); color: var(--on-accent); }

.offline-banner {
  position: sticky;
  top: calc(var(--topbar-h) + env(safe-area-inset-top));
  z-index: 25;
  padding: 8px var(--gap-4);
  background: var(--warn-wash);
  color: var(--warn);
  border-bottom: 1px solid rgba(252, 211, 77, 0.3);
  font-size: 13px;
  text-align: center;
}

/* ------------------------------------------------------------------- layout */
.layout { display: flex; min-height: calc(100dvh - var(--topbar-h)); }
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100dvh - var(--topbar-h));
  padding: var(--gap-3);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--gap-3);
  min-height: 40px;
  padding: 0 var(--gap-3);
  border-radius: var(--radius-s);
  border: 0;
  background: transparent;
  color: var(--text-dim);
  text-decoration: none;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
}
.nav-item svg { width: 18px; height: 18px; flex: none; opacity: 0.8; }
.nav-item:hover { background: rgba(148, 163, 184, 0.07); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--accent-wash); color: var(--text); }
.nav-item[aria-current="page"] svg { color: var(--accent); opacity: 1; }
.nav-gap { flex: 1; min-height: var(--gap-4); }
.count {
  margin-left: auto;
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--warn);
  color: #1b1403;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.main {
  flex: 1;
  min-width: 0;
  padding: var(--gap-5) max(var(--gap-5), env(safe-area-inset-right)) calc(var(--gap-5) * 2) var(--gap-5);
}
.view { max-width: 1240px; margin: 0 auto; }

.tabbar { display: none; }

/* A phone: the sidebar becomes a tab bar along the bottom, where a thumb is. */
@media (max-width: 899px) {
  .sidebar { display: none; }
  .brand-text { display: none; }
  .wide-only { display: none !important; }
  .main {
    padding: var(--gap-4) max(var(--gap-3), env(safe-area-inset-right))
             calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--gap-5)) max(var(--gap-3), env(safe-area-inset-left));
  }
  .tabbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(14, 20, 34, 0.96);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
  }
  .tab {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: 0;
    background: transparent;
    color: var(--text-faint);
    font-size: 11px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    text-decoration: none;
  }
  .tab svg { width: 22px; height: 22px; }
  .tab[aria-current="page"] { color: var(--accent); }
  .tab .count { position: absolute; top: 6px; left: 50%; margin-left: 6px; }
}
