/* =====================================================================
   Components — every module composes these; modules add NO visual rules of their own.
   Index: buttons · forms · combobox · alerts · panels/cards · KPIs · tables · toolbar/pagination ·
          tabs · badges · menus/popovers · tooltip · dialogs · toasts · skeleton · empty/state ·
          charts · page header/breadcrumbs
   ===================================================================== */

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: var(--control-h);
  padding: 0 var(--space-4); font-weight: var(--weight-semibold); font-size: var(--text-base); line-height: 1; white-space: nowrap;
  border-radius: var(--radius-sm); border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: background var(--ease), border-color var(--ease), color var(--ease), box-shadow var(--ease); }
.btn:hover { text-decoration: none; }
.btn svg { flex: none; }
.btn-primary { background: var(--primary); color: var(--text-on-brand); }
.btn-primary:hover { background: var(--primary-hover); color: var(--text-on-brand); }
.btn-accent { background: var(--accent-600); color: var(--white); }
.btn-accent:hover { background: var(--accent-700); color: var(--white); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-muted); border-color: var(--text-subtle); color: var(--text); }
.btn-danger { background: var(--surface); color: var(--bad); border-color: var(--bad-border); }
.btn-danger:hover { background: var(--bad-bg); color: var(--bad); }
.btn-danger-solid { background: var(--bad); color: var(--white); }
.btn-danger-solid:hover { background: var(--bad-strong); color: var(--white); }
.btn-sm { min-height: var(--control-h-sm); padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after { content: ""; position: absolute; width: 1em; height: 1em; border: 2px solid var(--white); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn-ghost.is-loading::after { border-color: var(--text-muted); border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn { display: inline-grid; place-items: center; width: var(--control-h); height: var(--control-h); padding: 0; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--text-muted); cursor: pointer; position: relative; transition: background var(--ease), color var(--ease); }
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn.sm { width: var(--control-h-sm); height: var(--control-h-sm); }
.icon-btn[aria-expanded="true"] { background: var(--surface-hover); color: var(--text); }
.icon-btn .dot-badge { position: absolute; top: 2px; right: 2px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: var(--radius-full);
  background: var(--bad); color: var(--white); font-size: 10px; font-weight: var(--weight-bold); display: grid; place-items: center; line-height: 1; }

/* ---------- Forms ---------- */
.field { display: grid; gap: var(--space-1); margin-bottom: var(--space-4); align-content: start; }
.field > label, .field-label { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--text); }
label.req::after { content: " *"; color: var(--bad); font-weight: var(--weight-bold); }   /* required marker, added automatically by SO.ui.markRequired */
.req-star { color: var(--bad); font-weight: var(--weight-bold); }
.input, select.input, textarea.input { width: 100%; min-height: var(--control-h); padding: .5rem .75rem; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text); transition: border-color var(--ease), box-shadow var(--ease); }
textarea.input { min-height: 5rem; resize: vertical; }
select.input { appearance: none; padding-right: 2.25rem; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .75rem center; }
.input::placeholder { color: var(--text-subtle); }
.input:hover:not(:disabled) { border-color: var(--text-subtle); }
.input:focus { border-color: var(--focus); outline: none; box-shadow: var(--ring); }
.input:disabled { background: var(--surface-hover); color: var(--text-subtle); cursor: not-allowed; }
.input[aria-invalid="true"] { border-color: var(--bad); }
.input[aria-invalid="true"]:focus { box-shadow: var(--ring-bad); }
input[type="date"].input { min-width: 0; }
.input-static { display: block; min-height: var(--control-h); padding: .5rem .75rem; border-radius: var(--radius-sm); background: var(--surface-hover);
  font-family: var(--mono); font-size: var(--text-sm); word-break: break-all; }
.hint { font-size: var(--text-xs); color: var(--text-subtle); }
.hint.ok { color: var(--ok); } .hint.bad { color: var(--bad); }
.field-error { font-size: var(--text-xs); color: var(--bad); font-weight: var(--weight-medium); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--space-4); }
.form-grid .full { grid-column: 1 / -1; }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-addon { display: grid; place-items: center; padding: 0 var(--space-3); background: var(--surface-hover); border: 1px solid var(--border-strong); border-left: 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--text-muted); font-size: var(--text-sm); white-space: nowrap; }
.input-icon { position: relative; }
.input-icon > svg { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--text-subtle); pointer-events: none; }
.input-icon > .input { padding-left: 2.25rem; }
.pw-rules { list-style: none; margin: var(--space-2) 0 0; padding: 0; font-size: var(--text-xs); color: var(--text-subtle); display: grid; gap: 2px; }
.pw-rules li.ok { color: var(--ok); } .pw-rules li.bad { color: var(--bad); }

