/* L5S1 — clinical health product theme
   Light, calm, high-trust · mobile-first */

@import url("https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=Fraunces:opsz,wght@9..144,500;9..144,600&display=swap");

:root {
  /* Surfaces */
  --bg: #f4f7f9;
  --bg-accent: #e8f2f1;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --surface-tint: #f0f7f6;

  /* Text */
  --text: #1a2b33;
  --text-secondary: #4a5d68;
  --muted: #6b7f8a;

  /* Brand — calm clinical teal */
  --primary: #0d9488;
  --primary-hover: #0f766e;
  --primary-soft: #ccfbf1;
  --primary-ink: #115e59;

  /* Supporting */
  --sky: #0284c7;
  --sky-soft: #e0f2fe;
  --lavender: #7c6bc4;
  --lavender-soft: #f0edf9;
  --success: #059669;
  --success-soft: #d1fae5;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;

  /* Pain scale (1 calm → 10 acute) */
  --pain-low: #34d399;
  --pain-mid: #fbbf24;
  --pain-high: #f87171;

  --border: #e2eaf0;
  --border-strong: #c5d4de;
  --shadow-sm: 0 1px 2px rgba(26, 43, 51, 0.04);
  --shadow: 0 4px 16px rgba(26, 43, 51, 0.06), 0 1px 3px rgba(26, 43, 51, 0.04);
  --shadow-lg: 0 12px 40px rgba(26, 43, 51, 0.08);

  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;

  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --tabbar-h: 4.25rem;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(900px 420px at 100% -5%, rgba(13, 148, 136, 0.09), transparent 55%),
    radial-gradient(700px 380px at -5% 20%, rgba(2, 132, 199, 0.06), transparent 50%),
    linear-gradient(180deg, #eef5f4 0%, var(--bg) 28%, #f7f9fb 100%);
  background-attachment: scroll;
  -webkit-font-smoothing: antialiased;
}

/*
 * Signed-in shell: body is a fixed-height column; only #app scrolls.
 * Tab bar stays at the bottom of the viewport without position:fixed
 * (fixed + transform/overscroll is unreliable on iOS Safari).
 */
body.is-authed {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#app {
  max-width: 440px;
  width: 100%;
  margin: 0 auto;
  padding: calc(0.85rem + var(--safe-top)) 1rem 2rem;
  min-height: 100dvh;
  box-sizing: border-box;
}

#app.is-authed {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  /* tab bar is in-flow below #app — only need a little breathing room */
  padding-bottom: 1.25rem;
}

/* Footer stays as a compact meta strip (domain + version); tab bar is separate nav */

/* ——— Header ——— */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.1rem;
  padding: 0.15rem 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.topbar-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 1;
  min-width: 0;
  justify-content: flex-end;
}

/* ——— Notifications ——— */
.notif-wrap {
  position: static;
}

.notif-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 2.35rem;
  height: 2.35rem;
  margin: 0;
  padding: 0;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  touch-action: manipulation;
}

.notif-btn:hover {
  border-color: var(--primary);
  color: var(--primary-ink);
  background: var(--primary-soft);
}

.notif-badge {
  position: absolute;
  top: -0.2rem;
  right: -0.25rem;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.28rem;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1.1rem;
  text-align: center;
  box-shadow: 0 0 0 2px var(--surface);
}

.notif-panel {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  width: min(20rem, calc(100vw - 2rem));
  max-height: min(24rem, 60vh);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 60;
  overflow: hidden;
}

.notif-panel[hidden] {
  display: none !important;
}

.notif-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
}

.notif-panel-head strong {
  font-size: 0.85rem;
}

.notif-mark-all {
  font-size: 0.72rem !important;
  padding: 0.25rem 0.45rem !important;
  min-height: 0 !important;
  box-shadow: none !important;
}

.notif-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.notif-item:hover {
  background: var(--surface-tint);
}

.notif-item.is-unread {
  background: color-mix(in srgb, var(--primary-soft) 55%, var(--surface));
}

.notif-item-main {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
  flex: 1;
}

.notif-title {
  font-size: 0.84rem;
  color: var(--text);
}

