/* WeightLog interface.
 *
 * Written for a phone held in one hand, in a bathroom, and widened from there. Two
 * rules shape most of what follows:
 *
 *   * nothing has a fixed pixel width, and every flex or grid child that holds text
 *     carries min-width: 0. Notes and usernames are written by people, and one of
 *     them will be forty characters with no spaces in it. Without those two, that
 *     one string decides the width of the whole document and the fixed bottom
 *     navigation slides off the screen with it;
 *
 *   * the number is the interface. The weight input and the figures under it are
 *     large, because they are read at arm's length, first thing in the morning.
 *
 * Both themes are defined here in full. The light one is not an afterthought: a
 * bathroom at seven in the morning is either very bright or very dark.
 */

/* -------------------------------------------------------------------- tokens */

:root {
  color-scheme: dark;

  --bg: #0c1116;
  --surface: #141c24;
  --surface-2: #1c2731;
  --surface-3: #253340;
  --text: #eaf1f6;
  --muted: #9bacba;
  --line: #2b3a48;
  --line-strong: #3a4d5e;

  --brand: #7cc4f0;
  --brand-strong: #4aa3dc;
  --brand-ink: #06121a;
  --accent: #f0b45a;
  --danger: #ff8189;
  --danger-strong: #e5525d;

  --radius: 0.9rem;
  --radius-lg: 1.2rem;
  --shadow: 0 1rem 2.5rem rgb(0 0 0 / 0.35);

  /* Room the fixed bottom navigation needs, so the last item is never under it. */
  --nav-height: 4.4rem;

  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg: #f2f6f8;
  --surface: #ffffff;
  --surface-2: #eaf1f4;
  --surface-3: #dde8ed;
  --text: #14212b;
  --muted: #55707f;
  --line: #cddbe3;
  --line-strong: #b3c7d2;

  --brand: #1a6fa8;
  --brand-strong: #125784;
  --brand-ink: #ffffff;
  --accent: #92570a;
  --danger: #b3283a;
  --danger-strong: #8f1c2c;

  --shadow: 0 1rem 2.5rem rgb(20 60 80 / 0.12);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;

    --bg: #f2f6f8;
    --surface: #ffffff;
    --surface-2: #eaf1f4;
    --surface-3: #dde8ed;
    --text: #14212b;
    --muted: #55707f;
    --line: #cddbe3;
    --line-strong: #b3c7d2;

    --brand: #1a6fa8;
    --brand-strong: #125784;
    --brand-ink: #ffffff;
    --accent: #92570a;
    --danger: #b3283a;
    --danger-strong: #8f1c2c;

    --shadow: 0 1rem 2.5rem rgb(20 60 80 / 0.12);
  }
}

/* ---------------------------------------------------------------- foundation */

*,
*::before,
*::after {
  box-sizing: border-box;
  min-width: 0;
  overflow-wrap: anywhere;
}

html,
body {
  margin: 0;
  padding: 0;
  /* Never hide horizontal overflow here. It masks the fault instead of fixing it, breaks
   * position: sticky in every descendant, and does not even stop the scroll in
   * Safari on iOS. */
}

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, p, ul, ol, figure {
  margin: 0;
}

ul, ol {
  padding: 0;
  list-style: none;
}

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

img, svg {
  max-width: 100%;
  height: auto;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------- shell */

.shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}

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

