/* ═══════════════════════════════════════════════
   Сократ — Global Styles
   White theme · Inter font · Clean & Modern
   ═══════════════════════════════════════════════ */

/* Removed external Google Fonts import to ensure instant offline clinical intranet rendering */
/* @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap'); */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:       #1A56DB;
  --blue-mid:   #3B82F6;
  --blue-soft:  #EFF6FF;
  --teal:       #0891B2;
  --teal-soft:  #ECFEFF;
  --green:      #10B981;
  --green-soft: #ECFDF5;
  --amber:      #F59E0B;
  --amber-soft: #FFFBEB;
  --red:        #EF4444;
  --red-soft:   #FEF2F2;
  --purple:     #8B5CF6;
  --purple-soft:#F5F3FF;

  --bg:         #F8FAFC;
  --surface:    #FFFFFF;
  --border:     #E2E8F0;
  --border-2:   #CBD5E1;
  --text:       #0F172A;
  --text-2:     #475569;
  --text-3:     #94A3B8;

  --sidebar-w:  220px;
  --sidebar-collapsed-w: 56px;
  --header-h:   64px;
  --page-pad:   28px;  /* page-content top/bottom padding */
  --radius:     12px;
  --radius-sm:  8px;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:     0 4px 16px rgba(0,0,0,.07), 0 1px 4px rgba(0,0,0,.04);
  --shadow-lg:  0 10px 40px rgba(0,0,0,.10), 0 2px 8px rgba(0,0,0,.05);
}

html { font-size: 14px; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  overflow: hidden;
}

/* ── Scrollbar ─────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; }

/* ══════════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  overflow: hidden;
}

/* ── Logo block ───────────────────────────────── */
.sidebar-logo {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 14px 14px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.sidebar-brand-text {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  background: linear-gradient(135deg, var(--blue) 0%, var(--teal) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 2px;
  margin-top: 4px;
  text-align: center;
}
.logo-imgs {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}
.logo-imgs img {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  object-position: center;
  display: block;
  flex-shrink: 0;
}

/* ── Toggle button ───────────────────────────── */
.sidebar-toggle {
  position: fixed;
  top: 50vh;
  left: var(--sidebar-w);
  transform: translate(-50%, -50%);
  z-index: 5000;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1.5px solid var(--border-2);
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
  transition: background .15s, color .15s, box-shadow .15s;
  padding: 0;
}
.sidebar-toggle:hover {
  background: var(--blue); color: #fff;
  border-color: var(--blue);
  box-shadow: 0 4px 14px rgba(26,86,219,.35);
}

/* ── Collapsed state — ONLY via html attribute (set before first paint) ── */
html[data-sidebar-collapsed="1"] .sidebar        { width: var(--sidebar-collapsed-w); }
html[data-sidebar-collapsed="1"] .sidebar-toggle { left: var(--sidebar-collapsed-w); }
html[data-sidebar-collapsed="1"] .main           { margin-left: var(--sidebar-collapsed-w); }

html[data-sidebar-collapsed="1"] .sidebar-text,
html[data-sidebar-collapsed="1"] .sidebar-label,
html[data-sidebar-collapsed="1"] .sidebar-brand-text,
html[data-sidebar-collapsed="1"] .nav-badge      { display: none !important; }

html[data-sidebar-collapsed="1"] .nav-item       { justify-content: center; padding: 10px 0; }
html[data-sidebar-collapsed="1"] .user-card      { justify-content: center; padding: 10px 0; }
html[data-sidebar-collapsed="1"] .sidebar-footer { padding: 8px 0; }

html[data-sidebar-collapsed="1"] .logo-imgs      { flex-direction: column; gap: 6px; }
html[data-sidebar-collapsed="1"] .logo-imgs img  { width: 30px; height: 30px; border-radius: 7px; }
html[data-sidebar-collapsed="1"] .sidebar-logo   { padding: 10px 4px; }

/* ── Transitions — enabled only AFTER first paint via data-sidebar-animate ── */
html[data-sidebar-animate="1"] .sidebar        { transition: width .22s ease; }
html[data-sidebar-animate="1"] .sidebar-toggle { transition: left .22s ease, background .15s, color .15s, box-shadow .15s; }
html[data-sidebar-animate="1"] .main           { transition: margin-left .22s ease; }

/* ── Nav ──────────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0 4px;
}
.sidebar-section { padding: 12px 10px 2px; }
.sidebar-label {
  font-size: 10px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-3);
  padding: 0 8px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-2);
  font-size: 13px; font-weight: 500;
  text-decoration: none;
  /* only animate colour/bg — never layout props that cause jitter on load */
  transition: background .15s, color .15s;
  margin: 0 4px 2px; white-space: nowrap;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--blue-soft); color: var(--blue); }
