/* =========================================================
   КРЕДИТНАЯ ДИАГНОСТИКА — UI 2026
   Тёмная премиум-тема (по умолчанию) + светлая через [data-theme="light"]
   ========================================================= */

/* ===================== ТЁМНАЯ ТЕМА (дефолт) ===================== */
:root {
  --bg: #050507;
  --surface: rgba(255, 255, 255, 0.03);
  --surface-hover: rgba(255, 255, 255, 0.06);
  --surface-strong: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(99, 102, 241, 0.5);
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #6366f1;
  --primary-strong: #4f46e5;
  --primary-soft: rgba(99, 102, 241, 0.15);
  --primary-border: rgba(99, 102, 241, 0.28);
  --primary-text: #a5b4fc;
  --primary-glow: rgba(99, 102, 241, 0.35);
  --accent: #34d399;
  --accent-soft: rgba(16, 185, 129, 0.15);
  --danger: #f87171;
  --danger-soft: rgba(239, 68, 68, 0.15);
  --warning: #fbbf24;
  --warning-soft: rgba(245, 158, 11, 0.15);
  --info: #60a5fa;
  --info-soft: rgba(59, 130, 246, 0.15);
  --positive: var(--accent);
  --positive-bg: rgba(16, 185, 129, 0.15);
  --positive-border: rgba(16, 185, 129, 0.25);
  --positive-text: #6ee7b7;
  --negative: var(--danger);
  --negative-bg: rgba(239, 68, 68, 0.15);
  --negative-border: rgba(239, 68, 68, 0.25);
  --negative-text: #fca5a5;
  --caution: var(--warning);
  --caution-bg: rgba(245, 158, 11, 0.15);
  --caution-border: rgba(245, 158, 11, 0.25);
  --caution-text: #fcd34d;
  --neutral: var(--info);
  --neutral-bg: rgba(59, 130, 246, 0.15);
  --neutral-border: rgba(59, 130, 246, 0.25);
  --radius: 20px;
  --radius-sm: 14px;
  --radius-xs: 10px;
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 25px 50px rgba(0, 0, 0, 0.5);
}

/* ===================== СВЕТЛАЯ ТЕМА ===================== */
:root[data-theme="light"] {
  --bg: #f4efe8;
  --surface: #fffdf9;
  --surface-hover: #f0ebe3;
  --surface-strong: #f6f1ea;
  --border: #d8cfc2;
  --border-hover: rgba(30, 111, 92, 0.5);
  --text: #1d2a33;
  --text-muted: #6a706e;
  --text-dim: #8a918e;
  --primary: #1e6f5c;
  --primary-strong: #2a9d8f;
  --primary-soft: rgba(30, 111, 92, 0.12);
  --primary-border: rgba(30, 111, 92, 0.28);
  --primary-text: #164d40;
  --primary-glow: rgba(30, 111, 92, 0.25);
  --accent: #1e6f5c;
  --accent-soft: rgba(30, 111, 92, 0.12);
  --danger: #a33232;
  --danger-soft: rgba(163, 50, 50, 0.12);
  --warning: #c36a21;
  --warning-soft: rgba(195, 106, 33, 0.15);
  --info: #3b6f8a;
  --info-soft: rgba(59, 111, 138, 0.12);
  --positive: var(--accent);
  --positive-bg: #d8eee7;
  --positive-border: #8bbdae;
  --positive-text: #164d40;
  --negative: var(--danger);
  --negative-bg: #f6d7d7;
  --negative-border: #d69a9a;
  --negative-text: #7d1f1f;
  --caution: var(--warning);
  --caution-bg: #f4dfbf;
  --caution-border: #d6b273;
  --caution-text: #7d5500;
  --neutral: var(--info);
  --neutral-bg: rgba(59, 111, 138, 0.12);
  --neutral-border: rgba(59, 111, 138, 0.28);
  --shadow-sm: 0 4px 12px rgba(34, 39, 44, 0.06);
  --shadow-md: 0 12px 32px rgba(34, 39, 44, 0.08);
  --shadow-lg: 0 25px 50px rgba(34, 39, 44, 0.12);
}

/* ===================== ОБЩИЕ ПРАВИЛА ===================== */
* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background-color: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* Фоновая сетка + светящиеся орбы */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    radial-gradient(circle at 15% 20%, rgba(99, 102, 241, 0.12), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(16, 185, 129, 0.08), transparent 40%);
  background-size: 32px 32px, 100% 100%, 100% 100%;
  z-index: -2;
  pointer-events: none;
}

