:root {
  /* Палитра бренда: бирюза → небо → тёмно-синий, акцент янтарный. */
  --bg: #eef3f8;
  --bg-soft: #f6f9fc;
  --card: #ffffff;
  --ink: #0f172a;          /* текст логотипа */
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0284c7;        /* sky-600 — основной */
  --brand-dark: #036aa1;
  --brand-soft: #e0f2fe;
  --accent: #14b8a6;       /* бирюза */
  --amber: #f59e0b;        /* янтарный акцент (узел-ссылка) */
  --ok-bg: #e4f6ec; --ok-ink: #157a3c;
  --warn-bg: #fdf2e2; --warn-ink: #97560f;
  --err-bg: #fdebeb; --err-ink: #b3261e;
  --shadow-sm: 0 1px 2px rgba(16,28,48,.06), 0 1px 3px rgba(16,28,48,.05);
  --shadow-md: 0 4px 12px rgba(16,28,48,.08), 0 2px 4px rgba(16,28,48,.04);
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.6 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }

/* --- Шапка --- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem 1.5rem; background: rgba(255,255,255,.92);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: .55rem;
  font-weight: 700; color: var(--ink); text-decoration: none; font-size: 1.15rem;
  letter-spacing: -.01em;
}
.brand img { height: 30px; width: auto; display: block; }
.brand .brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  border-radius: 9px; background: linear-gradient(135deg, var(--accent), #0ea5e9 55%, #1e3a8a);
  color: #fff; font-size: .95rem; font-weight: 800;
}
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.user { color: var(--muted); font-size: .9rem; }
.inline { display: inline; margin: 0; }

.container { max-width: 1140px; margin: 1.75rem auto; padding: 0 1.5rem; }

/* --- Карточки --- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.4rem 1.5rem; margin-bottom: 1.5rem; box-shadow: var(--shadow-sm);
}
h1, h2 { margin-top: 0; letter-spacing: -.02em; }
h2 { font-size: 1.25rem; font-weight: 700; }
.hint, .muted { color: var(--muted); }
.muted { font-size: .9rem; }
.hint { font-size: .92rem; margin-top: -.2rem; }

/* --- Кнопки --- */
.btn {
  border: 1px solid transparent; border-radius: 10px; padding: .55rem 1rem;
  font-size: .95rem; font-weight: 600; cursor: pointer; background: #eef1f6; color: var(--ink);
  transition: background .15s, box-shadow .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #e6eaf1; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--brand-soft); border-color: #c9ddf7; color: var(--brand-dark); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-sm { padding: .35rem .7rem; font-size: .82rem; border-radius: 8px; }
a.btn { text-decoration: none; display: inline-block; }
.navlink { color: var(--muted); text-decoration: none; font-size: .92rem; font-weight: 500; }
.navlink:hover { color: var(--brand); }
.grid .actions { text-align: right; white-space: nowrap; }

/* --- Формы --- */
.form { display: flex; flex-direction: column; gap: .85rem; max-width: 440px; }
.form label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; font-weight: 500; color: var(--muted); }
.form input, .form select {
  padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 10px;
  font-size: .95rem; background: #fff; color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
.form input:focus, .form select:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
.form label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; }
.form label.check input { width: auto; }
input[type=file] { padding: .4rem; }

