:root {
    --bg: #f5f7fb;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success-bg: #e8f5e9;
    --success-border: #a5d6a7;
    --success-text: #2e7d32;
}

body {
    font-family: "Segoe UI", Arial, sans-serif;
    max-width: 1200px;
    margin: 32px auto;
    padding: 0 20px 40px;
    color: var(--text);
    background: var(--bg);
}

h1, h2 {
    margin: 18px 0 12px;
    color: #111827;
}

.top-nav {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.top-nav a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    background: #eef2ff;
    border: 1px solid #dbe2ff;
    padding: 6px 12px;
    border-radius: 999px;
}

.top-nav a:hover {
    background: #e0e7ff;
}

.prompt-block {
    margin: 12px 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    background: #fff7d6;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.settings-api-block {
    margin: 16px 0;
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: 10px;
    padding: 14px 18px;
    background: var(--card);
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.08);
}

.settings-api-block strong {
    display: block;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    font-size: 15px;
    color: #111827;
}

details.prompt-block summary {
    font-weight: 600;
    cursor: pointer;
}

textarea,
input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-sizing: border-box;
    background: #fff;
}

textarea:focus,
input[type="text"]:focus {
    outline: none;
    border-color: #b6c5ff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

textarea {
    min-height: 140px;
}

button,
.actions > a,
.toolbar button {
    padding: 8px 16px;
    height: 36px;
    line-height: 20px;
    box-sizing: border-box;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.18);
}

button:hover,
.actions > a:hover,
.toolbar button:hover {
    background: var(--primary-hover);
}

.actions > a.link-view-html {
    background: #c00;
    box-shadow: 0 4px 10px rgba(204, 0, 0, 0.25);
}
.actions > a.link-view-html:hover {
    background: #e00;
}

button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.list {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    background: var(--card);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    border-radius: 8px;
}

.list-text {
    flex: 1;
}

.btn-icon {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    color: var(--primary);
    padding: 4px 6px;
    border-radius: 6px;
}

.btn-icon:hover {
    opacity: 1;
    color: #fff;
    background: var(--primary);
}

.btn-icon.is-save {
    color: var(--muted);
}

.error {
    color: #b91c1c;
    margin: 10px 0;
    background: #fef2f2;
    border: 1px solid #fecaca;
    padding: 8px 12px;
    border-radius: 10px;
}

.notice {
    margin: 10px 0;
    color: #1d4ed8;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    padding: 8px 12px;
    border-radius: 10px;
}

.save-status {
    margin: 6px 0 10px;
    color: #2e7d32;
    font-size: 13px;
}

.save-status.error {
    color: #c62828;
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    background: var(--card);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

th,
td {
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
    text-align: center;
}

th {
    background: #f3f4f6;
    color: #111827;
}

th:nth-child(2),
td:nth-child(2) {
    text-align: left;
    width: 46%;
    white-space: normal;
    word-break: break-word;
}

thead th {
    background: linear-gradient(180deg, #f8fafc, #eef2f7);
    border-bottom: 1px solid #e2e8f0;
    font-weight: 600;
}

th:first-child {
    width: 44px;
}

th:not(:nth-child(2)) {
    font-size: 13px;
    letter-spacing: 0.2px;
    text-transform: uppercase;
}

th:nth-child(n+3),
td:nth-child(n+3) {
    width: 76px;
}

table tbody tr:hover {
    background: transparent;
}

table td:hover {
    background: #f0f5ff;
}

table td.cell-link:hover {
    background: #e8f5e9;
}

table td.cell-no:hover {
    background: #ffebee;
}

table td.cell-wait:hover {
    background: #f3f4f6;
}

table td.cell-link,
table td.cell-no,
table td.cell-wait {
    text-align: center;
}

table td.cell-link {
    position: relative;
    padding: 10px 12px;
    vertical-align: middle;
}

table td.cell-link .status-link {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    text-decoration: none;
    line-height: 0;
}

table td.cell-no {
    padding: 10px 12px;
    vertical-align: middle;
}

table td.cell-wait {
    padding: 10px 12px;
    vertical-align: middle;
}

/* Визуально отделяем группу из двух последних столбцов (Статья + ИИ аудит) */
table th:nth-last-child(2),
table td:nth-last-child(2) {
    border-left: 10px solid #f5f7fb;
}
table td:nth-last-child(2),
table td:nth-last-child(1) {
    background: #fafbfd;
}
table td:nth-last-child(2).cell-link,
table td:nth-last-child(2).cell-no,
table td:nth-last-child(1).cell-link,
table td:nth-last-child(1).cell-no {
    background: #fafbfd;
}
table td:nth-last-child(2):hover,
table td:nth-last-child(1):hover {
    background: #f0f5ff;
}
table td:nth-last-child(2).cell-link:hover,
table td:nth-last-child(1).cell-link:hover {
    background: #e8f5e9;
}
table td:nth-last-child(2).cell-no:hover,
table td:nth-last-child(1).cell-no:hover {
    background: #ffebee;
}
table td:nth-last-child(2).cell-wait:hover,
table td:nth-last-child(1).cell-wait:hover {
    background: #f3f4f6;
}

.status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.status-yes,
.status-no {
    position: relative;
    border-radius: 50%;
    background: #2e7d32;
}

.status-yes::before {
    content: '';
    position: absolute;
    width: 8px;
    height: 4px;
    border-left: 2px solid #fff;
    border-bottom: 2px solid #fff;
    transform: rotate(-45deg);
}

.status-no {
    background: #c62828;
}

.status-no::before,
.status-no::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 12px;
    height: 2px;
    background: #fff;
    transform: translate(-50%, -50%);
}

.status-no::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.status-no::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

.status-wait {
    position: relative;
    border-radius: 50%;
    background: #9ca3af;
}

.status-wait::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 10px;
    height: 2px;
    background: #fff;
    transform: translate(-40%, -50%);
}