body::after {
  content: "";
  position: fixed;
  top: -150px;
  right: -150px;
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, var(--primary-glow), transparent 70%);
  border-radius: 50%;
  filter: blur(80px);
  z-index: -1;
  pointer-events: none;
  animation: orbFloat 20s infinite ease-in-out;
}

@keyframes orbFloat {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(-40px, 60px); }
}

a {
  color: var(--primary-text);
  text-decoration: none;
  transition: color 0.2s;
}
a:hover { color: var(--primary); }

/* ---------- Светлая: фон без сетки и неона ---------- */
:root[data-theme="light"] body::before {
  background:
    radial-gradient(circle at 15% 20%, rgba(216, 238, 231, 0.5), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(239, 227, 212, 0.8), transparent 40%);
}
:root[data-theme="light"] body::after { display: none; }

:root[data-theme="light"] a { color: #1e6f5c; }
:root[data-theme="light"] a:hover { color: #164d40; }

/* ===================== HEADER ===================== */
.page-header {
  position: sticky;
  top: 20px;
  z-index: 100;
  padding: 0 20px;
  margin-top: 20px;
  border-bottom: none;
  background: transparent;
}

.page-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgba(10, 10, 15, 0.65);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 10px 12px 10px 24px;
  box-shadow: var(--shadow-md);
}

:root[data-theme="light"] .page-header-inner {
  background: rgba(255, 253, 249, 0.85);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: grid;
  place-items: center;
  color: white;
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 0 20px var(--primary-glow);
  flex-shrink: 0;
}

:root[data-theme="light"] .brand-mark {
  background: linear-gradient(135deg, #1e6f5c, #2a9d8f);
  box-shadow: 0 0 20px rgba(30, 111, 92, 0.25);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text .subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0;
  margin-top: 2px;
}

/* Nav */
.auth-nav {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}
.auth-nav form { margin: 0; display: inline-flex; }

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}
.user-chip::before {
  content: "";
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent);
}

/* ===================== BUTTONS ===================== */
button, .actions a, .artifact-links a, .button-link, input[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: white;
  border: none;
  padding: 11px 22px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  box-shadow: 0 0 20px var(--primary-glow), inset 0 1px 0 rgba(255,255,255,0.2);
  font-family: inherit;
  min-height: 40px;
}
button:hover, .actions a:hover, .button-link:hover, input[type="submit"]:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 30px var(--primary-glow), inset 0 1px 0 rgba(255,255,255,0.3);
}

/* Светлая: кнопки — зелёные, не фиолетовые */
:root[data-theme="light"] button,
:root[data-theme="light"] .actions a,
:root[data-theme="light"] .button-link,
:root[data-theme="light"] input[type="submit"] {
  background: linear-gradient(135deg, #1e6f5c, #2a9d8f);
  color: #fffaf0;
  box-shadow: 0 0 20px rgba(30, 111, 92, 0.25), inset 0 1px 0 rgba(255,255,255,0.25);
}
:root[data-theme="light"] button:hover,
:root[data-theme="light"] .actions a:hover,
:root[data-theme="light"] .button-link:hover {
  color: #fffaf0;
  box-shadow: 0 0 30px rgba(30, 111, 92, 0.35), inset 0 1px 0 rgba(255,255,255,0.3);
}
:root[data-theme="light"] button:hover,
:root[data-theme="light"] .actions a:hover,
:root[data-theme="light"] .button-link:hover {
  box-shadow: 0 0 30px rgba(30, 111, 92, 0.35), inset 0 1px 0 rgba(255,255,255,0.3);
}

.secondary-button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: none;
}
.secondary-button:hover {
  background: var(--surface-hover);
  border-color: var(--border-hover);
  box-shadow: none;
}

/* ===================== LAYOUT ===================== */
.page-content {
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px 20px 80px;
  display: grid;
  gap: 24px;
}

.panel {
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
  transition: border-color 0.3s;
}
.panel:hover { border-color: rgba(255,255,255,0.12); }

:root[data-theme="light"] .panel {
  background: var(--surface);
  backdrop-filter: none;
}

