/* Core component library. Every interactive component defines default / hover / focus / active / disabled / loading / error states. */

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--card-pad); box-shadow: var(--shadow); }
.card > h2:first-child, .card > h3:first-child { margin-bottom: var(--sp-3); }
.card--flush { padding: 0; overflow: hidden; }
.card__head { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-3); } .card__head h2, .card__head h3 { margin: 0; }
.section-title { font-size: var(--fs-h2); margin: var(--sp-5) 0 var(--sp-3); }
.icon { flex: none; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); font: inherit; font-weight: 550; padding: .4rem .85rem; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; min-height: 2.25rem; line-height: 1.2; box-shadow: 0 1px 0 rgba(26, 26, 26, .06); transition: background var(--dur), border-color var(--dur), box-shadow var(--dur); white-space: nowrap; }
.btn:hover:not(:disabled):not(.is-disabled) { background: var(--surface-3); }
.btn:active:not(:disabled) { background: var(--border); box-shadow: inset 0 1px 2px rgba(26, 26, 26, .15); }
.btn:disabled, .btn.is-disabled { opacity: .5; cursor: not-allowed; pointer-events: none; box-shadow: none; }
.btn--primary { background: var(--brand); border-color: var(--brand-hover); color: var(--brand-contrast); }
.btn--primary:hover:not(:disabled):not(.is-disabled) { background: var(--brand-hover); } .btn--primary:active:not(:disabled) { background: var(--brand-hover); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; } .btn--danger:hover:not(:disabled) { background: var(--danger); filter: brightness(.9); }
.btn--danger-ghost { color: var(--danger); } .btn--danger-ghost:hover:not(:disabled) { background: var(--danger-bg); }
.btn--ghost { border-color: transparent; background: transparent; box-shadow: none; } .btn--ghost:hover:not(:disabled) { background: var(--hover); }
.btn--sm { padding: .2rem .6rem; min-height: 1.75rem; font-size: var(--fs-sm); }
.btn--block { width: 100%; margin-top: var(--sp-2); }
.btn.is-loading { position: relative; color: transparent; pointer-events: none; } .btn.is-loading > * { visibility: hidden; }
.btn.is-loading::after { content: ""; position: absolute; width: 1rem; height: 1rem; border: 2px solid var(--muted); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn--primary.is-loading::after { border-color: #fff; border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { background: none; border: 0; color: var(--link); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }
.icon-btn { display: inline-grid; place-items: center; width: 2.25rem; height: 2.25rem; background: transparent; border: 0; border-radius: var(--radius-sm); cursor: pointer; color: inherit; font-size: 1.25rem; position: relative; }
.icon-btn:hover { background: var(--hover); } .icon-btn:active { background: var(--border); }
.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; }
.seg .btn.is-on { background: var(--brand); color: var(--brand-contrast); border-color: var(--brand); }
.btn.is-on { background: var(--selected); border-color: var(--brand); color: var(--brand); }

/* ---------- form controls ---------- */
.input { width: 100%; font: inherit; padding: .45rem .65rem; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); min-height: 2.25rem; transition: border-color var(--dur), box-shadow var(--dur); }
.input::placeholder { color: var(--subtle); }
.input:hover:not(:disabled) { border-color: var(--muted); }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft), 0 0 0 1px var(--brand); }
.input:disabled { background: var(--surface-3); color: var(--muted); cursor: not-allowed; }
.input[aria-invalid="true"] { border-color: var(--danger); background: var(--danger-bg); } .input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--danger-bg), 0 0 0 1px var(--danger); }
.input.is-valid { border-color: var(--success); }
.input--sm { min-height: 2rem; padding: .25rem .5rem; width: auto; max-width: 16rem; }
textarea.input { resize: vertical; font-family: inherit; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 1rem) 55%, calc(100% - .7rem) 55%; background-size: .3rem .3rem; background-repeat: no-repeat; padding-right: 1.75rem; }
select[multiple].input { background-image: none; padding-right: .65rem; }
input[type=color].input { padding: 2px; height: 2.25rem; }
input[type=checkbox], input[type=radio] { accent-color: var(--brand); width: 1rem; height: 1rem; margin: 0; vertical-align: middle; }
.field { margin-bottom: var(--sp-4); } .field__label { display: block; font-weight: 600; margin-bottom: var(--sp-1); font-size: var(--fs-sm); }
.field__help { color: var(--muted); font-size: var(--fs-sm); margin: var(--sp-1) 0 0; } .field__error { color: var(--danger); font-size: var(--fs-sm); margin: var(--sp-1) 0 0; }
.field--check label { display: flex; gap: var(--sp-2); align-items: center; cursor: pointer; } .req { color: var(--danger); }
.field--inline { display: grid; gap: .15rem; min-width: 8rem; } .field--inline .field__label { font-size: var(--fs-sm); color: var(--muted); margin: 0; }
fieldset.field { border: 0; padding: 0; margin-left: 0; margin-right: 0; min-width: 0; } legend.field__label { padding: 0; }
.checkgroup { display: grid; gap: var(--sp-1); } .checkgroup__item { display: flex; gap: var(--sp-2); align-items: center; }
.form-section { grid-column: 1 / -1; margin: var(--sp-4) 0 var(--sp-2); padding-top: var(--sp-3); border-top: 1px solid var(--border); font-size: var(--fs-lg); }
.formgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); column-gap: var(--sp-4); }
.formgrid .form-section:first-child { margin-top: 0; border-top: 0; padding-top: 0; }
.actionlist { display: grid; gap: var(--sp-2); } .actionlist .btn--block { margin-top: 0; justify-content: flex-start; }
.form-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); padding-top: var(--sp-3); border-top: 1px solid var(--border); margin-top: var(--sp-4); }
.unsaved { display: none; } .is-dirty .unsaved { display: inline; color: var(--warning-text); font-size: var(--fs-sm); }
/* toggle switch: <label class="toggle"><input type="checkbox"><span class="toggle__track"></span>Text</label> */
.toggle { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle__track { width: 2.25rem; height: 1.25rem; border-radius: var(--radius-pill); background: var(--border-strong); position: relative; transition: background var(--dur); flex: none; }
.toggle__track::after { content: ""; position: absolute; left: 2px; top: 2px; width: 1rem; height: 1rem; border-radius: 50%; background: #fff; transition: transform var(--dur) var(--ease); box-shadow: 0 1px 2px rgba(0, 0, 0, .3); }
.toggle input:checked + .toggle__track { background: var(--brand); } .toggle input:checked + .toggle__track::after { transform: translateX(1rem); }
.toggle input:focus-visible + .toggle__track { outline: 2px solid var(--focus); outline-offset: 2px; } .toggle input:disabled + .toggle__track { opacity: .5; }

/* ---------- filter bar, chips, bulk bar ---------- */
.filterbar { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-3); flex-wrap: wrap; align-items: center; } .filterbar .input { max-width: 18rem; }
.filterbar--card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-3); box-shadow: var(--shadow); }
.chip { display: inline-flex; align-items: center; padding: 0 .55rem; margin: 0 .2rem .2rem 0; border-radius: var(--radius-pill); font-size: var(--fs-sm); background: var(--neutral-bg); border: 1px solid var(--border); line-height: 1.5; }
.chip__dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .3rem; background: var(--dot, var(--subtle)); }
.bulkbar { display: flex; gap: var(--sp-2); align-items: center; padding: var(--sp-2) var(--sp-3); background: var(--selected); border: 1px solid var(--brand); border-radius: var(--radius); margin-bottom: var(--sp-3); flex-wrap: wrap; }

