/* =====================================================================
   Component library — shared primitives (consumes tokens.css)
   Four groups (uzgodnione z klientem):
     1. UX states      — skeleton / empty / error / locked
     2. Interaction    — modal / toast / dropdown menu / tooltip
     3. Forms + tables  — validation / checkbox / radio / tag-input /
                          sortable + selectable table / pagination
     4. Consistency    — unified .alert + unified .avatar
   Class names are namespaced to avoid collisions with existing screens.
   ===================================================================== */

/* =====================================================================
   4. CONSISTENCY — unified Alert (zastępuje sidebar-block / candidate-note
      / review-hint / trans-status — patrz design-system.md)
   ===================================================================== */
.alert {
  display: flex; gap: var(--space-3); align-items: flex-start;
  border: 1px solid var(--border); border-left-width: 4px;
  border-radius: var(--radius-md); padding: var(--space-4) var(--space-5);
  background: var(--bg-surface); color: var(--text-body); font-size: var(--text-sm);
  line-height: var(--leading-normal);
}
.alert .alert-ic { font-size: 18px; line-height: 1.2; flex: 0 0 auto; }
.alert .alert-body { flex: 1; min-width: 0; }
.alert .alert-title { font-weight: var(--weight-semibold); color: var(--text-strong); margin-bottom: 2px; }
.alert .alert-close { background: transparent; border: 0; color: var(--text-muted); cursor: pointer; font-size: 16px; line-height: 1; }
.alert-info    { border-left-color: var(--status-info-fg);      background: var(--status-info-bg); }
.alert-success { border-left-color: var(--status-free-fg);      background: var(--status-free-bg); }
.alert-warn    { border-left-color: var(--status-sponsored-fg); background: var(--status-sponsored-bg); }
.alert-danger  { border-left-color: var(--status-error-fg);     background: var(--status-error-bg); }
.alert-info .alert-title    { color: var(--status-info-fg); }
.alert-success .alert-title { color: var(--status-free-fg); }
.alert-warn .alert-title    { color: var(--status-sponsored-fg); }
.alert-danger .alert-title  { color: var(--status-error-fg); }

/* =====================================================================
   4. CONSISTENCY — unified Avatar (zastępuje author-avatar / .who .avatar
      / .account-banner .avatar)
   ===================================================================== */
.avatar2 {
  width: 38px; height: 38px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; color: #fff; font-weight: 700;
  font-size: var(--text-sm); font-family: var(--font-sans);
  background: linear-gradient(135deg, var(--blue-500), var(--accent-500));
  overflow: hidden;
}
.avatar2 img { width: 100%; height: 100%; object-fit: cover; }
.avatar2.sm { width: 28px; height: 28px; font-size: var(--text-xs); }
.avatar2.lg { width: 56px; height: 56px; font-size: var(--text-lg); }
.avatar2.square { border-radius: var(--radius-md); }
.avatar-group { display: inline-flex; }
.avatar-group .avatar2 { box-shadow: 0 0 0 2px var(--bg-surface); margin-left: -10px; }
.avatar-group .avatar2:first-child { margin-left: 0; }

/* =====================================================================
   1. UX STATES — skeleton (loading)
   ===================================================================== */