.status-wait::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 6px;
    height: 6px;
    border-left: 2px solid #fff;
    border-bottom: 2px solid #fff;
    transform: translate(-85%, -50%) rotate(45deg);
}

.status-disabled {
    color: #9e9e9e;
    cursor: default;
}

.btn-delete {
    border: none;
    background: transparent;
    cursor: pointer;
    color: #b91c1c;
    font-size: 14px;
    padding: 4px 6px;
    border-radius: 6px;
}

.btn-delete:hover {
    color: #fff;
    background: var(--primary);
}

.actions {
    margin-bottom: 12px;
}

.actions-inline {
    margin: 6px 0;
}

.image-results {
    margin-top: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.image-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.image-card img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 8px;
}

.full-width-form {
    width: 100%;
    margin-bottom: 16px;
}

.btn-block {
    width: 100%;
    display: block;
    text-align: center;
    margin-top: 8px;
}

.pill-block {
    margin-top: 8px;
    width: 100%;
    justify-content: center;
}

.collect-row {
    display: flex;
    gap: 10px;
    align-items: center;
    width: 100%;
}

.collect-row input[type="text"] {
    flex: 1;
    width: auto;
    min-width: 0;
}

.collect-row button {
    white-space: nowrap;
}

.status-hidden {
    display: none !important;
}

.action-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 8px 0;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 14px;
    height: 36px;
    line-height: 20px;
    box-sizing: border-box;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #f8fafc;
    color: #475569;
    font-size: 14px;
}

.status-pill .spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0, 0, 0, 0.15);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.status-pill.is-success {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success-text);
}

.status-pill .status-text a,
.global-toast .toast-text a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: underline;
}
.status-pill .status-text a:hover,
.global-toast .toast-text a:hover {
    color: var(--primary-hover);
}

.global-toast {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
    color: #2e7d32;
    padding: 10px 14px;
    border-radius: 8px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
    font-size: 14px;
}

.global-toast .toast-close {
    border: none;
    background: transparent;
    color: #2e7d32;
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.pill-spaced {
    margin-bottom: 12px;
}

.status-pill.is-loading .spinner {
    display: inline-block;
}

.action-row-bottom {
    margin-bottom: 12px;
}

.action-row-top {
    margin-top: 12px;
}

.action-row-status {
    margin-top: 8px;
}

.heading-line {
    margin-left: 0;
}

.heading-line.h1 { margin-left: 0; }
.heading-line.h2 { margin-left: 16px; }
.heading-line.h3 { margin-left: 32px; }
.heading-line.h4 { margin-left: 48px; }
.heading-line.h5 { margin-left: 64px; }
.heading-line.h6 { margin-left: 80px; }

.list-item:hover,
.heading-row:hover,
.history-item:hover,
.history-headings li:hover,
.clean-list li:hover {
    background: #eef3ff;
}

/* clasters.php */
.item {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 10px;
    transition: background 0.2s ease;
}

.item-spaced {
    margin-top: 8px;
}

.item:hover {
    background: #f5f5f5;
}

.item-head {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    cursor: pointer;
}

.item-query {
    font-weight: 600;
    color: #333;
}

.item-meta {
    color: #777;
    font-size: 12px;
}

.item-meta-spaced {
    margin-top: 10px;
}

.item-meta-tight {
    margin-top: 6px;
}

.item-meta-bottom {
    margin-bottom: 12px;
}

.item-headings {
    display: none;
    margin-top: 8px;
    padding: 8px 10px;
    background: #fafafa;
    border-radius: 6px;
}

.item-headings-open {
    display: block;
}

.heading-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 6px 0;
    padding: 2px 4px;
    border-radius: 4px;
}

