/* ==========================================================================
   Mesh Commander 2 — app.css
   Hand-authored Material 3 shell. Color comes from tokens.css
   (--md-sys-color-*). Everything else (type, shape, motion, layout) lives
   here. No color literals: only var(--md-sys-color-*), transparent,
   currentColor, and color-mix() of those.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Static M3 tokens (type scale, shape, motion, state layers)
   -------------------------------------------------------------------------- */
:root {
  --md-ref-typeface: Roboto, "Segoe UI", system-ui, -apple-system, sans-serif;

  /* Type scale: size / line-height / weight per role. */
  --md-sys-typescale-display-large-size: 57px;
  --md-sys-typescale-display-large-line-height: 64px;
  --md-sys-typescale-display-large-weight: 400;

  --md-sys-typescale-display-medium-size: 45px;
  --md-sys-typescale-display-medium-line-height: 52px;
  --md-sys-typescale-display-medium-weight: 400;

  --md-sys-typescale-display-small-size: 36px;
  --md-sys-typescale-display-small-line-height: 44px;
  --md-sys-typescale-display-small-weight: 400;

  --md-sys-typescale-headline-large-size: 32px;
  --md-sys-typescale-headline-large-line-height: 40px;
  --md-sys-typescale-headline-large-weight: 400;

  --md-sys-typescale-headline-medium-size: 28px;
  --md-sys-typescale-headline-medium-line-height: 36px;
  --md-sys-typescale-headline-medium-weight: 400;

  --md-sys-typescale-headline-small-size: 24px;
  --md-sys-typescale-headline-small-line-height: 32px;
  --md-sys-typescale-headline-small-weight: 400;

  --md-sys-typescale-title-large-size: 22px;
  --md-sys-typescale-title-large-line-height: 28px;
  --md-sys-typescale-title-large-weight: 400;

  --md-sys-typescale-title-medium-size: 16px;
  --md-sys-typescale-title-medium-line-height: 24px;
  --md-sys-typescale-title-medium-weight: 500;

  --md-sys-typescale-title-small-size: 14px;
  --md-sys-typescale-title-small-line-height: 20px;
  --md-sys-typescale-title-small-weight: 500;

  --md-sys-typescale-body-large-size: 16px;
  --md-sys-typescale-body-large-line-height: 24px;
  --md-sys-typescale-body-large-weight: 400;

  --md-sys-typescale-body-medium-size: 14px;
  --md-sys-typescale-body-medium-line-height: 20px;
  --md-sys-typescale-body-medium-weight: 400;

  --md-sys-typescale-body-small-size: 12px;
  --md-sys-typescale-body-small-line-height: 16px;
  --md-sys-typescale-body-small-weight: 400;

  --md-sys-typescale-label-large-size: 14px;
  --md-sys-typescale-label-large-line-height: 20px;
  --md-sys-typescale-label-large-weight: 500;

  --md-sys-typescale-label-medium-size: 12px;
  --md-sys-typescale-label-medium-line-height: 16px;
  --md-sys-typescale-label-medium-weight: 500;

  --md-sys-typescale-label-small-size: 11px;
  --md-sys-typescale-label-small-line-height: 16px;
  --md-sys-typescale-label-small-weight: 500;

  /* Shape */
  --md-sys-shape-corner-none: 0px;
  --md-sys-shape-corner-extra-small: 4px;
  --md-sys-shape-corner-small: 8px;
  --md-sys-shape-corner-medium: 12px;
  --md-sys-shape-corner-large: 16px;
  --md-sys-shape-corner-extra-large: 28px;
  --md-sys-shape-corner-full: 9999px;

  /* Motion */
  --md-sys-motion-easing-standard: cubic-bezier(.2, 0, 0, 1);
  --md-sys-motion-easing-standard-decelerate: cubic-bezier(0, 0, 0, 1);
  --md-sys-motion-easing-standard-accelerate: cubic-bezier(.3, 0, 1, 1);
  --md-sys-motion-easing-emphasized: cubic-bezier(.2, 0, 0, 1);
  --md-sys-motion-duration-short: 100ms;
  --md-sys-motion-duration-medium: 250ms;
  --md-sys-motion-duration-long: 400ms;

  /* State layer opacities */
  --md-sys-state-hover-opacity: 0.08;
  --md-sys-state-focus-opacity: 0.10;
  --md-sys-state-pressed-opacity: 0.10;

  /* Shell metrics */
  --mc-app-bar-height: 64px;
  --mc-rail-width: 80px;
  --mc-nav-bar-height: 64px;
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-ref-typeface);
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: var(--md-sys-typescale-body-medium-line-height);
}

