:root {
  --radius:         12px;
  --radius-sm:      8px;
  --radius-pill:    999px;

  --font-mono:      'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --font-sans:      -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  --emotion-medo:      #e11d48;
  --emotion-raiva:     #ea580c;
  --emotion-tristeza:  #2563eb;
  --emotion-desespero: #7c3aed;
  --emotion-surpresa:  #d97706;
  --emotion-alivio:    #059669;
  --emotion-confusao:  #db2777;
  --emotion-calma:     #0d9488;

  --badge-positive: #15803d;
  --badge-negative: #b91c1c;
  --badge-neutral:  #6b7280;
  --badge-mixed:    #b45309;
}

:root[data-theme="light"] {
  --bg-base:        #fdf6f8;
  --bg-card:        #ffffff;
  --bg-elevated:    #fbe9ee;
  --bg-input:       #fdf6f8;

  --border:         #f3d4dc;
  --border-focus:   #ec4899;

  --text-primary:   #2d1b2e;
  --text-secondary: #6b5560;
  --text-muted:     #a8939d;

  --accent:         #db2777;
  --accent-hover:   #be185d;
  --danger:         #b91c1c;
  --danger-bg:      #fdecec;
  --success:        #15803d;
  --warning:        #b45309;

  --shadow-card:    0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.04);
  --shadow-pop:     0 10px 30px rgba(0, 0, 0, 0.12);
}

:root[data-theme="dark"] {
  --bg-base:        #14101e;
  --bg-card:        #1d1830;
  --bg-elevated:    #2a2342;
  --bg-input:       #110d1a;

  --border:         #3a3252;
  --border-focus:   #c4a7ff;

  --text-primary:   #ece7f5;
  --text-secondary: #a89cc4;
  --text-muted:     #6b6188;

  --accent:         #7c3aed;
  --accent-hover:   #8b5cf6;
  --danger:         #f87171;
  --danger-bg:      #2a1620;
  --success:        #6ee7b7;
  --warning:        #fbbf24;

  --shadow-card:    0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-pop:     0 10px 30px rgba(0, 0, 0, 0.4);
}

body,
.card,
textarea,
.model-trigger,
.model-dropdown,
.summary-badge,
.theme-toggle {
  transition: background-color 0.25s ease,
              color 0.25s ease,
              border-color 0.25s ease,
              box-shadow 0.25s ease;
}

@media (prefers-reduced-motion: reduce) {
  body,
  .card,
  textarea,
  .model-trigger,
  .model-dropdown,
  .summary-badge,
  .theme-toggle {
    transition: none;
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 2rem 1rem;
  transition: max-width 0.35s ease;
}

header {
  position: relative;
  text-align: center;
  margin-bottom: 3.5rem;
}

.theme-toggle {
  position: absolute;
  top: 0;
  right: 0;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}

.theme-toggle:hover {
  background: var(--bg-elevated);
  border-color: var(--border-focus);
}

.theme-toggle:focus-visible {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--border-focus) 35%, transparent);
}

.theme-toggle__icon {
  display: inline-block;
}

header h1 {
  margin: 0 0 0.5rem 0;
  font-size: 2rem;
  font-weight: 600;
}

header .subtitle {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

main {
  display: flex;
  flex-direction: column;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-card);
}

.field-group {
  margin-bottom: 1.5rem;
}

.field-group:last-child {
  margin-bottom: 0;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  font-size: 0.9rem;
}