/* ---------- tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); max-height: 75vh; }
.table-wrap.is-loading { opacity: .6; transition: opacity var(--dur); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table caption { text-align: left; }
.table th, .table td { padding: .6rem var(--sp-4); text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th.is-right, .table td.is-right { text-align: right; }
.table th { position: sticky; top: 0; z-index: 1; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table tbody tr { transition: background var(--dur); } .table tbody tr:hover { background: var(--hover); } .table tbody tr:last-child td { border-bottom: 0; }
.table tr.is-selected { background: var(--selected); }
.table input[type=checkbox] { width: 1rem; height: 1rem; }
.th-sort { all: unset; cursor: pointer; font-weight: 600; text-transform: inherit; } .th-sort:hover { color: var(--text); } .th-sort:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.rowactions { display: inline-flex; gap: var(--sp-1); flex-wrap: wrap; justify-content: flex-end; }
.pagination { display: flex; gap: var(--sp-3); align-items: center; justify-content: flex-end; padding: var(--sp-2) var(--sp-4); border-top: 1px solid var(--border); background: var(--surface); } .pagination__info { margin-right: auto; color: var(--muted); font-size: var(--fs-sm); }
@media (max-width: 52rem) { .table th, .table td { padding: .5rem var(--sp-3); } .pagination { flex-wrap: wrap; } }

/* ---------- states: empty, error, skeleton ---------- */
.state { padding: var(--sp-7) var(--sp-5); text-align: center; color: var(--muted); } .state--error { color: var(--danger); } .state p { margin: var(--sp-1) 0 var(--sp-3); }
.state h3 { color: var(--text); margin-bottom: var(--sp-1); } .state .icon { margin: 0 auto var(--sp-3); display: block; color: var(--subtle); }
.skeleton { display: block; border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--surface-3) 25%, var(--border) 50%, var(--surface-3) 75%); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; min-height: 1rem; }
.skeleton--line { height: .875rem; margin: var(--sp-2) 0; } .skeleton--block { height: 6rem; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- badges, status, alerts ---------- */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .05rem .55rem; border-radius: var(--radius-pill); font-size: var(--fs-xs); font-weight: 600; line-height: 1.5; white-space: nowrap; }
.badge::before { content: ""; width: .4rem; height: .4rem; border-radius: 50%; background: currentColor; }
.badge--success { color: var(--success); background: var(--success-bg); } .badge--warning { color: var(--warning-text); background: var(--warning-bg); }
.badge--danger { color: var(--danger); background: var(--danger-bg); } .badge--info { color: var(--info); background: var(--info-bg); } .badge--neutral { color: var(--neutral); background: var(--neutral-bg); }
.livedot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; background: var(--subtle); margin-right: .35rem; }
.livedot.is-live { background: var(--success); box-shadow: 0 0 0 3px var(--success-bg); } .livedot.is-lost { background: var(--danger); }
.alert { padding: var(--sp-3) var(--sp-4); border-radius: var(--radius); margin-bottom: var(--sp-4); border: 1px solid; border-left-width: 4px; }
.alert--danger { background: var(--danger-bg); border-color: var(--danger); } .alert--success { background: var(--success-bg); border-color: var(--success); }
.alert--warning { background: var(--warning-bg); border-color: var(--warning); } .alert--info { background: var(--info-bg); border-color: var(--info); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--sp-2) var(--sp-5); margin: 0; } .kv dt { color: var(--muted); } .kv dd { margin: 0; }