.panel h1, .panel h2, .panel h3 {
  overflow-wrap: anywhere;
  font-family: 'Space Grotesk', sans-serif;
  letter-spacing: -0.02em;
  color: var(--text);
}
.panel h1 { font-size: clamp(26px, 3vw, 34px); margin: 0 0 10px; }
.panel h2 { font-size: 22px; margin: 28px 0 14px; }
.panel h2:first-child { margin-top: 0; }
.panel h3 { font-size: 17px; margin: 0 0 10px; }

/* Eyebrow */
.eyebrow {
  margin: 0 0 8px;
  color: var(--primary-text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.eyebrow::before {
  content: "";
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent);
}

:root[data-theme="light"] .eyebrow { color: #1e6f5c; }

.muted { color: var(--text-muted); }
.error { color: var(--danger); }

/* ===================== UPLOAD FORM ===================== */
.upload-form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  padding: 18px;
  background: var(--surface-strong);
  border: 1px dashed var(--primary-border);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s;
}
.upload-form:hover { border-color: var(--primary); }

input[type="file"] {
  flex: 1;
  min-width: 200px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}
input[type="file"]::file-selector-button {
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 8px;
  margin-right: 10px;
  cursor: pointer;
  font-family: inherit;
}

:root[data-theme="light"] input[type="file"] {
  background: white;
  color: var(--text);
}

/* ===================== AUTH ===================== */
.auth-panel {
  max-width: 460px;
  margin: 40px auto;
  text-align: left;
}
.auth-panel h1 {
  font-size: 32px;
  margin-bottom: 6px;
}
.auth-panel .panel-desc {
  color: var(--text-muted);
  margin: 0 0 24px;
  font-size: 15px;
}

.auth-form { display: grid; gap: 16px; }
.auth-form label {
  display: grid;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}
.auth-form input {
  width: 100%;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font: inherit;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  transition: border-color 0.2s, background 0.2s;
}
.auth-form input:focus {
  outline: none;
  border-color: var(--primary);
  background: rgba(0, 0, 0, 0.4);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.auth-form input::placeholder { color: var(--text-dim); }

:root[data-theme="light"] .auth-form input { background: white; color: var(--text); }
:root[data-theme="light"] .auth-form input:focus {
  background: white;
  box-shadow: 0 0 0 3px rgba(30, 111, 92, 0.15);
}

.auth-switch {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}

.auth-alert {
  padding: 12px 16px;
  border-radius: var(--radius-xs);
  font-size: 14px;
  margin-bottom: 8px;
}
.auth-alert-error {
  background: var(--negative-bg);
  border: 1px solid var(--negative-border);
  color: var(--negative-text);
}
.auth-alert-success {
  background: var(--positive-bg);
  border: 1px solid var(--positive-border);
  color: var(--positive-text);
}

/* ===================== TABLES ===================== */
.cases-table, .pro-contracts-table, .pro-scores-table, .pro-events-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

.cases-table th, .pro-contracts-table th, .pro-scores-table th, .pro-events-table th {
  text-align: left;
  padding: 12px 16px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  background: transparent;
  white-space: nowrap;
}

.cases-table td, .pro-contracts-table td, .pro-scores-table td, .pro-events-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  overflow-wrap: anywhere;
}

.cases-table tbody tr, .pro-contracts-table tbody tr,
.pro-scores-table tbody tr, .pro-events-table tbody tr {
  transition: background 0.2s;
}
.cases-table tbody tr:hover, .pro-contracts-table tbody tr:hover,
.pro-scores-table tbody tr:hover, .pro-events-table tbody tr:hover {
  background: var(--surface-hover);
}
.cases-table tbody tr:last-child td, .pro-contracts-table tbody tr:last-child td {
  border-bottom: none;
}

.case-id {
  overflow-wrap: anywhere;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 13px;
  color: var(--primary-text);
}
:root[data-theme="light"] .case-id { color: #1e6f5c; }

/* Status badges */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.status::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
}
.status-completed {
  background: var(--positive-bg);
  color: var(--positive-text);
  border: 1px solid var(--positive-border);
}
.status-processing, .status-uploaded {
  background: var(--caution-bg);
  color: var(--caution-text);
  border: 1px solid var(--caution-border);
}
.status-failed {
  background: var(--negative-bg);
  color: var(--negative-text);
  border: 1px solid var(--negative-border);
}

.artifact-links { display: flex; gap: 8px; flex-wrap: wrap; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.actions a, .button-link, button { min-height: 40px; }

/* ===================== DASHBOARD HERO ===================== */
.dashboard-hero {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 8px;
}
.dashboard-hero h1 { margin: 0 0 8px; }
.dashboard-hero .actions { flex-shrink: 0; }

.subject-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}
.subject-loading-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 0 var(--primary-glow);
  animation: subjectLoadingPulse 1.6s ease-out infinite;
}
.subject-loaded {
  animation: subjectLoadedFade 0.35s ease-out;
}
@keyframes subjectLoadingPulse {
  0% { box-shadow: 0 0 0 0 var(--primary-glow); opacity: 0.7; }
  65%, 100% { box-shadow: 0 0 0 7px transparent; opacity: 1; }
}
@keyframes subjectLoadedFade {
  from { opacity: 0.4; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

.case-progress {
  width: 360px;
  max-width: 100%;
  margin-top: 12px;
  padding: 12px 14px 13px;
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-xs);
  background: linear-gradient(135deg, var(--primary-soft), var(--surface));
  box-shadow: var(--shadow-sm);
}
.case-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
}
.case-progress-track {
  position: relative;
  width: 100%;
  height: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-strong);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.24);
}
.case-progress-fill {
  position: relative;
  height: 100%;
  overflow: hidden;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--primary-strong), var(--positive));
  box-shadow: 0 0 14px var(--primary-glow);
  transition: width 0.55s cubic-bezier(0.4, 0, 0.2, 1);
}
.case-progress-glow {
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 20%, rgba(255, 255, 255, 0.5) 45%, transparent 70%);
  transform: translateX(-100%);
  animation: progressShimmer 2.2s ease-in-out infinite;
}
.case-progress-label {
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.3;
}
.case-progress-value {
  color: var(--primary-text);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 13px;
  line-height: 1;
}
.case-progress-caption {
  margin-top: 7px;
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.35;
}
@keyframes progressShimmer {
  0%, 35% { transform: translateX(-100%); }
  75%, 100% { transform: translateX(100%); }
}
@media (prefers-reduced-motion: reduce) {
  .case-progress-fill { transition: none; }
  .case-progress-glow { animation: none; }
  .subject-loading-dot, .subject-loaded { animation: none; }
}