.skeleton {
  background: linear-gradient(100deg, var(--bg-subtle) 30%, var(--bg-canvas) 50%, var(--bg-subtle) 70%);
  background-size: 200% 100%; animation: skl 1.3s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes skl { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-line { height: 12px; margin-bottom: 10px; }
.skeleton-line.title { height: 20px; width: 60%; margin-bottom: 16px; }
.skeleton-line.w80 { width: 80%; } .skeleton-line.w60 { width: 60%; } .skeleton-line.w40 { width: 40%; }
.skeleton-thumb { aspect-ratio: 16/10; width: 100%; border-radius: var(--radius-md); margin-bottom: var(--space-4); }
.skeleton-avatar { width: 40px; height: 40px; border-radius: 50%; }

/* UX STATES — empty / error / generic state card */
.state {
  text-align: center; padding: var(--space-8) var(--space-6);
  border: 1px dashed var(--border-strong); border-radius: var(--radius-lg);
  background: var(--bg-surface); color: var(--text-muted);
}
.state .state-ic {
  width: 64px; height: 64px; border-radius: var(--radius-pill); margin: 0 auto var(--space-4);
  display: grid; place-items: center; font-size: 28px; background: var(--bg-subtle); color: var(--text-muted);
}
.state h3 { font-size: var(--text-xl); color: var(--text-strong); margin-bottom: var(--space-2); }
.state p { max-width: 44ch; margin: 0 auto var(--space-5); }
.state .state-actions { display: flex; gap: var(--space-3); justify-content: center; flex-wrap: wrap; }
.state.error .state-ic  { background: var(--status-error-bg); color: var(--status-error-fg); }
.state.success .state-ic{ background: var(--status-free-bg); color: var(--status-free-fg); }

/* =====================================================================
   2. INTERACTION — Modal / dialog
   ===================================================================== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000; display: none;
  align-items: center; justify-content: center; padding: var(--space-5);
  background: rgba(7, 20, 37, 0.55); backdrop-filter: blur(2px);
}
.modal-overlay.is-open { display: flex; animation: fade var(--dur) var(--ease); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 460px; overflow: hidden; animation: pop var(--dur) var(--ease);
}
@keyframes pop { from { transform: translateY(8px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-5); border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: var(--text-lg); color: var(--text-strong); }
.modal-body { padding: var(--space-5); color: var(--text-body); font-size: var(--text-sm); line-height: var(--leading-normal); }
.modal-foot { display: flex; gap: var(--space-3); justify-content: flex-end; padding: var(--space-5); border-top: 1px solid var(--border); }
.modal.danger .modal-head h3 { color: var(--status-error-fg); }

/* =====================================================================
   2. INTERACTION — Toast
   ===================================================================== */
.toast-stack { position: fixed; right: var(--space-5); bottom: var(--space-5); z-index: 1100;
  display: flex; flex-direction: column; gap: var(--space-3); max-width: 360px; }
.toast {
  display: flex; align-items: flex-start; gap: var(--space-3); background: var(--bg-inverse); color: #fff;
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); box-shadow: var(--shadow-lg);
  font-size: var(--text-sm); animation: toast-in var(--dur) var(--ease); border-left: 4px solid var(--blue-500);
}
@keyframes toast-in { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast.success { border-left-color: #2fbf71; }
.toast.error   { border-left-color: var(--accent-500); }
.toast .toast-ic { font-size: 16px; }
.toast .toast-close { margin-left: auto; background: transparent; border: 0; color: #b9c8de; cursor: pointer; }

/* =====================================================================
   2. INTERACTION — Dropdown / action menu
   ===================================================================== */
.menu { position: relative; display: inline-block; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; z-index: 60;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); padding: 6px; display: none;
}
.menu.is-open .menu-list { display: block; animation: pop var(--dur-fast) var(--ease); }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: transparent; border: 0; padding: 9px 10px; border-radius: var(--radius-sm);
  font-size: var(--text-sm); color: var(--text-body); cursor: pointer; font-family: var(--font-sans); }
.menu-item:hover { background: var(--bg-subtle); color: var(--text-strong); }
.menu-item.danger { color: var(--status-error-fg); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }

/* =====================================================================
   2. INTERACTION — Tooltip (CSS-only, data-tooltip attribute)
   ===================================================================== */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%) translateY(4px);
  background: var(--bg-inverse); color: #fff; font-size: var(--text-xs); white-space: nowrap;
  padding: 5px 9px; border-radius: var(--radius-sm); opacity: 0; pointer-events: none; transition: opacity var(--dur), transform var(--dur); z-index: 70;
}
[data-tooltip]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* =====================================================================
   3. FORMS — validation states, hint, required
   ===================================================================== */