.container-narrow { max-width: 480px; }
.actions-col { display: flex; flex-direction: column; gap: .65rem; max-width: 340px; }
.actions-col .btn { text-align: center; padding: .65rem 1rem; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.pw-row { display: flex; gap: .4rem; align-items: center; }
.pw-row input { flex: 1; }
.error { color: var(--err-ink); font-size: .9rem; }

.badge { display: inline-block; padding: .2rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge-on { background: var(--ok-bg); color: var(--ok-ink); }
.badge-off { background: var(--err-bg); color: var(--err-ink); }
.link-url {
  width: 16rem; max-width: 48vw; padding: .4rem .55rem; border: 1px solid var(--line);
  border-radius: 8px; font-size: .8rem; font-family: ui-monospace, "SF Mono", Menlo, monospace; background: var(--bg-soft);
}
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .8rem; word-break: break-all; }

#import-form { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1.1rem; }
.filters input[type=text], .filters input[type=date] {
  padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 10px; font-size: .9rem; background: #fff; }
.filters input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.filters .date { display: flex; align-items: center; gap: .3rem; color: var(--muted); font-size: .85rem; }

/* --- Экран входа / публичные страницы (центрированная карточка на градиенте) --- */
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background:
    radial-gradient(1200px 600px at 50% -200px, var(--brand-soft), transparent),
    linear-gradient(180deg, #eef3fa, #e7eef8);
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 2rem 1.8rem; box-shadow: var(--shadow-md);
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: .6rem; margin-bottom: 1.4rem; text-align: center; }
.auth-brand img { height: 46px; }
.auth-brand .brand-mark { width: 46px; height: 46px; font-size: 1.4rem; border-radius: 13px; }
.auth-brand h1 { font-size: 1.3rem; margin: 0; }
.auth-brand p { margin: 0; color: var(--muted); font-size: .9rem; }
.auth-card .form { max-width: none; }
.auth-card .btn-primary { width: 100%; padding: .7rem; }

.login-card { /* legacy alias */
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 2rem; max-width: 400px; margin: 3rem auto; box-shadow: var(--shadow-md);
}

.alert { border-radius: 10px; padding: .65rem .85rem; margin: .75rem 0; font-size: .9rem; }
.alert-error, .alert-warn { background: var(--warn-bg); color: var(--warn-ink); }
.alert-error { background: var(--err-bg); color: var(--err-ink); }
.alert-ok { background: var(--ok-bg); color: var(--ok-ink); }
.errors ul { margin: .5rem 0 0; padding-left: 1.2rem; font-size: .9rem; }

/* --- Таблицы --- */
.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { text-align: left; padding: .65rem .7rem; border-bottom: 1px solid var(--line); }
.grid th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.grid .num { text-align: right; }
.grid tbody tr { transition: background .12s; }
.grid tbody tr:hover { background: var(--bg-soft); }

/* Компактный каталог: плотнее, без лишних переносов */
.grid.compact th, .grid.compact td { padding: .4rem .55rem; font-size: .88rem; }
.nowrap { white-space: nowrap; }
.truncate {
  display: inline-block; max-width: 22rem; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
}
.grid.studies td.actions { text-align: right; width: 1%; white-space: nowrap; }

/* Выпадающее меню действий в строке (нативный <details>) */
.rowmenu { position: relative; display: inline-block; }
.rowmenu > summary { list-style: none; cursor: pointer; }
.rowmenu > summary::-webkit-details-marker { display: none; }
.rowmenu[open] > summary { background: var(--brand-soft); border-color: #c9ddf7; color: var(--brand-dark); }
.rowmenu .menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 40;
  min-width: 190px; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow-md); padding: .35rem;
  display: flex; flex-direction: column; gap: 1px;
}
.rowmenu .menu a, .rowmenu .menu button {
  text-align: left; padding: .5rem .65rem; border-radius: 8px; background: none;
  border: none; font: inherit; color: var(--ink); text-decoration: none;
  cursor: pointer; white-space: nowrap;
}
.rowmenu .menu a:hover, .rowmenu .menu button:hover { background: var(--bg-soft); }
.rowmenu .menu .danger { color: var(--err-ink); }
.rowmenu .menu .danger:hover { background: var(--err-bg); }
@media (max-width: 640px) {
  .truncate { max-width: 70vw; }
  .grid.studies td.actions { text-align: left; }
  .rowmenu .menu { right: auto; left: 0; }
}

/* --- Дашборд --- */
.stats {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.stat { margin-bottom: 0; }
.stat h3 { margin: 0 0 .7rem; font-size: .95rem; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .03em; }
.stat .bigrow { display: flex; align-items: baseline; gap: .4rem; margin-bottom: .5rem; }
.stat .big { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; color: var(--ink); }
.stat .unit { color: var(--muted); font-size: .9rem; }
.kv { display: flex; align-items: baseline; gap: .5rem; padding: .25rem 0;
  border-bottom: 1px dashed var(--line); }
.kv:last-child { border-bottom: none; }
.kv span:first-child { color: var(--muted); font-size: .9rem; flex: 1; }
.kv b { font-size: 1.05rem; }
.kv .muted { flex: none; font-weight: 400; }
.danger-num { color: var(--err-ink); }
.modrow { display: flex; align-items: center; gap: .5rem; padding: .25rem 0; }
.modname { width: 3.5rem; font-weight: 600; font-size: .9rem; }
.modbar { flex: 1; height: 8px; background: var(--bg-soft); border-radius: 999px; overflow: hidden; }
.modbar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--brand)); }
.modrow b { width: 2.5rem; text-align: right; }

.progress {
  margin: .85rem 0; height: 22px; background: var(--bg-soft);
  border: 1px solid var(--line); border-radius: 999px; overflow: hidden;
}
.progress .bar {
  height: 100%; width: 0; min-width: 0;
  background: linear-gradient(90deg, var(--accent), var(--brand));
  color: #fff; font-size: .72rem; line-height: 22px; text-align: center;
  white-space: nowrap; transition: width .15s ease;
}
.progress .bar.bar-danger { background: linear-gradient(90deg, #ef4444, #b91c1c); }

.spinner { color: var(--muted); font-size: .9rem; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }

@media (max-width: 640px) {
  .topbar { padding: .65rem 1rem; }
  .container { margin: 1.1rem auto; padding: 0 1rem; }
  .grid thead { display: none; }
  .grid, .grid tbody, .grid tr, .grid td { display: block; width: 100%; }
  .grid tr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: .6rem; padding: .4rem .6rem; }
  .grid td { border: none; padding: .25rem .3rem; }
  .grid td::before { content: attr(data-label); color: var(--muted); font-size: .75rem; display: block; }
  .grid .num, .grid .actions { text-align: left; }
}
