/* ==========================================================================
   Components
   ========================================================================== */

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 620;
  white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-1);
}
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn--ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn--ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn--danger { background: var(--danger-solid); border-color: var(--danger-solid); color: #fff; }
.btn--danger:hover { filter: brightness(.94); }

.btn--ok { color: var(--ok-ink); border-color: var(--ok-border); background: var(--ok-bg); }
.btn--ok:hover { background: var(--ok-bg); filter: brightness(.97); }

.btn--sm { height: 28px; padding: 0 9px; font-size: 12.25px; gap: 5px; }
.btn--block { width: 100%; }

.btn-icon-only { padding: 0; width: 34px; }

/* ---------------------------------------------------------------- fields */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label,
.field-label {
  font-size: 11.5px;
  font-weight: 680;
  letter-spacing: .02em;
  color: var(--text-2);
}
.field__hint { font-size: 11.5px; color: var(--muted); }

.input, .select, .textarea {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input::placeholder { color: var(--faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--muted); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.select {
  appearance: none;
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.textarea { height: auto; min-height: 76px; padding: 8px 10px; resize: vertical; }
.select--sm {
  height: 30px;
  font-size: 12px;
  padding: 0 26px 0 8px;
  background-position: calc(100% - 14px) 13px, calc(100% - 9px) 13px;
}

.input--search { padding-left: 32px; }
.search-field { position: relative; }
.search-field > svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--faint);
  pointer-events: none;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.toolbar__spacer { margin-left: auto; }

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.segmented button {
  height: 28px;
  padding: 0 11px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
  font-weight: 680;
}
.segmented .count {
  margin-left: 5px;
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 680;
  line-height: 1.55;
  white-space: nowrap;
}
.badge--neutral { background: var(--neutral-bg); border-color: var(--neutral-border); color: var(--neutral-ink); }
.badge--accent  { background: var(--accent-soft); border-color: var(--accent-soft-2); color: var(--accent-ink); }
.badge--ok      { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok-ink); }
.badge--warn    { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-ink); }
.badge--danger  { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-ink); }
.badge--info    { background: var(--info-bg); border-color: var(--info-border); color: var(--info-ink); }
.badge--dot::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

/* ---------------------------------------------------------------- avatar */

.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .02em;
  box-shadow: inset 0 -8px 16px rgba(0, 0, 0, .16);
  user-select: none;
}
.avatar--sm { width: 26px; height: 26px; font-size: 10px; }
.avatar--lg { width: 42px; height: 42px; font-size: 14px; }

.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person__text { min-width: 0; line-height: 1.3; }
.person__name { font-weight: 620; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person__meta { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
}

.dashlet {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.dashlet::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--accent);
  z-index: 2;
}
.dashlet--ok::before { background: var(--ok-solid); }
.dashlet--warn::before { background: var(--warn-solid); }
.dashlet--danger::before { background: var(--danger-solid); }

.dashlet__head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 13px 14px 11px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.dashlet__icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.dashlet__titles { min-width: 0; }
.dashlet__title {
  font-size: 13.5px;
  font-weight: 690;
  color: var(--heading);
  line-height: 1.25;
}
.dashlet__sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.dashlet__actions { margin-left: auto; display: flex; align-items: center; gap: 3px; flex: 0 0 auto; }
.dashlet__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 10px 14px 12px;
}

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

.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--gutter);
  margin-bottom: var(--gutter);
}
.stat {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
}
.stat__label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 650;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.stat__value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -.02em;
  color: var(--heading);
  font-variant-numeric: tabular-nums;
}
.stat__value small { font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.stat__foot { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* ---------------------------------------------------------------- tables */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  overflow: auto;
  max-width: 100%;
}
table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  min-width: 640px;
}
table.data caption {
  caption-side: top;
  text-align: left;
  padding: 12px 14px 6px;
  color: var(--muted);
  font-size: 12px;
}
table.data th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--surface-hover); }
table.data .num, table.data .mono { font-variant-numeric: tabular-nums; }
table.data .align-right { text-align: right; }
table.data tfoot td {
  padding: 10px 12px;
  font-weight: 680;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  color: var(--heading);
}
.cell-strong { font-weight: 640; color: var(--heading); }
.cell-sub { font-size: 11.5px; color: var(--muted); }

/* ---------------------------------------------------------------- meters */

.meter {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.meter__fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 320ms var(--ease);
}
.meter__fill--warn { background: var(--warn-solid); }
.meter__fill--danger { background: var(--danger-solid); }

/* ---------------------------------------------------------------- lists */

.list { display: flex; flex-direction: column; }
.list__row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.list__row:last-child { border-bottom: 0; }
.list__row--start { align-items: flex-start; }

.dot-live {
  position: relative;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok-solid);
  flex: 0 0 auto;
}
.dot-live::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1px solid var(--ok-solid);
  opacity: 0;
  animation: live-ping 2.4s var(--ease) infinite;
}
@keyframes live-ping {
  0% { transform: scale(.6); opacity: .8; }
  70%, 100% { transform: scale(1.6); opacity: 0; }
}

/* ---------------------------------------------------------------- charts */

