/* ==========================================================================
   Platinum Age PM — Components
   Every reusable surface in the application, built from tokens.css.
   ========================================================================== */

/* ==========================================================================
   1. Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 38px;
  padding: 0 var(--sp-4);
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  font-size: var(--fs-button);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-button);
  text-transform: uppercase;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color var(--motion-fast) var(--ease-out),
    border-color var(--motion-fast) var(--ease-out),
    color var(--motion-fast) var(--ease-out);
}

.btn:hover {
  text-decoration: none;
}

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

/* Primary — filled royal blue, white text (4.53:1) */
.btn-primary {
  background: var(--accent-blue-solid);
  color: var(--text-on-accent);
  box-shadow: var(--shadow-action);
}

.btn-primary:hover {
  background: var(--accent-blue-solid-hover);
  color: var(--text-on-accent);
}

/* Secondary — dark outlined */
.btn-secondary {
  background: var(--bg-input);
  border-color: var(--border-input);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--bg-panel-raised);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

/* Ghost — no chrome until hover */
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-panel-raised);
  color: var(--text-primary);
}

/* Destructive — red outlined */
.btn-danger {
  background: transparent;
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.btn-danger:hover {
  background: var(--accent-red-dim);
  color: var(--accent-red);
}

/* Export / positive outlined */
.btn-success {
  background: transparent;
  border-color: var(--accent-green);
  color: var(--accent-green);
}

.btn-success:hover {
  background: var(--accent-green-dim);
  color: var(--accent-green);
}

.btn-sm {
  min-height: 30px;
  padding: 0 var(--sp-3);
  font-size: var(--fs-label);
  gap: var(--sp-1);
}

.btn-lg {
  min-height: 44px;
  padding: 0 var(--sp-6);
  font-size: var(--fs-body);
}

.btn-block {
  display: flex;
  width: 100%;
}

/* Square icon-only button. Always needs an aria-label. */
.btn-icon {
  width: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: var(--radius-small);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--motion-fast) var(--ease-out),
    color var(--motion-fast) var(--ease-out);
}

.btn-icon:hover {
  background: var(--bg-panel-raised);
  color: var(--text-primary);
}

.btn-icon:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 1px;
}

/* Row-level action button used inside dense tables */
.btn-row {
  min-height: 27px;
  padding: 0 var(--sp-3);
  font-size: 0.6875rem;
  letter-spacing: var(--ls-button);
  text-transform: uppercase;
  font-weight: var(--fw-semibold);
  border-radius: var(--radius-small);
  background: transparent;
  border: 1px solid var(--border-input);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
}

.btn-row:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
  background: var(--bg-panel-raised);
}

.btn-row-danger {
  border-color: rgba(255, 98, 104, 0.45);
  color: var(--accent-red);
}

.btn-row-danger:hover {
  background: var(--accent-red-dim);
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

/* Busy state driven by JS during fetch requests */
.btn.is-busy {
  pointer-events: none;
  opacity: 0.7;
}

.btn.is-busy .btn-spinner {
  display: inline-block;
}

.btn-spinner {
  display: none;
  width: 13px;
  height: 13px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 620ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .btn-spinner { animation-duration: 2s; }
}

/* ==========================================================================
   2. Panels
   ========================================================================== */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-large);
  padding: var(--panel-padding);
}

.panel-flush {
  padding: 0;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-panel-title);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  margin: 0;
}

.panel-title .icon {
  color: var(--accent-blue);
  width: 20px;
  height: 20px;
}

.panel-divider {
  border: 0;
  border-top: 1px solid var(--border-default);
  margin: var(--sp-4) 0 var(--sp-5);
}

.panel-intro {
  color: var(--text-secondary);
  font-size: var(--fs-body);
  line-height: var(--lh-relaxed);
  max-width: 76ch;
  margin-bottom: var(--sp-5);
}

.panel-section {
  margin-top: var(--sp-8);
}

.panel-section-title {
  font-size: var(--fs-card-title);
  font-weight: var(--fw-semibold);
  margin-bottom: var(--sp-2);
}

