/* Shared primitives. Public .olk-* names work without legacy class names. */
* { box-sizing: border-box; }
html { font-family: var(--olk-font); font-size: 100%; color: var(--olk-ink); background: var(--olk-canvas); font-synthesis: none; }
body { margin: 0; font-size: .875rem; line-height: 1.5; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
button:disabled { cursor: not-allowed; opacity: .6; }
:focus-visible { outline: 2px solid var(--olk-focus); outline-offset: 3px; }
h1, h2, h3, h4, p { margin-top: 0; }
h1, h2, h3, h4 { font-weight: 650; letter-spacing: -.025em; line-height: 1.3; color: var(--olk-ink); }
p { line-height: 1.65; }
svg { flex-shrink: 0; }
.icon { width: 20px; height: 20px; vertical-align: middle; }
[hidden] { display: none !important; }
.muted, .olk-muted { color: var(--olk-muted); }
.full, .olk-full { grid-column: 1 / -1; }
.preserve-lines { white-space: pre-wrap; }
.olk-stack { display: flex; flex-direction: column; gap: var(--olk-space-4); }
.olk-row { display: flex; align-items: center; flex-wrap: wrap; gap: var(--olk-space-3); }
.olk-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: var(--olk-space-5); }
.sr-only, .olk-visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.eyebrow { display: block; color: var(--olk-muted); font-size: .75rem; font-weight: 600; letter-spacing: .09em; margin-bottom: 10px; }
.brand-logo { display: block; width: 150px; max-width: 100%; height: auto; filter: var(--olk-logo-filter); }
.wordmark { display: inline-flex; align-items: center; line-height: 1; }

/* Buttons and links */
.btn, .olk-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 9px 15px; border: 1px solid transparent; border-radius: var(--olk-radius-md); font-size: .875rem; line-height: 1.5; font-weight: 600; color: var(--olk-ink); background: var(--olk-surface); text-align: center; transition: background var(--olk-motion-fast), border-color var(--olk-motion-fast), color var(--olk-motion-fast), transform var(--olk-motion-fast); }
.btn:active:not(:disabled), .olk-button:active:not(:disabled) { transform: translateY(1px); }
.btn .icon, .olk-button .icon { width: 18px; height: 18px; }
.btn-primary, .olk-button--primary { background: var(--olk-primary); color: var(--olk-on-primary); border-color: var(--olk-primary); }
.btn-primary:hover:not(:disabled), .olk-button--primary:hover:not(:disabled) { background: var(--olk-primary-hover); border-color: var(--olk-primary-hover); }
.btn-secondary, .olk-button--secondary { background: var(--olk-surface); border-color: var(--olk-border); }
.btn-secondary:hover:not(:disabled), .olk-button--secondary:hover:not(:disabled) { background: var(--olk-surface-hover); border-color: var(--olk-input-border); }
.btn-text, .olk-button--text { color: var(--olk-accent-ink); background: transparent; padding: 7px 9px; min-height: 36px; }
.btn-text:hover:not(:disabled), .olk-button--text:hover:not(:disabled) { background: var(--olk-accent); }
.btn-danger, .olk-button--danger { background: var(--olk-danger); color: var(--olk-on-danger); border-color: var(--olk-danger); }
.btn-danger:hover:not(:disabled), .olk-button--danger:hover:not(:disabled) { background: var(--olk-danger-hover); border-color: var(--olk-danger-hover); }
.btn-danger-text, .olk-button--danger-text { color: var(--olk-danger); background: transparent; }
.btn-danger-text:hover:not(:disabled), .olk-button--danger-text:hover:not(:disabled) { background: var(--olk-danger-soft); }
.btn-sidebar, .olk-button--sidebar { background: transparent; padding: 6px; min-height: 36px; color: var(--olk-muted); font-size: .8125rem; }
.btn-sidebar:hover, .olk-button--sidebar:hover { color: var(--olk-ink); background: var(--olk-surface-hover); }
.icon-button { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; flex-shrink: 0; border: 1px solid transparent; border-radius: var(--olk-radius-md); color: var(--olk-muted); background: transparent; transition: background var(--olk-motion-fast), color var(--olk-motion-fast); }
.icon-button:hover { color: var(--olk-accent-ink); background: var(--olk-accent); }
.text-link { display: inline-flex; align-items: center; gap: 7px; font-size: .875rem; font-weight: 600; color: var(--olk-accent-ink); }
.text-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.text-link .icon { width: 17px; height: 17px; }
.theme-toggle, .olk-theme-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; font: inherit; font-size: .8125rem; font-weight: 500; padding: 7px 11px; white-space: nowrap; border: 1px solid var(--olk-border); border-radius: var(--olk-radius-md); color: var(--olk-ink); background: var(--olk-surface); transition: background var(--olk-motion-fast), border-color var(--olk-motion-fast); }
.theme-toggle:hover, .olk-theme-toggle:hover { background: var(--olk-surface-hover); border-color: var(--olk-input-border); }
.theme-toggle .icon, .olk-theme-toggle .icon { width: 17px; height: 17px; }