.nav-item.active .nav-icon { color: var(--blue); }
.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  overflow: visible;
  display: block;
}
.nav-badge {
  margin-left: auto;
  background: var(--red); color: white;
  font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 99px;
  min-width: 18px; text-align: center;
}
.nav-badge.green { background: var(--green); }
.nav-badge.blue  { background: var(--blue); }

/* ── Footer / User ────────────────────────────── */
.sidebar-footer {
  flex-shrink: 0;
  padding: 10px 8px;
  border-top: 1px solid var(--border);
}
.user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer; text-decoration: none;
  transition: background .15s;
  overflow: hidden;
}
.user-card:hover { background: var(--bg); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: white; flex-shrink: 0;
}
.user-info { line-height: 1.3; min-width: 0; overflow: hidden; }
.user-info strong {
  display: block; font-size: 12.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-info span {
  font-size: 11px; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block;
}

/* ── Main content ──────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1; display: flex; flex-direction: column;
  min-height: 0; /* дочерний .page-content может сжиматься и скроллиться */
  height: 100vh;
  overflow-x: hidden;
  overflow-y: hidden;
  position: relative;
  z-index: 1;
}

/* ── Header ────────────────────────────────────── */
.header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 28px; gap: 16px;
  position: sticky; top: 0; z-index: 50;  /* below sidebar toggle (200) */
  overflow: visible; /* попап глобального поиска не обрезать */
}
.header-title { font-size: 16px; font-weight: 600; flex: 1; }
.header-title small { color: var(--text-3); font-weight: 400; font-size: 12px; margin-left: 8px; }

/* ── Search box ────────────────────────────────── */
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 12px; width: 240px;
  transition: border-color .15s, box-shadow .15s;
}
.search-box:focus-within {
  border-color: var(--blue-mid);
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}
.search-box input { background: none; border: none; outline: none; font-size: 13px; color: var(--text); width: 100%; font-family: inherit; }
.search-box input::placeholder { color: var(--text-3); }
.search-icon { color: var(--text-3); width: 15px; height: 15px; flex-shrink: 0; }

/* Глобальный поиск по разделам (шапка) */
.global-search-wrap {
  position: relative;
  flex-shrink: 0;
  width: 240px;
  z-index: 2;
}
.global-search-popover {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  min-width: 100%;
  max-width: min(380px, calc(100vw - 48px));
  max-height: min(320px, 50vh);
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
  z-index: 120;
  padding: 6px 0;
}
.global-search-popover[hidden] { display: none !important; }
.global-search-hint {
  padding: 8px 14px 10px;
  font-size: 11.5px;
  color: var(--text-3);
  line-height: 1.45;
}
.global-search-item {
  display: block;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  line-height: 1.35;
  transition: background 0.12s;
}
.global-search-item:hover,
.global-search-item.is-active {
  background: var(--blue-soft);
}
.global-search-item-desc {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-3);
  margin-top: 2px;
  line-height: 1.35;
}
.global-search-empty {
  padding: 14px;
  font-size: 13px;
  color: var(--text-2);
}