.notif-body {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

.notif-when {
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 500;
}

.notif-dot {
  width: 0.45rem;
  height: 0.45rem;
  margin-top: 0.35rem;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}

.notif-empty {
  padding: 1.25rem 0.75rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.user-chip {
  max-width: 8.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary-ink);
  background: var(--primary-soft);
  border: 1.5px solid color-mix(in srgb, var(--primary) 25%, transparent);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: none;
}

.user-chip:hover {
  background: color-mix(in srgb, var(--primary-soft) 70%, #fff);
  border-color: var(--primary);
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: linear-gradient(145deg, var(--primary) 0%, #0e7490 100%);
  color: #fff;
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: -0.02em;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.35);
}

.brand-mark-img {
  width: 36px;
  height: 36px;
  /* Icon already has rounded alpha; avoid clipping + white-looking edges */
  border-radius: 0;
  object-fit: contain;
  background: transparent;
  box-shadow: none;
  flex-shrink: 0;
}

.auth-logo {
  width: 72px;
  height: 72px;
  border-radius: 0;
  object-fit: contain;
  background: transparent;
  margin: 0 auto 0.9rem;
  display: block;
  box-shadow: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
  flex: 1 1 auto;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text);
  letter-spacing: -0.01em;
}

.brand-tag {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ——— Bottom tab bar (primary nav) ——— */
/* Sibling of #app under body; stays docked via flex shell (not position:fixed). */
.tabbar {
  display: none;
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  margin: 0;
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border-top: 1px solid var(--border);
  box-shadow: 0 -8px 28px rgba(26, 43, 51, 0.08);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  z-index: 100;
}

body.is-authed .tabbar:not([hidden]),
#app.is-authed ~ .tabbar:not([hidden]) {
  display: block;
}

.tabbar[hidden] {
  display: none !important;
}

.tabbar-inner {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  justify-content: space-between;
  gap: 0.1rem;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: 0.3rem 0.3rem 0.35rem;
  box-sizing: border-box;
}

.tabbar .tab {
  flex: 1 1 0;
  min-width: 0;
  max-width: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.12rem;
  margin: 0;
  padding: 0.35rem 0.1rem;
  border: none;
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  min-height: 3.15rem;
  /* Large hit target for mobile */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: none;
  pointer-events: auto;
  position: relative;
  z-index: 1;
}

/* Prefer [hidden] attribute; never leave a non-admin tab taking space */
.tabbar .tab[hidden] {
  display: none !important;
  flex: 0 0 0 !important;
  width: 0 !important;
  min-width: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  overflow: hidden !important;
  pointer-events: none !important;
}

.tabbar .tab:hover {
  color: var(--text-secondary);
  background: var(--surface-soft);
}

.tabbar .tab:active {
  transform: none;
  background: var(--primary-soft);
}

.tabbar .tab.active {
  color: var(--primary-ink);
  background: var(--primary-soft);
}

.tabbar .tab.active .tab-icon {
  stroke-width: 2.1;
}

.tab-icon {
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
  pointer-events: none; /* clicks hit the button, not the SVG */
}

.tab-label {
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  pointer-events: none;
}

@media (min-width: 480px) {
  .tabbar-inner {
    padding-inline: 0.5rem;
  }
  .tabbar .tab {
    font-size: 0.65rem;
  }
}

/* ——— Cards ——— */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.25rem 1.5rem;
  box-shadow: var(--shadow);
}

.card-header {
  margin-bottom: 1.15rem;
}

.card-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 0.28rem 0.6rem;
  border-radius: var(--radius-pill);
  margin-bottom: 0.65rem;
}

h1, h2, h3 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.25;
}

h1 { font-size: 1.55rem; }
h2 { font-size: 1.3rem; }
h3 {
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 1.25rem;
  margin-bottom: 0.6rem;
  color: var(--text-secondary);
}

.lede,
.muted {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
  margin: 0 0 0.25rem;
}

.lede { margin-bottom: 1.15rem; }

