/* Base components (SPEC-F0 deliverable 11). Behaviour in /js/ui, look here. Tokens only. */

/* ---------- Button ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: var(--control-h); padding: 0 var(--sp-4);
  border-radius: var(--radius); border: 1px solid transparent;
  font-size: var(--fs-14); font-weight: var(--fw-medium); line-height: 1; white-space: nowrap;
  color: var(--text); background: var(--surface); border-color: var(--border-strong);
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
  user-select: none;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--text-inverse); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--danger-text); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { height: 30px; padding: 0 var(--sp-3); font-size: var(--fs-13); }
.btn-lg { height: 44px; padding: 0 var(--sp-5); font-size: var(--fs-16); }
.btn-block { width: 100%; }
.btn-icon { width: var(--control-h); padding: 0; }
.btn-icon.btn-sm { width: 30px; }
.btn .icon { flex: none; }
.btn.is-loading { color: transparent !important; pointer-events: none; position: relative; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  color: var(--text-2); animation: pm-spin 700ms linear infinite;
}
.btn-primary.is-loading::after { color: var(--text-inverse); }
@keyframes pm-spin { to { transform: rotate(360deg); } }

/* ---------- Icon ---------- */
.icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.icon-20 { width: 20px; height: 20px; }

/* ---------- Field ---------- */
.field { display: flex; flex-direction: column; gap: var(--sp-1); }
.field-label { font-size: var(--fs-13); font-weight: var(--fw-medium); color: var(--text-2); display: flex; gap: var(--sp-1); }
.field-label .req { color: var(--danger); }
.input, .textarea {
  width: 100%; min-height: var(--control-h); padding: 0 var(--sp-3);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.textarea { padding: var(--sp-2) var(--sp-3); resize: vertical; line-height: var(--lh); }
.input:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus-visible, .textarea:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); border-radius: var(--radius); }
.input:disabled, .textarea:disabled { background: var(--surface-2); color: var(--text-3); cursor: not-allowed; }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.input[aria-invalid="true"]:focus-visible { box-shadow: 0 0 0 3px var(--danger-soft); }
.field-help { font-size: var(--fs-12); color: var(--text-3); }
.field-error { font-size: var(--fs-12); color: var(--danger-text); display: flex; align-items: center; gap: var(--sp-1); }
.field-error:empty { display: none; }
.input-code { font-variant-numeric: tabular-nums; letter-spacing: 0.3em; text-align: center; font-size: var(--fs-20); height: 48px; }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap .icon { position: absolute; left: var(--sp-3); color: var(--text-3); pointer-events: none; }
.input-wrap .input { padding-left: calc(var(--sp-3) + 16px + var(--sp-2)); }
.checkbox { display: flex; align-items: center; gap: var(--sp-2); min-height: var(--control-h); cursor: pointer; }
.checkbox.inline { display: inline-flex; }
.checkbox input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

/* ---------- Select (searchable) ---------- */
.select { position: relative; }
.select .input { padding-right: calc(var(--sp-3) + 20px); cursor: pointer; }
.select-chevron { position: absolute; right: var(--sp-3); top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; transition: transform var(--dur-fast) var(--ease); }
.select[aria-expanded="true"] .select-chevron { transform: translateY(-50%) rotate(180deg); }
.select-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); max-height: 280px; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-popover); padding: var(--sp-1);
  transform-origin: top; animation: pm-pop var(--dur-fast) var(--ease);
}
@keyframes pm-pop { from { opacity: 0; transform: translateY(-4px) scale(0.98); } to { opacity: 1; transform: none; } }
.select-option { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm); cursor: pointer; min-height: 36px; }
.select-option[aria-selected="true"] { background: var(--surface-2); }
.select-option.is-active { background: var(--accent-soft); color: var(--accent-text); }
.select-option .hint { color: var(--text-3); font-size: var(--fs-12); }
.select-empty { padding: var(--sp-3); color: var(--text-3); font-size: var(--fs-13); text-align: center; }

