/* Standard components: buttons, inputs, chips, badges, counts, tabs, cards, tables, states, toast, dialog, popover, menus. */

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 14px;
  border: 1px solid var(--c-line-2); border-radius: var(--r-1); background: var(--c-surface); color: var(--c-ink);
  font-size: var(--fs-13); font-weight: 550; text-decoration: none; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--c-surface-2); border-color: var(--c-faint); }
.btn-sm { min-height: 32px; padding: 0 10px; }
.btn-xs { min-height: 28px; padding: 0 8px; font-size: var(--fs-12); }
.btn-primary { background: var(--c-brand); border-color: var(--c-brand); color: #fff; }
.btn-primary:hover { background: var(--c-brand-700); border-color: var(--c-brand-700); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--c-brand-600); }
.btn-ghost:hover { background: var(--c-brand-50); border-color: transparent; }
.btn-block { display: flex; width: 100%; margin-top: var(--s-2); }
.btn[aria-pressed="true"] { background: var(--c-brand-50); border-color: var(--c-brand-100); color: var(--c-brand); }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none; border: 0; border-radius: var(--r-1);
  background: transparent; color: var(--c-ink-2); text-decoration: none;
}
.icon-btn:hover { background: var(--c-surface-3); color: var(--c-ink); }
.icon-btn-sm { width: 28px; height: 28px; }

.link { border: 0; padding: 0; background: none; color: var(--c-brand-600); font: inherit; text-decoration: underline; text-underline-offset: 2px; text-decoration-color: rgba(31, 100, 168, .35); cursor: pointer; }
.link:hover { text-decoration-color: currentColor; }

