/* Nutshell Health — base.css
 * Reset, document defaults, app shell and navigation.
 */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

h1, h2, h3, h4, h5, p, figure, blockquote, dl, dd { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

h1 { font-size: var(--fs-2xl); line-height: var(--lh-tight); letter-spacing: -.02em; font-weight: 700; }
h2 { font-size: var(--fs-xl); line-height: var(--lh-tight); letter-spacing: -.015em; font-weight: 660; }
h3 { font-size: var(--fs-lg); line-height: var(--lh-tight); letter-spacing: -.01em; font-weight: 640; }
h4 { font-size: var(--fs-md); line-height: var(--lh-tight); font-weight: 620; }

a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg, video { max-width: 100%; display: block; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; padding: 0; }

table { border-collapse: collapse; width: 100%; }

/* Visible, consistent focus for keyboard users on every interactive element. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--accent-soft); color: var(--accent-text); }

/* Screen-reader-only text that still receives focus when tabbed to. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--sp-4);
  top: -100px;
  z-index: 100;
  background: var(--surface);
  color: var(--text);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transition: top var(--dur) var(--ease);
}
.skip-link:focus { top: var(--sp-4); }

/* ------------------------------------------------------------- app shell */

.app {
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.app[hidden] { display: none; }

/* --------------------------------------------------------- side nav (desktop) */

.sidenav {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-5) var(--sp-3);
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3) var(--sp-5);
}

.brand-mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(140deg, var(--accent), #34d399);
  display: grid;
  place-items: center;
  color: #04231b;
  flex: none;
  box-shadow: var(--shadow-sm);
}
.brand-mark svg { width: 20px; height: 20px; }

.brand-name {
  font-weight: 680;
  font-size: var(--fs-md);
  letter-spacing: -.02em;
}
.brand-sub {
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.nav-group-label {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-subtle);
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
  font-weight: 600;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: var(--sp-3);
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-weight: 520;
  font-size: var(--fs-base);
  text-align: left;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-item:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }
.nav-item svg { width: 19px; height: 19px; flex: none; }
.nav-item[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 620;
}
/* Shape as well as colour marks the current page. */
.nav-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 22%;
  bottom: 22%;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.nav-spacer { flex: 1; }

.nav-profile {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--r-md);
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.nav-profile:hover { border-color: var(--border-strong); }
.avatar {
  width: 32px; height: 32px;
  border-radius: var(--r-full);
  background: var(--accent-soft);
  color: var(--accent-text);
  display: grid; place-items: center;
  font-weight: 680;
  font-size: var(--fs-sm);
  flex: none;
}
/* These are spans inside a button, so they need an explicit block display for
   the truncation rules below to apply at all. */
.nav-profile-name {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-profile-meta {
  display: block;
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ------------------------------------------------------------------ main */

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  min-height: 62px;
}

.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 {
  font-size: var(--fs-xl);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-sub {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-top: 1px;
}
.topbar-actions { display: flex; align-items: center; gap: var(--sp-2); }

.view {
  padding: var(--sp-6);
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

.view-enter { animation: viewIn var(--dur) var(--ease); }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------------------------------- bottom nav (mobile) */

.bottomnav { display: none; }

.fab { display: none; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }

  .sidenav { display: none; }

  .view {
    padding: var(--sp-4) var(--sp-4) calc(var(--bottom-nav-h) + var(--sp-12));
  }

  .topbar {
    padding: var(--sp-3) var(--sp-4);
    min-height: 56px;
  }
  .topbar-title h1 { font-size: var(--fs-lg); }

  .bottomnav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .bottomnav-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: var(--bottom-nav-h);
    color: var(--text-subtle);
    font-size: var(--fs-xs);
    font-weight: 560;
    padding: var(--sp-2) var(--sp-1);
    transition: color var(--dur-fast) var(--ease);
  }
  .bottomnav-item svg {
    width: 21px; height: 21px;
    transition: transform var(--dur) var(--ease);
  }
  .bottomnav-item[aria-current="page"] { color: var(--accent-text); font-weight: 640; }
  .bottomnav-item[aria-current="page"] svg { transform: translateY(-2px) scale(1.06); }

  /* A short bar above the active tab, so the current section is not signalled
     by colour alone. */
  .bottomnav-item[aria-current="page"]::before {
    content: "";
    position: absolute;
    top: 0;
    width: 26px;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--accent);
  }

  /* Floating quick-add, the primary action on mobile. */
  .fab {
    position: fixed;
    right: var(--sp-4);
    bottom: calc(var(--bottom-nav-h) + var(--sp-4) + env(safe-area-inset-bottom, 0px));
    z-index: 29;
    display: grid;
    place-items: center;
    width: 54px; height: 54px;
    border-radius: var(--r-full);
    background: var(--accent);
    color: #04231b;
    box-shadow: var(--shadow-lg);
    transition: transform var(--dur-fast) var(--ease);
  }
  .fab:active { transform: scale(.94); }
  .fab svg { width: 26px; height: 26px; }
}

@media (min-width: 901px) {
  .mobile-only { display: none !important; }
}
@media (max-width: 900px) {
  .desktop-only { display: none !important; }
}

@media print {
  .sidenav, .bottomnav, .fab, .topbar-actions { display: none !important; }
  body { background: #fff; }
  .view { padding: 0; }
}
