* { box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0; background: #fafafa; color: #222;
}
.topbar {
    background: #1e2230; color: #f5f5f5;
    padding: 12px 24px; display: flex; align-items: center; gap: 24px;
}
.brand { font-weight: 600; font-size: 16px; }
.topbar nav { display: flex; gap: 16px; align-items: center; }
.topbar nav a { color: #cbd5e1; text-decoration: none; font-size: 14px; }
.topbar nav a:hover { color: #fff; }

/* dropdown menus в навбаре */
.topbar nav .menu { position: relative; }
.topbar nav .menu-trigger {
    cursor: pointer;
    display: inline-flex; align-items: center; gap: 6px;
}
/* стрелка ▾ как ::after — её можно крутить на ховере */
.topbar nav .menu-trigger::after {
    content: "";
    display: inline-block;
    width: 0; height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    opacity: 0.7;
    transition: transform 160ms ease, opacity 160ms ease;
}
.topbar nav .menu:hover .menu-trigger::after,
.topbar nav .menu:focus-within .menu-trigger::after {
    transform: rotate(180deg);
    opacity: 1;
}
.topbar nav .menu-items {
    position: absolute; top: 100%; left: 0;
    background: #1e2230;
    padding: 6px 0;
    min-width: 180px;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.35);
    /* opacity-фейд вместо display:none — даёт плавность и оставляет
       hit-area под триггером (чтобы dropdown не закрывался при движении). */
    opacity: 0; visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 160ms ease, transform 160ms ease, visibility 0s linear 160ms;
    z-index: 100;
}
.topbar nav .menu:hover .menu-items,
.topbar nav .menu:focus-within .menu-items {
    opacity: 1; visibility: visible; transform: translateY(0);
    transition: opacity 160ms ease, transform 160ms ease, visibility 0s linear 0s;
}
.topbar nav .menu-items a {
    display: block;
    padding: 7px 16px;
    white-space: nowrap;
    font-size: 13px;
}
.topbar nav .menu-items a:hover { background: #2a3144; color: #fff; }

main { padding: 24px; max-width: 1400px; margin: 0 auto; }
h1 { font-size: 22px; margin: 0 0 18px 0; }
.muted { color: #6b7280; }
.small { font-size: 12px; }
.err { color: #b91c1c; }
.empty { padding: 40px; text-align: center; color: #6b7280; }
.back-link { display: inline-block; color: #6b7280; text-decoration: none; font-size: 13px; margin-bottom: 12px; }
.back-link:hover { color: #2563eb; }

/* ===== Table (tasks, logs, deliveries) ===== */
table.tasks { width: 100%; border-collapse: collapse; background: #fff;
              box-shadow: 0 1px 2px rgba(0,0,0,0.04); border-radius: 6px; overflow: hidden; }
table.tasks th, table.tasks td { padding: 10px 12px; border-bottom: 1px solid #eaeaea; vertical-align: top; }
table.tasks th { background: #f3f4f6; text-align: left; font-size: 12px; font-weight: 600; color: #4b5563; text-transform: uppercase; }
table.tasks tr.status-done, table.tasks tr.status-ok { background: #f0fdf4; }
table.tasks tr.status-skipped { background: #f9fafb; opacity: 0.7; }
table.tasks tr.status-expired, table.tasks tr.status-failed, table.tasks tr.status-dead { background: #fef2f2; }
table.tasks tr.status-running { background: #fffbeb; }

/* ===== Upload zones (human tasks) ===== */
.upload-cell { display: flex; flex-direction: column; gap: 6px; min-width: 220px; }
.dropzone {
    border: 2px dashed #94a3b8; border-radius: 6px; padding: 10px;
    text-align: center; cursor: pointer; transition: all 0.15s;
    display: flex; flex-direction: column; align-items: center;
}
.dropzone span { font-weight: 600; font-size: 13px; }
.dropzone small { color: #6b7280; font-size: 11px; }
.dropzone.drag-over { border-color: #2563eb; background: #eff6ff; }
.dropzone.uploading { border-color: #f59e0b; background: #fffbeb; pointer-events: none; }
.dropzone.error { border-color: #dc2626; background: #fef2f2; }
.dropzone .hidden-input { display: none; }

/* ===== Badges ===== */
.badge { padding: 3px 8px; border-radius: 4px; font-size: 12px; font-weight: 600;
         display: inline-flex; align-items: center; gap: 6px; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.err { background: #fee2e2; color: #991b1b; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.running { background: #fef3c7; color: #92400e; }
.badge.pending { background: #f3f4f6; color: #4b5563; }
.badge.live { background: #dbeafe; color: #1e40af; }
.badge.off { background: #f3f4f6; color: #6b7280; }
.undo-btn {
    background: none; border: none; color: #166534; cursor: pointer;
    padding: 0; font-size: 14px; line-height: 1; font-weight: 700; opacity: 0.5;
}
.undo-btn:hover { opacity: 1; color: #dc2626; }

/* ===== Source tags (logs) ===== */
.src-tag { display: inline-block; padding: 3px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.tag-clin { background: #ede9fe; color: #5b21b6; }
.tag-ohlp { background: #fde68a; color: #92400e; }
.tag-pubmed { background: #dbeafe; color: #1e40af; }
.tag-svc { background: #e5e7eb; color: #374151; }

.actions { display: flex; flex-direction: column; gap: 6px; }
.link { color: #2563eb; text-decoration: none; font-size: 13px; }
.link:hover { text-decoration: underline; }
.btn-link { background: none; border: none; color: #6b7280; cursor: pointer; padding: 0; font-size: 13px; text-align: left; }
.btn-link:hover { color: #dc2626; }

code { background: #eef2ff; padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.entrez { max-width: 320px; word-break: break-all; }

/* ===== Filters / pills ===== */
.filters { display: flex; gap: 8px; margin: 12px 0 18px 0; flex-wrap: wrap; }
.pill { padding: 6px 14px; border-radius: 999px; background: #fff; border: 1px solid #e5e7eb;
        font-size: 13px; color: #4b5563; text-decoration: none; }
.pill:hover { background: #f3f4f6; color: #1f2937; }
.pill.active { background: #2563eb; color: #fff; border-color: #2563eb; }

/* ===== Topic edit page ===== */
.page-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; align-items: start; }
@media (max-width: 1000px) { .page-grid { grid-template-columns: 1fr; } }
.topic-title { font-size: 26px; margin: 4px 0 8px 0; }
.topic-meta { display: flex; gap: 10px; align-items: center; margin-bottom: 20px; flex-wrap: wrap; }
.card { background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.05);
        padding: 18px 20px; margin-bottom: 16px; }
.card h3 { margin: 0 0 6px 0; font-size: 15px; font-weight: 600; color: #1f2937; }
.card .hint { color: #4b5563; font-size: 13px; line-height: 1.5; margin: 0 0 12px 0; }
.card .hint.small { font-size: 12px; }
.card.help { background: #f0f9ff; border-left: 3px solid #2563eb; }
.card.help h3 { color: #1e40af; }
.card.help ol { margin: 8px 0 0 18px; padding: 0; }
.card.help li { font-size: 13px; line-height: 1.55; margin-bottom: 8px; color: #1f2937; }

form input[type=text], form input[type=search], form textarea {
    width: 100%; padding: 8px 10px; font-family: inherit; font-size: 14px;
    border: 1px solid #d1d5db; border-radius: 5px; background: #fff;
}
form input:focus, form textarea:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
form textarea { font-family: ui-monospace, Menlo, monospace; min-height: 60px; resize: vertical; }
form button.primary {
    background: #2563eb; color: #fff; border: none; padding: 10px 24px;
    border-radius: 5px; cursor: pointer; font-size: 14px; font-weight: 600;
}
form button.primary:hover { background: #1d4ed8; }

.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.toggle input[type=checkbox] { width: 18px; height: 18px; cursor: pointer; }
.toggle span { font-size: 14px; color: #1f2937; }

.actions-row { display: flex; gap: 14px; align-items: center; margin: 20px 0; }

/* ===== MeSH chips ===== */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; min-height: 32px; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 10px; background: #eef2ff; border: 1px solid #c7d2fe;
    border-radius: 999px; font-size: 13px; color: #1e293b;
}
.chip strong { color: #1e3a8a; font-weight: 600; }
.chip-remove {
    background: none; border: none; color: #64748b;
    cursor: pointer; font-size: 16px; line-height: 1; padding: 0 0 0 4px;
}
.chip-remove:hover { color: #dc2626; }

/* ===== MeSH typeahead ===== */
.mesh-search label > span { display: block; margin-bottom: 4px; }
.mesh-results { margin-top: 8px; max-height: 320px; overflow-y: auto; border-radius: 5px; background: #fff; }
.mesh-row { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid #f1f5f9; }
.mesh-row:hover { background: #eff6ff; }
.mesh-row strong { color: #1e293b; }

.entrez-preview {
    background: #1e293b; color: #e2e8f0; padding: 12px;
    border-radius: 5px; font-size: 12px; word-break: break-all;
    margin: 0; white-space: pre-wrap; max-height: 200px; overflow-y: auto;
}

.secondary-btn {
    background: #fff; border: 1px solid #2563eb; color: #2563eb;
    padding: 8px 16px; border-radius: 5px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.secondary-btn:hover { background: #eff6ff; }
.secondary-btn:disabled { opacity: 0.5; cursor: default; }
#backfillResult { margin-top: 8px; }

.year-chart { display: flex; gap: 4px; align-items: flex-end; height: 78px; }
.year-bar { display: flex; flex-direction: column; align-items: center; flex: 1; }
.year-bar .bar { width: 100%; background: #60a5fa; border-radius: 2px 2px 0 0; min-height: 2px; }
.year-bar .year-label { font-size: 10px; color: #6b7280; margin-top: 3px; }
ul.co-mesh { margin: 6px 0 0 16px; padding: 0; }
ul.co-mesh li { font-size: 13px; margin-bottom: 3px; }

/* ===== Mobile ===== */
@media (max-width: 768px) {
    .topbar {
        flex-wrap: wrap; gap: 8px 16px; padding: 10px 14px;
    }
    .topbar nav { gap: 8px 14px; flex-wrap: wrap; }
    main { padding: 14px; }
    h1 { font-size: 19px; margin-bottom: 14px; }
    .topic-title { font-size: 21px; }
    .card { padding: 14px 16px; }
    /* широкие таблицы — горизонтальный скролл вместо ломки вёрстки */
    table.tasks { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .filters { gap: 6px; }
    .entrez { max-width: 100%; }
    .actions-row { flex-wrap: wrap; }
}