.heading-text {
    flex: 1;
    white-space: pre-wrap;
}

.badge-cleaned {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 11px;
    background: #e8f5e9;
    color: #2e7d32;
}

.empty {
    color: #777;
}

input.edit-input {
    width: 100%;
    padding: 4px 6px;
    font-size: 13px;
}

.btn-delete-query {
    color: #c62828;
    font-weight: 700;
}

.btn-plan {
    color: #1565c0;
    font-weight: 600;
}

.cluster-history {
    margin-top: 24px;
}

.cluster-history h2 {
    margin-bottom: 8px;
}

/* clastering.php */
.query {
    margin: 12px 0;
    font-weight: 600;
    background: #fff7d6;
    border: 1px solid #f7e3a1;
    padding: 8px 12px;
    border-radius: 10px;
}

.status,
.clean-status {
    margin-top: 8px;
    color: #1565c0;
}

.clean-error {
    color: #c62828;
}

.result {
    margin-top: 16px;
    padding: 12px;
    background: #f5f5f5;
    border-radius: 6px;
    white-space: pre-wrap;
}

.clean-result {
    margin-top: 12px;
    display: none;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 10px;
    background: #fafafa;
}

.clean-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.clean-list li {
    margin: 6px 0;
    padding: 2px 4px;
    border-radius: 4px;
}

.clean-btn {
    background: #6d4c41;
}

.clean-btn:hover {
    background: #5d4037;
}

.clean-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #1565c0;
    color: #fff;
    padding: 10px 12px;
    border-radius: 8px;
    display: none;
    align-items: center;
    gap: 10px;
    z-index: 10;
}

.toast.success {
    background: #2e7d32;
}

.toast.error {
    background: #c62828;
}

.toast-close {
    border: none;
    background: transparent;
    color: #fff;
    cursor: pointer;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.history {
    margin-top: 20px;
}

.history-item {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 10px;
    transition: background 0.2s ease;
}

.history-head {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.history-query {
    font-weight: 600;
    cursor: pointer;
}

.history-meta {
    color: #777;
    font-size: 12px;
}

.history-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.cluster-count {
    background: #455a64;
}

.cluster-count:hover {
    background: #37474f;
}

.history-insert,
.cluster-count {
    padding: 6px 10px;
    background: #2196f3;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.history-insert:hover,
.cluster-count:hover {
    background: #1976d2;
}

.history-headings {
    display: none;
    margin-top: 8px;
    padding: 8px 10px;
    background: #fafafa;
    border-radius: 6px;
}

.history-headings ul {
    margin: 0;
    padding-left: 0;
    list-style: none;
}

.history-headings li {
    list-style: none;
    padding: 2px 4px;
    border-radius: 4px;
}

.history-empty {
    color: #777;
}

.prompt-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.prompt-status {
    color: #1565c0;
}

.prompt-error {
    color: #c62828;
}

/* settings.php */
.tabs-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.tabs-row .tabs {
    margin-bottom: 0;
}

.btn-save-prompts {
    padding: 8px 16px;
    height: 36px;
    line-height: 20px;
    box-sizing: border-box;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
}

.btn-save-prompts:hover {
    background: var(--primary-hover);
}

.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.tab {
    padding: 8px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    background: #fafafa;
}

.tab.active {
    background: #e3f2fd;
    border-color: #90caf9;
}

.toolbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 8px;
}

.status {
    margin-top: 8px;
    color: #1565c0;
}

.section {
    display: none;
    margin-bottom: 24px;
}

.count {
    margin: 8px 0;
    color: #455a64;
    font-size: 13px;
}

.task-status {
    position: fixed;
    top: 16px;
    right: 16px;
    display: none;
    align-items: center;
    gap: 8px;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 999px;
    padding: 6px 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    z-index: 9999;
    font-size: 13px;
}

.task-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid #cfd8dc;
    border-top-color: #1565c0;
    animation: spin 0.8s linear infinite;
}

.hint {
    margin-bottom: 8px;
    color: #666;
    font-size: 13px;
}

/* plan page now uses .list styles */

.article-image-block {
    margin-top: 16px;
}

.article-image-block .article-pic {
    max-width: 100%;
    height: auto;
    display: block;
    margin-top: 8px;
}