/* Surfaces and tables */
.panel, .olk-panel { background: var(--olk-surface); border: 1px solid var(--olk-border); border-radius: var(--olk-radius-md); box-shadow: var(--olk-shadow); overflow: hidden; min-width: 0; }
.panel-header, .olk-panel-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 78px; padding: 22px 24px; }
.panel-header h2, .olk-panel-header h2 { font-size: 1rem; margin: 0; }
.panel-header p, .olk-panel-header p { font-size: .8125rem; color: var(--olk-muted); margin: 5px 0 0; }
.table-scroll, .olk-table-wrap { position: relative; overflow-x: auto; overscroll-behavior-inline: contain; }
.data-table, .olk-table { width: 100%; border-collapse: collapse; text-align: left; font-size: .875rem; }
.data-table th, .olk-table th { padding: 13px 20px; font-size: .8125rem; font-weight: 600; color: var(--olk-muted); background: var(--olk-surface-subtle); border-top: 1px solid var(--olk-border); border-bottom: 1px solid var(--olk-border); white-space: nowrap; }
.data-table td, .olk-table td { padding: 16px 20px; border-bottom: 1px solid var(--olk-border); vertical-align: middle; line-height: 1.5; }
.data-table th:first-child, .data-table td:first-child, .olk-table th:first-child, .olk-table td:first-child { padding-left: 24px; }
.data-table th:last-child, .data-table td:last-child, .olk-table th:last-child, .olk-table td:last-child { padding-right: 24px; text-align: right; }
.data-table tr:last-child td, .olk-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr, .olk-table tbody tr { transition: background var(--olk-motion-fast); }
.data-table tbody tr:hover, .olk-table tbody tr:hover { background: var(--olk-surface-hover); }
.data-table .badge, .olk-table .olk-badge { white-space: nowrap; overflow-wrap: normal; }
.entity-cell { display: flex; align-items: center; gap: 12px; min-width: 180px; }
.entity-cell > span:last-child { min-width: 0; }
.entity-cell strong { display: block; font-weight: 600; line-height: 1.5; overflow-wrap: anywhere; }
.entity-cell small { display: block; color: var(--olk-muted); font-size: .75rem; margin-top: 3px; }
.entity-avatar { width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--olk-accent-ink); border-radius: 50%; background: var(--olk-accent); }
.entity-avatar .icon { width: 19px; height: 19px; }
.entity-avatar.organization { background: var(--olk-surface-subtle); color: var(--olk-muted); border-radius: var(--olk-radius-md); }
.stacked-cell { display: flex; flex-direction: column; gap: 4px; overflow-wrap: anywhere; min-width: 140px; }
.stacked-cell strong { font-size: .875rem; font-weight: 600; }
.stacked-cell small { font-size: .75rem; color: var(--olk-muted); }
.cell-date { font-variant-numeric: tabular-nums; color: var(--olk-muted); font-size: .8125rem; white-space: nowrap; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.badge, .olk-badge { display: inline-flex; align-items: center; max-width: 100%; padding: 3px 9px; border-radius: 5px; background: var(--olk-info-soft); color: var(--olk-info); font-size: .75rem; font-weight: 600; line-height: 1.6; overflow-wrap: anywhere; }
.badge.success, .olk-badge.success, .olk-badge--success { background: var(--olk-success-soft); color: var(--olk-success); }
.badge.warning, .olk-badge.warning, .olk-badge--warning { background: var(--olk-warning-soft); color: var(--olk-warning); }
.badge.muted-badge, .olk-badge.muted-badge, .olk-badge--muted { background: var(--olk-surface-subtle); color: var(--olk-muted); }
.badge-group { display: flex; gap: 6px; flex-wrap: wrap; }
.count-label { display: inline-block; padding: 2px 7px; border-radius: var(--olk-radius-sm); background: var(--olk-surface-subtle); color: var(--olk-muted); font-size: .75rem; margin-left: 5px; vertical-align: middle; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 24px; border-top: 1px solid var(--olk-border); color: var(--olk-muted); font-size: .8125rem; }
.pagination > div { display: flex; align-items: center; gap: 12px; }
.pagination .btn { min-height: 36px; padding: 6px 10px; font-size: .8125rem; }

/* Inputs, validation, collections */
input, select, textarea, .olk-input, .olk-select { width: 100%; min-height: 42px; border: 1px solid var(--olk-input-border); border-radius: var(--olk-radius-md); background: var(--olk-surface); color: var(--olk-ink); padding: 9px 12px; font-size: .875rem; transition: border-color var(--olk-motion-fast), box-shadow var(--olk-motion-fast); }
input:focus, select:focus, textarea:focus { border-color: var(--olk-focus); outline: 2px solid var(--olk-focus); outline-offset: 2px; }
input::placeholder, textarea::placeholder { color: var(--olk-muted); opacity: 1; font-weight: 400; }
textarea { resize: vertical; min-height: 100px; line-height: 1.65; }
select { padding-right: 28px; }
select[multiple] { padding: 5px; }
select[multiple] option { padding: 7px; }
input:disabled, select:disabled, textarea:disabled, input[readonly], textarea[readonly] { background: var(--olk-disabled); color: var(--olk-muted); border-color: var(--olk-border); }
input[type='checkbox'], input[type='radio'] { width: 18px; height: 18px; min-height: 18px; margin: 2px 0 0; accent-color: var(--olk-primary); flex-shrink: 0; }
.form-grid, .olk-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; }
.form-field, .olk-field { display: flex; flex-direction: column; gap: 7px; min-width: 0; margin-bottom: 20px; }
.form-grid .form-field, .olk-form-grid .olk-field { margin-bottom: 0; }
.field-label { font-size: .875rem; font-weight: 600; line-height: 1.5; }
.field-help { font-size: .8125rem; line-height: 1.65; color: var(--olk-muted); margin: 0; }
.field-error { color: var(--olk-danger); font-size: .8125rem; line-height: 1.5; margin: 0; }
[aria-invalid='true'] { border-color: var(--olk-danger); }
.form-section { font-size: 1rem; margin: 8px 0 0; padding-top: 22px; border-top: 1px solid var(--olk-border); }
.form-section + .field-help { margin: 8px 0 16px; }
.modal-body > .form-section { margin-top: 24px; margin-bottom: 16px; }
.custom-field-wrapper > .form-field { height: 100%; }
.form-error { background: var(--olk-danger-soft); border: 1px solid var(--olk-danger); border-radius: var(--olk-radius-md); padding: 13px 16px; color: var(--olk-danger); font-size: .875rem; line-height: 1.6; margin-bottom: 22px; }
.form-error p { margin: 0; }
.form-error ul { padding-left: 20px; margin: 7px 0 0; }
.form-error a { text-decoration: underline; text-underline-offset: 3px; }
fieldset { border: 1px solid var(--olk-border); border-radius: var(--olk-radius-md); margin: 0; padding: 18px; min-width: 0; }
legend { color: var(--olk-ink); font-size: .875rem; font-weight: 600; padding: 0 7px; }
.check-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.checkbox-label { display: flex; align-items: flex-start; gap: 9px; font-size: .875rem; line-height: 1.6; }
.search-results { border: 1px solid var(--olk-border); border-radius: var(--olk-radius-md); max-height: 280px; overflow-y: auto; }
.search-results > .muted { padding: 18px; margin: 0; }
.search-result { display: flex; align-items: center; gap: 12px; padding: 14px; border-bottom: 1px solid var(--olk-border); cursor: pointer; }
.search-result:last-child { border-bottom: 0; }
.search-result:hover { background: var(--olk-surface-hover); }
.search-result strong { display: block; font-size: .875rem; }
.search-result small { display: block; font-size: .75rem; color: var(--olk-muted); margin-top: 4px; }

