/* ReAnalyst SSR — design system */
:root {
  --bg: #0c1117;
  --bg-elevated: #131b24;
  --surface: #1a2332;
  --border: #2d3a4d;
  --text: #e6edf3;
  --text-muted: #7d8590;
  --accent: #e4a853;
  --accent-dim: #c4933f;
  --error-bg: rgba(248, 81, 73, 0.12);
  --error-border: #f85149;
  --success-bg: rgba(46, 160, 67, 0.12);
  --success-border: #2ea043;
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'IBM Plex Sans', system-ui, sans-serif;
  --radius: 6px;
  --transition: 0.2s ease;
}

* { box-sizing: border-box; }

body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 120% 80% at 50% -20%, rgba(228, 168, 83, 0.06), transparent),
    linear-gradient(180deg, var(--bg) 0%, #0f1419 100%);
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

.layout {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1rem 2.5rem;
  box-sizing: border-box;
}

@media (min-width: 640px) {
  .layout { padding: 1.5rem 1.5rem 3rem; }
}

@media (min-width: 1024px) {
  .layout { padding: 2rem 2rem 3rem; }
}

nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.5rem;
  padding-bottom: 1.5rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

nav .brand {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-right: auto;
}

nav .brand a {
  color: var(--text);
  text-decoration: none;
  transition: color var(--transition);
}

nav .brand a:hover { color: var(--accent); }

nav a:not(.brand a) {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  transition: color var(--transition), background var(--transition);
}

nav a:not(.brand a):hover {
  color: var(--accent);
  background: rgba(228, 168, 83, 0.08);
}

nav a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent);
}

nav .nav-sep {
  width: 1px;
  height: 1.25rem;
  margin-left: 0.25rem;
  margin-right: 0.5rem;
  background: var(--border);
  flex-shrink: 0;
}

nav .lang-switch {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

nav .lang-switch a { color: var(--text-muted); }
nav .lang-switch a.active { color: var(--accent); font-weight: 600; }
nav .lang-divider {
  color: var(--border);
  user-select: none;
  font-weight: 400;
}

/* Active nav link by body class */
body.extract nav a[href*="/app/extract"],
body.competencies nav a[href*="/app/competencies"],
body.tables nav a[href*="/app/tables"],
body.search nav a[href*="/app/search"],
body.map nav a[href*="/app/map"],
body.zpd nav a[href*="/app/zpd"],
body.compare nav a[href*="/app/compare"],
body.settings nav a[href*="/app/settings"],
body.diagnostics nav a[href*="/app/diagnostics"] {
  color: var(--accent);
  background: rgba(228, 168, 83, 0.08);
}

/* Cards and sections for grouping content */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}
.card:last-child { margin-bottom: 0; }

.section {
  margin-bottom: 2rem;
}
.section:last-child { margin-bottom: 0; }
.section-title {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
  color: var(--text);
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

main {
  animation: fadeUp 0.5s ease backwards;
}

main .reveal { animation: fadeUp 0.45s ease backwards; }

main .reveal:nth-child(1) { animation-delay: 0.05s; }
main .reveal:nth-child(2) { animation-delay: 0.1s; }
main .reveal:nth-child(3) { animation-delay: 0.15s; }
main .reveal:nth-child(4) { animation-delay: 0.2s; }
main .reveal:nth-child(5) { animation-delay: 0.25s; }
main .reveal:nth-child(6) { animation-delay: 0.3s; }
main .reveal:nth-child(7) { animation-delay: 0.35s; }
main .reveal:nth-child(8) { animation-delay: 0.4s; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

h1 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  letter-spacing: -0.02em;
  color: var(--text);
}

h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  margin: 1.5rem 0 0.5rem;
  color: var(--text);
}

p { margin: 0 0 0.75rem; color: var(--text-muted); }

a[href]:not(nav a) {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition);
}

a[href]:not(nav a):hover { border-bottom-color: var(--accent); }

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

