/* Components — every interactive piece has default / hover / focus-visible / active / disabled / loading / error. */

/* Button */
.btn {
  --btn-bg: var(--paper); --btn-fg: var(--ink); --btn-bd: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 0 14px; border-radius: var(--radius);
  background: var(--btn-bg); color: var(--btn-fg); border: 1px solid var(--btn-bd);
  font-weight: 500; font-size: 14px; line-height: 1; white-space: nowrap; text-decoration: none;
  transition: background-color .15s, border-color .15s, transform .15s;
}
.btn:hover { --btn-bg: var(--panel); --btn-bd: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-primary { --btn-bg: var(--accent); --btn-fg: var(--on-accent); --btn-bd: var(--accent); }
.btn-primary:hover { --btn-bg: var(--accent-hover); --btn-bd: var(--accent-hover); }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; }
.btn-ghost:hover { --btn-bg: var(--sunken); --btn-bd: transparent; }
.btn-danger { --btn-fg: var(--bad); --btn-bd: color-mix(in oklab, var(--bad) 45%, var(--paper)); }
.btn-danger:hover { --btn-bg: color-mix(in oklab, var(--bad) 10%, var(--paper)); --btn-bd: var(--bad); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }
.btn-block { width: 100%; }
.btn.is-loading { pointer-events: none; }
.btn.is-loading > :not(.spinner) { opacity: .0; }
.btn.is-loading { position: relative; }
.btn.is-loading .spinner { position: absolute; }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Fields */
.field { display: grid; gap: 6px; align-content: start; }
.field > label, .field-label { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.input, .select, .textarea {
  width: 100%; min-height: 38px; padding: 7px 10px; border-radius: var(--radius);
  background: var(--paper); border: 1px solid var(--line-strong); color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.textarea { min-height: 88px; resize: vertical; line-height: 1.55; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-3); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 28%, transparent); }
.input[disabled], .select[disabled], .textarea[disabled] { background: var(--sunken); color: var(--ink-3); cursor: not-allowed; }
.input[aria-invalid="true"] { border-color: var(--bad); }
.field-hint { font-size: 12.5px; color: var(--ink-3); }
.field-error { font-size: 12.5px; color: var(--bad); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

/* Segmented + tabs */
.segmented { display: inline-flex; padding: 2px; border-radius: var(--radius); background: var(--sunken); border: 1px solid var(--line); }
.segmented button { min-height: 30px; padding: 0 12px; border: 0; border-radius: 4px; background: transparent; color: var(--ink-2); font-size: 13px; font-weight: 500; }
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"], .segmented button[aria-selected="true"] { background: var(--paper); color: var(--ink); box-shadow: 0 0 0 1px var(--line-strong); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a, .tabs button { padding: 10px 12px; border: 0; background: none; color: var(--ink-2); text-decoration: none; font-weight: 500; font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover, .tabs button:hover { color: var(--ink); }
.tabs [aria-current="page"], .tabs [aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

/* Tag / badge */
.tag { --tag: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; padding: 1px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; white-space: nowrap; color: var(--tag); background: color-mix(in oklab, var(--tag) 11%, var(--paper)); }
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag-ok { --tag: var(--ok); } .tag-warn { --tag: var(--warn); } .tag-bad { --tag: var(--bad); } .tag-info { --tag: var(--info); }
.tag-dev { --tag: var(--track-dev); } .tag-3d { --tag: var(--track-3d); } .tag-qa { --tag: var(--track-qa); }
/* Admin-created positions have keys p_<n>; pages build the class as tag-<key>, so match on the prefix. */
.tag[class*="tag-p_"] { --tag: var(--track-custom); }
.tag-plain::before { display: none; }

/* Avatar */
.avatar { width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; flex: none; font-size: 13px; font-weight: 600; color: var(--paper); background: var(--ink-2); }
.avatar-dev { background: var(--track-dev); } .avatar-3d { background: var(--track-3d); } .avatar-qa { background: var(--track-qa); }
.avatar[class*="avatar-p_"] { background: var(--track-custom); }

/* Position content editor (admin): criteria, starter plan and log-field rows inside the position drawer. */
.pc-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: start; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
.pc-fields { display: grid; gap: 8px; min-width: 0; }
.pc-duo { display: grid; grid-template-columns: minmax(0, 7rem) minmax(0, 1fr); gap: 8px; }
.pc-trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.pc-cell { display: grid; gap: 4px; min-width: 0; }
.pc-label { font-size: 12.5px; color: var(--ink-3); }
.pc-phase { display: grid; gap: 10px; padding: 12px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--sunken); }
[data-theme="dark"] .avatar { color: var(--sunken); }

/* Progress */
.progress { height: 6px; border-radius: 3px; background: var(--sunken); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .2s; }

/* Table */
.table-wrap { position: relative; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
.table { font-size: 14px; }
.table th, .table td { text-align: left; padding: 0 12px; height: 40px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { background: var(--panel); font-weight: 500; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--panel); }
.table tr[aria-selected="true"] { background: var(--accent-wash); }
.table .num { text-align: right; font-family: var(--mono); }
.table .actions { text-align: right; white-space: nowrap; }

/* Panel / section */
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel); border-radius: var(--radius) var(--radius) 0 0; }
.panel-head h2, .panel-head h3 { font-size: 15px; }
.panel-body { padding: 16px; }
.stat { display: grid; gap: 2px; padding: 14px 16px; border-left: 3px solid var(--line-strong); background: var(--panel); border-radius: 0 var(--radius) var(--radius) 0; }
.stat b { font-family: var(--mono); font-size: 24px; font-weight: 500; line-height: 1.2; }
.stat span { font-size: 13px; color: var(--ink-2); }

