:root {
    --bg: #0f1115;
    --card: #181b22;
    --line: #2a2f3a;
    --text: #e6e8ec;
    --muted: #8b93a1;
    --accent: #3b82f6;
    --ok: #22c55e;
    --warn: #f59e0b;
    --danger: #ef4444;
    --field: #0f1218;   /* фон полей ввода / трека прогресса / code */
    --chip: #374151;    /* фон вторичных кнопок и бейджей */
    --chip-text: #ffffff;
}

[data-theme="light"] {
    --bg: #f4f6f9;
    --card: #ffffff;
    --line: #dfe3ea;
    --text: #1a1d23;
    --muted: #5d6470;
    --accent: #2563eb;
    --ok: #16a34a;
    --warn: #b45309;
    --danger: #dc2626;
    --field: #f0f2f6;
    --chip: #e3e7ee;
    --chip-text: #1a1d23;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    transition: background .2s ease, color .2s ease;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; align-items: center; }
.topbar nav a { margin-left: 18px; }
.theme-toggle {
    margin-left: 18px; padding: 6px 10px; font-size: 14px; line-height: 1;
    background: var(--chip); color: var(--chip-text); border-radius: 8px;
}

main { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
main.wide { max-width: 1600px; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}
h1 { margin-top: 0; font-size: 22px; }
h2 { font-size: 17px; }

.url-form { display: flex; gap: 10px; }
.url-form input { flex: 1; }

/* Прогресс создания черновика (парсинг + очистка вотермарок) */
.progress-box { margin-top: 14px; }
.progress-box[hidden] { display: none; }
.progress-label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.progress-track {
    height: 8px; border-radius: 999px; overflow: hidden;
    background: var(--field); border: 1px solid var(--line);
}
.progress-fill {
    height: 100%; width: 0; border-radius: 999px;
    background: var(--accent); transition: width .3s ease;
}
/* Неопределённая стадия (парсинг) — бегущая полоса */
.progress-box.indeterminate .progress-fill {
    width: 40% !important;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    animation: progress-slide 1.1s infinite linear;
}
@keyframes progress-slide {
    0% { transform: translateX(-120%); }
    100% { transform: translateX(320%); }
}

input[type=url], input[type=text], input[type=password], textarea, select {
    width: 100%;
    padding: 10px 12px;
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
}
textarea { resize: vertical; }

button {
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary { background: var(--chip); color: var(--chip-text); }
button.publish { background: var(--ok); }
button.danger { background: var(--danger); }
button.primary { background: var(--accent); }

.hint { color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.ok-msg { color: var(--ok); }
code { background: var(--field); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

table.drafts { width: 100%; border-collapse: collapse; }
.drafts th, .drafts td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.drafts th { color: var(--muted); font-weight: 600; font-size: 13px; }
.drafts .title { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--chip-text); }
.badge.ok { background: rgba(34,197,94,.18); color: var(--ok); }
.badge.warn { background: rgba(234,179,8,.18); color: #a16207; }

.amenity-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 6px; }
.amenity-item { display: flex; align-items: center; gap: 8px; }
.amenity-item.pending { opacity: .85; }
.amenity-check { display: flex; align-items: center; gap: 8px; cursor: pointer; margin: 0; }
.amenity-check input { width: auto; }

.btn-link { font-weight: 600; }

/* Ряд действий в списке постов: две равнозначные кнопки в одну линию */
.row-actions { display: flex; align-items: stretch; gap: 8px; justify-content: flex-end; }
.row-actions form { margin: 0; display: flex; flex: 1; }
.row-btn {
    flex: 1;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 14px; border: none; border-radius: 8px;
    color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
    text-decoration: none; white-space: nowrap; min-width: 96px;
}
.row-btn:hover { filter: brightness(1.1); }
.row-btn.open { background: var(--ok); }
.row-btn.danger { background: var(--danger); }

.edit-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 12px; }
.grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 980px) { .grid { grid-template-columns: 1fr; } }

/* Превью держим в зоне видимости, пока крутишь длинную форму */
@media (min-width: 981px) {
    .grid > section:last-child { position: sticky; top: 16px; }
}

.counter { margin-top: 6px; font-size: 13px; color: var(--muted); }

/* Форма полей объявления: короткие поля раскладываем в несколько колонок,
   текстовые области (описание, удобства) — на всю ширину. */
.fields-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 2px 14px;
    align-items: start;
}
.fields-grid .field-group { grid-column: 1 / -1; }
.fields-grid .field-row--full { grid-column: 1 / -1; }

.field-group {
    font-size: 13px; color: var(--muted); font-weight: 600;
    margin: 14px 0 6px; border-bottom: 1px solid var(--line); padding-bottom: 4px;
}
.fields-grid .field-group:first-child { margin-top: 0; }
.field-row { margin-bottom: 8px; }
.field-row label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field-row .small { margin-top: 6px; }

/* Панель живого превью поста */
.preview {
    white-space: pre-wrap; word-wrap: break-word;
    font-size: 14px; line-height: 1.5;
    background: var(--field); border: 1px solid var(--line); border-radius: 8px;
    padding: 12px; min-height: 120px; max-height: 70vh; overflow-y: auto;
}
.preview a { color: var(--accent); }

/* Карта Google под превью */
.map-wrap { margin-top: 4px; }
.map-wrap[hidden] { display: none; }
.map-frame {
    width: 100%; height: 260px; border: 0;
    border-radius: 8px; border: 1px solid var(--line);
}

.photos {
    list-style: none; margin: 0; padding: 0;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px;
}
.photo-item {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px;
    background: var(--field);
}
.photo-item.dragging { opacity: .4; }
.photo-item.excluded { opacity: .45; }
.photo-item img { width: 90px; height: 64px; object-fit: cover; border-radius: 6px; cursor: zoom-in; }
.photo-item .drag { cursor: grab; color: var(--muted); font-size: 18px; }
.photo-item .idx { margin-left: auto; color: var(--muted); font-size: 13px; }
.photo-item .clean-badge { font-size: 11px; white-space: nowrap; }

/* Список тестеров в настройках */
.tester-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.tester-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tester-list form { margin: 0; }
.link-danger {
    background: none; border: none; padding: 0; margin: 0;
    color: var(--danger); font-weight: 600; font-size: 14px; cursor: pointer;
}
.link-danger:hover { text-decoration: underline; filter: none; }

/* Управление библиотекой удобств (страница /amenities) */
.amenity-manage { list-style: none; margin: 18px 0 0; padding: 0; }
.amenity-manage li {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 8px 0; border-bottom: 1px solid var(--line);
}
.amenity-manage form { margin: 0; }
button.small { padding: 4px 10px; font-size: 13px; }

/* Редактор библиотеки удобств: грузинский + русский */
.amenity-add { display: flex; gap: 8px; align-items: center; margin: 12px 0 20px; flex-wrap: wrap; }
.amenity-add input { flex: 1; min-width: 180px; }
.amenity-table { width: 100%; border-collapse: collapse; }
.amenity-table th {
    text-align: left; color: var(--muted); font-weight: 600; font-size: 13px;
    padding: 6px 8px; border-bottom: 1px solid var(--line);
}
.amenity-table td { padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.amenity-table td:last-child { width: 1%; white-space: nowrap; }
.amenity-table input { width: 100%; }

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

.settings-form { display: flex; gap: 10px; align-items: center; margin: 14px 0; flex-wrap: wrap; }
.settings-form label { min-width: 220px; }
.settings-form input { flex: 1; min-width: 240px; }
.settings-form input[type=file] { flex: 1 1 100%; }
.settings-form label.reveal { min-width: 0; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.settings-form label.reveal input { flex: none; min-width: 0; width: auto; }
.wm-preview { flex: 1 1 100%; display: flex; align-items: center; gap: 12px; }
.wm-preview img {
    max-width: 220px; max-height: 90px;
    background: repeating-conic-gradient(#8883 0% 25%, transparent 0% 50%) 0 / 16px 16px;
    border: 1px solid var(--line); border-radius: 8px; padding: 4px;
}
.help { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 14px; color: var(--muted); }
.help code { color: var(--text); }

.keys-form { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; }
.keys-form label { color: var(--muted); font-size: 13px; margin-top: 8px; }
.keys-actions {
    display: flex; align-items: center; justify-content: space-between;
    gap: 14px; margin-top: 16px; flex-wrap: wrap;
}
.keys-actions .reveal { display: flex; align-items: center; gap: 6px; cursor: pointer; margin: 0; }

/* Страница входа */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; margin: 0; }
.login-form { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.login-form button { margin-top: 4px; }

/* Полноэкранный просмотр фото (лайтбокс) */
.lightbox {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, .92);
    user-select: none;
}
.lightbox[hidden] { display: none; }
.lightbox .lb-img {
    max-width: 92vw; max-height: 90vh;
    object-fit: contain; border-radius: 6px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, .6);
}
.lb-btn {
    position: absolute; background: rgba(255, 255, 255, .1);
    color: #fff; border: none; border-radius: 50%;
    width: 44px; height: 44px; font-size: 22px; line-height: 1;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.lb-btn:hover { background: rgba(255, 255, 255, .22); }
.lb-close { top: 18px; right: 22px; }
.lb-nav { top: 50%; transform: translateY(-50%); width: 52px; height: 52px; font-size: 30px; }
.lb-prev { left: 18px; }
.lb-next { right: 18px; }
.lb-counter {
    position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
    color: var(--muted); font-size: 14px;
    background: rgba(0, 0, 0, .5); padding: 4px 12px; border-radius: 999px;
}