/* ——— Forms ——— */
label {
  display: block;
  margin: 0.9rem 0 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

label .hint {
  font-weight: 400;
  color: var(--muted);
}

input[type="email"],
input[type="text"],
input[type="datetime-local"],
input[type="search"],
textarea {
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

input::placeholder,
textarea::placeholder {
  color: #9aafb8;
}

input:hover,
textarea:hover {
  border-color: var(--border-strong);
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}

textarea {
  resize: vertical;
  min-height: 4.5rem;
}

/* ——— Pain slider ——— */
.pain-block {
  margin-top: 0.5rem;
  padding: 1rem;
  background: var(--surface-tint);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.pain-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}

.pain-header label {
  margin: 0;
}

.pain-readout {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--primary-ink);
  line-height: 1;
  min-width: 2ch;
  text-align: right;
}

.pain-readout[data-level="low"] { color: #059669; }
.pain-readout[data-level="mid"] { color: #d97706; }
.pain-readout[data-level="high"] { color: #dc2626; }

.pain-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.35rem;
  font-weight: 500;
}

input[type="range"] {
  width: 100%;
  height: 0.45rem;
  margin: 0.65rem 0 0.15rem;
  -webkit-appearance: none;
  appearance: none;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--pain-low), var(--pain-mid), var(--pain-high));
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--primary);
  box-shadow: var(--shadow);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--primary);
  box-shadow: var(--shadow);
  cursor: pointer;
}

/* ——— Buttons ——— */
.row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 1.15rem;
}

.auth-actions {
  margin-top: 1.25rem;
}

.auth-actions .primary,
.auth-actions .secondary {
  flex: 1 1 auto;
  min-width: 8rem;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.25rem;
  padding: 0.25rem;
  margin: 0 0 1rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}

@media (max-width: 380px) {
  .auth-tabs {
    grid-template-columns: 1fr;
  }
}

.auth-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: none;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--primary-ink);
  box-shadow: var(--shadow-sm);
}

.auth-panel {
  margin-bottom: 0.25rem;
}

.field-hint {
  margin: -0.35rem 0 0.75rem;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
}

.profile-edit {
  display: block;
  margin: 0.5rem 0 0;
}

button {
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  border: none;
  padding: 0.75rem 1.1rem;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, box-shadow 0.15s, border-color 0.15s;
}

button:active:not(:disabled) {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.primary {
  background: linear-gradient(180deg, #14b8a6 0%, var(--primary) 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.35);
}

button.primary:hover:not(:disabled) {
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-hover) 100%);
}

button.secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1.5px solid var(--border-strong);
}

button.secondary:hover:not(:disabled) {
  background: var(--surface-soft);
  border-color: var(--muted);
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1.5px solid var(--border);
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: var(--radius-pill);
}

button.ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface);
}

button.wide {
  width: 100%;
  margin-top: 1rem;
  padding: 0.9rem 1.1rem;
  font-size: 1rem;
}

/* ——— Tags / chips ——— */
.field-label {
  display: block;
  margin: 1rem 0 0.45rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0 0 0.25rem;
}

/* Pack-grouped check-in chips */
#tag-picker,
#edit-tag-picker {
  display: grid;
  gap: 0.75rem;
  margin: 0 0 0.35rem;
}

.tag-group {
  display: grid;
  gap: 0.4rem;
}

.tag-group-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.tag-group-chips.tags {
  margin: 0;
}

.tag-pack-hint {
  margin: 0;
  padding: 0.65rem 0.75rem;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text-secondary);
  background: var(--surface-soft);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

.tag-pack-hint .linkish {
  display: inline;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  box-shadow: none;
  color: var(--primary-ink);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.tags button {
  background: var(--surface-soft);
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  padding: 0.45rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 500;
  border-radius: var(--radius-pill);
  box-shadow: none;
}

.tags button:hover {
  border-color: var(--primary);
  color: var(--primary-ink);
}

.tags button.selected {
  background: var(--primary-soft);
  color: var(--primary-ink);
  border-color: var(--primary);
  font-weight: 600;
}

/* ——— Timeline ——— */
.section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  padding-top: 1.15rem;
  border-top: 1px solid var(--border);
}

.section-title h3 {
  margin: 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.timeline,
.entry-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.timeline li {
  position: relative;
  padding: 0.85rem 0.95rem 0.85rem 1rem;
  margin-bottom: 0.55rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary);
}