.panel-section-divider {
  border: 0;
  border-top: 1px solid var(--border-default);
  margin: var(--sp-3) 0 var(--sp-5);
}

/* ==========================================================================
   3. Summary / metric cards
   ========================================================================== */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--sp-4);
}

.summary-card {
  background: var(--bg-card-navy);
  border: 1px solid var(--border-blue);
  border-radius: var(--radius-medium);
  padding: var(--sp-5) var(--sp-5) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  min-height: 118px;
  text-decoration: none;
}

a.summary-card:hover {
  border-color: var(--border-blue-hover);
  background: var(--bg-card-navy-hover);
  text-decoration: none;
}

a.summary-card:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.summary-card-plain {
  background: var(--bg-panel);
  border-color: var(--border-default);
}

.stat-value {
  font-size: var(--fs-metric);
  font-weight: var(--fw-medium);
  line-height: 1.1;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.stat-value-green { color: var(--accent-green); }
.stat-value-amber { color: var(--accent-amber); }
.stat-value-red { color: var(--accent-red); }
.stat-value-blue { color: var(--accent-blue); }

.stat-caption {
  font-size: var(--fs-body-sm);
  color: var(--text-muted);
  margin-top: auto;
}

/* ==========================================================================
   4. Project cards
   ========================================================================== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(296px, 1fr));
  gap: var(--sp-4);
  align-items: start;
}

.project-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  width: 100%;
  text-align: left;
  background: var(--bg-card-navy);
  border: 1px solid var(--border-blue);
  border-radius: var(--radius-medium);
  padding: var(--sp-5);
  color: inherit;
  /* The whole card is a link, so the generic a:hover underline would
     underline every line of text inside it. */
  text-decoration: none;
  transition: border-color var(--motion-fast) var(--ease-out),
    transform var(--motion-fast) var(--ease-out),
    box-shadow var(--motion-fast) var(--ease-out);
}

.project-card:hover,
.project-card:hover .project-card-title,
.project-card:focus-visible {
  text-decoration: none;
}

.project-card:hover {
  border-color: var(--border-blue-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
}

.project-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.project-card-title {
  font-size: var(--fs-card-title);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  margin: 0;
}

.project-card-desc {
  font-size: var(--fs-body-sm);
  color: var(--text-secondary);
  line-height: var(--lh-normal);
  margin: 0;
}

/* Compact metadata strip, mirroring the reference offering cards. */
.meta-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-3);
  background: var(--bg-panel-dark);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-small);
  padding: var(--sp-3);
}

.meta-strip-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.meta-item .label {
  font-size: 0.625rem;
}

.meta-value {
  font-size: var(--fs-body-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta-value-muted {
  font-weight: var(--fw-regular);
  color: var(--text-secondary);
}

.project-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-top: auto;
  padding-top: var(--sp-1);
}

/* ==========================================================================
   5. Avatars
   ========================================================================== */
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-selected);
  border: 1px solid var(--border-blue);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6875rem;
  font-weight: var(--fw-semibold);
  letter-spacing: 0.02em;
  overflow: hidden;
  flex-shrink: 0;
  text-transform: uppercase;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-sm { width: 22px; height: 22px; font-size: 0.5625rem; }
.avatar-lg { width: 40px; height: 40px; font-size: 0.8125rem; }
.avatar-xl { width: 96px; height: 96px; font-size: 1.5rem; }

.avatar-stack {
  display: flex;
  align-items: center;
}

.avatar-stack .avatar + .avatar {
  margin-left: -8px;
}

.avatar-stack .avatar {
  box-shadow: 0 0 0 2px var(--bg-card-navy);
}

.avatar-more {
  background: var(--bg-panel-dark);
  border-color: var(--border-default);
  color: var(--text-secondary);
}

.person {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}