.form-group label {
  display: block;
  font-weight: 500;
  font-size: 0.875rem;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.form-group .form-hint,
.form-group .muted {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Settings: model combobox (searchable list + provider pricing) */
.model-combobox { position: relative; max-width: 32rem; }
.model-combobox-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  width: 100%;
  max-width: 32rem;
}
.model-combobox-row input[type="text"] {
  flex: 1;
  min-width: 0;
  max-width: none;
}
.model-combobox-toggle {
  flex-shrink: 0;
  white-space: nowrap;
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  transform: none !important;
}
.model-combobox-toggle:hover {
  background: var(--border) !important;
  transform: none !important;
}
.model-combobox-panel {
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  margin-top: 0.35rem;
  max-height: 280px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.model-combobox-panel[hidden] { display: none !important; }
.model-combobox-filter {
  margin: 0.5rem 0.5rem 0;
  width: calc(100% - 1rem);
  max-width: none;
}
.model-combobox-list {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0 0.5rem;
  overflow-y: auto;
  max-height: 220px;
}
.model-combobox-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.75rem;
  padding: 0.45rem 0.65rem;
  cursor: pointer;
  border-top: 1px solid transparent;
  font-size: 0.8125rem;
  line-height: 1.35;
}
.model-combobox-item:hover,
.model-combobox-item:focus {
  background: rgba(228, 168, 83, 0.1);
}
.model-combobox-item-id {
  font-weight: 500;
  color: var(--text);
  word-break: break-all;
}
.model-combobox-item-name {
  color: var(--text-muted);
  flex: 1 1 100%;
}
.model-combobox-item-price {
  color: var(--accent-dim);
  font-size: 0.75rem;
  flex: 1 1 100%;
}
.model-pricing-hint {
  margin-top: 0.4rem;
  margin-bottom: 0;
}

input[type="text"],
input[type="number"],
input[type="file"],
select,
textarea {
  font-family: var(--font-body);
  font-size: 0.9375rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  transition: border-color var(--transition), box-shadow var(--transition);
}

@media (min-width: 640px) {
  input[type="text"],
  input[type="number"],
  input[type="file"],
  textarea { max-width: 32rem; }
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(228, 168, 83, 0.15);
}

input::placeholder,
textarea::placeholder { color: var(--text-muted); opacity: 0.8; }

textarea { min-height: 7rem; resize: vertical; }

select { width: auto; min-width: 11rem; cursor: pointer; }

input[type="file"] {
  padding: 0.4rem 0;
  font-size: 0.875rem;
}

button, .btn {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.9375rem;
  padding: 0.5rem 1.15rem;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--bg);
  transition: background var(--transition), transform var(--transition);
}

button:hover, .btn:hover {
  background: var(--accent-dim);
  transform: translateY(-1px);
}

button:active, .btn:active { transform: translateY(0); }

button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

button:focus-visible,
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(228, 168, 83, 0.35);
}

.btn-link {
  border: none;
  background: transparent;
  color: var(--accent);
  padding: 0;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-link:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
}

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.field-error {
  color: #f85149;
  font-size: 0.82rem;
  margin-top: 0.3rem;
}

.toast-wrap {
  position: fixed;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 1000;
}