.timeline li.obs {
  border-left-color: var(--lavender);
  background: var(--lavender-soft);
}

.timeline .meta {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 0.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
}

.timeline .meta .badge,
.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary-ink);
  font-size: 0.7rem;
  font-weight: 600;
}

.badge.obs-badge {
  background: #e9e4f7;
  color: #5b4b9e;
}

.timeline .body {
  font-size: 0.9rem;
  color: var(--text);
}

/* ——— Entry cards (recent + summary timeline) ——— */
.entry-list {
  display: grid;
  gap: 0.65rem;
}

.swipe-hint {
  font-size: 0.78rem;
  margin: -0.25rem 0 0.55rem;
}

.entry-card {
  list-style: none;
  padding: 0.9rem 1rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary);
}

.entry-card[data-pain-band="low"] { border-left-color: var(--pain-low); }
.entry-card[data-pain-band="mid"] { border-left-color: var(--pain-mid); }
.entry-card[data-pain-band="high"] { border-left-color: var(--pain-high); }
.entry-card.obs {
  border-left-color: var(--lavender);
  background: var(--lavender-soft);
}

/* Swipeable recent entries: right = edit, left = delete */
.entry-swipe {
  list-style: none;
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  touch-action: pan-y;
  background: var(--surface-soft);
}

.entry-swipe-rail {
  position: absolute;
  inset: 0 auto 0 0;
  width: 96px;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
  z-index: 0;
}

.entry-swipe-rail--edit {
  left: 0;
  right: auto;
  background: linear-gradient(90deg, var(--primary) 0%, #0e7490 100%);
}

.entry-swipe-rail--delete {
  left: auto;
  right: 0;
  width: 96px;
  background: linear-gradient(270deg, #dc2626 0%, #f87171 100%);
}

.entry-swipe-front {
  position: relative;
  z-index: 1;
  margin: 0;
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
  background: var(--surface-soft);
  box-shadow: 0 0 0 1px var(--border);
}

.entry-swipe.is-dragging .entry-swipe-front {
  cursor: grabbing;
}

.entry-swipe-tip {
  display: none;
  margin: 0.35rem 0 0;
  font-size: 0.68rem;
}

.entry-swipe-removing {
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

/* Edit sheet */
.entry-edit-sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  align-items: end;
  justify-items: center;
}

.entry-edit-sheet[hidden] {
  display: none !important;
}

.entry-edit-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 32, 0.45);
  backdrop-filter: blur(4px);
}

.entry-edit-panel {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  max-height: min(88vh, 640px);
  overflow: auto;
  padding: 1.15rem 1.15rem calc(1.15rem + var(--safe-bottom));
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -12px 40px rgba(26, 43, 51, 0.18);
}

.entry-edit-panel h3 {
  margin: 0 0 0.25rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
}

.entry-edit-actions {
  display: flex;
  gap: 0.55rem;
  justify-content: flex-end;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.entry-edit-actions button {
  min-width: 6rem;
}

.entry-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.55rem;
  margin-bottom: 0.45rem;
}

.entry-when {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-right: auto;
}

.entry-notes {
  font-size: 0.92rem;
  color: var(--text);
  line-height: 1.45;
  margin-bottom: 0.5rem;
}

.pain-badge--low { background: var(--success-soft); color: #047857; }
.pain-badge--mid { background: var(--warning-soft); color: #b45309; }
.pain-badge--high { background: var(--danger-soft); color: #b91c1c; }

/* Tag badges */
.tag-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.15rem;
}

.tag-badges--wrap {
  margin-top: 0;
}

.tag-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  border: 1px solid transparent;
}

.tag-badge--side {
  background: #e0f2fe;
  color: #0369a1;
  border-color: #bae6fd;
}
.tag-badge--region {
  background: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}
.tag-badge--sensation {
  background: #fef3c7;
  color: #b45309;
  border-color: #fde68a;
}
.tag-badge--function {
  background: #f3e8ff;
  color: #7e22ce;
  border-color: #e9d5ff;
}
.tag-badge--condition {
  background: #ffe4e6;
  color: #be123c;
  border-color: #fecdd3;
}
.tag-badge--meta {
  background: #e9e4f7;
  color: #5b4b9e;
  border-color: #ddd6fe;
}
.tag-badge--default {
  background: var(--primary-soft);
  color: var(--primary-ink);
  border-color: #99f6e4;
}

.tag-badge-count {
  display: inline-grid;
  place-items: center;
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: color-mix(in srgb, currentColor 14%, #fff);
  font-size: 0.65rem;
  font-weight: 700;
}

/* Summary page extras */
.period-label {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary-ink);
}

.clin-toolbar {
  display: grid;
  gap: 0.65rem;
  margin: 0.85rem 0 0.5rem;
}

.clin-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
}

