/* ========== GLOBAL ========== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f5f5f7;
  --bg-card: #ffffff;
  --border-subtle: rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 2px 6px rgba(15, 23, 42, 0.06);
  --text-main: #111827;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --accent-strong: #1d4ed8;
  --danger-soft: #fee2e2;
  --danger-strong: #b91c1c;
  --neutral-soft: #e5e7eb;
  --chip-bg: #f3f4f6;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 600;
}

p {
  margin: 0 0 0.35rem;
}

/* ========== HEADER ========== */
.app-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border-subtle);
}

.app-header-inner {
  max-width: 1160px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.app-title-block {
  max-width: 640px;
}

.app-title {
  font-size: 1.4rem;
}

.app-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ========== LAYOUT ========== */
.app-main {
  max-width: 1160px;
  margin: 1.25rem auto 2rem;
  padding: 0 1.25rem;
  display: flex;
  gap: 1.5rem;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel-input {
  flex: 0 0 40%;
}

.panel-output {
  flex: 1;
}

.panel-title {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* ========== CARDS ========== */
.card {
  background: var(--bg-card);
  border-radius: 0.9rem;
  padding: 1rem 1rem 1.1rem;
  box-shadow: var(--shadow-soft);
}

.card-title {
  font-size: 1rem;
  margin-bottom: 0.65rem;
}

/* ========== FORM ELEMENTS ========== */
.form-group {
  margin-bottom: 0.7rem;
}

label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 0.25rem;
  color: #374151;
}

.label-optional {
  font-weight: normal;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.text-input,
.textarea-input,
.file-input {
  width: 100%;
  font: inherit;
  border-radius: 0.6rem;
  border: 1px solid rgba(15, 23, 42, 0.15);
  padding: 0.45rem 0.55rem;
  background: #ffffff;
}

.textarea-input {
  resize: vertical;
  min-height: 2.2rem;
}

.text-input:focus,
.textarea-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft);
}

.file-input {
  padding: 0.3rem 0.25rem;
}

.helper-text {
  font-size: 0.75rem;
  color: var(--text-muted);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
    monospace;
  font-size: 0.75rem;
  background: #f9fafb;
  padding: 0.15rem 0.3rem;
  border-radius: 0.25rem;
}

/* ========== BUTTONS ========== */
.primary-button,
.secondary-button,
.ghost-button {
  font: inherit;
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  white-space: nowrap;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  background: #e5e7eb;
  color: #111827;
}

.secondary-button:hover {
  background: #d4d4d8;
}

.ghost-button {
  background: transparent;
  border: 1px solid rgba(15, 23, 42, 0.12);
  color: #374151;
}

.ghost-button:hover {
  background: rgba(15, 23, 42, 0.03);
}

.form-footer {
  margin-top: 0.75rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.alias-footer {
  justify-content: flex-start;
}

/* ========== STUDIES LIST ========== */
.studies-list {
  margin-top: 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.study-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  border-radius: 0.6rem;
  background: #f9fafb;
  border: 1px solid rgba(15, 23, 42, 0.08);
  font-size: 0.8rem;
}

.study-chip-main {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.study-chip-title {
  font-weight: 500;
}

.study-chip-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.study-chip-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.chip-button {
  border-radius: 999px;
  border: none;
  padding: 0.2rem 0.5rem;
  font-size: 0.7rem;
  background: transparent;
  color: #4b5563;
  cursor: pointer;
}

.chip-button:hover {
  background: rgba(15, 23, 42, 0.06);
}

/* ========== ALIAS LIST ========== */
.alias-editor {
  margin-bottom: 0.65rem;
  border-radius: 0.65rem;
  padding: 0.6rem 0.7rem;
  background: #f9fafb;
}

.alias-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.25rem;
}

.alias-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  font-size: 0.8rem;
}

.alias-canonical {
  font-weight: 600;
}

.alias-badge {
  background: #e5e7eb;
  border-radius: 999px;
  padding: 0.15rem 0.45rem;
}

.alias-actions {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.5rem;
}

/* ========== SUMMARY CARD ========== */
.card-summary {
  border-left: 3px solid #e5e7eb;
}

.summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.summary-program-name {
  font-weight: 500;
  font-size: 0.95rem;
}

.summary-pill {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
}

.summary-pill-neutral {
  background: var(--neutral-soft);
  color: #4b5563;
}

.summary-pill-good {
  background: #dcfce7;
  color: #166534;
}

.summary-pill-warning {
  background: #fef9c3;
  color: #854d0e;
}

.summary-pill-bad {
  background: var(--danger-soft);
  color: var(--danger-strong);
}

.summary-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.summary-stat {
  min-width: 90px;
}

.summary-stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.summary-stat-value {
  font-size: 1rem;
  font-weight: 600;
}

.summary-list {
  padding-left: 1.1rem;
  margin: 0;
  font-size: 0.85rem;
}

/* ========== CHIPS (CORE / EXTENDED) ========== */
.chip-section + .chip-section {
  margin-top: 0.75rem;
}

.chip-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.8rem;
  background: var(--chip-bg);
  color: #111827;
}

.chip-muted {
  background: #f9fafb;
  color: var(--text-muted);
}

/* ========== MATRIX TABLE ========== */
.matrix-wrapper {
  position: relative;
  border-radius: 0.65rem;
  border: 1px solid rgba(15, 23, 42, 0.08);
  overflow: hidden;
}

.matrix-scroll-hint {
  font-size: 0.75rem;
  padding: 0.3rem 0.5rem;
  background: #f9fafb;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
  color: var(--text-muted);
}

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.matrix-table th,
.matrix-table td {
  padding: 0.35rem 0.45rem;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
  border-right: 1px solid rgba(15, 23, 42, 0.03);
  text-align: left;
}

.matrix-table th:last-child,
.matrix-table td:last-child {
  border-right: none;
}

.matrix-table thead {
  position: sticky;
  top: 0;
  background: #f9fafb;
  z-index: 1;
}

.matrix-col-biomarker {
  min-width: 150px;
}

.matrix-cell-present {
  text-align: center;
}

.matrix-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.8rem;
}

.matrix-placeholder {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ========== RESULTS LISTS ========== */
.two-column {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.subsection-title {
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.result-list {
  padding-left: 1.1rem;
  margin: 0;
  font-size: 0.8rem;
}

.placeholder-text {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ========== EXPORT AREA ========== */
.export-textarea {
  margin-top: 0.6rem;
  font-size: 0.8rem;
}

/* ========== FOOTER ========== */
.app-footer {
  padding: 1rem 1.25rem 1.5rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 960px) {
  .app-main {
    flex-direction: column;
  }

  .panel-input,
  .panel-output {
    flex: 1 1 auto;
  }
}

@media (max-width: 720px) {
  .app-header-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .two-column {
    grid-template-columns: 1fr;
  }

  .summary-stats {
    gap: 0.5rem;
  }
}