/* ---------- Chip (status, always icon + colour) ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 var(--sp-2) 0 6px;
  border-radius: var(--radius-full); font-size: var(--fs-12); font-weight: var(--fw-medium); white-space: nowrap;
  background: var(--neutral-soft); color: var(--neutral-text);
}
.chip .icon { width: 14px; height: 14px; }
.chip-ok { background: var(--ok-soft); color: var(--ok-text); }
.chip-warn { background: var(--warn-soft); color: var(--warn-text); }
.chip-danger { background: var(--danger-soft); color: var(--danger-text); }
.chip-accent { background: var(--accent-soft); color: var(--accent-text); }
.chip-neutral { background: var(--neutral-soft); color: var(--neutral-text); }
.chip-outline { background: transparent; border: 1px dashed var(--border-strong); color: var(--text-3); }

/* ---------- Badge counter ---------- */
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--radius-full); background: var(--accent); color: var(--text-inverse); font-size: 11px; font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.badge-neutral { background: var(--surface-3); color: var(--text-2); }
.badge-danger { background: var(--danger); }

/* ---------- Avatar (hue derived from the name) and avatar stack ---------- */
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; background: var(--c-teal-bg); color: var(--c-teal-fg); font-size: var(--fs-12); font-weight: var(--fw-semibold); letter-spacing: 0.02em; flex: none; }
.avatar-lg { width: 40px; height: 40px; font-size: var(--fs-14); }
.avatar-sm { width: 22px; height: 22px; font-size: 10px; }
.hue-blue { background: var(--c-blue-bg); color: var(--c-blue-fg); }
.hue-violet { background: var(--c-violet-bg); color: var(--c-violet-fg); }
.hue-pink { background: var(--c-pink-bg); color: var(--c-pink-fg); }
.hue-orange { background: var(--c-orange-bg); color: var(--c-orange-fg); }
.hue-yellow { background: var(--c-yellow-bg); color: var(--c-yellow-fg); }
.hue-green { background: var(--c-green-bg); color: var(--c-green-fg); }
.hue-teal { background: var(--c-teal-bg); color: var(--c-teal-fg); }
.hue-gray { background: var(--c-gray-bg); color: var(--c-gray-fg); }
.avatar-org { border-radius: 7px; font-size: 11px; letter-spacing: 0; }
.avatar-org.avatar-lg { border-radius: 10px; font-size: var(--fs-13); }
.avatar-org img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.avatar-stack { display: inline-flex; align-items: center; }
.avatar-stack .avatar { border: 2px solid var(--surface); margin-left: -8px; }
.avatar-stack .avatar:first-child { margin-left: 0; }
.avatar-stack .avatar-more { background: var(--surface-3); color: var(--text-2); }

/* ---------- Pill bar (gantt / calendar / resource rows) ---------- */
.pill { position: relative; display: flex; align-items: center; gap: var(--sp-2); height: 32px; padding: 0 6px 0 10px; border-radius: var(--radius-full); background: var(--c-blue-bg); color: var(--c-blue-fg); font-size: var(--fs-12); font-weight: var(--fw-medium); white-space: nowrap; overflow: hidden; cursor: pointer; border: 1px solid transparent; transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease); }
.pill:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.pill .pill-progress { position: absolute; inset: 0; width: var(--progress, 0%); background: currentColor; opacity: 0.14; pointer-events: none; }
.pill .pill-label { position: relative; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.pill .pill-label small { font-weight: var(--fw-regular); opacity: 0.8; }
.pill .avatar-stack { position: relative; flex: none; margin-left: auto; }
.pill .avatar-stack .avatar { border-color: var(--surface); }
.pill .icon { position: relative; width: 14px; height: 14px; flex: none; }
.pill.st-option { border: 1px dashed currentColor; background: color-mix(in srgb, currentColor 8%, var(--surface)); }
.pill.st-simulated { background: transparent; border: 1px dashed var(--border-strong); color: var(--text-2); }
.pill.st-conflict { box-shadow: 0 0 0 2px var(--danger); }
.pill.st-done { opacity: 0.7; }
.pill.is-selected { box-shadow: 0 0 0 2px var(--accent); }
.pill-pct { position: relative; font-variant-numeric: tabular-nums; font-size: 11px; opacity: 0.85; flex: none; }

/* ---------- Type icon (task type, request kind) ---------- */
.type-icon { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; flex: none; }
.type-icon-md { width: 28px; height: 28px; border-radius: 8px; }
.pill .type-icon { position: relative; width: 20px; height: 20px; border-radius: 5px; margin-left: -4px; background: color-mix(in srgb, var(--surface) 55%, transparent); color: inherit; }

/* ---------- Priority ---------- */
.prio { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-13); color: var(--text-2); }
.prio .icon { width: 14px; height: 14px; }
.prio-urgent { color: var(--danger-text); } .prio-high { color: var(--warn-text); } .prio-low { color: var(--text-3); }

