/* Shared components (replace shadcn/ui): buttons, menus, badges, alerts, cards, forms, tables, pager, dialogs, tabs,
   notifications, loading/empty states. */

/* ---------- buttons ---------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.375rem;
  min-height: 2.5rem; padding: 0 0.875rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--bg-surface); color: var(--text-primary);
  font-size: var(--text-small); font-weight: 500; line-height: 1.2; text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.button:hover { background: var(--bg-muted); text-decoration: none; }
.button:disabled, .button[aria-disabled="true"] { opacity: 0.6; cursor: not-allowed; }
.button-primary { background: var(--brand-primary); border-color: var(--brand-primary); color: #fff; }
.button-primary:hover { background: color-mix(in srgb, var(--brand-primary), white 12%); }
.button-danger { background: var(--state-error); border-color: var(--state-error); color: #fff; }
.button-danger:hover { background: color-mix(in srgb, var(--state-error), black 10%); }
.button-small { min-height: 2rem; padding: 0 0.625rem; font-size: var(--text-label); }
.button.is-current { background: var(--brand-primary); border-color: var(--brand-primary); color: #fff; }
.icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.5rem; height: 2.5rem; padding: 0;
  border: 0; border-radius: var(--radius-md); background: transparent; color: inherit; cursor: pointer;
}
.icon-button:hover { background: var(--bg-muted); }
.admin-sidebar .icon-button:hover { background: var(--sidebar-accent); }

/* ---------- avatar and account ---------- */
.avatar-button { display: inline-flex; padding: 0.125rem; border: 0; border-radius: 999px; background: transparent; cursor: pointer; }
.avatar { display: inline-grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: 999px; background: var(--brand-primary); color: #fff; font-size: var(--text-label); font-weight: 600; }
.role-chip { display: inline-flex; align-items: center; gap: 0.25rem; width: fit-content; margin-top: 0.25rem; padding: 0.125rem 0.5rem; border-radius: 999px; background: var(--bg-muted); color: var(--text-secondary); font-size: 0.6875rem; font-weight: 500; }

/* ---------- menus ---------- */
.menu { position: relative; display: inline-block; }
.menu-panel {
  position: absolute; z-index: 50; top: calc(100% + 0.375rem); left: 0;
  min-width: 12rem; max-width: min(18rem, calc(100vw - 1.5rem)); padding: 0.25rem;
  background: var(--bg-surface); border: 1px solid var(--border-default); border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
}
.menu-panel-end { left: auto; right: 0; width: 16rem; }
.menu-label { display: flex; flex-direction: column; gap: 0.125rem; padding: 0.5rem; min-width: 0; overflow-wrap: anywhere; }
.menu-label strong { font-size: var(--text-small); }
.menu-separator { margin: 0.25rem -0.25rem; }
.menu-item {
  display: flex; align-items: center; gap: 0.5rem; width: 100%;
  padding: 0.5rem; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-primary); text-align: start; text-decoration: none;
  font-size: var(--text-small); cursor: pointer;
}
.menu-item:hover, .menu-item:focus { background: var(--bg-muted); text-decoration: none; outline: none; }
.menu-item:focus-visible { box-shadow: inset 0 0 0 2px var(--brand-accent); }
.menu-item-danger { color: var(--state-error-text); }

/* ---------- badges ---------- */
/* A long badge (a list of missing settings) wraps rather than widening the page. */
.badge { display: inline-block; max-width: 100%; padding: 0.0625rem 0.5rem; border-radius: 999px; font-size: var(--text-caption); font-weight: 500; line-height: 1.5; overflow-wrap: anywhere; }
.badge-success { background: color-mix(in srgb, var(--state-success) 10%, white); color: var(--state-success-text); }
.badge-warning { background: color-mix(in srgb, var(--state-warning) 10%, white); color: var(--state-warning-text); }
.badge-error { background: color-mix(in srgb, var(--state-error) 10%, white); color: var(--state-error-text); }
.badge-info { background: color-mix(in srgb, var(--state-info) 10%, white); color: var(--state-info-text); }
.badge-neutral { background: var(--bg-muted); color: var(--text-secondary); border: 1px solid var(--border-default); }
.badge-primary { background: color-mix(in srgb, var(--brand-primary) 10%, white); color: var(--brand-primary); }
.badge-pending { background: color-mix(in srgb, var(--data-purple) 10%, white); color: var(--data-purple-text); }
.badge-danger { background: color-mix(in srgb, var(--state-error) 10%, white); color: var(--state-error-text); }