.clin-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.clin-presets button {
  border: 1.5px solid var(--border);
  background: var(--surface-soft);
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.5rem 0.25rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: none;
}

.clin-presets button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.clin-presets button.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-ink);
}

.clin-visit-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.45rem;
  margin: 0.5rem 0 0.25rem;
}

.clin-visit-label {
  flex: 1 1 10rem;
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.clin-visit-label input {
  margin-top: 0.25rem;
}

.clin-pack-hint {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--text-secondary);
}

.clin-pack-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 0.85rem;
}

.clin-pack-btn {
  border: 1.5px solid var(--border);
  background: var(--surface-soft);
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: none;
}

.clin-pack-btn.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-ink);
}

.export-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin: 0.75rem 0 0.35rem;
}

#obs-tag-picker {
  display: grid;
  gap: 0.65rem;
  margin: 0.35rem 0 0.85rem;
}

.clin-tag-group {
  margin-bottom: 0.65rem;
}

.clin-obs-list {
  margin-top: 0.35rem;
}

.entry-card--observation {
  border-left: 3px solid var(--primary);
}

.badge-obs {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--primary-ink);
  background: var(--primary-soft);
  border: 1px solid color-mix(in srgb, var(--primary) 28%, transparent);
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}

.clin-print-meta {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.print-only {
  display: none;
}

.hist-panel,
.clin-tags-panel {
  margin: 0.25rem 0 0.5rem;
}

.pain-histogram {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 0.25rem;
  align-items: end;
  min-height: 7.5rem;
  padding: 0.75rem 0.5rem 0.35rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.hist-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  min-width: 0;
}

.hist-bar-wrap {
  width: 100%;
  height: 4.5rem;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.hist-bar {
  width: 70%;
  min-height: 2px;
  border-radius: 4px 4px 2px 2px;
  background: var(--primary);
  transition: height 0.2s ease;
}

.hist-bar--low { background: var(--pain-low); }
.hist-bar--mid { background: var(--pain-mid); }
.hist-bar--high { background: var(--pain-high); }

.hist-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--muted);
}

.hist-count {
  font-size: 0.6rem;
  color: var(--text-secondary);
  min-height: 0.85rem;
}

.empty-inline {
  margin: 0.25rem 0;
  font-size: 0.85rem;
}

/* ——— In-app dialogs ——— */
body.dialog-open {
  overflow: hidden;
}

.app-dialog {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
}

.app-dialog[hidden] {
  display: none !important;
}