/* Empty, loading, feedback */
.empty-state, .olk-empty { padding: 48px 24px; text-align: center; }
.empty-icon { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: var(--olk-radius-lg); background: var(--olk-accent); color: var(--olk-accent-ink); margin-bottom: 18px; }
.empty-state h3, .olk-empty h3 { font-size: 1.125rem; margin: 0 0 9px; }
.empty-state p, .olk-empty p { color: var(--olk-muted); max-width: 430px; margin: 0 auto 20px; }
.empty-state .btn { margin-top: 2px; }
.loading-state { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 80px 20px; color: var(--olk-muted); }
.spinner, .is-loading::before { display: inline-block; width: 20px; height: 20px; border: 2px solid var(--olk-border); border-top-color: var(--olk-accent-ink); border-radius: 50%; animation: olk-spin 800ms linear infinite; flex-shrink: 0; }
.is-loading::before { content: ''; width: 16px; height: 16px; border-color: currentColor; border-right-color: transparent; }
.panel-empty { color: var(--olk-muted); padding: 0 24px 24px; margin: 0; }
.info-banner, .dashboard-note { display: flex; align-items: center; gap: 14px; background: var(--olk-accent); color: var(--olk-accent-ink); border: 1px solid var(--olk-border); border-radius: var(--olk-radius-md); padding: 18px 22px; margin-bottom: 24px; }
.info-banner p, .dashboard-note p { font-size: .8125rem; line-height: 1.65; margin: 0; }
.dashboard-note { margin-top: 24px; margin-bottom: 0; }
.dashboard-note strong { display: block; font-weight: 600; }
.dashboard-note p { margin-top: 5px; }
.dashboard-note > .text-link { margin-left: auto; }
#toasts { position: fixed; bottom: 24px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 10px; max-width: min(460px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: var(--olk-surface); color: var(--olk-ink); border: 1px solid var(--olk-border); border-left: 4px solid var(--olk-success); border-radius: var(--olk-radius-md); box-shadow: var(--olk-shadow-float); padding: 15px 20px; font-size: .875rem; line-height: 1.6; animation: olk-appear var(--olk-motion-normal) var(--olk-ease); }
.toast.is-error { background: var(--olk-danger-soft); border-color: var(--olk-danger); color: var(--olk-danger); }