.person-name {
  font-size: var(--fs-body-sm);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.person-sub {
  font-size: 0.6875rem;
  color: var(--text-muted);
}

/* ==========================================================================
   6. Badges and status pills
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--sp-2);
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font-size: 0.625rem;
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  white-space: nowrap;
  line-height: 1.6;
}

.badge .icon {
  width: 11px;
  height: 11px;
}

.badge-blue {
  background: var(--accent-blue-dim);
  border-color: rgba(77, 141, 247, 0.4);
  color: var(--accent-blue);
}

.badge-green {
  background: var(--accent-green-dim);
  border-color: rgba(49, 212, 155, 0.4);
  color: var(--accent-green);
}

.badge-amber {
  background: var(--accent-amber-dim);
  border-color: rgba(244, 182, 33, 0.4);
  color: var(--accent-amber);
}

.badge-red {
  background: var(--accent-red-dim);
  border-color: rgba(255, 98, 104, 0.4);
  color: var(--accent-red);
}

.badge-purple {
  background: var(--accent-purple-dim);
  border-color: rgba(180, 155, 255, 0.4);
  color: var(--accent-purple);
}

.badge-slate {
  background: var(--accent-slate-dim);
  border-color: var(--border-strong);
  color: var(--text-muted);
}

.badge-cyan {
  background: rgba(56, 189, 248, 0.13);
  border-color: rgba(56, 189, 248, 0.4);
  color: var(--accent-cyan);
}

/* Square-ish status pill used in dense tables */
.pill {
  border-radius: var(--radius-small);
}

/* Role badge beside the wordmark */
.role-badge {
  padding: 2px var(--sp-2);
  border-radius: var(--radius-pill);
  font-size: 0.625rem;
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  border: 1px solid;
}

.role-badge-member {
  background: var(--accent-blue-dim);
  border-color: rgba(77, 141, 247, 0.45);
  color: var(--accent-blue);
}

.role-badge-admin {
  background: var(--accent-amber-dim);
  border-color: rgba(244, 182, 33, 0.45);
  color: var(--accent-amber);
}

/* Inline warning chip, always carrying its own text */
.warn-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-label);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.warn-chip-red { color: var(--accent-red); }
.warn-chip-amber { color: var(--accent-amber); }

/* ==========================================================================
   7. Progress indicator
   Looks like a slider track but is presented as a read-only progressbar.
   ========================================================================== */
.progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
}

.progress-value {
  font-size: var(--fs-body-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.progress-fraction {
  font-size: var(--fs-label);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.progress-track {
  position: relative;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-panel-dark);
  border: 1px solid var(--border-default);
}

.progress-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--accent-blue);
  transition: width var(--motion-slow) var(--ease-out);
}

.progress-complete .progress-fill { background: var(--accent-green); }
.progress-at-risk .progress-fill { background: var(--accent-amber); }
.progress-overdue .progress-fill { background: var(--accent-red); }

.progress-complete .progress-value { color: var(--accent-green); }
.progress-at-risk .progress-value { color: var(--accent-amber); }
.progress-overdue .progress-value { color: var(--accent-red); }

/* The knob echoes a slider without implying drag: it is not focusable and
   the surrounding element is role="progressbar", not role="slider". */
.progress-knob {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  border-radius: 50%;
  background: var(--text-primary);
  border: 2px solid var(--accent-blue);
  transform: translateY(-50%);
  left: calc(6px + (100% - 12px) * var(--progress, 0) / 100);
  margin-left: -6px;
  transition: left var(--motion-slow) var(--ease-out);
  pointer-events: none;
}

.progress-complete .progress-knob { border-color: var(--accent-green); }
.progress-at-risk .progress-knob { border-color: var(--accent-amber); }
.progress-overdue .progress-knob { border-color: var(--accent-red); }

.progress-slim .progress-track { height: 6px; }
.progress-slim .progress-knob { display: none; }