/* ---------- Searchable dropdown (combobox) ---------- */
.combo { position: relative; }
.combo-list { position: absolute; z-index: var(--z-popover); left: 0; right: 0; top: calc(100% + 4px); max-height: 15rem; overflow: auto; margin: 0; padding: var(--space-1);
  list-style: none; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow-md); }
.combo-option { padding: .5rem .65rem; border-radius: 4px; cursor: pointer; font-size: var(--text-sm); }
.combo-option[aria-selected="true"] { background: var(--blue-100); }
.combo-option.is-chosen { font-weight: var(--weight-semibold); }
.combo-empty { padding: .6rem .65rem; color: var(--text-subtle); font-size: var(--text-sm); }

/* ---------- Alerts ---------- */
.alert { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); border: 1px solid transparent; font-size: var(--text-sm); margin-bottom: var(--space-4); }
.alert > svg { flex: none; margin-top: 2px; }
.alert-bad  { background: var(--bad-bg);  color: var(--bad);  border-color: var(--bad-border); }
.alert-ok   { background: var(--ok-bg);   color: var(--ok);   border-color: var(--ok-border); }
.alert-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }
.alert-info { background: var(--info-bg); color: var(--info); border-color: var(--info-border); }

/* ---------- Panels & cards ---------- */
.panel, .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); min-width: 0; }
.panel { padding: var(--space-5); }
.card { padding: var(--space-5); }
.panel.flush { padding: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); flex-wrap: wrap; }
.panel.flush > .panel-head { padding: var(--space-4) var(--space-5) 0; margin-bottom: var(--space-3); }
.panel-head h2, .panel-head h3 { margin: 0; font-size: var(--text-lg); }
.panel-head .sub { font-size: var(--text-sm); color: var(--text-subtle); margin: 2px 0 0; }

/* ---------- KPI / summary metrics ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4) var(--space-5); box-shadow: var(--shadow-sm); min-width: 0; }
.kpi-card .label { font-size: var(--text-xs); color: var(--text-muted); font-weight: var(--weight-semibold); text-transform: uppercase; letter-spacing: .05em; }
.kpi-card .value { font-size: 1.65rem; font-weight: 800; letter-spacing: -.02em; margin-top: var(--space-1); overflow-wrap: anywhere; }
.kpi-card .sub { font-size: var(--text-xs); color: var(--text-subtle); }
.kpi-card.tone-ok .value { color: var(--ok); } .kpi-card.tone-bad .value { color: var(--bad); } .kpi-card.tone-warn .value { color: var(--warn); }
.actions-row { display: flex; flex-wrap: wrap; gap: var(--space-3); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th { text-align: left; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: var(--weight-semibold);
  padding: var(--space-2) var(--space-3); background: var(--surface-muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: var(--space-3); border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.table td.wrap { white-space: normal; min-width: 12rem; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-muted); }
.table td.r, .table th.r { text-align: right; }
.table th .sort { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.table th .sort:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
.table th[aria-sort] .sort::after { content: ""; border: 4px solid transparent; }
.table th[aria-sort="ascending"] .sort::after { border-bottom-color: currentColor; border-top: 0; }
.table th[aria-sort="descending"] .sort::after { border-top-color: currentColor; border-bottom: 0; }
.table td.actions { text-align: right; width: 1%; white-space: nowrap; }

/* ---------- Table toolbar / filters / pagination ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; padding: 0 var(--space-5) var(--space-3); }
.toolbar .input-icon { flex: 1 1 14rem; max-width: 22rem; }
.toolbar select.input { width: auto; min-width: 9rem; }
.toolbar .count { margin-left: auto; font-size: var(--text-sm); color: var(--text-subtle); }
.pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-5); border-top: 1px solid var(--border); font-size: var(--text-sm); color: var(--text-muted); }
.pagination .pages { display: flex; align-items: center; gap: var(--space-2); }
.pagination select.input { width: auto; min-height: var(--control-h-sm); padding-top: 0; padding-bottom: 0; }

/* ---------- Tabs ---------- */
.tabs-list { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); overflow-x: auto; margin-bottom: var(--space-4); }
.tab { appearance: none; background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: var(--space-3) var(--space-4); cursor: pointer;
  font-weight: var(--weight-semibold); font-size: var(--text-sm); color: var(--text-muted); white-space: nowrap; display: inline-flex; align-items: center; gap: var(--space-2); }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.tab .tab-count { background: var(--surface-hover); color: var(--text-muted); border-radius: var(--radius-full); font-size: var(--text-xs); padding: 0 .5rem; }
