/* Primitive component styling (Tw* components) - design-system.md §6–§7. */

/* --- Text --- */
.tw-text { margin: 0; }
.tw-h1 { font-size: var(--font-xl); font-weight: 700; letter-spacing: -0.02em; }
.tw-h2 { font-size: var(--font-lg); font-weight: 600; letter-spacing: -0.01em; }
.tw-h3 { font-size: var(--font-lg); font-weight: 600; letter-spacing: -0.01em; }
.tw-h4 { font-size: var(--font-md); font-weight: 600; }
.tw-subtitle { font-size: var(--font-sm); font-weight: 600; color: var(--text-2); }
.tw-caption { font-size: var(--font-xs); color: var(--text-3); }
.tw-body { font-size: var(--font-md); }

/* --- Button --- */
.tw-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: 0 var(--space-4); height: 38px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  font-family: var(--font-sans); font-size: var(--font-sm); font-weight: 500;
  cursor: pointer; transition: all var(--dur-fast) var(--ease);
}
.tw-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.tw-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.tw-btn-filled.tw-color-primary { background: var(--accent); color: var(--accent-contrast); }
.tw-btn-filled.tw-color-primary:hover { background: var(--accent-hover); }
.tw-btn-filled.tw-color-secondary { background: var(--surface-3); color: var(--text-1); }
.tw-btn-filled.tw-color-secondary:hover { background: var(--surface-2); }
.tw-btn-filled.tw-color-error { background: var(--danger); color: #fff; }
.tw-btn-filled.tw-color-error:hover { background: var(--danger-surface); color: var(--danger); }
.tw-btn-filled.tw-color-success { background: var(--success); color: #fff; }
.tw-btn-filled.tw-color-warning { background: var(--warning); color: #fff; }

.tw-btn-outlined { background: transparent; border-color: var(--border-strong); color: var(--text-1); }
.tw-btn-outlined:hover { background: var(--surface-2); }
.tw-btn-outlined.tw-color-primary { border-color: var(--accent); color: var(--accent); }

.tw-btn-text { background: transparent; color: var(--accent); }
.tw-btn-text:hover { background: var(--surface-2); }

.tw-size-sm { height: 32px; padding: 0 var(--space-3); font-size: var(--font-xs); }
.tw-size-lg { height: 44px; padding: 0 var(--space-5); }

/* --- Grid / Item --- */
.tw-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--space-3); }
.tw-item { min-width: 0; }
.tw-field, .tw-input-wrap { min-width: 0; max-width: 100%; }
.tw-input, .tw-textarea { min-width: 0; max-width: 100%; box-sizing: border-box; }
.tw-item-1 { grid-column: span 1; }
.tw-item-2 { grid-column: span 2; }
.tw-item-3 { grid-column: span 3; }
.tw-item-4 { grid-column: span 4; }
.tw-item-5 { grid-column: span 5; }
.tw-item-6 { grid-column: span 6; }
.tw-item-7 { grid-column: span 7; }
.tw-item-8 { grid-column: span 8; }
.tw-item-9 { grid-column: span 9; }
.tw-item-10 { grid-column: span 10; }
.tw-item-11 { grid-column: span 11; }
.tw-item-12 { grid-column: span 12; }

/* --- Container / Card --- */
.tw-container { max-width: var(--content-max-width); margin: 0 auto; padding: 0 var(--space-4); width: 100%; box-sizing: border-box; }
.tw-card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-4); }

/* --- Divider --- */
.tw-divider { border: none; border-top: 1px solid var(--border); margin: var(--space-3) 0; }

/* --- Stack --- */
.tw-stack { display: flex; gap: var(--space-2); }
.tw-stack-col { flex-direction: column; }
.tw-stack-row { flex-direction: row; }
.tw-justify-start { justify-content: flex-start; }
.tw-justify-center { justify-content: center; }
.tw-justify-end { justify-content: flex-end; }
.tw-justify-between { justify-content: space-between; }
.tw-justify-around { justify-content: space-around; }
.tw-align-start { align-items: flex-start; }
.tw-align-center { align-items: center; }
.tw-align-end { align-items: flex-end; }
.tw-align-stretch { align-items: stretch; }

/* --- Field / Input --- */
.tw-field { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-3); }
.tw-field-label { font-size: var(--font-xs); font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.08em; }
.tw-input, .tw-textarea, .tw-select {
  font-family: var(--font-mono); font-size: 13px;
  background: var(--surface-2); color: var(--text-1);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3); transition: border-color var(--dur-fast) var(--ease);
}
.tw-input:focus, .tw-textarea:focus, .tw-select:focus {
  outline: none; border-color: var(--focus); background-color: var(--surface-1);
}
.tw-input-outlined { background: transparent; }
.tw-input-filled { background: var(--surface-2); }
.tw-textarea { resize: vertical; min-height: 120px; }