.chart { width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 9px; font-family: var(--font-sans); }
.chart .grid-line { stroke: var(--grid-line); stroke-width: 1; }
.chart .bar { fill: var(--chart-1); transition: opacity 120ms var(--ease); }
.chart .bar:hover { opacity: .78; }
.chart .bar--today { fill: var(--accent); }
.chart .bar--empty { fill: var(--surface-3); }
.chart .value-label { fill: var(--text-2); font-size: 8.5px; font-weight: 650; }
.chart .axis-label { fill: var(--muted); font-size: 9px; }
.chart .axis-label--today { fill: var(--accent-ink); font-weight: 700; }

.spark { width: 100%; height: 34px; }
.spark path { fill: none; stroke: var(--chart-2); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- toast */

.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  min-width: 250px;
  max-width: 380px;
  padding: 11px 13px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-2);
  font-size: 12.75px;
  pointer-events: auto;
  animation: toast-in 200ms var(--ease);
}
.toast--ok { border-left: 3px solid var(--ok-solid); }
.toast--danger { border-left: 3px solid var(--danger-solid); }
.toast--info { border-left: 3px solid var(--info-solid); }
.toast__icon { flex: 0 0 auto; margin-top: 1px; }
.toast__body { min-width: 0; }
.toast__title { font-weight: 680; }
.toast__msg { color: var(--text-2); margin-top: 1px; }
.toast.is-leaving { animation: toast-out 180ms var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

/* ---------------------------------------------------------------- modal */

dialog.modal {
  width: min(560px, calc(100vw - 28px));
  max-height: min(86vh, 820px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
dialog.modal::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }
dialog.modal[open] { display: flex; flex-direction: column; }

.modal__head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.modal__title { font-size: 15.5px; font-weight: 700; }
.modal__sub { font-size: 12.25px; color: var(--muted); margin-top: 3px; }
.modal__close { margin-left: auto; }
.modal__body { padding: 16px 18px; overflow: auto; }
.modal__foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid .field--full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- palette */

.palette {
  position: fixed;
  inset: 0;
  z-index: 190;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh 16px 16px;
  background: var(--scrim);
  backdrop-filter: blur(2px);
}
.palette__panel {
  width: min(600px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
  animation: palette-in 160ms var(--ease);
}
@keyframes palette-in { from { opacity: 0; transform: translateY(-6px) scale(.99); } }

.palette__search {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  color: var(--faint);
}
.palette__search input {
  flex: 1 1 auto;
  height: 52px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.palette__search kbd {
  font-size: 10.5px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  background: var(--surface-2);
}
.palette__list { max-height: min(52vh, 420px); overflow: auto; padding: 6px; }
.palette__group {
  padding: 8px 10px 4px;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--faint);
}
.palette__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 13px;
}
.palette__item[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-ink); }
.palette__item .hint { margin-left: auto; font-size: 11px; color: var(--muted); }
.palette__empty { padding: 18px; text-align: center; color: var(--muted); font-size: 13px; }
.palette__foot {
  display: flex;
  gap: 14px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 11px;
  color: var(--muted);
}

/* ---------------------------------------------------------------- empty */

.empty {
  display: grid;
  place-items: center;
  gap: 6px;
  padding: 30px 18px;
  text-align: center;
  color: var(--muted);
}
.empty__icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--surface-3);
  color: var(--muted);
}
.empty__title { font-size: 13px; font-weight: 650; color: var(--text-2); }
.empty__body { font-size: 12px; max-width: 40ch; }

/* ---------------------------------------------------------------- menus */

.menu-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 240px;
  padding: 6px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-pop);
  z-index: 120;
}
.menu-pop[hidden] { display: none; }
.menu-pop__head { display: flex; flex-direction: column; gap: 1px; padding: 8px 10px; }
.menu-sep { height: 1px; margin: 5px 2px; background: var(--border); }
.menu-label {
  padding: 6px 10px 4px;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--faint);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--r-xs);
  background: transparent;
  color: var(--text);
  font-size: 12.75px;
  text-align: left;
}
.menu-item:hover { background: var(--surface-hover); }
.menu-item[aria-checked="true"] { color: var(--accent-ink); font-weight: 650; }
.menu-item--danger { color: var(--danger-ink); }
.menu-item--danger:hover { background: var(--danger-bg); }
.menu-item kbd {
  font-size: 10px;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
}

.modal__form { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }

.form-error {
  margin-top: 12px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger-ink);
  font-size: 12.5px;
}

.foot-card__icon {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* ---------------------------------------------------------------- skeleton */

.skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { to { background-position: -220% 0; } }

/* ---------------------------------------------------------------- table footer */

.table-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 11.5px;
  color: var(--muted);
}
.table-foot strong { color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- messages */

.message-row { cursor: pointer; }
.message-row--unread td { background: var(--accent-soft); }
.message-row--unread td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.message-row--unread .cell-strong { font-weight: 750; }
.message-body {
  white-space: pre-wrap;
  line-height: 1.62;
  color: var(--text-2);
  font-size: 13px;
}
.message-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }

/* ---------------------------------------------------------------- progress cell */

.cell-meter { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.cell-meter .meter { width: 76px; }

/* ---------------------------------------------------------------- split panel */

.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: var(--gutter);
  align-items: start;
}
@media (max-width: 1050px) {
  .split-grid { grid-template-columns: minmax(0, 1fr); }
}
