/* Cross-feature components. Feature styles should compose these primitives. */

.app-panel {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  box-shadow: var(--shadow-xs);
}

.app-panel.is-subtle {
  border-color: transparent;
  background: var(--surface-subtle);
  box-shadow: none;
}

.app-panel.is-flat {
  border-color: transparent;
  box-shadow: none;
}

.question-blank {
  display: inline-block;
  box-sizing: border-box;
  width: 5em;
  min-width: 4em;
  height: 1em;
  margin-inline: 0.08em;
  border-bottom: 1px solid currentColor;
  vertical-align: -0.12em;
  white-space: nowrap;
}

.app-panel.is-primary {
  border-color: var(--primary-border);
  background: var(--primary-soft);
}

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

.app-section-header h2,
.app-section-header h3 {
  margin-top: 3px;
  line-height: var(--lh-tight);
}

.app-section-header p {
  margin-top: var(--space-1);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.app-action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.app-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-1);
  padding: var(--space-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}

.app-tabs.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.app-tabs > button,
.app-tabs > [role="tab"] {
  min-height: 36px;
  border-color: transparent;
  padding: 6px 12px;
  background: transparent;
  color: var(--text-secondary);
}

.app-tabs > button:not(:disabled):hover,
.app-tabs > [role="tab"]:not(:disabled):hover {
  border-color: transparent;
  background: color-mix(in srgb, var(--surface-raised) 72%, transparent);
  color: var(--text);
}

.app-tabs > button.active,
.app-tabs > button.is-active,
.app-tabs > button[aria-selected="true"],
.app-tabs > [role="tab"].active,
.app-tabs > [role="tab"].is-active,
.app-tabs > [role="tab"][aria-selected="true"] {
  border-color: var(--primary-border);
  background: var(--surface-raised);
  color: var(--primary);
  box-shadow: var(--shadow-xs);
  font-weight: 650;
}

.app-tabs.is-compact {
  display: inline-flex;
  grid-template-columns: none;
  border-color: transparent;
  border-radius: var(--radius-full);
}

.app-tabs.is-compact > button {
  flex: 0 0 auto;
  min-height: 32px;
  border-radius: var(--radius-full);
  padding: 5px 11px;
}

.app-tabs.is-underline {
  display: flex;
  grid-template-columns: none;
  gap: var(--space-1);
  padding: 0;
  border-width: 0 0 1px;
  border-radius: 0;
  background: transparent;
}

.app-tabs.is-underline > button {
  flex: 0 0 auto;
  border-width: 0 0 2px;
  border-radius: 0;
  box-shadow: none;
}

.app-tabs.is-underline > button:not(:disabled):hover {
  border-bottom-color: var(--border-emphasis);
  background: transparent;
}

.app-tabs.is-underline > button.active,
.app-tabs.is-underline > button.is-active,
.app-tabs.is-underline > button[aria-selected="true"] {
  border-bottom-color: var(--primary);
  background: transparent;
  color: var(--primary);
  box-shadow: none;
}

.app-field-grid {
  display: grid;
  align-items: end;
  gap: var(--space-3);
}

.app-field {
  display: grid;
  gap: var(--space-1);
}

.app-alert {
  padding: 10px 12px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.app-alert:empty {
  display: none;
}

.app-alert.is-good {
  border-color: var(--good-border);
  background: var(--good-soft);
  color: var(--good);
}

.app-alert.is-warning {
  border-color: var(--warn-border);
  background: var(--warn-soft);
  color: var(--warn);
}

.app-alert.is-error,
.app-alert.error {
  border-color: var(--bad-border);
  background: var(--bad-soft);
  color: var(--bad);
}

.app-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 3px 10px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  background: var(--surface-subtle);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 600;
}

.app-status.is-ready,
.app-status.is-good {
  border-color: var(--good-border);
  background: var(--good-soft);
  color: var(--good);
}

.app-status.is-warning {
  border-color: var(--warn-border);
  background: var(--warn-soft);
  color: var(--warn);
}

.app-status.is-error {
  border-color: var(--bad-border);
  background: var(--bad-soft);
  color: var(--bad);
}

.app-status-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: var(--radius-full);
  background: currentColor;
}

.app-status.is-loading .app-status-dot {
  animation: app-status-pulse 1.1s ease-in-out infinite alternate;
}

@keyframes app-status-pulse {
  from { opacity: 0.25; }
  to { opacity: 1; }
}

.app-progress {
  height: 8px;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--border-default);
}

.app-progress-bar {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width var(--dur-med) var(--ease);
}

.app-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: var(--space-3);
}

.app-metric {
  min-width: 0;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}

.app-metric > dt,
.app-metric > .app-metric-label {
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

.app-table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.app-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.app-table-wrap th,
.app-table-wrap td {
  border-bottom: 1px solid var(--border-default);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

.app-dialog {
  width: min(560px, calc(100% - (2 * var(--app-page-gutter))));
  max-height: min(82vh, 760px);
  overflow: auto;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.app-dialog::backdrop {
  background: color-mix(in srgb, var(--ink) 48%, transparent);
}

.app-button-link {
  display: inline-flex;
  min-height: 41px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-emphasis);
  border-radius: var(--radius-md);
  padding: 9px 14px;
  background: var(--surface-raised);
  color: var(--text);
  text-decoration: none;
}

.app-button-link:not(.is-disabled):hover {
  border-color: var(--text-tertiary);
  background: var(--surface-subtle);
}

.app-button-link.is-disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.inline-question-asset {
  display: inline-block;
  max-width: calc(100% - 0.36em);
  height: auto;
  margin: 0.08em 0.18em;
  vertical-align: middle;
  object-fit: contain;
}

/* Material charts/text images are block assets; unresolved small symbols stay inline. */
.material-asset {
  display: block;
  clear: both;
  width: fit-content;
  max-width: 100%;
  margin: 16px auto;
  padding: 0;
  overflow: visible;
  text-align: center;
}

.material-asset-image {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  object-fit: contain;
}

.material-asset figcaption {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: 1.4;
  text-align: center;
}

.percentage-value {
  display: inline;
  white-space: nowrap;
  font: inherit;
  font-variant-numeric: tabular-nums;
}

.option-text .inline-question-asset,
.exam-option .inline-question-asset {
  max-height: min(14rem, 42vh);
}

@media (max-width: 640px) {
  .app-section-header {
    align-items: stretch;
    flex-direction: column;
  }

  .app-section-header > .app-action-row {
    justify-content: flex-start;
  }

  .app-dialog {
    padding: var(--space-4);
  }
}