/* ── Header button ─────────────────────────────── */
.header-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all .15s; position: relative; flex-shrink: 0;
  text-decoration: none; color: var(--text-2);
}
.header-btn:hover { background: var(--bg); border-color: var(--border-2); }
.header-btn svg { width: 17px; height: 17px; }
.notif-dot {
  position: absolute; top: 7px; right: 7px;
  width: 7px; height: 7px; background: var(--red);
  border-radius: 50%; border: 2px solid white;
}

/* ── Buttons ───────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all .15s; border: none;
  text-decoration: none; white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: #1344b3; box-shadow: 0 4px 12px rgba(26,86,219,.3); }
.btn-ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-green { background: var(--green); color: white; }
.btn-green:hover { background: #059669; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Page content ──────────────────────────────── */
.page-content {
  flex: 1;
  min-height: 0; /* обязательно для flex + overflow-y: иначе страница не скроллится */
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 28px 28px 48px;   /* 48px bottom padding = breathing room */
}
.page-top {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 24px; gap: 16px;
}
.page-top h2 { font-size: 20px; font-weight: 700; }
.page-top p { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.page-top-actions { display: flex; gap: 10px; align-items: center; }

/* ── Cards ─────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-header h3 { font-size: 14px; font-weight: 600; }
.card-header .meta { font-size: 12px; color: var(--text-3); }
.card-body { padding: 20px; }

/* ── KPI Cards ─────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px; margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow-sm); transition: box-shadow .2s, transform .2s;
}
.kpi-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.kpi-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; }
.kpi-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.kpi-icon svg { width: 20px; height: 20px; overflow: visible; display: block; }
.kpi-badge { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 99px; }
.kpi-badge.up { background: var(--green-soft); color: var(--green); }
.kpi-badge.down { background: var(--red-soft); color: var(--red); }
.kpi-badge.neutral { background: var(--bg); color: var(--text-3); }
.kpi-value { font-size: 28px; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.kpi-label { font-size: 12.5px; color: var(--text-2); }

/* ── Grids ─────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.grid-3-2 { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }

/* ── Table ─────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-3);
  padding: 8px 14px; border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 11px 14px; font-size: 12.5px;
  border-bottom: 1px solid var(--border);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }

/* ── Status pills ──────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: 99px;
}
.pill-green { background: var(--green-soft); color: var(--green); }
.pill-amber { background: var(--amber-soft); color: var(--amber); }
.pill-red   { background: var(--red-soft);   color: var(--red);   }
.pill-blue  { background: var(--blue-soft);  color: var(--blue);  }
.pill-gray  { background: var(--bg); color: var(--text-3); border: 1px solid var(--border); }

/* ── Tags ──────────────────────────────────────── */
.tag {
  font-size: 11px; font-weight: 500;
  padding: 3px 9px; border-radius: 99px;
  background: var(--bg); border: 1px solid var(--border); color: var(--text-2);
}
.tags { display: flex; flex-wrap: wrap; gap: 5px; }

/* ── Forms ─────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: 12.5px; font-weight: 500;
  color: var(--text-2); margin-bottom: 6px;
}
.form-control {
  width: 100%;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px;
  font-size: 13px; font-family: inherit; color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  border-color: var(--blue-mid);
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}
.form-control::placeholder { color: var(--text-3); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }
.form-hint { font-size: 11.5px; color: var(--text-3); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Progress bar ──────────────────────────────── */
.progress-bar { height: 6px; border-radius: 99px; background: var(--border); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 99px; transition: width .4s; }

/* ── Tabs ──────────────────────────────────────── */
.tabs-nav {
  display: flex; gap: 2px; background: var(--bg);
  border-radius: var(--radius-sm); padding: 3px; width: fit-content;
}
.tab-btn {
  padding: 6px 14px; border-radius: 6px;
  font-size: 12.5px; font-weight: 500; cursor: pointer;
  color: var(--text-2); transition: all .15s; border: none; background: none;
  font-family: inherit;
}
.tab-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ── Upload zone ───────────────────────────────── */
.upload-zone {
  background: var(--surface); border: 2px dashed var(--border-2);
  border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px;
  cursor: pointer; transition: all .2s;
  padding: 40px 24px; text-align: center;
}
.upload-zone:hover, .upload-zone.drag {
  border-color: var(--blue-mid); background: var(--blue-soft);
}
.upload-zone h3 { font-size: 14.5px; font-weight: 600; }
.upload-zone p { font-size: 12.5px; color: var(--text-2); line-height: 1.6; }

/* ── Chips ─────────────────────────────────────── */
.chip {
  font-size: 11px; font-weight: 500; padding: 4px 10px;
  border-radius: 99px; border: 1px solid var(--border);
  color: var(--text-2); background: var(--surface); cursor: pointer;
  transition: all .15s;
}
.chip.active { background: var(--blue-soft); border-color: #bfdbfe; color: var(--blue); }

/* ── Alerts / Flash ────────────────────────────── */
.flash-messages {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 999999 !important; /* extremely high to block everything */
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none; /* so click-through works for other elements if clicked outside toasts */
}
.flash {
  position: relative;
  padding: 14px 40px 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  max-width: 360px;
  width: 320px;
  box-shadow: var(--shadow-lg);
  background: var(--surface) !important; /* solid white background to cover background bleed-through */
  color: var(--text) !important;
  overflow: hidden;
  box-sizing: border-box;
  z-index: 1000000;
  pointer-events: auto; /* make toast elements interactive */
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  animation: toastSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.flash.hide {
  animation: toastSlideOut 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(50px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}
@keyframes toastSlideOut {
  from {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateX(50px) scale(0.9);
  }
}

/* Status variants with solid left border and modern accent styling */
.flash-success {
  border-left: 4px solid var(--green) !important;
}
.flash-error {
  border-left: 4px solid var(--red) !important;
}
.flash-info {
  border-left: 4px solid var(--blue) !important;
}
.flash-warning {
  border-left: 4px solid var(--amber) !important;
}

/* Close Button styling */
.flash-close {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-3);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  transition: all 0.15s ease;
  user-select: none;
}
.flash-close:hover {
  background: var(--bg);
  color: var(--text-2);
}

/* Shrinking Progress Bar */
.flash-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  width: 100%;
  transform-origin: left;
  animation: toastProgress 2s linear forwards;
}
.flash-success .flash-progress { background: var(--green); }
.flash-error .flash-progress   { background: var(--red); }
.flash-info .flash-progress    { background: var(--blue); }
.flash-warning .flash-progress { background: var(--amber); }

@keyframes toastProgress {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

/* ── Activity dot ──────────────────────────────── */
.activity-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-top: 4px; }

/* ── AI Float Button ───────────────────────────── */
.ai-float-btn {
  position: fixed; bottom: 24px; right: 24px;
  background: linear-gradient(135deg, var(--blue) 0%, var(--teal) 100%);
  color: white; border: none; border-radius: 99px;
  padding: 12px 20px; font-size: 13px; font-weight: 600;
  font-family: inherit; cursor: pointer;
  box-shadow: 0 4px 20px rgba(26,86,219,.4);
  display: flex; align-items: center; gap: 8px;
  transition: all .2s; z-index: 150;
}
.ai-float-btn:hover { box-shadow: 0 6px 28px rgba(26,86,219,.5); transform: translateY(-1px); }
.ai-float-btn svg { width: 16px; height: 16px; }

/* ── Donut chart ───────────────────────────────── */
.donut {
  width: 120px; height: 120px; border-radius: 50%; position: relative; margin: 0 auto;
}
.donut::after {
  content: ''; position: absolute; inset: 28px;
  background: var(--surface); border-radius: 50%;
}
.donut-legend { display: flex; flex-direction: column; gap: 8px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.legend-label { flex: 1; color: var(--text-2); }
.legend-val { font-weight: 600; }

/* ── Bar chart ─────────────────────────────────── */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; gap: 2px; }
.bar { flex: 1; border-radius: 4px 4px 0 0; transition: opacity .2s; }
.bar:hover { opacity: .8; }
.bar-label { font-size: 10px; color: var(--text-3); }

/* ── Area chart ────────────────────────────────── */
.area-chart { position: relative; height: 140px; overflow: hidden; }
.area-chart svg { width: 100%; height: 100%; }

/* ── Empty state ───────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 60px 20px; text-align: center; gap: 12px;
}
.empty-state svg {
  opacity: .25;
  overflow: visible;
  display: block;
  flex-shrink: 0;
}
.empty-state h3 { font-size: 15px; font-weight: 600; }
.empty-state p { color: var(--text-3); font-size: 13px; }

/* ── Loading spinner ───────────────────────────── */
.spinner {
  width: 20px; height: 20px; border: 2px solid var(--border);
  border-top-color: var(--blue); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Pulse animation ───────────────────────────── */
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .6; transform: scale(1.3); }
}
.pulse { animation: pulse 1.5s infinite; }

/* ── Code/pre ──────────────────────────────────── */
pre, code {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12px;
}
pre {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 16px;
  overflow-x: auto; line-height: 1.6;
}

/* ── Section header ────────────────────────────── */
.section-header {
  font-size: 13.5px; font-weight: 600;
  margin-bottom: 12px; color: var(--text);
}

/* ── Divider ───────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ── Modal overlay (simple) ────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.3); z-index: 300;
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 28px;
  width: 480px; max-width: 95vw; max-height: 90vh; overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-3); }
.modal-close:hover { color: var(--text); }
.modal-close svg { width: 20px; height: 20px; }

/* ── Chat ──────────────────────────────────────── */
.chat-messages { display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 78%; box-sizing: border-box; min-width: 0; }
/* Явная ширина ряда: иначе при align-self:flex-start flex сжимает блок по странной intrinsic-ширине → ломается перенос кириллицы */
.msg.bot, .msg.assistant {
  align-self: stretch;
  width: 100%;
  max-width: min(92%, 720px);
  box-sizing: border-box;
}
.msg.user { align-self: flex-end; }
.msg-bubble {
  padding: 12px 16px; border-radius: 16px;
  font-size: 13px; line-height: 1.65;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
}
.msg.bot .msg-bubble, .msg.assistant .msg-bubble {
  background: var(--bg); border: 1px solid var(--border);
  border-bottom-left-radius: 4px; color: var(--text);
  word-break: normal;
  overflow-wrap: break-word;
  hyphens: manual;
  /* BFC: убирает странные наслоения и «узкую колонку» от float/markdown */
  display: flow-root;
  position: relative;
  z-index: 0;
}
/* Текст ответа не ломать посередине слова (кириллица); только перенос по словам */
.msg.bot .msg-bubble :where(p, li, h1, h2, h3, blockquote, td, th),
.msg.assistant .msg-bubble :where(p, li, h1, h2, h3, blockquote, td, th) {
  word-break: normal;
  overflow-wrap: break-word;
  max-width: 100%;
}
/* Длинные URL — отдельно, не наследовать break-all на весь абзац */
.msg.bot .msg-bubble a, .msg.assistant .msg-bubble a {
  overflow-wrap: anywhere;
  word-break: break-all;
}
.msg.user .msg-bubble {
  background: var(--blue); color: white; border-bottom-right-radius: 4px;
}
.msg-time { font-size: 10.5px; color: var(--text-3); margin-top: 4px; padding: 0 4px; }
.msg.user .msg-time { text-align: right; }
.msg-options { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.msg-option {
  font-size: 12px; font-weight: 500; padding: 6px 12px;
  border: 1px solid #bfdbfe; background: var(--blue-soft);
  color: var(--blue); border-radius: 99px; cursor: pointer; transition: all .15s;
}
.msg-option:hover { background: var(--blue); color: white; border-color: var(--blue); }

/* Markdown inside bot/assistant bubbles */
.msg.bot .msg-bubble h1, .msg.assistant .msg-bubble h1,
.msg.bot .msg-bubble h2, .msg.assistant .msg-bubble h2,
.msg.bot .msg-bubble h3, .msg.assistant .msg-bubble h3 { font-weight: 700; margin: 10px 0 4px; line-height: 1.3; }
.msg.bot .msg-bubble h1, .msg.assistant .msg-bubble h1 { font-size: 15px; }
.msg.bot .msg-bubble h2, .msg.assistant .msg-bubble h2 { font-size: 14px; }
.msg.bot .msg-bubble h3, .msg.assistant .msg-bubble h3 { font-size: 13px; }
.msg.bot .msg-bubble p, .msg.assistant .msg-bubble p { margin-bottom: 6px; line-height: 1.65; }
.msg.bot .msg-bubble ul, .msg.bot .msg-bubble ol,
.msg.assistant .msg-bubble ul, .msg.assistant .msg-bubble ol { padding-left: 18px; margin: 4px 0 8px; }
.msg.bot .msg-bubble li, .msg.assistant .msg-bubble li { margin-bottom: 3px; }
.msg.bot .msg-bubble strong, .msg.assistant .msg-bubble strong { font-weight: 700; }
.msg.bot .msg-bubble em, .msg.assistant .msg-bubble em { font-style: italic; }
.msg.bot .msg-bubble a, .msg.assistant .msg-bubble a { color: var(--blue); text-decoration: underline; }
.msg.bot .msg-bubble code, .msg.assistant .msg-bubble code { background: var(--border); padding: 1px 5px; border-radius: 4px; font-size: 12px; font-family: monospace; }
.msg.bot .msg-bubble hr, .msg.assistant .msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.msg.bot .msg-bubble table, .msg.assistant .msg-bubble table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 12.5px; }
.msg.bot .msg-bubble th, .msg.bot .msg-bubble td,
.msg.assistant .msg-bubble th, .msg.assistant .msg-bubble td { padding: 5px 9px; border: 1px solid var(--border); }

/* ── SSE streaming output ──────────────────────── */
.stream-output {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 16px;
  font-size: 13px; line-height: 1.7; min-height: 120px;
  overflow-y: auto; max-height: 500px;
}

/* ── Before/After table ────────────────────────── */
.cell-err { background: #fee2e2; color: #b91c1c; }
.cell-dup { background: #fef9c3; color: #92400e; }
.cell-ok  { background: #dcfce7; color: #166534; }

/* ── Grant card ────────────────────────────────── */
.grant-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow-sm); cursor: pointer;
  transition: all .2s; display: flex; flex-direction: column; gap: 12px;
}
.grant-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.grant-source { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.grant-title { font-size: 14px; font-weight: 600; line-height: 1.45; }
.grant-amount { font-size: 20px; font-weight: 700; color: var(--blue); }
.grant-amount small { font-size: 12px; font-weight: 400; color: var(--text-3); margin-left: 4px; }
.grant-footer { display: flex; align-items: center; justify-content: space-between; padding-top: 12px; border-top: 1px solid var(--border); }
.grant-footer span { font-size: 12px; color: var(--text-3); }
.deadline-badge { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 6px; }
.deadline-badge.urgent { background: var(--red-soft); color: var(--red); }
.deadline-badge.soon { background: var(--amber-soft); color: var(--amber); }
.deadline-badge.ok { background: var(--green-soft); color: var(--green); }

/* ── Utility ───────────────────────────────────── */
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-4 { margin-bottom: 4px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.text-sm { font-size: 12px; }
.text-muted { color: var(--text-3); }
.font-600 { font-weight: 600; }
.w-full { width: 100%; }