/* Alert (inline) */
.alert { display: flex; gap: 10px; padding: 10px 12px; border-radius: var(--radius); font-size: 14px; border: 1px solid color-mix(in oklab, var(--tone) 40%, var(--paper)); background: color-mix(in oklab, var(--tone) 9%, var(--paper)); color: var(--ink); --tone: var(--info); }
.alert .icon { color: var(--tone); margin-top: 2px; }
.alert-error { --tone: var(--bad); } .alert-warn { --tone: var(--warn); } .alert-ok { --tone: var(--ok); }

/* Skeleton */
.skeleton { display: block; border-radius: 4px; min-height: 14px; background: linear-gradient(90deg, var(--sunken) 25%, var(--panel) 50%, var(--sunken) 75%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.skeleton[data-w="short"] { width: 55%; }

/* Empty state */
.empty { display: grid; justify-items: start; gap: 10px; padding: 32px 24px; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--panel); }
.empty > .icon { width: 28px; height: 28px; color: var(--ink-3); }
.empty h2 { font-size: 16px; }
.empty p { color: var(--ink-2); font-size: 14px; }

/* Toast */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 90; display: grid; gap: 8px; width: min(380px, calc(100vw - 32px)); }
.toast { display: flex; align-items: flex-start; gap: 10px; padding: 11px 12px; border-radius: var(--radius); background: var(--ink); color: var(--paper); box-shadow: var(--shadow); font-size: 14px; animation: toast-in .18s ease-out; }
.toast .icon { margin-top: 2px; }
.toast-ok .icon { color: var(--ok); } .toast-error .icon { color: var(--bad); }
[data-theme="dark"] .toast { background: var(--line); color: var(--ink); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* Drawer + dialog */
.scrim { position: fixed; inset: 0; z-index: 60; background: var(--scrim); animation: fade-in .15s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 61; width: min(480px, 100vw); background: var(--paper); border-left: 1px solid var(--line-strong); box-shadow: var(--shadow); display: flex; flex-direction: column; animation: drawer-in .18s ease-out; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.drawer-body { padding: 16px; overflow-y: auto; flex: 1; }
.drawer-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; background: var(--panel); }
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }
dialog.dialog { margin: auto; padding: 0; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--paper); color: var(--ink); box-shadow: var(--shadow); width: min(420px, calc(100vw - 32px)); }
dialog.dialog::backdrop { background: var(--scrim); }
.dialog-body { padding: 20px; display: grid; gap: 8px; }
.dialog-foot { padding: 12px 20px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--line); background: var(--panel); }

/* Command palette */
dialog.palette { width: min(480px, calc(100vw - 32px)); margin-top: 12vh; }
.palette-list { list-style: none; padding: 0; display: grid; gap: 2px; max-height: 320px; overflow-y: auto; }
.palette-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius); cursor: pointer; font-size: 14px; }
.palette-item[aria-selected="true"], .palette-item:hover { background: var(--accent-wash); }
.palette-empty { padding: 8px 10px; color: var(--ink-3); font-size: 14px; }

/* Touch targets: at least 36px on phones and coarse pointers (the WCAG 2.2 minimum is 24px). */
@media (max-width: 860px), (pointer: coarse) {
  .btn-sm, .segmented button { min-height: 36px; }
  .btn-sm { min-width: 36px; }
  .btn-icon.btn-sm { width: 36px; }
}