h1,
h2,
p {
  margin: 0;
}

a {
  text-decoration: none;
  color: inherit;
}

button {
  font-family: inherit;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

svg {
  display: block;
}

/* Author `svg { display: block }` above outranks the UA's `[hidden]` rule by
   cascade origin — restate it or hidden icons render anyway. */
[hidden] {
  display: none !important;
}

/* Type-scale utilities (only the roles actually used in the shell). */
.headline-medium {
  font-size: var(--md-sys-typescale-headline-medium-size);
  line-height: var(--md-sys-typescale-headline-medium-line-height);
  font-weight: var(--md-sys-typescale-headline-medium-weight);
}

.title-large {
  font-size: var(--md-sys-typescale-title-large-size);
  line-height: var(--md-sys-typescale-title-large-line-height);
  font-weight: var(--md-sys-typescale-title-large-weight);
}

.title-medium {
  font-size: var(--md-sys-typescale-title-medium-size);
  line-height: var(--md-sys-typescale-title-medium-line-height);
  font-weight: var(--md-sys-typescale-title-medium-weight);
}

.title-small {
  font-size: var(--md-sys-typescale-title-small-size);
  line-height: var(--md-sys-typescale-title-small-line-height);
  font-weight: var(--md-sys-typescale-title-small-weight);
}

.body-medium {
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: var(--md-sys-typescale-body-medium-line-height);
  font-weight: var(--md-sys-typescale-body-medium-weight);
}

.body-small {
  font-size: var(--md-sys-typescale-body-small-size);
  line-height: var(--md-sys-typescale-body-small-line-height);
  font-weight: var(--md-sys-typescale-body-small-weight);
}

.label-medium {
  font-size: var(--md-sys-typescale-label-medium-size);
  line-height: var(--md-sys-typescale-label-medium-line-height);
  font-weight: var(--md-sys-typescale-label-medium-weight);
}

.label-small {
  font-size: var(--md-sys-typescale-label-small-size);
  line-height: var(--md-sys-typescale-label-small-line-height);
  font-weight: var(--md-sys-typescale-label-small-weight);
}

/* --------------------------------------------------------------------------
   3. Shell layout — grid on body: app bar + rail/bar + main
   -------------------------------------------------------------------------- */
body {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: var(--mc-app-bar-height) 1fr var(--mc-nav-bar-height);
  grid-template-areas:
    "appbar"
    "main"
    "navbar";
}

.app-bar {
  grid-area: appbar;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.app-mark {
  display: flex;
  align-items: center;
  color: var(--md-sys-color-primary);
  flex: none;
}

.app-mark svg {
  width: 22px;
  height: 22px;
}

.app-bar__title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav {
  grid-area: navbar;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

main {
  grid-area: main;
  overflow-y: auto;
}

.view-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

@media (min-width: 600px) {
  body {
    grid-template-columns: var(--mc-rail-width) 1fr;
    grid-template-rows: var(--mc-app-bar-height) 1fr;
    grid-template-areas:
      "appbar appbar"
      "rail   main";
  }

  .nav {
    grid-area: rail;
    flex-direction: column;
    align-items: stretch;
    border-top: none;
    border-right: 1px solid var(--md-sys-color-outline-variant);
    padding-block: 12px;
  }

  .theme-toggle {
    margin-top: auto;
  }
}

/* --------------------------------------------------------------------------
   4. Nav rail / nav bar destinations
   -------------------------------------------------------------------------- */
.nav-link {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
  color: var(--md-sys-color-on-surface-variant);
  transition: color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

@media (min-width: 600px) {
  .nav-link {
    flex: none;
    padding: 8px 4px;
  }
}

.nav-link__indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 32px;
  border-radius: var(--md-sys-shape-corner-full);
  color: var(--md-sys-color-on-surface-variant);
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.nav-link__indicator svg {
  width: 24px;
  height: 24px;
}

.nav-link__label {
  color: var(--md-sys-color-on-surface-variant);
}

.nav-link:hover:not([aria-current="page"]) .nav-link__indicator {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}

.nav-link[aria-current="page"] .nav-link__indicator {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.nav-link[aria-current="page"] .nav-link__label {
  color: var(--md-sys-color-on-surface);
}

/* .logout-button shares every icon-button style EXCEPT the rail's
   margin-top: auto — only the theme toggle gets that, so the pair groups at
   the rail bottom instead of flex splitting the free space between two
   autos (one auto per flex item is one distribution point each). */
.theme-toggle,
.logout-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  /* margin-inline only: the rail media query sets margin-top: auto, and this
     rule is later in source order — a `margin` shorthand here would erase it. */
  margin-inline: auto;
  border-radius: var(--md-sys-shape-corner-full);
  color: var(--md-sys-color-on-surface-variant);
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.theme-toggle:hover,
.logout-button:hover {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}

.theme-toggle svg,
.logout-button svg {
  width: 24px;
  height: 24px;
}

/* --------------------------------------------------------------------------
   5. Cards
   -------------------------------------------------------------------------- */
.card {
  border-radius: var(--md-sys-shape-corner-medium);
  padding: 16px;
  color: var(--md-sys-color-on-surface);
}

.card--filled {
  background: var(--md-sys-color-surface-container-highest);
}

.card--elevated {
  background: var(--md-sys-color-surface-container-low);
  box-shadow:
    0 1px 2px color-mix(in srgb, var(--md-sys-color-shadow) 30%, transparent),
    0 1px 3px 1px color-mix(in srgb, var(--md-sys-color-shadow) 15%, transparent);
}

.card--outlined {
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.card--brand {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

/* --------------------------------------------------------------------------
   6. Chips (status chip)
   -------------------------------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--md-sys-shape-corner-small);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface-variant);
  flex: none;
  margin-left: auto;
}

.chip__dot {
  width: 8px;
  height: 8px;
  border-radius: var(--md-sys-shape-corner-full);
  background: currentColor;
  flex: none;
}

/* --------------------------------------------------------------------------
   7. States & accessibility
   -------------------------------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* Screen-reader-only text: kept in the a11y tree, clipped from the visual
   canvas. Standard clip-rect pattern (not `display:none`/`visibility:hidden`,
   both of which remove it from the accessibility tree too). */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0ms !important;
    animation-duration: 0ms !important;
  }
}

/* --------------------------------------------------------------------------
   8. View sections
   -------------------------------------------------------------------------- */
main > section {
  display: none;
}

main > section.is-active {
  display: block;
}

.surface-ladder {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.surface-ladder .card {
  min-height: 88px;
  display: flex;
  align-items: flex-end;
}

.surface-ladder .card--brand {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-end;
  gap: 4px;
}

/* Ladder swatches as classes, not style= attributes: the client ships under
   a strict CSP (style-src 'self'), which blocks inline styles. */
.card--scl-lowest  { background: var(--md-sys-color-surface-container-lowest); }
.card--scl-low     { background: var(--md-sys-color-surface-container-low); }
.card--scl-mid     { background: var(--md-sys-color-surface-container); }
.card--scl-high    { background: var(--md-sys-color-surface-container-high); }
.card--scl-highest { background: var(--md-sys-color-surface-container-highest); }

.view-heading {
  margin-bottom: 8px;
}

.view-lede {
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 16px;
}

.empty-state {
  color: var(--md-sys-color-on-surface-variant);
}

/* --------------------------------------------------------------------------
   9. App boot states & login layer
   -------------------------------------------------------------------------- */
/* `checking`: probe in flight — hide the shell AND the login layer so
   neither flashes before the answer is known. Uses visibility (not
   display) so it never fights the shell's own display/grid rules. */
body[data-app-state="checking"] .app-bar,
body[data-app-state="checking"] .nav,
body[data-app-state="checking"] main,
body[data-app-state="checking"] .login-layer {
  visibility: hidden;
}

.login-layer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
}

body[data-app-state="login"] .login-layer {
  display: flex;
}

.login-card {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 24px;
}

.login-card__mark {
  margin-bottom: 8px;
}

.login-card__title {
  margin-bottom: 24px;
  text-align: center;
}

.login-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-error {
  color: var(--md-sys-color-error);
  min-height: var(--md-sys-typescale-body-small-line-height);
}

.login-form .btn--filled {
  width: 100%;
}

/* --------------------------------------------------------------------------
   10. M3 outlined text field
   -------------------------------------------------------------------------- */
.text-field {
  position: relative;
  display: flex;
  flex-direction: column;
}

.text-field__input {
  height: 56px;
  width: 100%;
  padding: 0 16px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: var(--md-sys-typescale-body-large-size);
  line-height: var(--md-sys-typescale-body-large-line-height);
  caret-color: var(--md-sys-color-primary);
  transition: border-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.text-field__input:focus {
  outline: none;
  border-width: 2px;
  border-color: var(--md-sys-color-primary);
  /* Compensate the extra 1px of border (both sides) so focus doesn't
     shift the text — border-box sizing keeps the field's outer size fixed. */
  padding: 0 15px;
}

.text-field__label {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  padding: 0 4px;
  /* Matches .card--elevated's background exactly so the label reads as a
     notch cut into the border, not a box floating over it. */
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-large-size);
  line-height: var(--md-sys-typescale-body-large-line-height);
  pointer-events: none;
  transition:
    top var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
    font-size var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
    color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.text-field__input:focus + .text-field__label,
.text-field__input:not(:placeholder-shown) + .text-field__label {
  top: 0;
  font-size: var(--md-sys-typescale-body-small-size);
  line-height: var(--md-sys-typescale-body-small-line-height);
}

.text-field__input:focus + .text-field__label {
  color: var(--md-sys-color-primary);
}

/* --------------------------------------------------------------------------
   11. M3 filled button
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: var(--md-sys-typescale-label-large-size);
  line-height: var(--md-sys-typescale-label-large-line-height);
  font-weight: var(--md-sys-typescale-label-large-weight);
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.btn--filled {
  height: 40px;
  padding: 0 24px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.btn--filled:hover:not(:disabled) {
  background: color-mix(in srgb, var(--md-sys-color-on-primary) 8%, var(--md-sys-color-primary));
}

.btn--filled:active:not(:disabled) {
  background: color-mix(in srgb, var(--md-sys-color-on-primary) 10%, var(--md-sys-color-primary));
}

.btn--filled:disabled {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
  color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
  cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   12. Messages — shell & panes
   -------------------------------------------------------------------------- */
/* Overrides `main > section.is-active { display: block }` (id + class beats
   class alone): the messages view is a fixed-height two-pane app, not a
   scrolling document like the other views, so it fills `main`'s 1fr row
   instead of growing it. */
main > section#view-messages.is-active {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.msg-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
}

.msg-list-pane,
.msg-thread-pane {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.msg-list-pane {
  overflow-y: auto;
  padding: 8px;
}

/* Narrow (<600px): single pane at a time, toggled by data-pane. */
.msg-shell[data-pane="list"] .msg-thread-pane {
  display: none;
}

.msg-shell[data-pane="thread"] .msg-list-pane {
  display: none;
}

@media (min-width: 600px) {
  .msg-shell {
    grid-template-columns: 320px 1fr;
  }

  .msg-shell[data-pane="list"] .msg-thread-pane,
  .msg-shell[data-pane="thread"] .msg-list-pane {
    display: flex;
  }

  .msg-list-pane {
    border-right: 1px solid var(--md-sys-color-outline-variant);
  }
}

.msg-back {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: var(--md-sys-shape-corner-full);
  color: var(--md-sys-color-on-surface);
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.msg-back:hover {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
}

@media (max-width: 599.98px) {
  .msg-back {
    display: inline-flex;
  }
}

/* --------------------------------------------------------------------------
   13. Messages — conversation list (M3-Expressive-inspired list rows)
   -------------------------------------------------------------------------- */
.msg-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.msg-list-empty {
  padding: 24px 16px;
  text-align: center;
}

.msg-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.msg-row:hover {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, var(--md-sys-color-surface-container-low));
}

.msg-row[aria-current="true"] {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.msg-row__badge {
  flex: none;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

/* The active row and the badge would otherwise share `secondary-container`
   and fuse — invert the badge's pair on the active row instead. Swapping a
   role with its on- role keeps the contrast guarantee in both modes and
   reads unmistakably as "selected". */
.msg-row[aria-current="true"] .msg-row__badge {
  background: var(--md-sys-color-on-secondary-container);
  color: var(--md-sys-color-secondary-container);
}

.msg-row__body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.msg-row__headline,
.msg-row__preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-row__preview {
  color: var(--md-sys-color-on-surface-variant);
}

.msg-row[aria-current="true"] .msg-row__preview {
  color: var(--md-sys-color-on-secondary-container);
}

/* Trailing column: time on top, unread pill underneath. Badges never render
   on the active row (buildListRow skips them there), so no aria-current
   variant is needed for .msg-row__unread — but selectors stay independent
   of aria-current regardless, per the design-standards rule. */
.msg-row__meta {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.msg-row__time {
  color: var(--md-sys-color-on-surface-variant);
}

.msg-row[aria-current="true"] .msg-row__time {
  color: var(--md-sys-color-on-secondary-container);
}

.msg-row__unread {
  flex: none;
  min-width: 20px;
  height: 20px;
  box-sizing: border-box;
  padding: 0 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
}

/* Unread emphasis: headline gains weight, preview reads at full contrast
   instead of the muted on-surface-variant tone used for read rows. */
.msg-row--unread .msg-row__headline {
  font-weight: 600;
}

.msg-row--unread .msg-row__preview {
  color: var(--md-sys-color-on-surface);
}

.msg-thread-empty {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* --------------------------------------------------------------------------
   14. Messages — thread & bubbles
   -------------------------------------------------------------------------- */
.msg-thread {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.msg-thread__header {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.msg-thread__titles {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.msg-thread__title,
.msg-thread__subtitle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-thread__subtitle {
  color: var(--md-sys-color-on-surface-variant);
}

.msg-thread__link-banner {
  flex: none;
  padding: 8px 16px;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface-variant);
}

.msg-bubbles {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 16px;
}

.msg-bubble-wrap {
  max-width: 75%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-bubble-wrap--in {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-bubble-wrap--out {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-bubble {
  max-width: 100%;
  padding: 8px 12px;
  border-radius: var(--md-sys-shape-corner-large);
  overflow-wrap: anywhere;
}

.msg-bubble--in {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  border-end-start-radius: var(--md-sys-shape-corner-extra-small);
}

.msg-bubble--out {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border-end-end-radius: var(--md-sys-shape-corner-extra-small);
}

.msg-bubble__sender {
  margin: 0 0 2px;
  color: var(--md-sys-color-on-surface-variant);
}

.msg-bubble__text {
  margin: 0;
  white-space: pre-wrap;
}

.msg-bubble__footer {
  margin-top: 4px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--md-sys-color-on-surface-variant);
}

.msg-bubble--out .msg-bubble__footer {
  color: color-mix(in srgb, var(--md-sys-color-on-secondary-container) 80%, transparent);
}

.msg-bubble__kind {
  padding: 1px 8px;
  border-radius: var(--md-sys-shape-corner-small);
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
}

.msg-bubble__kind--alert {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

.msg-bubble__pki {
  color: currentColor;
}

.msg-bubble__ack--failed {
  color: var(--md-sys-color-error);
}

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.msg-reaction-pill {
  padding: 2px 10px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface-variant);
}

.msg-jump-chip {
  position: absolute;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%);
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  box-shadow:
    0 1px 2px color-mix(in srgb, var(--md-sys-color-shadow) 30%, transparent),
    0 1px 3px 1px color-mix(in srgb, var(--md-sys-color-shadow) 15%, transparent);
}

/* --------------------------------------------------------------------------
   15. Messages — composer
   -------------------------------------------------------------------------- */
.msg-composer {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 16px;
}

.msg-composer__field {
  flex: 1 1 auto;
  min-width: 0;
}

.text-field--compact .text-field__input {
  height: 48px;
}

.msg-byte-counter {
  flex: none;
  color: var(--md-sys-color-on-surface-variant);
}

.msg-byte-counter.is-error {
  color: var(--md-sys-color-error);
}

.msg-send {
  flex: none;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.msg-send:hover:not(:disabled) {
  background: color-mix(in srgb, var(--md-sys-color-on-primary) 8%, var(--md-sys-color-primary));
}

.msg-send:disabled {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
  color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
  cursor: not-allowed;
}

.msg-send-error {
  margin: 0 16px 12px;
  min-height: var(--md-sys-typescale-body-small-line-height);
  color: var(--md-sys-color-error);
}
