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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #222633;
  --border: #2e3340;
  --text: #e4e6ed;
  --text-dim: #8b8fa3;
  --accent: #6c8cff;
  --accent-hover: #829dff;
  --green: #4caf7d;
  --red: #ef5350;
  --orange: #ff9800;
  --radius: 10px;
  --radius-sm: 6px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.hero {
  margin-bottom: 2rem;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hero h1 {
  font-size: 2rem;
  font-weight: 700;
  margin: 0.25rem 0 0.5rem;
}

.hero-copy {
  color: var(--text-dim);
  max-width: 600px;
}

/* Tabs */
.tab-nav {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 0.75rem 1.25rem;
  font-size: 0.95rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Panels */
.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 800px) {
  .panel-grid {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.panel-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

/* Forms */
.form-step {
  margin-bottom: 1.5rem;
}

.form-hint {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.form-select,
.form-input,
select,
input[type="text"],
input[type="date"] {
  width: 100%;
  padding: 0.6rem 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
}

.form-select:focus,
select:focus,
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(108, 140, 255, 0.15);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.field label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}

.field input,
.field select {
  width: 100%;
}

/* Patient fields */
.patient-fields {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.patient-fields h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--accent);
}

/* Items */
.items-container {
  margin-bottom: 1.5rem;
}

.scale-group {
  margin-bottom: 1.25rem;
}

.scale-group-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.5rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.5rem;
}

.item-grid-flat {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.5rem;
}

.item-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.item-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.item-field label {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 500;
}

.scale-badge {
  font-size: 0.6rem;
  font-weight: 700;
  color: #fff;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  white-space: nowrap;
}

.scale-badges {
  display: flex;
  gap: 0.2rem;
  flex-wrap: wrap;
}

.scale-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.legend-chip {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.item-field select {
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
}

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

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

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

button:hover {
  background: var(--border);
}

/* Result display */
.result-display {
  margin-top: 1.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
}

.result-display h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--green);
}

.result-display .result-row {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.result-display .result-row:last-child {
  border-bottom: none;
}

.result-display .result-label {
  color: var(--text-dim);
}

.result-display .result-value {
  font-weight: 600;
}

.result-display .classification {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
}

.classification.clinical {
  background: rgba(239, 83, 80, 0.15);
  color: var(--red);
}

.classification.borderline {
  background: rgba(255, 152, 0, 0.15);
  color: var(--orange);
}

.classification.normal {
  background: rgba(76, 175, 125, 0.15);
  color: var(--green);
}

/* Questionnaire info */
#questionnaire-info {
  font-size: 0.9rem;
}

#questionnaire-info .info-row {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

#questionnaire-info .info-label {
  color: var(--text-dim);
}

#questionnaire-info .scale-list {
  margin-top: 0.75rem;
}

#questionnaire-info .scale-item {
  padding: 0.35rem 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* Result cards */
.result-list,
.patient-list {
  max-height: 500px;
  overflow-y: auto;
}

.result-card,
.patient-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.result-card header,
.patient-card header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
}

.result-card h3,
.patient-card h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

.result-card .meta,
.patient-card .meta {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.2rem;
}

.result-card .badge,
.patient-card .badge {
  background: var(--accent);
  color: #fff;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.result-card .sync {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 0.35rem;
}

.empty-state {
  color: var(--text-dim);
  font-style: italic;
  padding: 1rem 0;
}

/* Loading */
.loading {
  text-align: center;
  padding: 2rem;
  color: var(--text-dim);
}

/* Error */
.error-msg {
  background: rgba(239, 83, 80, 0.1);
  border: 1px solid rgba(239, 83, 80, 0.3);
  color: var(--red);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-top: 1rem;
}

/* ── Result detail ─────────────────────────────────────────── */

.result-detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  overflow-y: auto;
}

.result-detail-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 800px;
  width: 100%;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  position: relative;
}

.result-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.result-detail-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.result-detail-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  line-height: 1;
}

.result-detail-close:hover {
  color: var(--text);
}

.result-detail-body {
  padding: 1.5rem;
}

.result-detail-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.result-detail-meta .meta-item {
  font-size: 0.85rem;
}

.result-detail-meta .meta-label {
  color: var(--text-dim);
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.15rem;
}

.result-detail-meta .meta-value {
  font-weight: 600;
}

/* Scale result cards */
.scale-result-section {
  margin-bottom: 1.5rem;
}

.scale-result-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--accent);
}

.scale-result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.scale-result-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
}

.scale-result-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.scale-result-table tr:last-child td {
  border-bottom: none;
}

.scale-result-table .scale-name {
  font-weight: 600;
}

.scale-result-table .scale-id {
  color: var(--text-dim);
  font-size: 0.75rem;
}

/* Classification badges */
.badge-classification {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-classification.elevado,
.badge-classification.clinical {
  background: rgba(239, 83, 80, 0.15);
  color: var(--red);
}

.badge-classification.borderline {
  background: rgba(255, 152, 0, 0.15);
  color: var(--orange);
}

.badge-classification.normal {
  background: rgba(76, 175, 125, 0.15);
  color: var(--green);
}

/* Responses table */
.responses-section {
  margin-top: 1.5rem;
}

.responses-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--accent);
}

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

.responses-table th {
  text-align: left;
  padding: 0.4rem 0.6rem;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}

.responses-table td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

.responses-table tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}

.responses-table .item-num {
  color: var(--text-dim);
  font-weight: 600;
  width: 40px;
}

.responses-table .item-text {
  max-width: 300px;
}

.responses-table .item-value {
  text-align: center;
  font-weight: 700;
  width: 50px;
}

.responses-table .item-reverse {
  text-align: center;
  width: 30px;
}

.responses-table .reverse-yes {
  color: var(--orange);
  font-size: 0.7rem;
}

/* Global score highlight */
.global-score-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.global-score-card .score-label {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.global-score-card .score-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.global-score-card .score-classification {
  font-size: 0.85rem;
  font-weight: 600;
}

/* Expandable result card */
.result-card {
  cursor: pointer;
  transition: border-color 0.2s;
}

.result-card:hover {
  border-color: var(--accent);
}

.result-card .expand-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.35rem;
}

/* Toggle for responses */
.toggle-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  margin-bottom: 0.75rem;
}

.toggle-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.toggle-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