/* ==========================================================================
   8. Forms
   ========================================================================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: var(--sp-4) var(--sp-5);
}

.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-label {
  margin-bottom: 0;
}

.field-label .req {
  color: var(--accent-red);
  margin-left: 3px;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 40px;
  padding: 0 var(--sp-3);
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-small);
  color: var(--text-primary);
  font-size: var(--fs-body);
  transition: border-color var(--motion-fast) var(--ease-out),
    box-shadow var(--motion-fast) var(--ease-out);
}

.textarea {
  min-height: 96px;
  padding: var(--sp-3);
  line-height: var(--lh-normal);
  resize: vertical;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-muted);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--border-strong);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(77, 141, 247, 0.2);
}

.input[disabled],
.select[disabled],
.textarea[disabled],
.input[readonly] {
  background: var(--bg-input-disabled);
  color: var(--text-muted);
}

.select {
  appearance: none;
  padding-right: var(--sp-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238996ae' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--sp-3) center;
}

.input-sm,
.select-sm {
  min-height: 34px;
  font-size: var(--fs-body-sm);
}

.field-help {
  display: block;
  font-size: var(--fs-body-sm);
  color: var(--text-muted);
  line-height: var(--lh-normal);
}

.field-error {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-body-sm);
  color: var(--accent-red);
  font-weight: var(--fw-medium);
}

.field.has-error .input,
.field.has-error .select,
.field.has-error .textarea {
  border-color: var(--accent-red);
}

.field.has-error .input:focus,
.field.has-error .select:focus,
.field.has-error .textarea:focus {
  box-shadow: 0 0 0 3px rgba(255, 98, 104, 0.2);
}

/* Checkbox and radio */
.check {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--sp-3);
  cursor: pointer;
  font-size: var(--fs-body);
  line-height: 1.45;
  min-height: 22px;
}

.check input[type="checkbox"],
.check input[type="radio"] {
  appearance: none;
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  flex-shrink: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  transition: background-color var(--motion-fast) var(--ease-out),
    border-color var(--motion-fast) var(--ease-out);
}

.check input[type="radio"] {
  border-radius: 50%;
}

.check input[type="checkbox"]:checked,
.check input[type="radio"]:checked {
  background: var(--accent-blue-solid);
  border-color: var(--accent-blue-solid);
}

.check input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.check input[type="radio"]:checked::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: #fff;
}

.check input:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

.check input[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.check-text {
  color: var(--text-secondary);
}

/* Form action bar */
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-6);
}

.form-actions-split {
  justify-content: space-between;
}

/* Multi-select list used for participants and departments */
.chip-select {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: var(--sp-3);
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-small);
}

.chip-option {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 5px var(--sp-3);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-pill);
  background: var(--bg-panel-dark);
  font-size: var(--fs-body-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--ease-out),
    color var(--motion-fast) var(--ease-out);
}

.chip-option:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.chip-option input {
  appearance: none;
  width: 14px;
  height: 14px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  position: relative;
  cursor: pointer;
}

.chip-option input:checked {
  background: var(--accent-blue-solid);
  border-color: var(--accent-blue-solid);
}

.chip-option input:checked::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 0.5px;
  width: 4px;
  height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.chip-option input:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

.chip-option:has(input:checked) {
  border-color: var(--border-blue-hover);
  background: var(--bg-selected);
  color: var(--text-primary);
}

/* Filter toolbar above tables and card grids */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
}

.toolbar .input,
.toolbar .select {
  min-height: 34px;
  font-size: var(--fs-body-sm);
  width: auto;
}

.toolbar-search {
  position: relative;
  flex: 1 1 200px;
  min-width: 170px;
  max-width: 320px;
}

.toolbar-search .input {
  width: 100%;
  padding-left: var(--sp-8);
}

.toolbar-search .icon {
  position: absolute;
  left: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 15px;
  height: 15px;
  pointer-events: none;
}

/* ==========================================================================
   9. Tables
   ========================================================================== */
.table-wrap {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-medium);
  overflow: hidden;
  background: var(--bg-panel-dark);
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  min-width: 640px;
  font-size: var(--fs-body-sm);
}

.table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-panel-dark);
  padding: var(--sp-3) var(--sp-3);
  text-align: left;
  font-size: var(--fs-label);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 1px solid var(--border-default);
}