/* ---------- Card / surface ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--sp-5); }
.card-flush { padding: 0; overflow: hidden; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding-bottom: var(--sp-3); }

/* ---------- Table ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-14); font-variant-numeric: tabular-nums; }
.table th { position: sticky; top: 0; z-index: 1; text-align: left; font-size: var(--fs-12); font-weight: var(--fw-medium); color: var(--text-2); background: var(--surface); padding: 0 var(--sp-3); height: 36px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th.sortable { cursor: pointer; }
.table th.sortable:hover { color: var(--text); }
.table td { padding: 0 var(--sp-3); height: var(--row-h); border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.table td.td-wrap { white-space: normal; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color var(--dur-fast) var(--ease); }
.table tbody tr.is-clickable { cursor: pointer; }
.table tbody tr.is-clickable:hover { background: var(--surface-2); }
.table tbody tr.is-selected { background: var(--accent-soft); }
.table tbody tr.is-selected td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
.table .td-num, .table .th-num { text-align: right; }
.table .td-muted { color: var(--text-3); }
.table-empty { padding: var(--sp-10) var(--sp-5); text-align: center; color: var(--text-3); }

/* Responsive column hiding: table({ columns: [{ ..., hide: 'lt-1400' }] }) */
@media (max-width: 1399px) { .hide-lt-1400 { display: none !important; } }
@media (max-width: 1099px) { .hide-lt-1100 { display: none !important; } }
@media (max-width: 759px) { .hide-lt-760 { display: none !important; } }

/* ---------- List (the "lista" of lista + pannello) ---------- */
.list-item { display: flex; align-items: center; gap: var(--sp-3); min-height: var(--row-h); padding: var(--sp-2) var(--sp-3); border-radius: var(--radius); cursor: pointer; transition: background-color var(--dur-fast) var(--ease); width: 100%; min-width: 0; text-align: left; color: inherit; }
.list-item:hover { background: var(--surface-2); }
.list-item.is-selected { background: var(--accent-soft); }
.list-item.is-selected .list-title { color: var(--accent-text); }
.list-title { font-weight: var(--fw-medium); }
.list-sub { font-size: var(--fs-12); color: var(--text-3); }

/* ---------- Empty state ---------- */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: var(--sp-2); padding: var(--sp-12) var(--sp-5); color: var(--text-3); }
.empty .icon { width: 28px; height: 28px; color: var(--text-3); }
.empty strong { color: var(--text-2); font-weight: var(--fw-medium); }

/* ---------- Toast ---------- */
.toasts { position: fixed; z-index: 100; right: var(--sp-5); bottom: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2); pointer-events: none; max-width: min(380px, calc(100vw - 2 * var(--sp-4))); }
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4);
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-popover);
  font-size: var(--fs-13); line-height: 1.4;
  animation: pm-toast-in var(--dur) var(--ease);
}
.toast .icon { margin-top: 1px; }
.toast-ok .icon { color: var(--ok); }
.toast-warn .icon { color: var(--warn); }
.toast-danger .icon { color: var(--danger); }
.toast-info .icon { color: var(--accent); }
.toast .toast-action { font-weight: var(--fw-medium); color: var(--accent-text); margin-left: var(--sp-2); }
.toast .toast-close { color: var(--text-3); margin-left: auto; }
.toast.is-leaving { animation: pm-toast-out var(--dur-fast) var(--ease) forwards; }
@keyframes pm-toast-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes pm-toast-out { to { opacity: 0; transform: translateY(6px) scale(0.98); } }
@media (max-width: 640px) { .toasts { left: var(--sp-4); right: var(--sp-4); bottom: calc(var(--sp-4) + env(safe-area-inset-bottom)); max-width: none; } }