.topbar__mark {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 0.6rem;
  background: var(--brand);
  color: var(--brand-ink);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.topbar__name {
  min-width: 0;
  font-size: 1.05rem;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.topbar__account {
  flex: 0 1 auto;
  min-width: 0;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.topbar__username {
  display: block;
  min-width: 0;
  max-width: 11rem;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.85rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: 62rem;
  margin: 0 auto;
  padding: 1rem 1rem calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 1.5rem);
}

.main:focus {
  outline: none;
}

/* ---------------------------------------------------------------- navigation */

.nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: flex;
  min-width: 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(10px);
}

.nav__item {
  position: relative;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 0.55rem 0.25rem;
  color: var(--muted);
  font-size: 0.72rem;
}

.nav__item--active {
  color: var(--brand);
}

.nav__icon {
  width: 1.4rem;
  height: 1.4rem;
  background: currentColor;
  /* One mask per icon keeps them monochrome and theme-aware with no icon font and
   * no second network request. */
  mask-position: center;
  mask-repeat: no-repeat;
  mask-size: contain;
}

.nav__icon[data-icon="scale"] {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='4'/%3E%3Cpath d='M8 9.5a5 5 0 0 1 8 0'/%3E%3Cpath d='m12 10-1.5 2.5'/%3E%3C/svg%3E");
}

.nav__icon[data-icon="history"] {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 12a9 9 0 1 0 3-6.7'/%3E%3Cpath d='M3 4v5h5'/%3E%3Cpath d='M12 8v4l3 2'/%3E%3C/svg%3E");
}

.nav__icon[data-icon="trend"] {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 3v18h18'/%3E%3Cpath d='m7 14 4-4 3 3 6-7'/%3E%3C/svg%3E");
}

.nav__icon[data-icon="admin"] {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3 4 6v6c0 5 3.4 8.4 8 9 4.6-.6 8-4 8-9V6z'/%3E%3C/svg%3E");
}

.nav__icon[data-icon="settings"] {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M19.4 15a1.7 1.7 0 0 0 .3 1.9l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.9-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1A1.7 1.7 0 0 0 9 19.4a1.7 1.7 0 0 0-1.9.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.9 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1A1.7 1.7 0 0 0 4.6 9a1.7 1.7 0 0 0-.3-1.9l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.9.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.9-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.9V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z'/%3E%3C/svg%3E");
}

.nav__label {
  min-width: 0;
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* -------------------------------------------------------------------- screen */

.screen {
  display: grid;
  gap: 1.1rem;
  min-width: 0;
}

.screen__head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  align-items: flex-end;
  justify-content: space-between;
  min-width: 0;
}

.screen__title-block {
  flex: 1 1 14rem;
  min-width: 0;
}

.screen__title {
  min-width: 0;
  font-size: 1.65rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.screen__copy,
.screen__meta {
  min-width: 0;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.screen__meta {
  font-size: 0.85rem;
}

.eyebrow {
  color: var(--brand);
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ------------------------------------------------------------------ controls */

.button {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.button--primary {
  background: var(--brand);
  color: var(--brand-ink);
}

.button--primary:hover {
  background: var(--brand-strong);
}

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

.button--ghost:hover {
  background: var(--surface-2);
}

.button--danger {
  border-color: var(--danger);
  background: transparent;
  color: var(--danger);
}

.button--danger:hover {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
}

.button--small {
  min-height: 2.1rem;
  padding: 0.25rem 0.7rem;
  font-size: 0.82rem;
}

.button--wide {
  flex: 0 1 auto;
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.input {
  width: 100%;
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  /* 1rem or more, or iOS Safari zooms the whole page in on focus and leaves it
   * there, which looks exactly like the horizontal overflow bug. */
  font-size: 1rem;
}

.input:disabled {
  opacity: 0.55;
}

.input--area {
  min-height: 5rem;
  resize: vertical;
}

/* A number with its unit written after it, inside the same box. */
.input-group {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}

.input-group .input {
  padding-right: 3rem;
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.input-group__suffix {
  position: absolute;
  right: 0.9rem;
  color: var(--muted);
  font-weight: 700;
  pointer-events: none;
}

.field {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
}

.field__label {
  font-size: 0.88rem;
  font-weight: 700;
}

.field__hint {
  min-width: 0;
  color: var(--muted);
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.toggle {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  min-width: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.toggle input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--brand);
}

/* The period buttons above the chart: one row, every button the same width. */
.range {
  display: flex;
  min-width: 0;
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.range__button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 2.2rem;
  padding: 0.2rem 0.3rem;
  border: 0;
  border-radius: calc(var(--radius) - 0.2rem);
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.range__button--active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.2);
}

/* The year, month and day selectors on the history screen. */
.filters {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  min-width: 0;
}

.search-form {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  min-width: 0;
}

.search-form .input {
  flex: 1 1 auto;
  min-width: 0;
}

.search-form .button {
  flex: none;
}

/* ------------------------------------------------------------- notices, toast */

.notice {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.notice--warning {
  border-color: var(--accent);
  color: var(--accent);
}

.notice--goal {
  display: grid;
  gap: 0.15rem 0.6rem;
  grid-template-columns: minmax(0, 1fr) auto;
  border-color: var(--brand);
  color: var(--text);
}

.notice__title {
  grid-column: 1;
  min-width: 0;
  font-weight: 750;
}

/* Placed explicitly: an item with a definite row is placed before the auto ones,
 * and without the column it would take the first column and push the text right. */
.notice__go {
  flex: none;
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  color: var(--brand);
  font-weight: 700;
}

.toast-stack {
  position: fixed;
  right: 0.75rem;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 0.75rem);
  left: 0.75rem;
  z-index: 60;
  display: grid;
  gap: 0.5rem;
  justify-items: center;
  pointer-events: none;
}

.toast {
  min-width: 0;
  max-width: 100%;
  padding: 0.7rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-3);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.toast--success { border-color: var(--brand); }
.toast--warning { border-color: var(--accent); }
.toast--error   { border-color: var(--danger); }

/* --------------------------------------------------------------------- cards */

.card-stack {
  display: grid;
  gap: 0.8rem;
  min-width: 0;
}

.card {
  display: grid;
  gap: 0.6rem;
  min-width: 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.card__title {
  min-width: 0;
  font-size: 1.05rem;
}

.card__copy {
  min-width: 0;
  color: var(--muted);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-width: 0;
}

.identity {
  min-width: 0;
}

.identity__value {
  display: inline-block;
  min-width: 0;
  max-width: 100%;
  padding: 0.3rem 0.6rem;
  border-radius: 0.5rem;
  background: var(--surface-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

/* ----------------------------------------------------------------- the form */

.entry-form {
  gap: 0.8rem;
}

.entry-form .button {
  justify-self: start;
}

/* -------------------------------------------------------------------- stats */

.stat-grid {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
}

@media (min-width: 40rem) {
  .stat-grid {
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  }
}

.stat {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.stat__value {
  min-width: 0;
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.stat__label {
  min-width: 0;
  color: var(--muted);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.stat__sub {
  min-width: 0;
  color: var(--muted);
  font-size: 0.74rem;
  overflow-wrap: anywhere;
}

/* A change in weight. Down is the brand color and up is the accent, because most
 * people here are trying to lose, and the colors say "the way you wanted" and
 * "the other way" without saying which is good. */
.delta--down { color: var(--brand); }
.delta--up   { color: var(--accent); }
.delta--flat { color: var(--muted); }

/* ------------------------------------------------------------------ readings */

.recent {
  display: grid;
  gap: 0.5rem;
  min-width: 0;
}

.recent__head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: baseline;
  justify-content: space-between;
  min-width: 0;
}

.recent__title {
  min-width: 0;
  font-size: 1.05rem;
}

.recent__all {
  color: var(--brand);
  font-size: 0.88rem;
  font-weight: 700;
}

.entry-list {
  display: grid;
  gap: 0.4rem;
  min-width: 0;
}

.entry {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.entry__body {
  display: grid;
  gap: 0.15rem;
  width: 100%;
  min-width: 0;
  padding: 0.65rem 0.85rem;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.entry__body:hover {
  background: var(--surface-2);
}

.entry__top {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.7rem;
  align-items: baseline;
  min-width: 0;
}

.entry__weight {
  min-width: 0;
  font-size: 1.2rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.entry__delta {
  min-width: 0;
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.entry__when {
  min-width: 0;
  color: var(--muted);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.entry__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.6rem;
  min-width: 0;
  font-size: 0.78rem;
}

.entry__meta > * {
  min-width: 0;
  overflow-wrap: anywhere;
}

.entry__condition {
  padding: 0 0.4rem;
  border-radius: 0.4rem;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
}

.entry__notes {
  color: var(--muted);
}

/* --------------------------------------------------------------------- chart */

.chart {
  display: grid;
  gap: 0.5rem;
  min-width: 0;
}

.chart__svg {
  display: block;
  width: 100%;
  height: auto;
  min-width: 0;
}

.chart__grid {
  stroke: var(--line);
  stroke-width: 1;
}

.chart__axis-label {
  fill: var(--muted);
  font-size: 12px;
}

.chart__average {
  fill: none;
  stroke: var(--brand);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart__point {
  fill: var(--muted);
  opacity: 0.75;
}

.chart__last {
  fill: var(--brand);
  stroke: var(--bg);
  stroke-width: 2;
}

.chart__last-label {
  fill: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.chart__goal {
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: 6 5;
}

.chart__goal-label {
  fill: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.chart__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1rem;
  min-width: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.chart__key {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
  min-width: 0;
}

.chart__key::before {
  content: "";
  flex: none;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
}

.chart__key--points::before {
  width: 0.6rem;
  height: 0.6rem;
  background: var(--muted);
}

.chart__key--average::before {
  height: 0.2rem;
  border-radius: 0.1rem;
  background: var(--brand);
}

.chart__key--goal::before {
  height: 0;
  border-top: 2px dashed var(--accent);
  border-radius: 0;
}

/* ---------------------------------------------------------------------- goal */

.goal__status {
  min-width: 0;
  font-size: 1rem;
  font-weight: 700;
}

.goal__status--reached {
  color: var(--brand);
}

.goal__status--warning {
  color: var(--accent);
}

.progress {
  width: 100%;
  height: 0.6rem;
  min-width: 0;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-3);
}

.progress__fill {
  height: 100%;
  border-radius: 999px;
  background: var(--brand);
  transition: width 0.4s ease;
}

.progress__label {
  min-width: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

/* --------------------------------------------------------------------- admin */

.badge {
  flex: none;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 750;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.badge--admin {
  border-color: var(--brand);
  color: var(--brand);
}

/* A wide table scrolls inside its own box rather than dragging the document. */
.table-wrap {
  min-width: 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.table th,
.table td {
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.table th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.cell--name {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  min-width: 0;
}

.cell__username {
  min-width: 0;
  font-weight: 700;
  overflow-wrap: anywhere;
  white-space: normal;
}

.row--inactive .cell__username,
.row--inactive td {
  color: var(--muted);
}

.row--inactive .button,
.row--inactive .badge {
  opacity: 1;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
}

.pagination__status {
  min-width: 0;
  color: var(--muted);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------- dialogs */

.dialog {
  width: 100%;
  max-width: 32rem;
  max-height: calc(100dvh - 1rem);
  min-width: 0;
  margin: auto;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 0.55);
}

.dialog__body {
  display: grid;
  gap: 0.9rem;
  min-width: 0;
  padding: 1.1rem;
  overflow-y: auto;
}

.dialog__title {
  min-width: 0;
  font-size: 1.2rem;
  overflow-wrap: anywhere;
}

.dialog__fields {
  display: grid;
  gap: 0.75rem;
  min-width: 0;
}

.dialog__row {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
  min-width: 0;
}

@media (min-width: 30rem) {
  .dialog__row {
    grid-template-columns: 1fr 1fr;
  }
}

.dialog__copy {
  min-width: 0;
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.dialog__error {
  min-width: 0;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.dialog__rule {
  width: 100%;
  margin: 0.2rem 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.dialog__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
  min-width: 0;
}

.dialog__actions .button {
  flex: 1 1 8rem;
}

/* --------------------------------------------------- empty, loading and boot */

.empty-state {
  display: grid;
  gap: 0.5rem;
  justify-items: center;
  min-width: 0;
  padding: 2.5rem 1rem;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  text-align: center;
}

.empty-state--inline {
  padding: 1.6rem 1rem;
}

.empty-state__icon {
  width: 2.6rem;
  height: 2.6rem;
  background: var(--muted);
  mask-position: center;
  mask-repeat: no-repeat;
  mask-size: contain;
}

.empty-state__icon[data-icon="scale"] {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='4'/%3E%3Cpath d='M8 9.5a5 5 0 0 1 8 0'/%3E%3Cpath d='m12 10-1.5 2.5'/%3E%3C/svg%3E");
}

.empty-state__icon[data-icon="trend"] {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 3v18h18'/%3E%3Cpath d='m7 14 4-4 3 3 6-7'/%3E%3C/svg%3E");
}

.empty-state__title {
  min-width: 0;
  font-size: 1.05rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.empty-state__copy {
  min-width: 0;
  max-width: 32rem;
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.loading {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 3rem 1rem;
  color: var(--muted);
}

.loading__spinner {
  width: 1.2rem;
  height: 1.2rem;
  border: 2px solid var(--line-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .loading__spinner {
    animation: none;
  }

  .progress__fill {
    transition: none;
  }
}

.fatal {
  display: grid;
  gap: 0.7rem;
  justify-items: center;
  min-width: 0;
  padding: 3rem 1rem;
  text-align: center;
}

.fatal__title {
  min-width: 0;
  font-size: 1.3rem;
  overflow-wrap: anywhere;
}

.fatal__copy {
  min-width: 0;
  max-width: 32rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.boot-screen {
  display: grid;
  gap: 0.8rem;
  place-content: center;
  min-height: 100dvh;
  min-width: 0;
  justify-items: center;
}

.boot-mark {
  display: grid;
  place-items: center;
  width: 3.2rem;
  height: 3.2rem;
  border-radius: 0.9rem;
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 800;
}

.boot-text {
  color: var(--muted);
}

/* Below 360px the padding is what is left to give back. */
@media (max-width: 22.5rem) {
  .main {
    padding-right: 0.7rem;
    padding-left: 0.7rem;
  }

  .screen__title {
    font-size: 1.4rem;
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .range__button {
    font-size: 0.72rem;
  }
}
