/* Reusable components: buttons, chips, cards, forms, tables, tabs, dialogs, toasts, skeletons, banners ... */

/* ---------- tones (used by chips, banners, badges) */
.tone-ok { color: var(--ok-fg); background: var(--ok-bg); border-color: var(--ok-bd); }
.tone-warn { color: var(--warn-fg); background: var(--warn-bg); border-color: var(--warn-bd); }
.tone-bad { color: var(--bad-fg); background: var(--bad-bg); border-color: var(--bad-bd); }
.tone-info { color: var(--info-fg); background: var(--info-bg); border-color: var(--info-bd); }
.tone-merged { color: var(--merged-fg); background: var(--merged-bg); border-color: var(--merged-bd); }
.tone-neutral { color: var(--neutral-fg); background: var(--neutral-bg); border-color: var(--neutral-bd); }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem; height: 2.25rem; padding: 0 0.9rem;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); border-radius: var(--radius-sm);
  font-weight: 560; font-size: 0.9rem; line-height: 1; white-space: nowrap; text-decoration: none;
  transition: background var(--ease), border-color var(--ease), box-shadow var(--ease), transform var(--ease);
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }
.btn:active { transform: translateY(0.5px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn--primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
.btn--danger { color: var(--bad-fg); background: var(--bad-bg); border-color: var(--bad-bd); }
.btn--danger:hover { background: var(--bad-bg); border-color: var(--bad-fg); }
.btn--solid-danger { color: #fff; background: #c62828; border-color: #c62828; }
.btn--solid-danger:hover { background: #a61f1f; border-color: #a61f1f; }
.btn--ok { color: var(--ok-fg); background: var(--ok-bg); border-color: var(--ok-bd); }
.btn--ok:hover { border-color: var(--ok-fg); background: var(--ok-bg); }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover { background: var(--surface-hover); }
.btn--sm { height: 1.9rem; padding: 0 0.65rem; font-size: 0.84rem; }
.btn--icon { width: 2.25rem; padding: 0; }
.btn--sm.btn--icon { width: 1.9rem; }
.btn--block { width: 100%; }
.btn.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-busy::after {
  content: ""; position: absolute; width: 1rem; height: 1rem; border-radius: 50%; border: 2px solid currentColor;
  border-color: var(--on-primary) transparent var(--on-primary) transparent; animation: kc-spin 0.7s linear infinite;
}
.btn:not(.btn--primary).is-busy::after { border-color: var(--text) transparent var(--text) transparent; }
.btn-group { display: inline-flex; }
.btn-group > .btn { border-radius: 0; margin-left: -1px; }
.btn-group > .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group > .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--text); }

.link-btn { border: 0; background: none; padding: 0; color: var(--link); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }

/* ---------- chips */
.chip {
  display: inline-flex; align-items: center; gap: 0.32rem; padding: 0.08rem 0.55rem; border-radius: 999px; border: 1px solid;
  font-size: 0.75rem; font-weight: 620; line-height: 1.55; white-space: nowrap; vertical-align: middle;
}
.chip .icon { width: 0.95em; height: 0.95em; }
.chip--mono { font-family: var(--font-mono); font-weight: 560; }
.chip--plain { color: var(--text-2); background: var(--surface-2); border-color: var(--border); }
.chips { display: flex; gap: 0.35rem; flex-wrap: wrap; align-items: center; }
.count-badge {
  display: inline-grid; place-items: center; min-width: 1.35rem; height: 1.35rem; padding: 0 0.4rem; border-radius: 999px;
  background: var(--primary); color: var(--on-primary); font-size: 0.72rem; font-weight: 700; line-height: 1;
}

/* ---------- cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); min-width: 0; }
.card__head { display: flex; align-items: center; gap: 0.6rem; padding: 0.8rem 1.1rem; border-bottom: 1px solid var(--border); min-height: 3.1rem; }
.card__title { font-size: 0.95rem; font-weight: 650; display: flex; align-items: center; gap: 0.5rem; }
.card__title .icon { color: var(--muted); }
.card__body { padding: 1.1rem; }
.card__body--flush { padding: 0; }
.card__foot { padding: 0.75rem 1.1rem; border-top: 1px solid var(--border); display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.card--link { transition: border-color var(--ease), box-shadow var(--ease), transform var(--ease); color: inherit; display: block; }
.card--link:hover { border-color: var(--primary); box-shadow: var(--shadow); text-decoration: none; transform: translateY(-1px); }

/* ---------- forms */
.field { display: grid; gap: 0.35rem; min-width: 0; }
.field > label, .label { font-size: 0.82rem; font-weight: 620; color: var(--text-2); }
.field .help { font-size: 0.8rem; color: var(--muted); }
.field .error-text { font-size: 0.82rem; color: var(--bad-fg); }
.req { color: var(--bad-fg); }
.input, .select, .textarea {
  width: 100%; min-height: 2.35rem; padding: 0.4rem 0.7rem; border: 1px solid var(--border-strong); background: var(--surface);
  border-radius: var(--radius-sm); color: var(--text); transition: border-color var(--ease), box-shadow var(--ease);
}
.textarea { min-height: 5.5rem; resize: vertical; line-height: 1.5; }
.select { padding-right: 1.9rem; appearance: none; -webkit-appearance: none; background-repeat: no-repeat; background-position: right 0.6rem center; background-size: 0.9rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3bb' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--muted); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--bad-fg); }
.input[readonly], .input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); color: var(--muted); }
.input--sm, .select--sm { min-height: 1.95rem; font-size: 0.86rem; padding-top: 0.2rem; padding-bottom: 0.2rem; }
.input-icon { position: relative; }
.input-icon > .icon { position: absolute; left: 0.7rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon > .input { padding-left: 2.2rem; }
.check { display: flex; gap: 0.55rem; align-items: flex-start; cursor: pointer; font-size: 0.92rem; }
.check input { margin-top: 0.22rem; width: 1rem; height: 1rem; accent-color: var(--primary); flex: none; }
.check small { display: block; color: var(--muted); font-size: 0.8rem; }
.check--box { padding: 0.65rem 0.8rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.check--box:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 0.9rem; align-items: start; }
.char-count { font-size: 0.78rem; color: var(--muted); text-align: right; }
.char-count.is-ok { color: var(--ok-fg); }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; font-size: 0.9rem; }
.table th {
  text-align: left; font-size: 0.74rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
  padding: 0.55rem 0.85rem; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2);
}
.table td { padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.is-clickable { cursor: pointer; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- tabs */
.tabs { display: flex; gap: 0.15rem; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.65rem 0.95rem; border: 0; background: none; color: var(--muted);
  font-weight: 600; font-size: 0.9rem; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; text-decoration: none;
  transition: color var(--ease), border-color var(--ease);
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab[aria-selected="true"], .tab.is-active { color: var(--text); border-bottom-color: var(--primary); }
.seg { display: inline-flex; padding: 0.2rem; background: var(--surface-hover); border-radius: var(--radius); gap: 0.15rem; flex-wrap: wrap; }
.seg__btn { border: 0; background: none; padding: 0.3rem 0.7rem; border-radius: var(--radius-sm); font-size: 0.84rem; font-weight: 600; color: var(--muted); display: inline-flex; gap: 0.4rem; align-items: center; }
.seg__btn:hover { color: var(--text); }
.seg__btn[aria-pressed="true"], .seg__btn[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- banners */
.banner { display: flex; gap: 0.7rem; align-items: flex-start; padding: 0.75rem 0.95rem; border: 1px solid; border-radius: var(--radius); font-size: 0.9rem; }
.banner > .icon { margin-top: 0.15rem; }
.banner__body { min-width: 0; flex: 1; }
.banner__body strong { font-weight: 650; }
.banner__body p + p, .banner__body ul { margin-top: 0.3rem; }
.banner ul { padding-left: 1.2rem; }
.banner--flat { border-radius: 0; border-left: 0; border-right: 0; }

/* ---------- skeleton / empty / error */
.skeleton {
  display: block; border-radius: 6px; height: 1rem;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-hover) 37%, var(--surface-2) 63%); background-size: 300% 100%;
  animation: kc-shimmer 1.5s linear infinite;
}
.skeleton--title { height: 1.6rem; width: 40%; }
.skeleton--block { height: 6rem; border-radius: var(--radius); }
.skeleton--tile { height: 5.5rem; border-radius: var(--radius-lg); }
.empty { display: grid; justify-items: center; gap: 0.55rem; text-align: center; padding: 2.6rem 1.5rem; color: var(--muted); }
.empty__icon { width: 3.2rem; height: 3.2rem; border-radius: 50%; display: grid; place-items: center; background: var(--surface-hover); color: var(--muted); }
.empty__title { color: var(--text); font-weight: 650; font-size: 1rem; }
.empty__text { max-width: 36rem; font-size: 0.9rem; }

/* ---------- progress / bars */
.bar { height: 0.5rem; border-radius: 999px; background: var(--surface-hover); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: inherit; transition: width 300ms ease; }
.bar--ok > span { background: #2fb872; }
.bar--warn > span { background: #e8a31a; }
.bar--bad > span { background: #e5483f; }

/* ---------- menus */
.menu-anchor { position: relative; display: inline-block; }
.menu {
  position: absolute; z-index: 80; min-width: 13rem; max-width: 20rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 0.3rem; animation: kc-rise 120ms ease-out;
}
.menu--right { right: 0; } .menu--up { bottom: calc(100% + 0.35rem); } .menu--down { top: calc(100% + 0.35rem); }
.menu__item {
  display: flex; align-items: center; gap: 0.6rem; width: 100%; padding: 0.5rem 0.65rem; border: 0; background: none; border-radius: var(--radius-sm);
  text-align: left; color: var(--text); font-size: 0.9rem; text-decoration: none;
}
.menu__item:hover, .menu__item:focus-visible { background: var(--surface-hover); text-decoration: none; }
.menu__item.is-danger { color: var(--bad-fg); }
.menu__item[disabled] { opacity: 0.5; pointer-events: none; }
.menu__sep { height: 1px; background: var(--border); margin: 0.3rem 0; }
.menu__label { padding: 0.4rem 0.65rem 0.2rem; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 650; }

/* ---------- dialogs */
dialog.dialog {
  padding: 0; border: 1px solid var(--border-strong); border-radius: var(--radius-lg); background: var(--surface); color: var(--text);
  width: min(34rem, calc(100vw - 1.5rem)); max-height: calc(100dvh - 2rem); box-shadow: var(--shadow-lg); overflow: hidden;
}
dialog.dialog[open] { display: flex; flex-direction: column; animation: kc-rise 160ms ease-out; }
dialog.dialog::backdrop { background: var(--overlay); animation: kc-fade 160ms ease-out; }
.dialog--sm { width: min(26rem, calc(100vw - 1.5rem)); }
.dialog--lg { width: min(52rem, calc(100vw - 1.5rem)); }
.dialog--xl { width: min(72rem, calc(100vw - 1.5rem)); }
.dialog__head { display: flex; align-items: center; gap: 0.6rem; padding: 0.95rem 1.15rem; border-bottom: 1px solid var(--border); }
.dialog__title { font-size: 1.02rem; font-weight: 650; flex: 1; }
.dialog__body { padding: 1.1rem 1.15rem; overflow: auto; display: grid; gap: 0.9rem; align-content: start; }
.dialog__foot { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 0.8rem 1.15rem; border-top: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
dialog.dialog--drawer { margin: 0 0 0 auto; height: 100dvh; max-height: none; width: min(34rem, 100vw); border-radius: var(--radius-lg) 0 0 var(--radius-lg); border-right: 0; }
dialog.dialog--drawer[open] { animation: kc-slide-in 200ms cubic-bezier(0.2, 0, 0, 1); }
dialog.dialog--palette { margin-top: 8vh; width: min(40rem, calc(100vw - 1.5rem)); max-height: 78dvh; }
@keyframes kc-slide-in { from { transform: translateX(2rem); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- toasts */
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 3000; display: flex; flex-direction: column; gap: 0.5rem; max-width: min(26rem, calc(100vw - 2rem)); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; gap: 0.65rem; align-items: flex-start; padding: 0.7rem 0.85rem; background: var(--surface);
  border: 1px solid var(--border-strong); border-left: 4px solid var(--info-fg); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  animation: kc-rise 180ms ease-out; font-size: 0.9rem;
}
.toast--ok { border-left-color: var(--ok-fg); } .toast--bad { border-left-color: var(--bad-fg); } .toast--warn { border-left-color: var(--warn-fg); }
.toast .icon { margin-top: 0.15rem; }
.toast--ok .icon { color: var(--ok-fg); } .toast--bad .icon { color: var(--bad-fg); } .toast--warn .icon { color: var(--warn-fg); } .toast--info .icon { color: var(--info-fg); }
.toast__body { flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* ---------- key/value + definition lists */
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.4rem 1.1rem; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- code / pre blocks used outside documents */
.code {
  font-family: var(--font-mono); font-size: 0.82rem; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.6rem 0.75rem; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0;
}

/* ---------- editor token colours (classes assigned by the CodeMirror highlight style) */
.tok-h1 { color: var(--tok-h); font-weight: 700; font-size: 1.12em; }
.tok-h2 { color: var(--tok-h); font-weight: 700; font-size: 1.06em; }
.tok-h3 { color: var(--tok-h); font-weight: 650; }
.tok-strong { font-weight: 700; }
.tok-em { font-style: italic; }
.tok-strike { text-decoration: line-through; }
.tok-link { color: var(--tok-link); }
.tok-mono { color: var(--tok-str); background: var(--tok-mono-bg); border-radius: 3px; }
.tok-quote { color: var(--tok-quote); font-style: italic; }
.tok-meta { color: var(--tok-meta); }
.tok-kw { color: var(--tok-kw); }
.tok-str { color: var(--tok-str); }
.tok-num { color: var(--tok-num); }
.tok-comment { color: var(--tok-comment); font-style: italic; }
.tok-type { color: var(--tok-type); }
.tok-fn { color: var(--tok-fn); }
.tok-prop { color: var(--tok-prop); }
.tok-tag { color: var(--tok-tag); }
.tok-punct { color: var(--tok-meta); }
.tok-invalid { color: var(--bad-fg); text-decoration: underline wavy; }