/* ---------- Side panel ---------- */
.panel-scrim { position: fixed; inset: 0; z-index: 40; background: var(--scrim); animation: pm-fade var(--dur) var(--ease); }
.panel-scrim.is-leaving { animation: pm-fade-out var(--dur-fast) var(--ease) forwards; }
.panel {
  position: fixed; z-index: 41; top: 0; right: 0; bottom: 0; width: min(var(--panel-w), 100vw);
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-panel);
  display: flex; flex-direction: column;
  animation: pm-slide-in var(--dur) var(--ease);
}
.panel.is-leaving { animation: pm-slide-out var(--dur-fast) var(--ease) forwards; }
.panel-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); min-height: var(--topbar-h); }
.panel-head h2 { font-size: var(--fs-16); flex: 1; }
.panel-body { padding: var(--sp-5) var(--sp-4); overflow: auto; flex: 1; }
.panel-foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); }
@keyframes pm-slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pm-slide-out { to { transform: translateX(24px); opacity: 0; } }
@keyframes pm-fade { from { opacity: 0; } }
@keyframes pm-fade-out { to { opacity: 0; } }
@media (max-width: 760px) {
  .panel { width: 100vw; border-left: 0; }
  @keyframes pm-slide-in { from { transform: translateX(100%); opacity: 1; } to { transform: none; } }
  @keyframes pm-slide-out { to { transform: translateX(100%); } }
}

/* ---------- Inline save state (SPECIFICHE 8.1 §2) ---------- */
.save-state { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-12); color: var(--text-3); transition: color var(--dur) var(--ease); }
.save-state .icon { width: 14px; height: 14px; }
.save-state[data-state="saving"] .icon { animation: pm-spin 900ms linear infinite; }
.save-state[data-state="saved"] { color: var(--ok-text); }
.save-state[data-state="conflict"] { color: var(--warn-text); }
.save-state[data-state="offline"] { color: var(--danger-text); }

/* ---------- Key/value description ---------- */
.kv { display: grid; grid-template-columns: minmax(120px, 160px) 1fr; gap: var(--sp-2) var(--sp-4); font-size: var(--fs-14); }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; }

/* ---------- Segmented control ---------- */
.segmented { display: inline-flex; background: var(--surface-2); border-radius: var(--radius); padding: 2px; gap: 2px; }
.segmented button { height: 28px; padding: 0 var(--sp-3); border-radius: var(--radius-sm); font-size: var(--fs-13); color: var(--text-2); transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- Alert (inline message) ---------- */
.alert { display: flex; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--radius); font-size: var(--fs-13); border: 1px solid transparent; }
.alert .icon { margin-top: 2px; }
.alert-info { background: var(--accent-soft); color: var(--accent-text); }
.alert-warn { background: var(--warn-soft); color: var(--warn-text); }
.alert-danger { background: var(--danger-soft); color: var(--danger-text); }
.alert-ok { background: var(--ok-soft); color: var(--ok-text); }

/* ---------- Code list (recovery codes) ---------- */
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-2); font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: var(--fs-14); }
.codes li { padding: var(--sp-2) var(--sp-3); background: var(--surface-2); border-radius: var(--radius-sm); text-align: center; letter-spacing: 0.05em; }

/* ---------- Skeleton ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: pm-shimmer 1.2s linear infinite; border-radius: var(--radius-sm); min-height: 12px; }
@keyframes pm-shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; background: var(--surface-2); } }