.app-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 32, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.app-dialog-panel {
  position: relative;
  width: min(100%, 360px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1.25rem 1.2rem 1.1rem;
  animation: dialog-in 0.16s ease-out;
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.app-dialog-title {
  margin: 0 0 0.45rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.app-dialog-message {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.app-dialog-message[hidden] {
  display: none !important;
}

.app-dialog-field {
  margin: 0 0 1rem;
}

.app-dialog-field[hidden] {
  display: none !important;
}

.app-dialog-label {
  display: block;
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.app-dialog-label-text {
  display: block;
  margin-bottom: 0.35rem;
}

.app-dialog-select {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.55rem 0.65rem;
  font: inherit;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

.app-dialog-input {
  width: 100%;
  margin: 0;
}

.app-dialog-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.app-dialog-actions button {
  min-width: 5.5rem;
}

button.danger,
.app-dialog-confirm.danger {
  background: linear-gradient(180deg, #f87171 0%, #dc2626 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.3);
}

button.danger:hover:not(:disabled),
.app-dialog-confirm.danger:hover:not(:disabled) {
  background: linear-gradient(180deg, #ef4444 0%, #b91c1c 100%);
}

/* ——— Status ——— */
.status {
  min-height: 1.25rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--success);
  margin: 0.65rem 0 0;
}

.status.error {
  color: var(--danger);
  background: var(--danger-soft);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  min-height: auto;
}

/* ——— Clinician stats ——— */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin: 1.1rem 0;
}

.summary-grid .stat {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 0.85rem;
}

.summary-grid .stat span {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.summary-grid .stat strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 600;
  color: var(--primary-ink);
  letter-spacing: -0.02em;
}

/* ——— Partner chips ——— */
.checkbox {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0.85rem 0;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
}

.checkbox input {
  width: 1.1rem;
  height: 1.1rem;
  margin: 0;
  accent-color: var(--primary);
}

.patient-chip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 0.55rem;
  background: var(--surface-soft);
}

.patient-chip span {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}

.patient-chip .secondary {
  padding: 0.45rem 0.85rem;
  font-size: 0.8rem;
}

/* ——— Auth extras ——— */
.auth-hero {
  text-align: center;
  margin-bottom: 1.35rem;
}

.auth-hero h1 {
  margin-bottom: 0.45rem;
}

.secure-note {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  margin-top: 1.15rem;
  padding: 0.75rem 0.85rem;
  background: var(--sky-soft);
  border-radius: var(--radius-sm);
  border: 1px solid #bae6fd;
  font-size: 0.8rem;
  color: #0c4a6e;
  line-height: 1.4;
}

.secure-note svg {
  flex-shrink: 0;
  margin-top: 0.1rem;
}

/* ——— Divider / footer ——— */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

.footer {
  text-align: center;
  margin-top: 1.5rem;
  padding: 0.65rem 0.5rem 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.4rem 0.55rem;
}

.footer-sep {
  opacity: 0.45;
  user-select: none;
}

.footer-link {
  color: var(--primary-ink);
  text-decoration: none;
  font-weight: 600;
}

.footer-link:hover {
  text-decoration: underline;
}

/* When signed in, keep meta quiet above the docked tab bar */
#app.is-authed .footer {
  margin-top: 1.25rem;
  margin-bottom: 0.15rem;
  opacity: 0.9;
}

.version-pill {
  display: inline-block;
  max-width: 7.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.65rem;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.02em;
  color: var(--primary-ink);
  background: var(--primary-soft);
  border: 1px solid color-mix(in srgb, var(--primary) 28%, transparent);
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  flex-shrink: 1;
}

/* ——— Profile / devices ——— */
.profile-meta {
  display: grid;
  gap: 0.55rem;
  margin-bottom: 0.5rem;
}

.profile-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.profile-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.profile-row strong {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.device-list {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0;
  display: grid;
  gap: 0.65rem;
}

.device-card {
  display: grid;
  gap: 0.65rem;
  padding: 0.9rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.device-card.is-current {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  background: color-mix(in srgb, var(--primary-soft) 55%, var(--surface-soft));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--primary) 18%, transparent);
}

.device-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.device-title-row .device-name-input {
  flex: 1 1 auto;
  min-width: 0;
}

.device-badge {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--primary-ink);
  background: var(--primary-soft);
  border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent);
  white-space: nowrap;
}

.device-name-input {
  width: 100%;
  margin: 0;
  font-weight: 600;
}

.device-meta {
  margin-top: 0.35rem;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
}

.device-code-banner {
  margin-top: 0.85rem;
  padding: 1rem;
  background: linear-gradient(145deg, var(--primary-soft), var(--surface-tint));
  border: 1px solid color-mix(in srgb, var(--primary) 28%, var(--border));
  border-radius: var(--radius-sm);
  text-align: center;
}

.device-code-display {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--primary-ink);
  margin: 0.25rem 0 0.5rem;
}

.device-code-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.65rem;
}

.device-code-list {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0;
  display: grid;
  gap: 0.35rem;
}

/* ——— Tag packs (profile) ——— */
.pack-list {
  display: grid;
  gap: 0.55rem;
  margin: 0.75rem 0 0.35rem;
}

