/* ==========================================================================
   Reset + primitives. Everything here consumes tokens.css.
   ========================================================================== */

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

/* `hidden` must win over any component `display`. Several components below set
   `display: grid|flex`, which would otherwise override the user-agent rule. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--fg);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 { margin: 0; font-weight: var(--weight-semibold); line-height: var(--leading-tight); letter-spacing: var(--tracking-tight); }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

a { color: var(--fg-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }

::selection { background: var(--accent-100); color: var(--accent-700); }

/* --- typography roles ---------------------------------------------------- */
.page-title   { font-size: var(--text-xl); font-weight: var(--weight-semibold); }
.section-title{ font-size: var(--text-lg); font-weight: var(--weight-semibold); }
.card-title   { font-size: var(--text-md); font-weight: var(--weight-semibold); }
.label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--fg-muted);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}
.meta { font-size: var(--text-xs); color: var(--fg-muted); }
.muted { color: var(--fg-muted); }
.subtle { color: var(--fg-subtle); }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- money ---------------------------------------------------------------
   Financial values are the reason this product exists. They get tabular
   figures everywhere so columns align and digits do not shimmer on refresh. */
.money {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  letter-spacing: var(--tracking-tight);
}
.money--lg { font-size: var(--text-2xl); font-weight: var(--weight-semibold); }
.money--table { font-size: var(--text-sm); font-weight: var(--weight-medium); }
.num { font-variant-numeric: tabular-nums; }

/* --- surfaces ------------------------------------------------------------ */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.card__header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
.card__body { padding: var(--space-5); }
.card__body--flush { padding: 0; }
.card__footer {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* --- buttons -------------------------------------------------------------
   Buttons never change size while loading: the label is hidden with
   visibility, not removed, so the box keeps its width. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  position: relative;
  padding: 0 var(--space-4);
  height: 34px;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--fg);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast), border-color var(--transition-fast),
              color var(--transition-fast);
}
.btn:hover:not(:disabled) { background: var(--bg-hover); }
.btn:active:not(:disabled) { background: var(--bg-active); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

.btn--primary {
  background: var(--accent-500); border-color: var(--accent-500); color: #fff;
}
.btn--primary:hover:not(:disabled) { background: var(--accent-600); border-color: var(--accent-600); }
.btn--primary:active:not(:disabled) { background: var(--accent-700); }

.btn--danger { color: var(--danger-fg); border-color: var(--border-strong); }
.btn--danger:hover:not(:disabled) { background: var(--danger-bg); border-color: var(--danger-dot); }

.btn--ghost { background: transparent; border-color: transparent; color: var(--fg-muted); }
.btn--ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--fg); }

.btn--sm { height: 28px; padding: 0 var(--space-3); font-size: var(--text-xs); }
.btn--lg { height: 46px; padding: 0 var(--space-6); font-size: var(--text-md); width: 100%; }
.btn--block { width: 100%; }

.btn.is-loading { pointer-events: none; }
.btn.is-loading > * { visibility: hidden; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 14px; height: 14px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- forms --------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field__label { font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--fg-muted); }
.field__hint { font-size: var(--text-xs); color: var(--fg-subtle); }

.input, .select, .textarea {
  width: 100%;
  padding: 0 var(--space-3);
  height: 34px;
  font-family: inherit;
  font-size: var(--text-sm);
  color: var(--fg);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.textarea { height: auto; padding: var(--space-2) var(--space-3); min-height: 72px; resize: vertical;
            font-family: var(--font-mono); font-size: var(--text-xs); line-height: 1.6; }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--border-focus); box-shadow: var(--focus-ring);
}
.input::placeholder { color: var(--fg-subtle); }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%239ba3af' stroke-width='1.5' d='M3 4.5 6 7.5 9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right var(--space-3) center;
  padding-right: var(--space-8);
}
.checkbox { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); cursor: pointer; }
.checkbox input { width: 15px; height: 15px; accent-color: var(--accent-500); cursor: pointer; }

/* --- status system -------------------------------------------------------
   One semantic vocabulary, used identically everywhere. */
.status {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  background: var(--muted-bg); color: var(--muted-fg);
}
.status::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted-dot); flex: none;
}
.status--ok     { background: var(--ok-bg);     color: var(--ok-fg); }
.status--ok::before     { background: var(--ok-dot); }
.status--warn   { background: var(--warn-bg);   color: var(--warn-fg); }
.status--warn::before   { background: var(--warn-dot); }
.status--danger { background: var(--danger-bg); color: var(--danger-fg); }
.status--danger::before { background: var(--danger-dot); }
.status--info   { background: var(--info-bg);   color: var(--info-fg); }
.status--info::before   { background: var(--info-dot); }
.status--live::before { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; background: var(--muted-dot); }
.dot--ok { background: var(--ok-dot); }
.dot--warn { background: var(--warn-dot); }
.dot--danger { background: var(--danger-dot); }

/* --- tables --------------------------------------------------------------
   Dense enough for real operational use. Money right-aligned. No button
   forest: row actions live behind the row itself. */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th {
  padding: var(--space-2) var(--space-4);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--fg-muted);
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--transition-fast); }
.table tbody tr:hover { background: var(--bg-hover); }
.table .num, .table .money { text-align: right; }
.table th.num, .table th.money { text-align: right; }
.table a.row-link { color: var(--fg); font-weight: var(--weight-medium); }
.table a.row-link:hover { color: var(--fg-accent); }

/* --- empty / error / loading states -------------------------------------- */
.empty {
  padding: var(--space-12) var(--space-6);
  text-align: center;
}
.empty__title { font-size: var(--text-md); font-weight: var(--weight-medium); margin-bottom: var(--space-2); }
.empty__body { font-size: var(--text-sm); color: var(--fg-muted); max-width: 42ch; margin: 0 auto var(--space-5); }

.skeleton {
  background: linear-gradient(90deg, var(--bg-active) 25%, var(--bg-hover) 50%, var(--bg-active) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.notice {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  background: var(--bg-sunken);
}
.notice--ok     { background: var(--ok-bg);     border-color: var(--ok-dot);     color: var(--ok-fg); }
.notice--warn   { background: var(--warn-bg);   border-color: var(--warn-dot);   color: var(--warn-fg); }
.notice--danger { background: var(--danger-bg); border-color: var(--danger-dot); color: var(--danger-fg); }
.notice--info   { background: var(--info-bg);   border-color: var(--info-dot);   color: var(--info-fg); }
.notice strong { font-weight: var(--weight-semibold); }

/* --- layout helpers ------------------------------------------------------ */
.stack { display: flex; flex-direction: column; }
.stack--2 { gap: var(--space-2); } .stack--3 { gap: var(--space-3); }
.stack--4 { gap: var(--space-4); } .stack--6 { gap: var(--space-6); }
.row { display: flex; align-items: center; gap: var(--space-3); }
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: var(--space-4); }

/* --- copy-to-clipboard --------------------------------------------------- */
.copy {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  word-break: break-all;
}
.copy__value { flex: 1; min-width: 0; }

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