/* ── Inputs ── */
.input {
  width: 100%; min-height: 36px; padding: 6px 10px; border: 1px solid var(--c-line-2); border-radius: var(--r-1);
  background: var(--c-surface); font-size: var(--fs-13);
}
.input:focus-visible { outline-offset: 0; border-color: var(--c-focus); }
.input-sm { min-height: 30px; }
.select { width: auto; padding-right: 28px; }
.check, .radio { display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 2px 6px; border-radius: var(--r-1); cursor: pointer; font-size: var(--fs-13); }
.check:hover, .radio:hover { background: var(--c-surface-2); }
.check input, .radio input { width: 16px; height: 16px; accent-color: var(--c-brand-600); flex: none; }
.check-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Segmented control */
.seg { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: var(--s-3); }
.seg-btn {
  min-height: 30px; padding: 0 10px; border: 1px solid var(--c-line-2); border-radius: 999px; background: var(--c-surface);
  font-size: var(--fs-12); font-weight: 550; color: var(--c-ink-2); display: inline-flex; gap: 6px; align-items: center;
}
.seg-btn[aria-pressed="true"] { background: var(--c-brand); border-color: var(--c-brand); color: #fff; }
.seg-btn[aria-pressed="true"] .count { background: rgba(255, 255, 255, .2); color: #fff; }
.seg-sm .seg-btn { min-height: 26px; }

/* ── Badges & counts ── */
.badge {
  display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 999px; font-size: var(--fs-11);
  font-weight: 650; letter-spacing: .01em; white-space: nowrap; vertical-align: 1px; background: var(--c-surface-3); color: var(--c-ink-2);
}
.badge-good { background: var(--c-good-bg); color: var(--c-good); }
.badge-info { background: var(--c-info-bg); color: var(--c-info); }
.badge-warn { background: var(--c-warn-bg); color: var(--c-warn); }
.badge-danger { background: var(--c-danger-bg); color: var(--c-danger); }
.badge-neutral { background: var(--c-surface-3); color: var(--c-ink-2); }
.badge-quiet { background: transparent; border: 1px solid var(--c-line-2); color: var(--c-muted); }

.count {
  display: inline-flex; align-items: center; justify-content: center; gap: 3px; min-width: 20px; height: 18px; padding: 0 6px;
  border-radius: 999px; background: var(--c-surface-3); color: var(--c-ink-2); font-size: var(--fs-11); font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.count-brand { background: var(--c-brand); color: #fff; }
.count-loading { color: var(--c-faint); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.pill { display: inline-flex; align-items: center; gap: 4px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--s-3); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1px rgba(0, 0, 0, .1); }

/* ── Chips (active filters) ── */
.chips { display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.chip {
  display: inline-flex; align-items: center; flex: none; height: 32px; border-radius: 999px; background: var(--c-brand-50);
  border: 1px solid var(--c-brand-100); color: var(--c-brand); font-size: var(--fs-12); font-weight: 600;
}
.chip-main { border: 0; background: none; color: inherit; padding: 0 4px 0 12px; height: 100%; display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.chip-k { color: var(--c-ink-2); font-weight: 500; }
.chip-x { border: 0; background: none; color: inherit; width: 28px; height: 28px; margin-right: 2px; border-radius: 50%; display: grid; place-items: center; }
.chip-x:hover { background: var(--c-brand-100); }
.chip-x .i { width: 14px; height: 14px; }

/* ── Tabs ── */
.tabs {
  display: flex; gap: 2px; overflow-x: auto; scrollbar-width: thin; border-bottom: 1px solid var(--c-line);
  padding: 0 var(--s-2); background: var(--c-surface); position: sticky; top: 0; z-index: 5;
}
.tab {
  flex: none; display: inline-flex; align-items: center; gap: 5px; min-height: 42px; padding: 0 8px; border: 0;
  border-bottom: 2px solid transparent; background: none; color: var(--c-muted); font-size: var(--fs-13); font-weight: 600;
}
.tab:hover { color: var(--c-ink); }
.tab[aria-selected="true"] { color: var(--c-brand); border-bottom-color: var(--c-brand); }
.tab[aria-selected="true"] .count { background: var(--c-brand-50); color: var(--c-brand); }

/* ── Sections, cards, lists ── */
.sec { margin: 0 0 var(--s-4); }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); margin-bottom: var(--s-2); min-height: 28px; }
.sec-title { display: flex; align-items: center; gap: 8px; font-size: var(--fs-13); font-weight: 700; color: var(--c-ink); text-transform: none; }
.sec.collapsed .sec-body { display: none; }

.card { border: 1px solid var(--c-line); border-radius: var(--r-2); background: var(--c-surface); padding: var(--s-3); }
.card-title { font-weight: 650; margin-bottom: var(--s-2); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.card-list { display: grid; gap: var(--s-2); }

.row-list { display: flex; flex-direction: column; border: 1px solid var(--c-line); border-radius: var(--r-2); overflow: hidden; background: var(--c-surface); }
.row-list > .empty { border: 0; }
.row-item {
  display: flex; align-items: center; gap: var(--s-2); width: 100%; min-height: 48px; padding: 8px 10px 8px 12px; border: 0;
  border-bottom: 1px solid var(--c-line); background: var(--c-surface); text-align: left;
}
.row-item:last-child, .row-list > .btn-block { border-bottom: 0; }
.row-item:hover { background: var(--c-surface-2); }
.ri-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ri-title { font-weight: 600; font-size: var(--fs-13); display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.ri-sub { color: var(--c-muted); font-size: var(--fs-12); overflow: hidden; text-overflow: ellipsis; }
.ri-side { display: flex; align-items: center; gap: 6px; flex: none; }
.ri-year { font-size: var(--fs-12); color: var(--c-muted); font-variant-numeric: tabular-nums; }
.ri-chev { color: var(--c-faint); }
.ri-note { font-size: var(--fs-12); color: var(--c-muted); padding: 0 12px 8px; margin-top: -4px; border-bottom: 1px solid var(--c-line); background: var(--c-surface); }
.row-list .btn-block { margin: 0; border-radius: 0; }

.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

/* Key–value */
.kv { display: grid; grid-template-columns: minmax(110px, 34%) 1fr; gap: 6px 12px; margin: 0; font-size: var(--fs-13); }
.kv dt { color: var(--c-muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* Progress */
.progress { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.progress-track { flex: 1; height: 6px; border-radius: 999px; background: var(--c-surface-3); overflow: hidden; max-width: 200px; }
.progress-fill { height: 100%; background: var(--c-data); border-radius: 999px; }
.progress-text { font-size: var(--fs-12); color: var(--c-muted); white-space: nowrap; }

/* Groups (collapsible lists) */
.group { border: 1px solid var(--c-line); border-radius: var(--r-2); background: var(--c-surface); margin-bottom: var(--s-2); }
.group > summary {
  list-style: none; display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: var(--fs-13);
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before { content: ""; width: 7px; height: 7px; border-right: 2px solid var(--c-faint); border-bottom: 2px solid var(--c-faint); transform: rotate(-45deg); transition: transform .15s; margin-right: 2px; }
.group[open] > summary::before { transform: rotate(45deg); }
.group-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.gt-main { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.gt-sub { font-size: var(--fs-12); font-weight: 500; color: var(--c-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group > .row-list, .group > .subgroup { border: 0; border-top: 1px solid var(--c-line); border-radius: 0 0 var(--r-2) var(--r-2); }
.group > .doc-row:first-of-type { border-top: 1px solid var(--c-line); }
.group > .btn { margin: 6px 12px 10px; }
.subgroup { padding: 0; }
.subgroup-title { display: flex; align-items: center; gap: 6px; padding: 10px 12px 4px; font-size: var(--fs-12); font-weight: 650; color: var(--c-ink-2); }
.group-open { margin-left: auto; }

/* ── Tables ── */
.table-wrap { overflow: auto; max-height: 520px; border: 1px solid var(--c-line); border-radius: var(--r-2); background: var(--c-surface); }
.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-12); font-variant-numeric: tabular-nums; }
.tbl th { position: sticky; top: 0; z-index: 1; background: var(--c-surface-2); text-align: left; font-weight: 650; color: var(--c-ink-2); border-bottom: 1px solid var(--c-line); padding: 0; }
.th-btn { width: 100%; border: 0; background: none; padding: 8px 10px; text-align: inherit; font-weight: 650; display: flex; gap: 4px; align-items: center; justify-content: space-between; }
.tbl th.num .th-btn { justify-content: flex-end; }
.sort-ind { font-size: 9px; color: var(--c-brand-600); }
.tbl td { padding: 7px 10px; border-bottom: 1px solid var(--c-line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:hover td { background: var(--c-surface-2); }
.tbl-compact td, .tbl-compact th { padding: 5px 8px; }
.table-wrap .btn-block { margin: 0; border-radius: 0; border-top: 1px solid var(--c-line); }

/* ── Empty / loading / error ── */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: var(--s-5) var(--s-4); color: var(--c-muted); }
.empty .i { width: 26px; height: 26px; color: var(--c-faint); }
.empty-title { font-weight: 650; color: var(--c-ink-2); font-size: var(--fs-13); }
.empty-sub { font-size: var(--fs-12); max-width: 320px; }
.empty-error .i { color: var(--c-danger); }
.skeleton { display: grid; gap: 10px; padding: var(--s-4); }
.sk-line { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--c-surface-3), var(--c-surface-2), var(--c-surface-3)); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.spinner { width: 16px; height: 16px; border: 2px solid var(--c-line-2); border-top-color: var(--c-brand-600); border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.note { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: var(--r-1); background: var(--c-info-bg); color: var(--c-info); font-size: var(--fs-12); margin: var(--s-2) 0; }
.note-warn { background: var(--c-warn-bg); color: var(--c-warn); }
.note .link { color: inherit; }

/* ── Toast ── */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 4000; display: grid; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; background: var(--c-ink); color: #fff; padding: 10px 14px; border-radius: var(--r-2); box-shadow: var(--sh-3); font-size: var(--fs-13); max-width: 420px; transition: opacity .25s, transform .25s; }
.toast-danger { background: var(--c-danger); }
.toast.leaving { opacity: 0; transform: translateY(8px); }

/* ── Dialog ── */
.dialog-backdrop { position: fixed; inset: 0; z-index: 3000; background: rgba(12, 22, 34, .45); display: grid; place-items: center; padding: var(--s-4); animation: fade .15s; }
.dialog {
  width: min(560px, 100%); max-height: calc(100dvh - 48px); display: flex; flex-direction: column; background: var(--c-surface);
  border-radius: var(--r-3); box-shadow: var(--sh-3); overflow: hidden; animation: rise .2s var(--ease);
}
.dialog-wide { width: min(1000px, 100%); }
.dialog-full { width: min(1200px, 100%); height: calc(100dvh - 48px); }
.dialog-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 18px; border-bottom: 1px solid var(--c-line); }
.dialog-title { flex: 1; font-size: var(--fs-16); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-body { padding: var(--s-4); overflow: auto; flex: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.99); } }
body.modal-open { overflow: hidden; }

/* ── Popover & menus ── */
.popover { position: fixed; z-index: 2500; background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-2); box-shadow: var(--sh-3); overflow: auto; animation: rise .15s var(--ease); }
.menu { min-width: 240px; padding: 6px; }
.menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--c-line); margin-bottom: 4px; }
.menu-name { font-weight: 650; }
.menu-sub { font-size: var(--fs-12); color: var(--c-muted); }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 38px; padding: 0 10px; border: 0; border-radius: var(--r-1); background: none; text-align: left; font-size: var(--fs-13); }
.menu-item:hover, .menu-item:focus-visible { background: var(--c-surface-2); }
.menu-foot { padding: 8px 10px 4px; margin-top: 4px; border-top: 1px solid var(--c-line); font-size: var(--fs-11); color: var(--c-muted); }

.avatar {
  display: inline-grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 50%; background: var(--c-brand-50);
  color: var(--c-brand); font-size: var(--fs-12); font-weight: 700; object-fit: cover;
}