.table tbody td {
  padding: var(--sp-3);
  border-bottom: 1px solid var(--border-default);
  color: var(--text-secondary);
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tbody tr {
  transition: background-color var(--motion-fast) var(--ease-out);
}

.table tbody tr:hover {
  background: var(--bg-panel-raised);
}

.table tbody tr.is-selected {
  background: var(--bg-selected);
}

/* Two-line cell: white semibold primary over muted secondary detail. */
.cell-primary {
  color: var(--text-primary);
  font-weight: var(--fw-semibold);
  display: block;
}

.cell-secondary {
  color: var(--text-muted);
  font-size: 0.75rem;
  display: block;
  margin-top: 2px;
}

.col-narrow { width: 1%; white-space: nowrap; }
.col-actions { width: 1%; white-space: nowrap; text-align: right; }

.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}

.th-sort:hover { color: var(--text-secondary); }
.th-sort[aria-sort="ascending"],
.th-sort[aria-sort="descending"] { color: var(--accent-blue); }

/* Summary statistics strip above a table */
.stat-strip {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-6);
  padding: var(--sp-4) var(--sp-5);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-medium);
  background: var(--bg-panel-dark);
}

.stat-strip-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-strip-value {
  font-size: 1.0625rem;
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

/* Drag handle for task reordering */
.drag-handle {
  color: var(--text-muted);
  cursor: grab;
  background: transparent;
  border: 0;
  padding: var(--sp-1);
  border-radius: var(--radius-small);
}

.drag-handle:hover { color: var(--text-primary); }
.drag-handle:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 1px; }
tr.is-dragging { opacity: 0.45; }
tr.is-drop-target td { box-shadow: inset 0 2px 0 var(--accent-blue); }

/* ==========================================================================
   10. Modal dialog
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: var(--bg-overlay);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--sp-6);
  overflow-y: auto;
  animation: overlay-in var(--motion-base) var(--ease-out);
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  position: relative;
  width: 100%;
  max-width: 960px;
  max-height: calc(100vh - var(--sp-12));
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow-modal);
  overflow: hidden;
}

.modal-sm { max-width: 520px; }
.modal-md { max-width: 720px; }

.modal-header {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--border-default);
  background: var(--bg-panel);
}

.modal-title {
  font-size: 1.3125rem;
  font-weight: var(--fw-semibold);
  margin: 0 0 var(--sp-2);
}

.modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--sp-6);
}

.modal-footer {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border-default);
  background: var(--bg-panel-dark);
}

.modal-close {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-small);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border: 1px solid transparent;
}

.modal-close:hover {
  background: var(--bg-panel-raised);
  color: var(--text-primary);
}

.modal-close:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 1px;
}

/* Two-column modal body on wide viewports */
.modal-columns {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: var(--sp-6);
}

@media (max-width: 860px) {
  .modal-columns { grid-template-columns: minmax(0, 1fr); }
  .modal-overlay { padding: 0; }
  .modal {
    max-width: 100%;
    min-height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: 0;
  }
}

body.modal-open {
  overflow: hidden;
}

/* ==========================================================================
   11. Chat / comments
   ========================================================================== */
.chat {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-medium);
  background: var(--bg-panel-dark);
  overflow: hidden;
}

.chat-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  max-height: 360px;
  min-height: 160px;
  overscroll-behavior: contain;
}

.chat-tall .chat-scroll { max-height: 480px; }

.comment {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
}

.comment-body {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--bubble-other-border);
  background: var(--bubble-other-bg);
  border-radius: var(--radius-medium);
  padding: var(--sp-3) var(--sp-4);
}

/* Project lead bubbles are green-accented and additionally carry a
   "PROJECT LEAD" text label so ownership never depends on colour. */
.comment-lead .comment-body {
  border-color: var(--bubble-lead-border);
  background: var(--bubble-lead-bg);
}

.comment-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-bottom: 5px;
}