:root[data-theme="light"] .case-progress {
  background: linear-gradient(135deg, var(--primary-soft), var(--surface));
}
:root[data-theme="light"] .case-progress-track {
  box-shadow: inset 0 1px 2px rgba(34, 39, 44, 0.12);
}
:root[data-theme="light"] .case-progress-value {
  color: var(--primary);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric-card {
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.metric-card::after {
  content: "";
  position: absolute;
  top: -40px; right: -40px;
  width: 100px; height: 100px;
  background: var(--primary);
  filter: blur(40px);
  opacity: 0.3;
  pointer-events: none;
}
.metric-card span {
  display: block;
  min-height: 20px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  position: relative;
}
.metric-card strong {
  display: block;
  margin-top: 10px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 26px;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--text);
  position: relative;
}

:root[data-theme="light"] .metric-card {
  background: linear-gradient(135deg, #1e6f5c, #2a9d8f);
  color: #fffaf0;
}
:root[data-theme="light"] .metric-card span { color: #cfe5dd; }
:root[data-theme="light"] .metric-card strong { color: #fffaf0; }
:root[data-theme="light"] .metric-card::after { opacity: 0.15; }

/* ===================== MARKERS (Pro dashboard) ===================== */
.marker-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.marker-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  padding: 16px;
  transition: all 0.3s;
}
.marker-card:hover {
  background: var(--surface-hover);
  transform: translateY(-2px);
}
.marker-title {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.3;
  text-transform: uppercase;
  word-break: break-word;
}
.marker-meta {
  margin-top: 6px;
  color: var(--text-dim);
  font-size: 12px;
}
.marker-value {
  margin-top: 14px;
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.marker-critical  { border-color: var(--negative-border); border-left-color: var(--negative); background: var(--negative-bg); }
.marker-high      { border-color: var(--negative-border); border-left-color: var(--negative); background: var(--negative-bg); }
.marker-medium    { border-color: var(--caution-border); border-left-color: var(--caution); background: var(--caution-bg); }
.marker-positive  { border-color: var(--positive-border); border-left-color: var(--positive); background: var(--positive-bg); }
.marker-off       { opacity: 0.55; border-left-color: var(--text-dim); }

/* ===================== TABLE COLUMN WIDTHS (Pro) ===================== */
.pro-contracts-table, .pro-scores-table, .pro-events-table { table-layout: fixed; }
.score-bureau-col { width: 12%; }
.score-value-col { width: 11%; }
.score-level-col { width: 25%; }
.score-date-col { width: 12%; }
.score-factors-col { width: auto; }
.contract-creditor-col { width: 18%; }
.contract-product-col { width: 12%; }
.contract-status-col { width: 10%; }
.contract-date-col { width: 9%; }
.contract-money-col { width: 10%; }
.contract-confidence-col { width: 12%; }
.event-date-col { width: 130px; }
.event-type-col { width: 220px; }
.event-description-col { width: auto; }

.pro-contracts-table th:nth-child(4), .pro-contracts-table td:nth-child(4),
.pro-contracts-table th:nth-child(5), .pro-contracts-table td:nth-child(5),
.pro-contracts-table th:nth-child(6), .pro-contracts-table td:nth-child(6),
.pro-contracts-table th:nth-child(7), .pro-contracts-table td:nth-child(7),
.pro-contracts-table th:nth-child(8), .pro-contracts-table td:nth-child(8),
.pro-scores-table th:nth-child(2), .pro-scores-table td:nth-child(2),
.pro-scores-table th:nth-child(4), .pro-scores-table td:nth-child(4),
.pro-events-table th:nth-child(1), .pro-events-table td:nth-child(1) {
  white-space: nowrap;
  overflow-wrap: normal;
}
.pro-contracts-table th:nth-child(2), .pro-contracts-table td:nth-child(2) {
  overflow-wrap: anywhere;
}

.muted-row { color: var(--text-muted); background: rgba(255,255,255,0.02); }
.warning-text { margin-top: 4px; color: var(--negative-text); font-size: 12px; }

:root[data-theme="light"] .muted-row { background: rgba(0,0,0,0.03); }

/* ===================== CASE DETAIL — VISUAL MODEL ===================== */
.visual-summary {
  border-left: 4px solid var(--primary);
  background: var(--primary-soft);
  padding: 24px;
  border-radius: var(--radius-sm);
  margin-bottom: 24px;
}
.visual-summary h2 {
  margin: 0 0 12px;
  font-size: 26px;
  font-family: 'Space Grotesk', sans-serif;
}
.visual-summary .summary-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}
.visual-summary .summary-desc {
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.6;
  margin: 0;
}

.visual-signal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 20px;
}
.visual-signal-grid h3 { margin: 0 0 10px; font-size: 15px; }
.signal-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}
.signal-list li {
  padding: 10px 14px;
  border-radius: var(--radius-xs);
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.signal-list li::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  margin-top: 8px;
  flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
}
.signal-positive { background: var(--positive-bg); color: var(--positive-text); }
.signal-positive li::before { background: var(--positive); color: var(--positive); }
.signal-caution { background: var(--caution-bg); color: var(--caution-text); }
.signal-caution li::before { background: var(--caution); color: var(--caution); }

/* Key metrics */
.visual-metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.visual-metric, .risk-card, .roadmap-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 18px;
  transition: all 0.3s;
}
.visual-metric:hover, .risk-card:hover, .roadmap-card:hover {
  background: var(--surface-hover);
  transform: translateY(-2px);
}
.visual-metric span, .risk-card span {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.visual-metric strong {
  display: block;
  margin-top: 8px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 26px;
  line-height: 1.1;
  overflow-wrap: anywhere;
  color: var(--text);
}
.visual-metric p, .risk-card p {
  margin: 10px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

/* Risk traffic light */
.risk-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.risk-card strong {
  display: block;
  margin-bottom: 6px;
  font-size: 16px;
  color: var(--text);
}
.risk-card .risk-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.visual-tone-positive {
  border-color: var(--positive-border);
  border-left-color: var(--positive);
  background: var(--positive-bg);
}
.visual-tone-warning {
  border-color: var(--caution-border);
  border-left-color: var(--caution);
  background: var(--caution-bg);
}
.visual-tone-danger {
  border-color: var(--negative-border);
  border-left-color: var(--negative);
  background: var(--negative-bg);
}
.visual-tone-neutral { border-color: var(--neutral-border); border-left-color: var(--neutral); background: var(--neutral-bg); }

.risk-badge-danger  { background: var(--negative-bg); color: var(--negative-text); border: 1px solid var(--negative-border); }
.risk-badge-warning { background: var(--caution-bg); color: var(--caution-text); border: 1px solid var(--caution-border); }
.risk-badge-positive{ background: var(--positive-bg); color: var(--positive-text); border: 1px solid var(--positive-border); }
.risk-badge-neutral { background: var(--neutral-bg); color: var(--neutral); border: 1px solid var(--neutral-border); }

/* Rehabilitation stage track */
.stage-track {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin: 16px 0;
}
.stage-track span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  padding: 12px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  transition: all 0.3s;
}

.recommendation-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.recommendation-card {
  padding: 18px;
  border: 1px solid var(--primary-border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
}
.recommendation-card strong {
  display: block;
  color: var(--text);
  font-size: 16px;
  margin-bottom: 8px;
}
.recommendation-card p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.55;
}
.stage-track span.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  border-color: var(--primary);
  color: white;
  box-shadow: 0 0 20px var(--primary-glow);
}