/* Native dialogs preserve focus management and modal semantics. */
.modal, .olk-dialog { width: 560px; max-width: calc(100vw - 32px); max-height: calc(100dvh - 48px); padding: 0; border: 1px solid var(--olk-border); border-radius: var(--olk-radius-lg); box-shadow: var(--olk-shadow-float); color: var(--olk-ink); background: var(--olk-surface); }
.modal-wide { width: 940px; }
.modal[open], .olk-dialog[open] { animation: olk-appear var(--olk-motion-normal) var(--olk-ease); }
.modal::backdrop, .olk-dialog::backdrop { background: var(--olk-backdrop); }
.modal > form, .olk-dialog > form { display: flex; flex-direction: column; max-height: calc(100dvh - 50px); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 24px 28px 22px; border-bottom: 1px solid var(--olk-border); flex-shrink: 0; }
.modal-header h2 { font-size: 1.375rem; margin: 0; }
.modal-header p { font-size: .8125rem; color: var(--olk-muted); margin: 6px 0 0; }
.modal-header .icon-button { margin-right: -5px; }
.modal-body { padding: 26px 28px; overflow-y: auto; overscroll-behavior: contain; }
.modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 18px 28px; border-top: 1px solid var(--olk-border); background: var(--olk-surface-subtle); flex-shrink: 0; }
.modal-footer .btn, .modal-footer .olk-button { min-width: 96px; }
.dialog-description { font-size: .875rem; color: var(--olk-muted); line-height: 1.75; margin: 0; }

@keyframes olk-spin { to { transform: rotate(360deg); } }
@keyframes olk-appear { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@media (max-width: 600px) {
  input, select, textarea, .olk-input, .olk-select { font-size: 1rem; }
  .form-grid, .olk-form-grid, .check-list { grid-template-columns: 1fr; }
  .panel-header, .olk-panel-header { padding: 18px; flex-wrap: wrap; }
  .pagination { padding: 16px; flex-wrap: wrap; }
  .pagination > div { gap: 8px; flex-wrap: wrap; }
  .modal, .olk-dialog { max-width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .modal > form, .olk-dialog > form { max-height: calc(100dvh - 18px); }
  .modal-header, .modal-body { padding: 20px; }
  .modal-footer { padding: 16px 20px; flex-wrap: wrap; }
  .modal-footer .btn, .modal-footer .olk-button { flex: 1; }
  .info-banner, .dashboard-note { padding: 16px; align-items: flex-start; flex-wrap: wrap; }
  .dashboard-note > div { flex: 1; min-width: 180px; }
  .dashboard-note > .text-link { margin-left: 34px; }
  #toasts { right: 16px; bottom: 16px; }
}
@media (pointer: coarse) {
  .btn, .olk-button, .icon-button, .pagination .btn, .btn-text, .olk-button--text { min-height: 44px; }
  .icon-button { width: 44px; }
  .checkbox-label { min-height: 44px; align-items: center; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