.comment-author {
  font-size: var(--fs-body-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
}

.comment-time {
  font-size: 0.6875rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.comment-text {
  font-size: var(--fs-body);
  color: var(--text-secondary);
  line-height: var(--lh-relaxed);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0;
  max-width: none;
}

.comment-removed .comment-text {
  color: var(--text-muted);
  font-style: italic;
}

.comment-actions {
  display: flex;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}

.comment-edited {
  font-size: 0.625rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.chat-composer {
  flex-shrink: 0;
  border-top: 1px solid var(--border-default);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.chat-composer .textarea {
  min-height: 62px;
  background: var(--bg-input);
}

.chat-composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.chat-older {
  align-self: center;
  margin-bottom: var(--sp-2);
}

.chat-readonly-note {
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border-default);
  font-size: var(--fs-body-sm);
  color: var(--text-muted);
  background: var(--bg-panel);
}

/* ==========================================================================
   12. Feedback: alerts, toasts, empty and loading states
   ========================================================================== */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid;
  border-radius: var(--radius-small);
  font-size: var(--fs-body);
  line-height: var(--lh-normal);
}

.alert .icon { margin-top: 2px; }
.alert p { margin: 0; max-width: none; }

.alert-success {
  background: var(--accent-green-dim);
  border-color: rgba(49, 212, 155, 0.4);
  color: var(--accent-green);
}

.alert-error {
  background: var(--accent-red-dim);
  border-color: rgba(255, 98, 104, 0.4);
  color: var(--accent-red);
}

.alert-warning {
  background: var(--accent-amber-dim);
  border-color: rgba(244, 182, 33, 0.4);
  color: var(--accent-amber);
}

.alert-info {
  background: var(--accent-blue-dim);
  border-color: rgba(77, 141, 247, 0.4);
  color: var(--accent-blue);
}

.alert-list {
  margin: var(--sp-2) 0 0;
  padding-left: var(--sp-5);
  list-style: disc;
}

.toast-region {
  position: fixed;
  right: var(--sp-5);
  bottom: var(--sp-5);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  max-width: 360px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-small);
  border: 1px solid var(--border-default);
  background: var(--bg-panel);
  box-shadow: var(--shadow-card-hover);
  font-size: var(--fs-body-sm);
  color: var(--text-primary);
  animation: toast-in var(--motion-base) var(--ease-out);
}

.toast-success { border-color: rgba(49, 212, 155, 0.45); }
.toast-success .icon { color: var(--accent-green); }
.toast-error { border-color: rgba(255, 98, 104, 0.45); }
.toast-error .icon { color: var(--accent-red); }
.toast-info .icon { color: var(--accent-blue); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--sp-3);
  padding: var(--sp-12) var(--sp-6);
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-medium);
  background: var(--bg-panel-dark);
}

.empty-state .icon {
  width: 30px;
  height: 30px;
  color: var(--text-muted);
}

.empty-title {
  font-size: var(--fs-card-title);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
}

.empty-text {
  font-size: var(--fs-body);
  color: var(--text-secondary);
  max-width: 46ch;
  margin: 0;
}

/* Skeleton shown while a fetch is in flight */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-panel-dark) 25%,
    var(--bg-panel-raised) 37%,
    var(--bg-panel-dark) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius-small);
}

@keyframes shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}

.skeleton-line { height: 12px; margin-bottom: var(--sp-2); }
.skeleton-line-lg { height: 20px; width: 55%; }
.skeleton-block { height: 90px; }

.loading-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-8);
  color: var(--text-muted);
  font-size: var(--fs-body-sm);
}

/* ==========================================================================
   13. Tabs, pagination, dropdown menus
   ========================================================================== */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--border-default);
}

.tab {
  padding: var(--sp-2) var(--sp-4);
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--fs-body-sm);
  font-weight: var(--fw-medium);
  text-decoration: none;
  margin-bottom: -1px;
}

.tab:hover {
  color: var(--text-primary);
  text-decoration: none;
}

.tab[aria-selected="true"],
.tab.is-active {
  color: var(--accent-blue);
  border-bottom-color: var(--accent-blue);
}

.tab:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: -2px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-top: var(--sp-5);
}