:root[data-theme="light"] .stage-track span { background: white; }
:root[data-theme="light"] .stage-track span.active {
  background: linear-gradient(135deg, #1e6f5c, #2a9d8f);
  border-color: #1e6f5c;
  box-shadow: 0 0 20px rgba(30, 111, 92, 0.3);
}

/* Roadmap */
.roadmap-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.roadmap-card { border-left-color: var(--primary); }
.roadmap-card h3 {
  margin: 0 0 4px;
  color: var(--primary-text);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.roadmap-card strong {
  display: block;
  margin-bottom: 12px;
  font-size: 17px;
  color: var(--text);
}
.roadmap-card ul {
  padding-left: 18px;
  margin: 0 0 12px;
  color: var(--text);
  font-size: 14px;
}
.roadmap-card ul li { margin-bottom: 6px; }
.roadmap-card .avoid {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--negative-bg);
  border: 1px solid var(--negative-border);
  border-radius: var(--radius-xs);
  color: var(--negative-text);
  font-size: 13px;
}

:root[data-theme="light"] .roadmap-card h3 { color: #1e6f5c; }
/* Do / Don't split */
.do-dont-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.do-card, .dont-card {
  padding: 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.do-card {
  background: var(--positive-bg);
  border-color: var(--positive-border);
}
.dont-card {
  background: var(--negative-bg);
  border-color: var(--negative-border);
}
.do-card h3 { color: var(--positive-text); margin: 0 0 12px; }
.dont-card h3 { color: var(--negative-text); margin: 0 0 12px; }
.do-card ul, .dont-card ul {
  padding-left: 18px;
  margin: 0;
  color: var(--text);
  font-size: 14px;
}
.do-card li, .dont-card li { margin-bottom: 6px; }

:root[data-theme="light"] .do-card ul { color: #1d2a33; }
:root[data-theme="light"] .dont-card ul { color: #1d2a33; }

/* Bureau card */
.bureau-card {
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.bureau-card h4 {
  margin: 0 0 8px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 15px;
  color: #818cf8;
}
.bureau-stats {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--text-muted);
  font-size: 13px;
}
.bureau-stats strong { color: var(--text); }

:root[data-theme="light"] .bureau-card h4 { color: #1e6f5c; }

/* Markdown blocks */
.markdown {
  font-size: 15px;
  line-height: 1.7;
  overflow-wrap: anywhere;
  color: var(--text);
}
.markdown h2 {
  margin: 28px 0 12px;
  font-size: 22px;
  font-family: 'Space Grotesk', sans-serif;
  color: var(--text);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.markdown h2:first-child { margin-top: 0; }
.markdown h3 {
  margin: 22px 0 10px;
  font-size: 17px;
  color: #818cf8;
}
.markdown p { margin: 0 0 12px; }
.markdown ul {
  margin: 0 0 14px 22px;
  padding: 0;
}
.markdown li { margin-bottom: 6px; color: var(--text); }
.markdown li::marker { color: var(--primary); }
.markdown strong { color: var(--text); }
.markdown code {
  background: rgba(99, 102, 241, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}
.markdown blockquote {
  border-left: 3px solid var(--primary);
  padding: 8px 16px;
  margin: 12px 0;
  background: var(--surface);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
  color: var(--text-muted);
}

:root[data-theme="light"] .markdown h3 { color: #1e6f5c; }
:root[data-theme="light"] .markdown blockquote { background: #f6f1ea; }

/* Timeline */
.timeline-list { display: grid; gap: 12px; }
.timeline-item {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 16px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: all 0.2s;
}
.timeline-item:hover {
  background: var(--surface-hover);
  border-color: var(--border-hover);
}
.timeline-date {
  color: var(--primary-text);
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
}
.timeline-type {
  display: inline-block;
  padding: 2px 8px;
  background: var(--primary-soft);
  color: var(--primary-text);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
}
.timeline-item p { margin: 4px 0; color: var(--text); }
.timeline-meta { color: var(--text-dim); font-size: 12px; margin-top: 4px; }

:root[data-theme="light"] .timeline-date { color: #1e6f5c; }
:root[data-theme="light"] .timeline-type { background: rgba(30, 111, 92, 0.12); color: #164d40; }

/* Compact table variant */
.compact-table { font-size: 13px; }

/* Empty state */
.empty-state {
  padding: 32px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

/* ===================== THEME TOGGLE BUTTON ===================== */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.3s;
  padding: 0;
  box-shadow: none;
  min-height: 0;
  flex-shrink: 0;
}
.theme-toggle:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border-hover);
  transform: rotate(15deg);
  box-shadow: none;
}
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: block; }

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 960px) {
  .dashboard-grid { grid-template-columns: repeat(2, 1fr); }
  .marker-grid, .visual-signal-grid, .visual-metrics-grid,
  .risk-grid, .roadmap-grid { grid-template-columns: 1fr 1fr; }
  .do-dont-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  body::after { display: none; }
  .page-header { padding: 0 12px; margin-top: 12px; top: 12px; }
  .page-header-inner {
    padding: 10px 12px;
    flex-direction: column;
    align-items: stretch;
    border-radius: 20px;
    gap: 12px;
  }
  .brand { font-size: 17px; }
  .brand-text .subtitle { display: none; }
  .auth-nav { justify-content: center; }
  .page-content { padding: 16px 12px 60px; gap: 16px; }
  .panel { padding: 18px; border-radius: 16px; }
  .panel h1 { font-size: 22px; }
  .panel h2 { font-size: 18px; }
  .upload-form { flex-direction: column; align-items: stretch; }
  input[type="file"], button, .button-link, .actions a, input[type="submit"] { width: 100%; }
  .actions { display: grid; grid-template-columns: 1fr; }
  .dashboard-hero { flex-direction: column; }
  .dashboard-hero .actions { width: 100%; margin-top: 8px; }
  .dashboard-grid, .marker-grid, .visual-signal-grid,
  .visual-metrics-grid, .risk-grid, .roadmap-grid, .stage-track {
    grid-template-columns: 1fr;
  }
  .recommendation-card-grid { grid-template-columns: 1fr; }
  .metric-card strong { font-size: 22px; }
  .timeline-item { grid-template-columns: 1fr; gap: 6px; }
  .timeline-date { font-size: 13px; }

  .cases-table, .cases-table thead, .cases-table tbody,
  .cases-table tr, .cases-table td, .cases-table th { display: block; }
  .cases-table thead { display: none; }
  .cases-table tr {
    padding: 14px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
  }
  .cases-table td {
    display: grid;
    grid-template-columns: minmax(100px, 40%) 1fr;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
  }
  .cases-table td:last-child { border-bottom: 0; }
  .cases-table td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .table-scroll {
    overflow-x: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
  }
  .pro-contracts-table, .pro-scores-table, .pro-events-table {
    table-layout: auto;
    min-width: 720px;
  }
  .markdown { font-size: 14px; }
  .markdown h2 { font-size: 18px; }
  .markdown h3 { font-size: 15px; }
  .visual-summary h2 { font-size: 20px; }
  .marker-value { font-size: 20px; }
}

@media (max-width: 420px) {
  .page-content { padding: 12px 10px 40px; }
  .panel { padding: 14px; }
  .cases-table td { grid-template-columns: 1fr; gap: 3px; }
  .cases-table td::before { font-size: 11px; }
  .compact-table { font-size: 12px; }
  .marker-card { padding: 12px; }
  .marker-title { font-size: 10px; }
}
