/* Дизайн-токени взято з сайту-квізу referat_ua (індиго + зелена CTA, Plus Jakarta Sans) */
:root {
  --bg-page: #f4f6f8;
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-tag: #e0e7ff;

  --border-light: #e5e7eb;
  --border-medium: #d1d5db;

  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-cta: #16a34a;
  --color-cta-hover: #15803d;
  --color-danger: #dc2626;
  --color-warn: #d97706;

  --text-main: #111827;
  --text-heading: #0f172a;
  --text-sub: #374151;
  --text-muted: #6b7280;
  --text-tag: #4338ca;

  --font-heading: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.07);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg-page);
  color: var(--text-main);
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); }
h1, h2, h3 { font-family: var(--font-heading); color: var(--text-heading); }
h1 { font-size: 1.5rem; font-weight: 800; }
h2 { font-size: 1.15rem; font-weight: 700; }

/* ---------- Шапка ---------- */
.site-header {
  background: #fff;
  border-bottom: 1px solid var(--border-light);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  position: sticky; top: 0; z-index: 10;
}
.header-inner {
  max-width: 1200px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
}
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.logo-mark {
  width: 34px; height: 34px; border-radius: var(--radius-md);
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff; font-family: var(--font-heading); font-weight: 800;
  display: grid; place-items: center;
}
.logo-text { font-family: var(--font-heading); font-weight: 800; color: var(--text-heading); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a {
  padding: 7px 12px; border-radius: var(--radius-md);
  color: var(--text-sub); font-weight: 600; font-size: 0.92rem; text-decoration: none;
}
.nav a:hover { background: var(--bg-subtle); }
.nav a.active { background: var(--bg-tag); color: var(--text-tag); }
.who { font-size: 0.88rem; color: var(--text-muted); }
.who strong { color: var(--text-main); }
.who a { margin-left: 8px; font-weight: 600; text-decoration: none; }

/* ---------- Вміст ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 28px 16px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.muted { color: var(--text-muted); }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 24px;
}
.card + .card { margin-top: 20px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; align-items: stretch; grid-auto-rows: 1fr; }
/* у ряду плашок відступ між картками задає gap, а не загальне правило .card + .card */
.stats .card + .card { margin-top: 0; }
.stats .stat { display: flex; flex-direction: column; justify-content: flex-start; }
.stats + .card { margin-top: 20px; }
.stat .num { font-family: var(--font-heading); font-size: 2rem; font-weight: 800; color: var(--text-heading); }
.stat .label { color: var(--text-muted); font-size: 0.9rem; }

/* ---------- Вкладки ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs a {
  padding: 8px 16px; border-radius: var(--radius-full);
  border: 1.5px solid var(--border-light); background: #fff;
  font-weight: 600; font-size: 0.9rem; color: var(--text-sub); text-decoration: none; white-space: nowrap;
}
.tabs a.active { border-color: var(--color-primary); background: var(--bg-tag); color: var(--text-tag); }

/* ---------- Таблиці ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th {
  text-align: left; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--text-muted); font-weight: 700; padding: 10px 12px; border-bottom: 1.5px solid var(--border-light);
}
td { padding: 11px 12px; border-bottom: 1px solid var(--border-light); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr.urgent td { background: #fef2f2; }
.empty { text-align: center; color: var(--text-muted); padding: 36px 12px; }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: var(--radius-full);
  font-size: 0.78rem; font-weight: 700; background: var(--bg-tag); color: var(--text-tag);
}
.badge.green { background: #dcfce7; color: #166534; }
.badge.red { background: #fee2e2; color: #991b1b; }
.badge.gray { background: #f3f4f6; color: var(--text-muted); }

/* ---------- Форми ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-sub); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%; padding: 10px 13px;
  border: 1.5px solid var(--border-light); border-radius: var(--radius-md);
  font-size: 0.95rem; font-family: var(--font-body); background: #fff;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--color-primary); }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { margin-bottom: 0; flex: 1; min-width: 180px; }

.btn {
  display: inline-block; border: none; border-radius: var(--radius-md);
  padding: 10px 18px; font-weight: 700; font-size: 0.92rem; cursor: pointer;
  background: var(--color-primary); color: #fff; text-decoration: none; font-family: var(--font-body);
}
.btn:hover { background: var(--color-primary-hover); }
.btn.cta { background: var(--color-cta); }
.btn.cta:hover { background: var(--color-cta-hover); }
.btn.ghost { background: #fff; color: var(--text-sub); border: 1.5px solid var(--border-light); }
.btn.ghost:hover { border-color: var(--border-medium); background: var(--bg-subtle); }
.btn.small { padding: 6px 12px; font-size: 0.82rem; }

.flash { padding: 10px 14px; border-radius: var(--radius-md); font-size: 0.9rem; font-weight: 600; margin-bottom: 16px; }
.flash.ok { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }
.flash.error { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }

/* ---------- Вхід ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { text-align: center; font-size: 1.3rem; }
.auth-card .sub { text-align: center; color: var(--text-muted); font-size: 0.9rem; margin: 4px 0 22px; }
.auth-card .btn { width: 100%; padding: 12px; }
.user-list { display: grid; gap: 8px; }
.user-list button {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  padding: 13px 16px; border: 1.5px solid var(--border-light); border-radius: var(--radius-md);
  background: #fff; font-size: 0.95rem; font-weight: 600; cursor: pointer; font-family: var(--font-body);
  color: var(--text-main);
}
.user-list button:hover { border-color: var(--color-primary); background: #f8faff; }
.user-list .role { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }

@media (max-width: 640px) {
  .header-inner { gap: 10px; }
  .nav { order: 3; flex-basis: 100%; }
  .card { padding: 18px; }
}

/* ---------- Черга / донори ---------- */
.code { font-family: var(--font-heading); font-weight: 800; white-space: nowrap; }
.code a { text-decoration: none; }
.nowrap { white-space: nowrap; }
.small { font-size: 0.8rem; }
.danger { color: var(--color-danger); }
.art-title { font-weight: 600; }
.art-meta { font-size: 0.8rem; color: var(--text-muted); margin: 2px 0 4px; word-break: break-word; }
a.plain { color: inherit; text-decoration: none; }
a.plain:hover { color: var(--color-primary); }

/* Комірка кількості цитувань: зелена, коли набрано потрібну кількість */
.count-cell { white-space: nowrap; }
.count-cell.done { background: #dcfce7 !important; color: #166534; }

/* Перехід за посиланням на конкретну статтю - рядок підсвічується */
tr:target td { background: #fef9c3 !important; transition: background 0.3s; }
tr { scroll-margin-top: 90px; }

.chip {
  display: inline-block; margin: 0 4px 4px 0; padding: 2px 9px; border-radius: var(--radius-full);
  font-size: 0.8rem; font-weight: 700; text-decoration: none;
  background: #f3f4f6; color: var(--text-sub); border: 1px solid var(--border-light);
}
.chip:hover { border-color: var(--color-primary); color: var(--color-primary); }
.chip.maup { background: #ede9fe; color: #5b21b6; border-color: #ddd6fe; }
.chip.general { background: #e0f2fe; color: #075985; border-color: #bae6fd; }
.badge.warn { background: #fef3c7; color: #92400e; }

/* ---------- Форми ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid [hidden] { display: none; }
.form-actions { margin-top: 6px; }
.hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 600; cursor: pointer; margin-top: 8px; }
textarea { resize: vertical; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice label {
  display: flex; flex-direction: column; gap: 2px; padding: 14px 16px 14px 42px; position: relative;
  border: 1.5px solid var(--border-light); border-radius: var(--radius-md); cursor: pointer; font-weight: 400;
}
.choice label:has(input:checked) { border-color: var(--color-primary); background: #f8faff; }
.choice input { position: absolute; left: 16px; top: 17px; }
.choice span { font-size: 0.82rem; color: var(--text-muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.danger { background: var(--color-danger); }
.btn.danger:hover { background: #b91c1c; }
details.card summary { cursor: pointer; }
h3 { font-size: 1rem; font-family: var(--font-heading); }

@media (max-width: 640px) {
  .form-grid, .choice { grid-template-columns: 1fr; }
}
.actions form { display: inline; }
.delete-box { margin-top: 20px; border-top: 1px solid var(--border-light); padding-top: 16px; }
.row-blocked td { color: var(--text-muted); }

/* Таблиці з кнопками на вузьких екранах: рядок перетворюється на картку */
@media (max-width: 720px) {
  .stack-table, .stack-table tbody, .stack-table tr, .stack-table td { display: block; width: 100%; }
  .stack-table tr { padding: 10px 0; border-bottom: 1px solid var(--border-light); }
  .stack-table tr:last-child { border-bottom: none; }
  .stack-table thead { display: none; }
  .stack-table td { border: none; padding: 3px 0; white-space: normal; }
}
.field .maup-flag, .maup-flag {
  display: flex; gap: 12px; align-items: flex-start; cursor: pointer;
  padding: 14px 16px; border: 1.5px solid var(--border-light); border-radius: var(--radius-md); background: var(--bg-subtle);
}
.maup-flag:has(input:checked) { border-color: #7c3aed; background: #f5f3ff; }
.maup-flag input { width: 18px; height: 18px; margin-top: 2px; accent-color: #7c3aed; }
.maup-flag span { display: flex; flex-direction: column; gap: 2px; }
.maup-flag small { color: var(--text-muted); font-size: 0.82rem; font-weight: 400; }
.score { display: inline-block; padding: 0 7px; border-radius: var(--radius-full); font-weight: 700; font-size: 0.75rem; margin-right: 4px; }
.score.hi { background: #dcfce7; color: #166534; }
.score.mid { background: #fef3c7; color: #92400e; }
.score.lo { background: #f3f4f6; color: var(--text-muted); }
.doi-row { display: flex; gap: 8px; }
.doi-row input { flex: 1; }
.doi-row .btn { white-space: nowrap; }
.triple { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
.triple label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-sub); margin-bottom: 6px; }

/* ---------- Адмін ---------- */
.password-reveal { border: 2px solid var(--color-cta); }
.pw-box { display: flex; gap: 10px; align-items: center; margin: 12px 0; }
.pw-box code { font-size: 1.3rem; font-weight: 700; padding: 8px 14px; background: var(--bg-subtle); border-radius: var(--radius-md); letter-spacing: 0.04em; }
.inline-mini { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.inline-mini input, .inline-mini select { width: auto; padding: 6px 9px; font-size: 0.85rem; }
.setting-row { padding-bottom: 12px; border-bottom: 1px solid var(--border-light); }
.setting-row:last-child { border-bottom: none; }

/* ---------- Вставки системою ---------- */
mark { background: #fef08a; color: inherit; padding: 0 2px; border-radius: 3px; }
.insert-item { display: grid; grid-template-columns: 70px 1fr; gap: 10px; padding: 12px 0; border-top: 1px solid var(--border-light); }
.insert-item .ins-text { margin: 4px 0; line-height: 1.5; }
.insert-item .small { margin-top: 4px; line-height: 1.45; }
@media (max-width: 640px) { .insert-item { grid-template-columns: 1fr; } }
.btn.danger-text { color: var(--color-danger); }
.btn.danger-text:hover { border-color: #fecaca; background: #fef2f2; }

/* ---------- Пошук і фільтри ---------- */
.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filter-bar .search-input { flex: 1; min-width: 220px; max-width: 520px; }
.manager-filter select { width: auto; min-width: 200px; }
input[type=search] {
  width: 100%; padding: 10px 13px; border: 1.5px solid var(--border-light); border-radius: var(--radius-md);
  font-size: 0.95rem; font-family: var(--font-body); background: #fff;
}
input[type=search]:focus { outline: none; border-color: var(--color-primary); }
.tab-archive { margin-left: auto; }
.next-steps { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border-light); }
.next-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 6px 0; }
.next-row form { display: inline; }

/* ---------- Дашборд ---------- */
.who-tag { display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 0 7px; border-radius: var(--radius-full);
           background: var(--bg-subtle); border: 1px solid var(--border-light); color: var(--text-sub); }
.progress-row + .progress-row { margin-top: 18px; }
.progress-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.progress-head a { color: var(--text-heading); text-decoration: none; }
.progress-num { font-variant-numeric: tabular-nums; color: var(--text-sub); }
/* метр: один колір, нейтральна доріжка, закруглений кінець заповнення */
.meter { height: 10px; background: #eef0f4; border-radius: var(--radius-full); overflow: hidden; }
.meter-fill { height: 100%; background: var(--color-primary); border-radius: var(--radius-full); min-width: 4px; }
.stages { display: flex; align-items: stretch; gap: 8px; flex-wrap: wrap; }
.stage { flex: 1; min-width: 120px; padding: 12px 14px; border: 1px solid var(--border-light); border-radius: var(--radius-md); background: var(--bg-subtle); }
.stage-num { font-family: var(--font-heading); font-size: 1.7rem; font-weight: 800; color: var(--text-heading); font-variant-numeric: tabular-nums; }
.stage-label { font-weight: 600; color: var(--text-sub); font-size: 0.9rem; }
.stage-arrow { align-self: center; color: var(--text-muted); font-size: 1.2rem; }
.num-table td:not(:first-child), .num-table th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.attention { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-top: 20px; }
.attention .card + .card { margin-top: 0; }
.attention h2 { font-size: 1rem; }
.att-row { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--border-light); }
.att-row:first-of-type { margin-top: 8px; }
.att-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.88rem; }
@media (max-width: 640px) { .stage-arrow { display: none; } .stage { min-width: 45%; } }
.stage-label { overflow-wrap: anywhere; hyphens: auto; }