.tab[aria-selected="true"] .tab-count { background: var(--blue-100); color: var(--primary); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: .15rem .6rem; border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: var(--weight-bold); line-height: 1.4; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--slate-200); color: var(--slate-700); }
.badge.plain::before { display: none; }

/* ---------- Menus & popovers ---------- */
.popover { position: fixed; z-index: var(--z-popover); min-width: 12rem; max-width: min(24rem, calc(100vw - 1rem)); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: var(--space-1); }
.menu-item { display: flex; align-items: center; gap: var(--space-3); width: 100%; padding: .5rem .7rem; border: 0; background: none; border-radius: var(--radius-sm);
  font-size: var(--text-sm); text-align: left; color: var(--text); cursor: pointer; text-decoration: none; }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-hover); outline: none; text-decoration: none; color: var(--text); }
.menu-item.danger { color: var(--bad); } .menu-item.danger:hover, .menu-item.danger:focus-visible { background: var(--bad-bg); color: var(--bad); }
.menu-item[disabled] { opacity: .5; cursor: not-allowed; }
.menu-item svg { flex: none; color: var(--text-subtle); } .menu-item.danger svg { color: currentColor; }
.menu-sep { height: 1px; background: var(--border); margin: var(--space-1) 0; border: 0; }
.menu-head { padding: .5rem .7rem; font-size: var(--text-sm); }
.menu-head b { display: block; } .menu-head span { color: var(--text-subtle); font-size: var(--text-xs); }
.notice-list { max-height: 22rem; overflow: auto; }
.notice { display: flex; gap: var(--space-3); padding: var(--space-3); border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-size: var(--text-sm); }
a.notice:hover { background: var(--surface-hover); text-decoration: none; color: var(--text); }
.notice .ico { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; }
.notice .ico.warn { background: var(--warn-bg); color: var(--warn); } .notice .ico.bad { background: var(--bad-bg); color: var(--bad); } .notice .ico.info { background: var(--info-bg); color: var(--info); }
.notice b { display: block; } .notice span { color: var(--text-subtle); font-size: var(--text-xs); }

/* ---------- Tooltip ---------- */
.tooltip { position: fixed; z-index: var(--z-tooltip); background: var(--slate-900); color: var(--white); font-size: var(--text-xs); padding: .3rem .55rem; border-radius: 4px; pointer-events: none; max-width: 18rem; }

/* ---------- Dialogs ---------- */
dialog.dialog { border: 0; border-radius: var(--radius-lg); padding: 0; width: min(560px, calc(100% - 2rem)); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
dialog.dialog.sm { width: min(440px, calc(100% - 2rem)); }
dialog.dialog::backdrop { background: var(--overlay); }
.dialog-head { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); }
.dialog-head h2 { margin: 0; font-size: var(--text-lg); }
.dialog-body { padding: var(--space-5); max-height: 70vh; overflow: auto; }
.dialog-body > p:last-child { margin-bottom: 0; }
.dialog-foot { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--space-3); background: var(--surface-muted); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.dialog-icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; margin-bottom: var(--space-3); background: var(--blue-100); color: var(--primary); }
.dialog-icon.danger { background: var(--bad-bg); color: var(--bad); }

/* ---------- Toasts ---------- */
.toast-region { position: fixed; inset: auto var(--space-4) var(--space-4) auto; z-index: var(--z-toast); display: grid; gap: var(--space-2); width: min(380px, calc(100vw - 2rem));
  margin: 0; padding: 0; border: 0; background: transparent; overflow: visible; }