.field .req { color: var(--status-error-fg); }
.field-hint { font-size: var(--text-xs); color: var(--text-muted); }
.field-error { font-size: var(--text-xs); color: var(--status-error-fg); display: none; align-items: center; gap: 5px; }
.field.has-error .input, .field.has-error .select { border-color: var(--status-error-fg); }
.field.has-error .input:focus { box-shadow: 0 0 0 3px var(--status-error-bg); }
.field.has-error .field-error { display: flex; }
.field.has-success .input { border-color: var(--status-free-fg); }

/* custom checkbox / radio */
.check, .radioc { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: var(--text-sm); color: var(--text-body); }
.check input, .radioc input { position: absolute; opacity: 0; width: 0; height: 0; }
.check .box, .radioc .box { width: 18px; height: 18px; border: 1.5px solid var(--border-strong);
  background: var(--bg-surface); display: grid; place-items: center; flex: 0 0 auto; transition: all var(--dur); }
.check .box { border-radius: 5px; } .radioc .box { border-radius: 50%; }
.check input:checked + .box, .radioc input:checked + .box { background: var(--accent-500); border-color: var(--accent-500); }
.check .box::after { content: "✓"; color: #fff; font-size: 12px; font-weight: 800; opacity: 0; }
.check input:checked + .box::after { opacity: 1; }
.radioc .box::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #fff; opacity: 0; }
.radioc input:checked + .box::after { opacity: 1; }
.check input:focus-visible + .box, .radioc input:focus-visible + .box { box-shadow: 0 0 0 3px var(--accent-100); }

/* tag / token input */
.tag-input { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 7px 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--bg-surface); cursor: text; }
.tag-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-100); }
.tag-input .token { display: inline-flex; align-items: center; gap: 6px; background: var(--bg-subtle);
  border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 3px 6px 3px 11px; font-size: var(--text-xs); color: var(--text-brand); }
.tag-input .token button { background: transparent; border: 0; color: var(--text-muted); cursor: pointer; font-size: 13px; line-height: 1; }
.tag-input input { border: 0; outline: 0; flex: 1; min-width: 80px; font-family: var(--font-sans); font-size: var(--text-sm); background: transparent; color: var(--text-strong); }

/* =====================================================================
   3. TABLES — sortable headers, row selection, bulk bar, pagination
   (extends .data-table from admin.css)
   ===================================================================== */
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable::after { content: "↕"; opacity: 0.4; margin-left: 6px; font-size: 11px; }
.data-table th.sortable.asc::after  { content: "↑"; opacity: 1; }
.data-table th.sortable.desc::after { content: "↓"; opacity: 1; }
.data-table td.col-check, .data-table th.col-check { width: 40px; text-align: center; }
.data-table tbody tr.selected td { background: var(--accent-50); }
.data-table.sticky thead th { position: sticky; top: 60px; z-index: 5; }

.bulk-bar { display: none; align-items: center; gap: var(--space-4); padding: 10px var(--space-5);
  background: var(--bg-inverse); color: #fff; border-radius: var(--radius-md); margin-bottom: var(--space-3); }
.bulk-bar.is-on { display: flex; animation: fade var(--dur); }
.bulk-bar .count { font-weight: 700; }
.bulk-bar .spacer { margin-left: auto; }
.bulk-bar .btn-ghost { color: #fff; border-color: rgba(255,255,255,0.4); }

.pagination { display: flex; align-items: center; gap: 4px; justify-content: center; flex-wrap: wrap; }
.pagination a, .pagination span { display: inline-grid; place-items: center; min-width: 36px; height: 36px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius-md); font-size: var(--text-sm); color: var(--text-body); background: var(--bg-surface); }
.pagination a:hover { border-color: var(--border-strong); }
.pagination .current { background: var(--brand); color: var(--text-inverse); border-color: var(--brand); font-weight: 700; }
.pagination .gap { border: 0; background: transparent; color: var(--text-muted); min-width: auto; }
.pagination .nav-btn { font-weight: 600; }