.pack-card {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin: 0;
  padding: 0.85rem 0.9rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}

.pack-card.is-on {
  border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
  background: color-mix(in srgb, var(--primary-soft) 45%, var(--surface-soft));
}

.pack-card.is-locked {
  cursor: default;
  opacity: 0.95;
}

.pack-card input {
  margin-top: 0.2rem;
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
  accent-color: var(--primary);
}

.pack-card-body {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
  flex: 1;
}

.pack-card-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pack-card-title strong {
  font-size: 0.92rem;
}

.pack-card-desc {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

.pack-card-meta {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
}

.device-code-item {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.82rem;
  padding: 0.45rem 0.55rem;
  background: var(--surface-soft);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.device-code-item .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.device-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.device-actions .secondary,
.device-actions .ghost {
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
}

/* ——— Admin ——— */
.admin-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.25rem;
  padding: 0.25rem;
  margin-bottom: 1rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}

.admin-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.5rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: none;
}

.admin-tab.active {
  background: var(--surface);
  color: var(--primary-ink);
  box-shadow: var(--shadow-sm);
}

.admin-form {
  margin-bottom: 1rem;
}

.admin-list {
  display: grid;
  gap: 0.65rem;
}

.admin-card {
  padding: 0.85rem 0.95rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.admin-card h4 {
  margin: 0 0 0.35rem;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
}

.admin-card .meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.55rem;
}

.admin-card .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.admin-card .actions button {
  padding: 0.4rem 0.65rem;
  font-size: 0.75rem;
}

.admin-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--primary-ink);
}

.admin-devices {
  margin-top: 0.85rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.admin-devices .section-title h3 {
  margin-top: 0;
  font-size: 0.85rem;
}

.admin-device-list {
  list-style: none;
  padding: 0;
  margin: 0.4rem 0 0;
  display: grid;
  gap: 0.45rem;
}

.admin-device-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.65rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.admin-device-main {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
}

.admin-device-main strong {
  font-size: 0.88rem;
}

.admin-device-main .meta {
  font-size: 0.72rem;
  color: var(--muted);
}

.badge-locked {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--danger);
  background: var(--danger-soft);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

.badge-default {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--primary-ink);
  background: var(--primary-soft);
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
}

.badge-custom {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-soft);
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.badge-ok {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--success);
  background: var(--success-soft);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

.badge.role-partner {
  background: var(--lavender-soft);
  color: #5b4b9e;
}

.badge.role-patient {
  background: var(--sky-soft);
  color: #0369a1;
}

.tag-row-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tag-row-head h4 {
  margin: 0;
}

.tag-pos {
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* ——— Empty states ——— */
.empty-state {
  text-align: center;
  padding: 1.25rem 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Focus visible for a11y */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

button:focus:not(:focus-visible) {
  outline: none;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}

/* ——— Print: exam-room friendly summary ——— */
@media print {
  body {
    background: #fff !important;
    color: #111 !important;
  }

  body * {
    box-shadow: none !important;
  }

  .no-print,
  .tabbar,
  .topbar-actions,
  .notif-wrap,
  #btn-logout,
  #user-chip,
  .footer {
    display: none !important;
  }

  #app {
    max-width: none;
    margin: 0;
    padding: 0.5rem 0.75rem;
    min-height: 0;
    overflow: visible;
  }

  body.is-authed {
    height: auto;
    max-height: none;
    overflow: visible;
    display: block;
  }

  #app.is-authed {
    overflow: visible;
    flex: none;
    min-height: 0;
    padding-bottom: 0;
  }

  .print-only {
    display: block !important;
  }

  #view-auth,
  #view-patient,
  #view-partner,
  #view-profile,
  #view-admin {
    display: none !important;
  }

  #view-clinician {
    display: block !important;
    border: none;
    padding: 0;
    background: transparent;
  }

  .card {
    border: none;
    box-shadow: none;
    padding: 0;
  }

  .section-title {
    break-after: avoid;
  }

  .entry-list {
    break-inside: avoid;
  }

  .pain-histogram {
    break-inside: avoid;
  }
}