/* ---------- alerts ---------- */
.alert { padding: 0.875rem 1rem; border-radius: var(--radius); border: 1px solid var(--border-default); background: var(--bg-surface); }
.alert > :last-child { margin-bottom: 0; }
.alert p { margin: 0 0 0.75rem; }
.alert-error { border-color: color-mix(in srgb, var(--state-error) 40%, white); background: color-mix(in srgb, var(--state-error) 5%, white); color: var(--state-error-text); }
.alert-info { border-color: color-mix(in srgb, var(--state-info) 35%, white); background: color-mix(in srgb, var(--state-info) 5%, white); color: var(--state-info-text); }
.alert-success { border-color: color-mix(in srgb, var(--state-success) 35%, white); background: color-mix(in srgb, var(--state-success) 5%, white); color: var(--state-success-text); }

/* ---------- cards ---------- */
.card { background: var(--bg-surface); border: 1px solid var(--border-default); border-radius: var(--radius-xl); padding: 1rem 1.125rem; min-width: 0; box-shadow: var(--shadow-sm); }
.card > h2:first-child { margin-bottom: 0.75rem; }

/* ---------- forms ---------- */
.form { display: grid; gap: 1rem; max-width: 40rem; }
.field { display: grid; gap: 0.375rem; min-width: 0; }
.field label { font-size: var(--text-label); font-weight: 500; color: var(--text-secondary); }
.field .required { color: var(--state-error-text); }
.field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea, .input {
  width: 100%; min-height: 2.5rem; padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--bg-surface); color: var(--text-primary); font-size: var(--text-small);
}
.field textarea { min-height: 5rem; resize: vertical; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible, .input:focus-visible { outline: var(--focus-ring); outline-offset: 0; border-color: var(--brand-accent); }
.field [aria-invalid="true"] { border-color: var(--state-error); }
.field-check { display: flex; align-items: flex-start; gap: 0.5rem; flex-wrap: wrap; }
.field-check input { width: 1.125rem; height: 1.125rem; margin: 0.15rem 0 0; accent-color: var(--brand-primary); }
.field-check .field-error { flex-basis: 100%; }
.field-hint { margin: 0; font-size: var(--text-caption); color: var(--text-muted); }
.field-error { margin: 0; font-size: var(--text-caption); font-weight: 500; color: var(--state-error-text); }
.field-inline { display: flex; }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.form-error-summary { padding: 0.75rem 1rem; border: 1px solid color-mix(in srgb, var(--state-error) 40%, white); border-radius: var(--radius); background: color-mix(in srgb, var(--state-error) 5%, white); color: var(--state-error-text); font-size: var(--text-small); }
.form-error-summary ul { margin: 0; padding-left: 1.25rem; }
.form-error-summary a { color: inherit; }
.form-error-title { margin: 0 0 0.25rem; font-weight: 600; }

/* ---------- tables ---------- */
.table-toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
.table-toolbar .field-inline:first-child { flex: 1 1 14rem; }
.table-toolbar .field-inline { flex: 0 1 12rem; }
/* position: relative keeps absolutely placed screen-reader text inside the scroll box (no page-wide overflow). */
.table-wrap { position: relative; overflow-x: auto; border: 1px solid var(--border-default); border-radius: var(--radius); background: var(--bg-surface); }
.table { width: 100%; font-size: var(--text-small); }
.table th, .table td { padding: 0.625rem 0.75rem; text-align: start; border-bottom: 1px solid var(--border-default); vertical-align: middle; }
.table th { background: var(--bg-muted); color: var(--text-secondary); font-size: var(--text-label); font-weight: 600; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--bg-muted), var(--border-default) 30%); }
.table .align-end { text-align: end; font-variant-numeric: tabular-nums; }
.table-message { padding: 1.5rem 0.75rem !important; text-align: center !important; color: var(--text-muted); }
.sort-button { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0; border: 0; background: none; font: inherit; color: inherit; cursor: pointer; }
.sort-indicator { font-size: 0.625rem; color: var(--text-muted); }
.table-status { margin: 0.5rem 0 0; font-size: var(--text-caption); color: var(--text-muted); }
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }
.pager:empty { display: none; }
.pager-info { font-size: var(--text-label); color: var(--text-secondary); }

