/* Health layout refinements across desktop, tablets and small phones. */
body { line-height: 1.5; }
.entry {
  padding-top: max(24px, env(safe-area-inset-top, 0px));
  padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
}
#notice:not(:empty) { top: calc(78px + env(safe-area-inset-top, 0px)); }
.shell, .workspace-area, .content, #view, .health-board, .panel, .row,
.heading > div, .section-head > * { min-width: 0; }

/* The app menu stays within the viewport without its own scroll area. */
.rail {
  overflow: hidden;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.side-brand, .side-label, .rail-bottom { flex: none; }
.local-nav { flex: none; overflow: visible; }
.rail-bottom a, .rail-bottom button { overflow-wrap: anywhere; }

/* Keep the location and profile controls usable as the header narrows. */
.workspace-top {
  position: sticky;
  top: 0;
  z-index: 20;
  min-width: 0;
  height: calc(65px + env(safe-area-inset-top, 0px));
  min-height: calc(65px + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
}
.top-location { flex: 1 1 auto; min-width: 0; }
.top-location strong {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.top-actions { flex: none; min-width: 0; }
.account-link { min-width: 0; max-width: min(250px, 32vw); }
.account-link .id-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.icon-button, .mobile-menu { min-width: 44px; min-height: 44px; }

/* The record lists use flexible columns and wrap long personal text. */
.content { padding-inline: clamp(18px, 2.5vw, 36px); font-size: 1rem; }
.heading { align-items: flex-end; }
.heading h1 { overflow-wrap: anywhere; }
.heading h1[tabindex="-1"]:focus { outline: none; }
.heading .primary { max-width: 100%; text-align: center; }
.cards, .health-board { min-width: 0; }
.card, .panel { overflow-wrap: anywhere; }
.row > div { min-width: 0; }
.row > div:first-child { flex: 1 1 auto; }
.row > div:last-child { flex: 0 1 auto; text-align: right; }
.row button.title { font-size: 1rem; line-height: 1.45; }
.row strong { white-space: normal; overflow-wrap: anywhere; }
.toolbar input, dialog input, dialog select, dialog textarea { max-width: 100%; }
#record-list { min-height: 110px; }

/* Dialogs scroll internally when their content is taller than the screen. */
dialog {
  max-height: calc(100dvh - 32px);
  overflow: auto;
  overscroll-behavior: contain;
  overflow-wrap: anywhere;
}
dialog form, dialog label, dialog .grid { min-width: 0; }
dialog input, dialog select, dialog textarea { width: 100%; font-size: 1rem; }
dialog .actions > button, dialog .actions > a { min-width: 0; min-height: 44px; }
dialog .actions > a { align-content: center; }
body #id-access-status { width: min(560px, calc(100% - 32px)); }

@media (max-width: 800px) {
  .rail {
    width: min(280px, calc(100vw - 40px));
    padding-left: max(14px, env(safe-area-inset-left, 0px));
  }
  .workspace-top {
    height: calc(58px + env(safe-area-inset-top, 0px));
    min-height: calc(58px + env(safe-area-inset-top, 0px));
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
  .account-link { max-width: 160px; }
}

@media (max-width: 600px) {
  .workspace-top {
    gap: 7px;
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }
  .top-location { gap: 6px; }
  .top-actions { gap: 3px; }
  .account-link { max-width: 44px; }
  .content { padding: 20px 16px 32px; }
  .heading { align-items: stretch; gap: 14px; }
  .heading h1 { font-size: clamp(1.5rem, 6vw, 1.9rem); }
  .heading .primary { width: 100%; }
  .health-board { gap: 16px; }
  .cards { gap: 10px; margin-bottom: 16px; }
  .card { padding: 16px; }
  .panel { padding: 18px; margin-top: 16px; }
  .section-head { align-items: flex-start; }
  .section-head h2 { flex: 1 1 150px; }
  .section-head button { max-width: 100%; white-space: normal; }
  .row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .row > div:last-child { text-align: left; }
  .toolbar { margin: 14px 0; }
  dialog { width: calc(100% - 20px); max-height: calc(100dvh - 20px); padding: 20px; }
  dialog .actions { gap: 10px; }
  dialog .actions > button, dialog .actions > a { flex: 1 1 135px; text-align: center; }
}

@media (max-width: 390px) {
  .top-location > span:first-child, .top-divider { display: none; }
  .content { padding-inline: 14px; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .cards .card:last-child { grid-column: auto; }
  .card { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .card .metric { margin: 0; flex: none; }
  .section-head button { width: 100%; }
}

/* Imported readings share the Documents-style card layout. */
.device-intro { margin-top: 0; }
.device-intro p { max-width: 780px; line-height: 1.6; }
.device-intro .actions { justify-content: flex-start; margin: 18px 0 0; }
.device-intro .actions .tag { align-content: center; }
.device-intro #device-status:empty { display: none; }
.device-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,310px),1fr)); gap: 16px; margin-top: 18px; }
.device-card { margin: 0; padding: 0; }
.device-card summary { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 98px; padding: 20px; cursor: pointer; list-style: none; }
.device-card summary::-webkit-details-marker { display: none; }
.device-card summary span { display: grid; gap: 5px; min-width: 0; }
.device-card summary strong { font-size: 15px; }
.device-card summary b { color: var(--accent-dark); font-size: clamp(17px,2vw,22px); text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.device-card .device-days { max-height: 270px; overflow: auto; margin: 0 20px; border-top: 1px solid var(--line); }
.device-days > div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.device-days > div:last-child { border: 0; }
.device-card > p { margin: 0; padding: 0 20px 18px; }
@media (max-width: 600px) {
 .device-intro .actions { align-items: stretch; }
 .device-intro .actions > * { flex: 1 1 100%; text-align: center; }
 .device-grid { gap: 12px; }
 .device-card summary { padding: 16px; }
}

@media (max-height: 650px) {
  .rail { padding-block: 10px; }
  .side-brand { min-height: 40px; margin-bottom: 10px; }
  .side-label { margin-bottom: 5px; }
  .local-nav { gap: 1px; }
  .local-nav button { min-height: 36px; padding-block: 5px; }
  .rail-bottom { gap: 0; padding-top: 6px; }
  .rail-bottom a, .rail-bottom button { min-height: 32px; padding-block: 4px; }
}

@media (max-height: 460px) {
  .side-label, .rail-bottom a:nth-child(2) { display: none; }
  .side-brand { margin-bottom: 5px; }
  .local-nav button { min-height: 32px; padding-block: 3px; }
  .rail-bottom a, .rail-bottom button { min-height: 30px; }
}

@media (max-width: 800px) and (max-height: 400px) {
  .local-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; }
  .local-nav button { gap: 5px; font-size: 13px; padding-inline: 6px; }
  .local-nav svg { width: 15px; height: 15px; }
}