/* --- Native select: simple, keyboard/mobile-friendly, no custom popup --- */
.tw-select {
  appearance: none; font-family: var(--font-sans); font-size: var(--font-sm);
  min-width: 0; max-width: 100%; min-height: 40px; box-sizing: border-box;
  padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='m4 6 4 4 4-4' fill='none' stroke='%23818a99' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: right 12px center; background-repeat: no-repeat;
}
.tw-select.tw-select-dense { min-height: 34px; padding-right: 36px; }
.tw-select option { background: var(--surface-1); color: var(--text-1); }
.tw-select:enabled:hover { border-color: var(--border-strong); }
.tw-select:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.tw-select:disabled { opacity: 0.55; cursor: not-allowed; }
.tw-select.tw-control-error { border-color: var(--danger); }
.tw-control-error-text { color: var(--danger); font-size: var(--font-xs); }

/* --- Native checkbox / radio: retain browser keyboard and forced-color behavior --- */
.tw-checkbox, .tw-radio {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: 32px; max-width: 100%; color: var(--text-2);
  cursor: pointer; font-size: var(--font-sm); line-height: 1.5;
}
.tw-checkbox input, .tw-radio input {
  accent-color: var(--accent); width: 18px; height: 18px; margin: 0;
  flex: 0 0 auto; cursor: inherit;
}
.tw-checkbox span, .tw-radio span { overflow-wrap: anywhere; }
.tw-checkbox input:focus-visible, .tw-radio input:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.tw-checkbox:has(input:checked), .tw-radio:has(input:checked) { color: var(--text-1); }
.tw-choice-sm input { width: 16px; height: 16px; }
.tw-choice-lg input { width: 20px; height: 20px; }
.tw-control-disabled { opacity: 0.55; cursor: not-allowed; }
.tw-checkbox.tw-control-error input, .tw-radio-group.tw-control-error input { outline: 1px solid var(--danger); outline-offset: 2px; }
.tw-radio-group { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
@media (forced-colors: active) {
  .tw-select { appearance: auto; background-image: none; }
}

/* --- Toasts --- */
.tw-toast-container {
  position: fixed; right: 16px; bottom: 16px;
  display: flex; flex-direction: column; gap: var(--space-2);
  z-index: 1000; max-width: 360px;
}
.tw-toast {
  background: var(--surface-1); color: var(--text-1);
  padding: var(--space-3); border-radius: var(--radius-md);
  box-shadow: var(--shadow-3); border: 1px solid var(--border);
  font-size: var(--font-sm);
  animation: tw-toast-in var(--dur-drawer) var(--ease);
}
.tw-toast.tw-success { border-left: 3px solid var(--success); }
.tw-toast.tw-error   { border-left: 3px solid var(--danger); }
.tw-toast.tw-warning { border-left: 3px solid var(--warning); }
.tw-toast.tw-info    { border-left: 3px solid var(--info); }

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

/* --- Output and copy action: one shared gap, no stacked field margins --- */
.tw-output-copy { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.tw-output-copy-content { min-width: 0; }
.tw-output-copy-content > .tw-tool-output > .tw-field,
.tw-output-copy-content > .tw-field { margin-bottom: 0; }
.tw-output-copy-actions { display: flex; align-items: flex-start; }

/* --- Copy button --- */
.tw-copy-btn { display: inline-flex; gap: var(--space-2); align-items: center; }

/* --- Split pane --- */
.tw-split { display: flex; align-items: stretch; height: 100%; }
.tw-split-left, .tw-split-right { overflow: auto; }
.tw-split-handle {
  width: 6px; cursor: col-resize;
  background: var(--surface-3);
  transition: background var(--dur-fast) var(--ease);
}
.tw-split-handle:hover { background: var(--accent); }
.tw-split-handle:focus-visible { outline: 2px solid var(--focus); }

/* --- Skeleton shimmer --- */
.tw-skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: tw-shimmer 1.4s ease infinite;
  border-radius: var(--radius-md);
}
@keyframes tw-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* --- Focus ring utility --- */
.tw-focus-ring:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* --- Icon --- */
.tw-icon { width: 16px; height: 16px; display: inline-block; }

/* --- Link --- */
.tw-link {
  color: var(--accent); cursor: pointer;
  text-decoration: underline; text-decoration-thickness: 0.08em;
  text-underline-offset: 0.2em;
}
.tw-link:hover { color: var(--accent-hover); }
.tw-link:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Quick navigation is a rounded control, not an inline prose link. */
.tw-quick-link {
  display: inline-flex; align-items: center; min-height: 40px;
  box-sizing: border-box; border-radius: var(--radius-md);
  color: var(--text-2); font-weight: 500; text-decoration: none;
}
.tw-quick-link:hover { color: var(--text-1); background: var(--surface-2); }
.tw-quick-link.active, .tw-quick-link.active:hover {
  color: var(--accent); background: var(--accent-surface); font-weight: 600;
}

/* --- Alert --- */
.tw-alert {
  padding: var(--space-3); border-radius: var(--radius-md);
  border: 1px solid var(--border); font-size: var(--font-sm);
  margin-bottom: var(--space-3);
}
.tw-alert-success { background: var(--success-surface); color: var(--success); border-color: var(--success); }
.tw-alert-error { background: var(--danger-surface); color: var(--danger); border-color: var(--danger); }
.tw-alert-warning { background: var(--warning-surface); color: var(--warning); border-color: var(--warning); }
.tw-alert-info { background: var(--info-surface); color: var(--info); border-color: var(--info); }
.tw-alert-normal { background: var(--surface-2); color: var(--text-1); }

/* --- List --- */
.tw-list { list-style: none; margin: 0; padding: 0; }
.tw-list-item { padding: var(--space-2) 0; border-bottom: 1px solid var(--border); font-size: var(--font-sm); }

/* --- Icon button --- */
.tw-icon-btn {
  width: 40px; height: 40px; display: inline-flex;
  align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--text-1);
  border-radius: var(--radius-sm); cursor: pointer;
}
.tw-icon-btn:hover { background: var(--surface-2); }
.tw-icon-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* --- Image --- */
.tw-image { max-width: 100%; }