.pagination-pages {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.page-link {
  min-width: 32px;
  height: 32px;
  padding: 0 var(--sp-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-small);
  font-size: var(--fs-body-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}

.page-link:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
  text-decoration: none;
}

.page-link[aria-current="page"] {
  background: var(--bg-selected);
  border-color: var(--border-blue-hover);
  color: var(--accent-blue-hover);
}

.page-link.is-disabled {
  opacity: 0.4;
  pointer-events: none;
}

.pagination-summary {
  font-size: var(--fs-body-sm);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.menu {
  position: relative;
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 220px;
  background: var(--bg-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-medium);
  box-shadow: var(--shadow-card-hover);
  padding: var(--sp-2);
  z-index: var(--z-header);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-small);
  color: var(--text-secondary);
  font-size: var(--fs-body-sm);
  text-align: left;
  text-decoration: none;
}

.menu-item:hover {
  background: var(--bg-panel-raised);
  color: var(--text-primary);
  text-decoration: none;
}

.menu-item .icon { color: var(--text-muted); }
.menu-item:hover .icon { color: var(--accent-blue); }
.menu-divider {
  border-top: 1px solid var(--border-default);
  margin: var(--sp-2) 0;
}

/* ==========================================================================
   14. Definition lists used in detail views
   ========================================================================== */
.detail-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--sp-4);
  margin: 0;
}

.detail-item { min-width: 0; }

.detail-item dt {
  font-size: var(--fs-label);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.detail-item dd {
  margin: 0;
  font-size: var(--fs-body);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   15. Activity feed
   ========================================================================== */
.activity-list {
  display: flex;
  flex-direction: column;
}

.activity-item {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border-default);
}

.activity-item:last-child { border-bottom: 0; }

.activity-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: var(--radius-small);
  background: var(--bg-panel-dark);
  border: 1px solid var(--border-default);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-blue);
}

.activity-text {
  font-size: var(--fs-body-sm);
  color: var(--text-secondary);
  line-height: var(--lh-normal);
  margin: 0;
  max-width: none;
}

.activity-text strong {
  color: var(--text-primary);
  font-weight: var(--fw-semibold);
}

.activity-time {
  font-size: 0.6875rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.activity-unread {
  background: var(--accent-blue-dim);
  border-left: 2px solid var(--accent-blue);
  padding-left: var(--sp-3);
  margin-left: calc(var(--sp-3) * -1);
}

/* ==========================================================================
   16. Notification bell
   ========================================================================== */
.bell {
  position: relative;
}

.bell-count {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: var(--accent-red);
  color: #1a0507;
  font-size: 0.625rem;
  font-weight: var(--fw-bold);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   17. Responsive component adjustments
   ========================================================================== */
@media (max-width: 768px) {
  .panel { padding: var(--panel-padding-sm); }
  .modal-header,
  .modal-body,
  .modal-footer { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .card-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid,
  .form-grid-2 { grid-template-columns: minmax(0, 1fr); }
  .stat-strip { gap: var(--sp-4); }
  .toast-region { right: var(--sp-3); left: var(--sp-3); bottom: var(--sp-3); max-width: none; }

  /* Touch targets */
  .btn { min-height: 42px; }
  .btn-row { min-height: 34px; }
  .btn-icon { width: 42px; min-height: 42px; }
  .page-link { min-width: 40px; height: 40px; }
}

/* ==========================================================================
   18. Dialog element defaults
   --------------------------------------------------------------------------
   .modal sets display:flex, which would override the user-agent's
   display:none for a <dialog> that is not open. Without this rule every
   dialog on the page renders inline as a visible panel.
   ========================================================================== */
dialog.modal:not([open]) {
  display: none;
}

dialog.modal {
  /* The UA centres a modal dialog; these keep it inside the viewport and let
     only its body scroll. */
  margin: auto;
  padding: 0;
  border: 1px solid var(--border-default);
  color: var(--text-primary);
}

dialog.modal::backdrop {
  background: var(--bg-overlay);
}

dialog.modal > form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: calc(100vh - var(--sp-12));
}