textarea,
.text-input {
  width: 100%;
  padding: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

textarea {
  resize: vertical;
}

textarea:focus,
.text-input:focus {
  outline: none;
  border-color: var(--border-focus);
}

/* Model Selector */
.model-selector {
  position: relative;
}

.model-trigger {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.9rem;
  transition: border-color 0.2s;
}

.model-trigger:hover {
  border-color: var(--border-focus);
}

.model-trigger[aria-expanded="true"] {
  border-color: var(--border-focus);
}

.model-trigger__label {
  flex: 1;
  text-align: left;
}

.model-trigger__arrow {
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.model-trigger[aria-expanded="true"] .model-trigger__arrow {
  transform: scaleY(-1);
}

.model-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  list-style: none;
  padding: 0.25rem 0;
  margin: 0;
  max-height: 240px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: var(--shadow-pop);
}

.model-dropdown[hidden] {
  display: none;
}

.model-option {
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background-color 0.15s;
}

.model-option__provider {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.model-option__name {
  font-size: 0.9rem;
  color: var(--text-primary);
}

.model-option:hover,
.model-option[aria-selected="true"] {
  background: var(--bg-elevated);
}

.field-hint {
  margin: 0.5rem 0 0 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Analyze Button */
.btn-analyze {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: background-color 0.2s;
  width: 100%;
}

.btn-analyze:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-analyze:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-analyze__spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.btn-analyze__spinner:not([hidden]) {
  display: inline-block;
}

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

/* Result Card */
.result-card {
  border-color: var(--border);
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.result-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.result-meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: right;
}

.sentiments-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.sentiment-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sentiment-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 500;
}

.sentiment-bar-track {
  height: 8px;
  background: var(--bg-elevated);
  border-radius: 4px;
  overflow: hidden;
}

.sentiment-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--text-muted);
  transition: width 0.4s ease, background-color 0.25s ease;
}

.sentiment-bar-fill[data-emotion="medo"]      { background: var(--emotion-medo); }
.sentiment-bar-fill[data-emotion="raiva"]     { background: var(--emotion-raiva); }
.sentiment-bar-fill[data-emotion="tristeza"]  { background: var(--emotion-tristeza); }
.sentiment-bar-fill[data-emotion="desespero"] { background: var(--emotion-desespero); }
.sentiment-bar-fill[data-emotion="surpresa"]  { background: var(--emotion-surpresa); }
.sentiment-bar-fill[data-emotion="alivio"]    { background: var(--emotion-alivio); }
.sentiment-bar-fill[data-emotion="confusao"]  { background: var(--emotion-confusao); }
.sentiment-bar-fill[data-emotion="calma"]     { background: var(--emotion-calma); }

.sentiment-value {
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.result-summary {
  display: grid;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
}

.summary-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.summary-label {
  min-width: 140px;
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.summary-badge {
  padding: 0.3rem 0.6rem;
  background: var(--badge-positive);
  color: #fff;
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  font-weight: 500;
}

.summary-badge.negative {
  background: var(--badge-negative);
}

.summary-badge.neutral {
  background: var(--badge-neutral);
}

.summary-badge.mixed {
  background: var(--badge-mixed);
}

.summary-intensity {
  flex: 1;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
}

.summary-intensity-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.summary-confidence {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.summary-justificativa {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-primary);
}

.raw-json {
  margin-top: 1rem;
}

.raw-json summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 0.5rem;
  border-radius: 4px;
  user-select: none;
  transition: background-color 0.15s;
}

.raw-json summary:hover {
  background: var(--bg-elevated);
}

.raw-json pre {
  margin: 0.75rem 0 0 0;
  padding: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.4;
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
}

/* Error Card */
.error-card {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.error-card h2 {
  color: var(--danger);
  margin-top: 0;
}

#error-message {
  margin: 0;
  color: var(--text-primary);
  word-break: break-word;
}

/* ── Split layout ── */
.container.layout--split {
  max-width: 1280px;
}

.container.layout--split #main-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

/* Form card: coluna 1 */
.container.layout--split #main-content > .card:first-child {
  grid-column: 1;
  grid-row: 1;
  margin-bottom: 0;
}

/* Result card: coluna 2 */
.container.layout--split #result-section {
  grid-column: 2;
  grid-row: 1;
  margin-bottom: 0;
}

/* Fade-in no resultado */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.result-card.result--animate {
  animation: fadeInUp 0.3s ease forwards;
}

/* ── Mobile ≤899px: layout de coluna única ── */
@media (max-width: 899px) {
  .container.layout--split {
    max-width: 760px;
  }

  .container.layout--split #main-content {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .container.layout--split #main-content > .card:first-child,
  .container.layout--split #result-section {
    grid-column: unset;
    grid-row: unset;
    margin-bottom: 1.5rem;
  }
}