/* --- Card content --- */
.tw-card-content { padding: var(--space-4); }

/* --- Progress --- */
.tw-progress { width: 100%; height: 8px; border-radius: var(--radius-sm); accent-color: var(--accent); }
.tw-progress-indeterminate {
  display: block; height: 8px; border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--accent) 25%, var(--accent-surface) 50%, var(--accent) 75%);
  background-size: 200% 100%;
  animation: tw-shimmer 1.4s ease infinite;
}

/* A bounded, centered status above progress; usable before any .NET bootstrap. */
.tw-loading-block {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: min(100%, 20rem);
  margin-inline: auto;
  text-align: center;
}
.tw-loading-status {
  margin: 0;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text-1);
}
.tw-loading-block > .tw-progress {
  flex: none;
  width: 100%;
}
@media (prefers-reduced-motion: reduce) {
  .tw-loading-block > .tw-progress-indeterminate { animation: none; }
}

/* --- Slider --- */
.tw-slider { width: 100%; accent-color: var(--accent); }

/* --- Layout --- */
.tw-layout { position: relative; display: flex; flex: 1; min-height: 0; }

/* --- Nav menu --- */
.tw-nav-menu { display: flex; flex-direction: column; gap: var(--space-1); }
.tw-nav-link {
  display: block; padding: var(--space-2) var(--space-3);
  color: var(--text-2); text-decoration: none; border-radius: var(--radius-md);
  font-size: var(--font-sm); border-left: 3px solid transparent;
  transition: background var(--dur-fast) var(--ease);
}
.tw-nav-link:hover { background: var(--surface-2); color: var(--text-1); }
.tw-nav-link:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.tw-nav-link-active, .tw-nav-link-active:hover {
  background: var(--accent-surface); color: var(--accent);
  border-left-color: var(--accent); font-weight: 600;
}
.tw-nav-match {
  background: var(--accent-surface); color: var(--accent);
  border-radius: var(--radius-sm); padding: 0 1px; font-weight: 600;
}
.tw-nav-actions {
  display: flex; gap: var(--space-1);
  padding: 0 var(--space-2) var(--space-2);
}
.tw-nav-group { display: flex; flex-direction: column; gap: var(--space-1); }
.tw-nav-group-toggle {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: var(--space-2) var(--space-3);
  background: transparent; border: none; cursor: pointer;
  color: var(--text-3); font-weight: 700; text-align: left;
  text-transform: uppercase; letter-spacing: 0.06em; font-size: var(--font-xs);
  border-radius: var(--radius-md); transition: background var(--dur-fast) var(--ease);
}
.tw-nav-group-toggle-label { display: inline-flex; align-items: center; gap: var(--space-2); }
.tw-nav-group-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tw-nav-group-toggle:hover { background: var(--surface-2); color: var(--text-1); }
.tw-nav-group-toggle .tw-icon { transition: transform var(--dur-fast) var(--ease); }
.tw-nav-group-body { display: flex; flex-direction: column; gap: var(--space-1); padding-left: var(--space-2); }

.tw-nav-section-label {
  padding: var(--space-2) var(--space-3) var(--space-1);
  color: var(--text-3); font-weight: 700; text-align: left;
  text-transform: uppercase; letter-spacing: 0.06em; font-size: var(--font-xs);
}
.tw-nav-recent {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
}
.tw-nav-recent-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.tw-nav-badge {
  flex: none; font-size: var(--font-xs); font-weight: 600;
  color: var(--text-3); background: var(--surface-2);
  border-radius: 99px; padding: 0 7px; line-height: 1.5;
}