/* ---------- dialogs ---------- */
.dialog { width: min(32rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); padding: 0; border: 0; border-radius: var(--radius-xl); background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-lg); }
.dialog-sm { width: min(26rem, calc(100vw - 2rem)); }
.dialog::backdrop { background: rgba(6, 20, 63, 0.5); }
.dialog-body { display: grid; gap: 0.75rem; padding: 1.25rem; }
.dialog-body p { margin: 0; color: var(--text-secondary); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin: -0.25rem -0.5rem 0 0; }
.dialog-title { font-size: var(--text-h5); }
.dialog-footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; margin-top: 0.25rem; }

/* ---------- tabs ---------- */
.tabs { min-width: 0; }
.tabs [role="tablist"] { display: flex; gap: 0.25rem; margin: 1rem 0 0.75rem; border-bottom: 1px solid var(--border-default); overflow-x: auto; }
.tabs [role="tab"] { padding: 0.5rem 0.875rem; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--text-muted); font-size: var(--text-small); font-weight: 500; white-space: nowrap; cursor: pointer; }
.tabs [role="tab"][aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--brand-secondary); }
.tabs [role="tabpanel"] { outline: none; }
.tabs [role="tabpanel"]:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }

/* ---------- notifications ---------- */
.toast-region { position: fixed; z-index: 90; top: 1rem; right: 1rem; display: flex; flex-direction: column; gap: 0.5rem; width: min(22rem, calc(100vw - 2rem)); pointer-events: none; }
.toast { display: flex; align-items: flex-start; gap: 0.5rem; padding: 0.75rem 0.75rem 0.75rem 1rem; border: 1px solid var(--border-default); border-left-width: 4px; border-radius: var(--radius); background: var(--bg-surface); box-shadow: var(--shadow-lg); font-size: var(--text-small); pointer-events: auto; animation: toast-in 0.2s ease; }
.toast p { flex: 1; margin: 0; }
.toast-success { border-left-color: var(--state-success); }
.toast-error { border-left-color: var(--state-error); }
.toast-warning { border-left-color: var(--state-warning); }
.toast-info { border-left-color: var(--state-info); }
.toast.is-leaving { opacity: 0; transition: opacity 0.2s ease; }
.toast-close { border: 0; background: none; color: var(--text-muted); font-size: 1.25rem; line-height: 1; cursor: pointer; padding: 0 0.25rem; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-0.5rem); } }

/* ---------- loading, empty ---------- */
.spinner { display: inline-block; width: 1rem; height: 1rem; border: 2px solid currentColor; border-right-color: transparent; border-radius: 999px; vertical-align: -0.15em; animation: spin 0.7s linear infinite; opacity: 0.7; }
.spinner-sm { width: 0.875rem; height: 0.875rem; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { color: var(--text-muted); }
.empty-state { margin: 0; padding: 1.5rem 1rem; text-align: center; color: var(--text-muted); border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.state-box { margin-top: 0.75rem; min-height: 3rem; }

/* ---------- password field (components/password-input.php) ---------- */
.password-input { position: relative; }
.password-input input { padding-right: 2.5rem !important; }
.password-toggle { position: absolute; top: 50%; right: 0.25rem; display: inline-flex; align-items: center; justify-content: center; width: 1.75rem; height: 1.75rem; padding: 0; transform: translateY(-50%); border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-muted); cursor: pointer; }
.password-toggle:hover { background: var(--bg-muted); color: var(--text-primary); }
.password-toggle:focus-visible { outline: var(--focus-ring); }
.password-toggle .icon { width: 0.875rem; height: 0.875rem; }
.password-toggle .icon-hide, .password-toggle[aria-pressed="true"] .icon-show { display: none; }
.password-toggle[aria-pressed="true"] .icon-hide { display: inline; }

/* ---------- small utilities ---------- */
.text-error { color: var(--state-error-text); }
.text-warning { color: var(--state-warning-text); }
.strong { font-weight: 600; }
fieldset.field { margin: 0; padding: 0; border: 0; min-width: 0; }
.field-legend { margin-bottom: 0.375rem; padding: 0; font-size: var(--text-label); font-weight: 500; color: var(--text-secondary); }
/* Narrow screens: a long button label wraps instead of pushing the page sideways. */
@media (max-width: 40rem) {
  .button { max-width: 100%; white-space: normal; text-align: center; }
}
.button-ghost { border-color: transparent; background: transparent; }
.button-ghost:hover { background: var(--bg-muted); }