.toast { display: flex; gap: var(--space-3); align-items: flex-start; background: var(--toast-bg); color: var(--white); padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); font-size: var(--text-sm); border-left: 4px solid var(--info-border); }
.toast.success { border-left-color: var(--toast-ok-line); } .toast.error { border-left-color: var(--toast-bad-line); background: var(--toast-bad-bg); }
.toast .msg { flex: 1; } .toast button { all: unset; cursor: pointer; opacity: .7; line-height: 1; } .toast button:hover { opacity: 1; }

/* ---------- Loading skeletons ---------- */
.skeleton { background: linear-gradient(90deg, var(--slate-200), var(--slate-100), var(--slate-200)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--radius-sm); min-height: 1em; }
.skeleton.line { height: .9rem; } .skeleton.block { height: 14rem; } .skeleton.kpi { height: 5.5rem; border-radius: var(--radius); }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- Empty / error / permission states ---------- */
.state { display: grid; justify-items: center; text-align: center; gap: var(--space-2); padding: var(--space-8) var(--space-5); color: var(--text-muted); }
.state .state-icon { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-hover); color: var(--text-subtle); margin-bottom: var(--space-1); }
.state.bad .state-icon { background: var(--bad-bg); color: var(--bad); } .state.lock .state-icon { background: var(--warn-bg); color: var(--warn); }
.state h3 { margin: 0; font-size: var(--text-lg); color: var(--text); }
.state p { margin: 0; max-width: 34rem; font-size: var(--text-sm); }
.state .btn { margin-top: var(--space-3); }

/* ---------- Charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart-grid { stroke: var(--chart-grid); } .chart-axis-label { fill: var(--chart-axis); font-size: 10px; }
.chart-s1 { fill: var(--chart-1); } .chart-s2 { fill: var(--chart-2); } .chart-s3 { fill: var(--chart-3); } .chart-s4 { fill: var(--chart-4); }
.chart-bar:hover { opacity: .8; }
.legend { display: flex; flex-wrap: wrap; gap: var(--space-4); font-size: var(--text-xs); color: var(--text-muted); }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }
.dot.chart-s1 { background: var(--chart-1); } .dot.chart-s2 { background: var(--chart-2); } .dot.chart-s3 { background: var(--chart-3); } .dot.chart-s4 { background: var(--chart-4); }
.bar-list { display: grid; gap: var(--space-3); }
.bar-item .top { display: flex; justify-content: space-between; font-size: var(--text-sm); margin-bottom: 4px; gap: var(--space-3); }
.bar-track { height: 8px; background: var(--chart-track); border-radius: var(--radius-full); overflow: hidden; }
.bar-fill { height: 100%; background: var(--chart-1); border-radius: var(--radius-full); }

/* ---------- Brand lockup (logo + name) ---------- */
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.15rem; letter-spacing: -.02em; color: var(--brand-900); min-width: 0; }
.brand:hover { text-decoration: none; color: var(--brand-900); }
.brand-mark { flex: none; width: 30px; height: 30px; border-radius: 8px; background: var(--brand-900); color: var(--white); display: grid; place-items: center; }
.brand.inverse, .brand.inverse:hover { color: var(--white); }
.brand-mark.inverse, .brand.inverse .brand-mark { background: var(--white); color: var(--brand-900); }

/* ---------- Page header & breadcrumbs ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-4); }
.page-header h1 { font-size: var(--text-2xl); margin: 0; }
.page-header p { margin: var(--space-1) 0 0; color: var(--text-muted); font-size: var(--text-sm); max-width: 46rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.breadcrumbs { min-width: 0; }
.breadcrumbs ol { display: flex; align-items: center; gap: var(--space-2); list-style: none; margin: 0; padding: 0; font-size: var(--text-sm); color: var(--text-subtle); white-space: nowrap; }
.breadcrumbs li + li::before { content: "/"; margin-right: var(--space-2); color: var(--slate-300); }
.breadcrumbs li[aria-current="page"] { color: var(--text); font-weight: var(--weight-semibold); overflow: hidden; text-overflow: ellipsis; }
.hint-block { font-size: var(--text-sm); color: var(--text-subtle); }

@media (max-width: 980px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .kpis, .form-grid { grid-template-columns: 1fr; } .toolbar .input-icon { max-width: none; } .pagination { justify-content: center; } }