/* ---------- tabs, stepper, progress ---------- */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); margin: var(--sp-4) 0; flex-wrap: wrap; }
.tabs button, .tabs a { background: none; border: 0; border-bottom: 2px solid transparent; padding: var(--sp-2) var(--sp-3); cursor: pointer; color: var(--muted); font: inherit; text-decoration: none; margin-bottom: -1px; }
.tabs button:hover, .tabs a:hover { color: var(--text); background: var(--hover); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.tabs button.is-on, .tabs a.is-on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.stepper { display: flex; list-style: none; padding: 0; margin: 0 0 var(--sp-5); gap: var(--sp-1); flex-wrap: wrap; counter-reset: s; }
.stepper__item { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-1) var(--sp-3) var(--sp-1) var(--sp-1); border-radius: var(--radius-pill); font-size: var(--fs-sm); color: var(--muted); }
.stepper__num { display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; border: 2px solid var(--border-strong); font-weight: 700; font-size: var(--fs-xs); }
.stepper__item.is-current { color: var(--text); font-weight: 600; background: var(--selected); } .stepper__item.is-current .stepper__num { border-color: var(--brand); background: var(--brand); color: var(--brand-contrast); }
.stepper__item.is-done .stepper__num { border-color: var(--success); background: var(--success); color: #fff; } .stepper__item.is-done { color: var(--text); }
@media (max-width: 52rem) { .stepper__label { display: none; } .stepper__item.is-current .stepper__label { display: inline; } }
.progress { height: .5rem; background: var(--neutral-bg); border-radius: var(--radius-pill); overflow: hidden; } .progress__bar { height: 100%; width: var(--pct, 0%); background: var(--brand); transition: width .3s var(--ease); }
.wizard-nav { display: flex; justify-content: space-between; gap: var(--sp-3); margin-top: var(--sp-5); padding-top: var(--sp-4); border-top: 1px solid var(--border); }

/* ---------- metrics ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr)); gap: var(--sp-3); margin: var(--sp-4) 0; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-3) var(--sp-4); } .stat strong { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; } .stat span { color: var(--muted); font-size: var(--fs-sm); }
.stat--bad strong { color: var(--danger); } .stat--good strong { color: var(--success); } .stat--warn strong { color: var(--warning-text); }
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 var(--sp-4) var(--sp-5); } .timeline li::before { content: ""; position: absolute; left: .3rem; top: .35rem; width: .55rem; height: .55rem; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.timeline li::after { content: ""; position: absolute; left: .55rem; top: 1.1rem; bottom: 0; width: 1px; background: var(--border); } .timeline li:last-child::after { display: none; }
.timeline time { display: block; color: var(--muted); font-size: var(--fs-xs); }

/* ---------- dropdown, menu, tooltip ---------- */
.dropdown { position: relative; }
.usermenu { display: flex; align-items: center; gap: var(--sp-2); background: none; border: 0; cursor: pointer; font: inherit; padding: var(--sp-1) var(--sp-2); border-radius: var(--radius-sm); }
.avatar { display: inline-grid; place-items: center; width: 1.75rem; height: 1.75rem; border-radius: 50%; background: var(--brand); color: var(--brand-contrast); font-weight: 700; font-size: var(--fs-sm); }
.dropdown__menu { position: absolute; right: 0; top: calc(100% + .25rem); min-width: 14rem; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: var(--sp-1); z-index: var(--z-drop); animation: pop .12s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }
.dropdown__menu[hidden] { display: none; }
.dropdown__head { padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); display: grid; margin: calc(var(--sp-1) * -1) calc(var(--sp-1) * -1) var(--sp-1); } .dropdown__head small { color: var(--muted); }
.dropdown__menu a, .dropdown__menu button { display: flex; width: 100%; gap: var(--sp-2); align-items: center; padding: var(--sp-2) var(--sp-3); color: inherit; text-decoration: none; background: none; border: 0; border-radius: var(--radius-sm); font: inherit; cursor: pointer; text-align: left; }
.dropdown__menu a:hover, .dropdown__menu button:hover { background: var(--hover); }
.dropdown__menu .is-danger { color: var(--danger); }
.dropdown__sep { height: 1px; background: var(--border); margin: var(--sp-1) 0; }
.bell__count { position: absolute; top: 2px; right: 2px; min-width: 1rem; height: 1rem; padding: 0 .25rem; border-radius: var(--radius-pill); background: var(--danger); color: #fff; font-size: .6875rem; font-weight: 700; line-height: 1rem; text-align: center; }
[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after { content: attr(data-tip); position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); background: var(--gray-900); color: #fff; font-size: var(--fs-xs); padding: .25rem .5rem; border-radius: var(--radius-sm); white-space: nowrap; z-index: var(--z-overlay); pointer-events: none; box-shadow: var(--shadow-md); }

/* ---------- modal, drawer, toast ---------- */
.modal-overlay { position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; z-index: var(--z-overlay); padding: var(--sp-4); animation: fade .12s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); color: var(--text); border-radius: var(--radius-lg); width: min(32rem, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: pop .15s var(--ease); }
.modal--lg { width: min(54rem, 100%); } .modal--sm { width: min(24rem, 100%); }
.modal__head { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); } .modal__head h2 { margin: 0; }
.modal__body { padding: var(--sp-5); overflow-y: auto; }
.modal__foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.modal--danger .modal__head h2 { color: var(--danger); }
.drawer-overlay { position: fixed; inset: 0; background: var(--overlay); z-index: var(--z-overlay); display: flex; justify-content: flex-end; animation: fade .12s; }
.drawer { width: min(30rem, 100%); background: var(--surface); height: 100%; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: slide .2s var(--ease); }
@keyframes slide { from { transform: translateX(2rem); opacity: 0; } }
.drawer__head { display: flex; justify-content: space-between; align-items: center; padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); } .drawer__head h2 { margin: 0; }
.drawer__body { padding: var(--sp-5); overflow-y: auto; flex: 1; } .drawer__foot { padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--sp-2); }
.toasts { position: fixed; right: var(--sp-4); bottom: var(--sp-4); display: grid; gap: var(--sp-2); z-index: var(--z-toast); max-width: min(26rem, calc(100vw - 2rem)); }
.toast { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--radius); background: var(--gray-900); color: #fff; box-shadow: var(--shadow-lg); border-left: 4px solid var(--info); animation: pop .2s var(--ease); }
.toast--success { border-color: var(--green-500); } .toast--danger { border-color: var(--danger); } .toast__close { background: none; border: 0; cursor: pointer; color: inherit; font-size: 1.1rem; opacity: .7; } .toast__close:hover { opacity: 1; }

/* ---------- lists ---------- */
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain > li { padding: var(--sp-2) 0; border-bottom: 1px solid var(--border); } ul.plain > li:last-child { border-bottom: 0; }
.dropdown__menu .notiflist { list-style: none; margin: 0; padding: 0; max-height: 18rem; overflow-y: auto; }
.table a { font-weight: 600; text-decoration: none; } .table a:hover { text-decoration: underline; }