.toast {
  min-width: 220px;
  max-width: 360px;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.toast.success {
  border-color: var(--success-border);
}

.toast.error {
  border-color: var(--error-border);
}

.message {
  margin: 1rem 0 1.25rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border-left: 4px solid;
  font-size: 0.9375rem;
}

.message.error {
  background: var(--error-bg);
  border-left-color: var(--error-border);
  color: #f85149;
}

.message.success {
  background: var(--success-bg);
  border-left-color: var(--success-border);
  color: #2ea043;
}

/* Progress bar (multiple file upload) */
.progress-wrap {
  margin: 1rem 0 1.5rem;
  display: none;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 4rem;
}

.progress-wrap.visible { display: block; }

.progress-bar {
  height: 10px;
  background: var(--bg-elevated);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress-bar-inner {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: 5px;
  width: 0%;
  transition: width 0.25s ease;
}

.progress-text {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 1rem;
}
.card > .table-wrap:first-child { margin-top: 0; }
.table-wrap table { margin-top: 0; }

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 600px;
  margin-top: 1rem;
  font-size: 0.9rem;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  word-wrap: break-word;
  border-bottom: 1px solid var(--border);
}

/* Long text column in competencies/search tables */
table td:nth-child(4) { max-width: 28rem; }

th {
  background: var(--surface);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tbody tr { transition: background var(--transition); }

tbody tr:hover { background: rgba(228, 168, 83, 0.04); }

tbody tr:last-child td { border-bottom: none; }

/* Extract page: uploaded docs table actions */
.retry-btn,
.download-btn {
  margin-right: 0.5rem;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
  padding: 0.35rem 0.65rem;
  font-size: 0.8125rem;
}
.retry-btn:hover,
.download-btn:hover {
  background: rgba(228, 168, 83, 0.1);
  border-color: var(--accent);
}
.delete-btn {
  margin-right: 0;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0.35rem 0.65rem;
  font-size: 0.8125rem;
}
.delete-btn:hover {
  color: #f85149;
  border-color: #f85149;
  background: var(--error-bg);
}

.pagination { margin-top: 1.5rem; display: flex; gap: 0.75rem; flex-wrap: wrap; }

.pagination a {
  font-weight: 500;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--border);
  transition: background var(--transition), border-color var(--transition);
}

.pagination a:hover {
  background: rgba(228, 168, 83, 0.1);
  border-color: var(--accent);
}

.pagination a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(228, 168, 83, 0.4);
}

/* Empty table state */
tbody tr.empty-row td {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
}

.muted { color: var(--text-muted); font-size: 0.9rem; }
.muted .nav-divider { margin: 0 0.5rem; color: var(--border); }

.page-lead { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.9375rem; }

.diagnostics-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.diagnostics-list li {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1.5rem;
  line-height: 1.5;
}

.diagnostics-list li:last-child { border-bottom: none; }
.diagnostics-list .key { color: var(--text-muted); font-size: 0.9375rem; }
.diagnostics-list .value { font-weight: 500; color: var(--text); text-align: right; }

.tables-list { margin-top: 1rem; }
.tables-list table { margin-top: 0.5rem; }

.badge.distance {
  display: inline-block;
  padding: 0.2em 0.5em;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}

/* Graph component (vis-network) */
.graph-section .graph-container-vis {
  width: 100%;
  height: 560px;
  min-height: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.graph-section .graph-container-vis:focus-within {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent);
}
.graph-section .graph-container-vis canvas {
  background: var(--surface) !important;
}

/* Custom node tooltip (map): description + match % */
.map-node-tooltip {
  max-width: 320px;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.map-node-tooltip br + br { margin-top: 0.35em; }

/* Map display options panel */
.map-display-options {
  padding: 0.75rem 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.map-display-options summary {
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
  user-select: none;
}
.map-display-options summary:hover {
  color: var(--text);
}
.map-options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
  gap: 1rem 1.5rem;
  margin-top: 1rem;
  align-items: end;
}
.map-options-grid .form-group {
  margin-bottom: 0;
}
.map-options-grid input[type="range"] {
  vertical-align: middle;
}
.map-options-grid .btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.map-options-grid .btn-secondary:hover {
  background: var(--border);
}

/* Selection tables (ZPD) */
.selection-table-wrap {
  margin-top: 1rem;
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}
.selection-table-wrap table { margin-top: 0; }
.selection-search {
  margin-bottom: 0.5rem;
  max-width: 24rem;
}
.selection-table-wrap input[type="checkbox"],
.selection-table-wrap input[type="radio"] {
  width: auto;
  max-width: none;
  cursor: pointer;
}
.selection-table-wrap td {
  vertical-align: middle;
}
.zpd-selection-caption {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}
