:root {
    --bg-body: #f5f6fa;
    --bg-container: #ffffff;
    --bg-panel: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --input-bg: #ffffff;
    --input-text: #1e293b;
    --button-bg: #4f46e5;
    --button-hover: #4338ca;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --error-bg: #fee2e2;
    --error-text: #991b1b;
    --command-bg: #f8fafc;
    --footer-bg: #ffffff;
    --footer-text: #94a3b8;
    --link-color: #4f46e5;
}

* {
    box-sizing: border-box;
}
body {
    font-family: system-ui, -apple-system, sans-serif;
    margin: 0;
    padding: 20px;
    background: var(--bg-body);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--bg-container);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    overflow: hidden;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.content {
    display: flex;
    gap: 20px;
    padding: 20px;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}
.form-panel {
    flex: 2;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.history-panel {
    flex: 1;
    min-width: 250px;
    background: var(--bg-panel);
    border-radius: 10px;
    padding: 15px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.history-panel h3 {
    margin-top: 0;
    font-size: 1rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}
.previous-query {
    background: var(--bg-container);
    border-radius: 6px;
    padding: 12px;
    font-family: monospace;
    font-size: 13px;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    user-select: text;
    -webkit-user-select: text;
    color: var(--text-primary);
}

.textarea-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
}
.textarea-wrapper textarea {
    width: 100%;
    flex: 1;
    min-height: 80px;
    padding: 12px;
    font-size: 14px;
    font-family: monospace;
    background: var(--input-bg);
    color: var(--input-text);
    border: none;
    border-radius: 0;
    resize: vertical;
    outline: none;
}
.textarea-wrapper .invalid-list {
    border: none;
    border-top: 1px solid var(--border-color);
    border-radius: 0;
    margin-top: 0;
    max-height: 120px;
}

form {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

button {
    background: var(--button-bg);
    color: white;
    border: none;
    padding: 10px 24px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 15px;
    transition: background 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
    font-family: inherit;
}
button:hover {
    background: var(--button-hover);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}
button:disabled {
    background-color: #475569;
    box-shadow: none;
    cursor: not-allowed;
}
.message {
    margin-top: 20px;
    padding: 12px;
    border-radius: 8px;
    display: none;
}
.success {
    background-color: var(--success-bg);
    color: var(--success-text);
    border: 1px solid var(--success-text);
}
.error {
    background-color: var(--error-bg);
    color: var(--error-text);
    border: 1px solid var(--error-text);
}
.command-output {
    background-color: var(--command-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    margin-top: 15px;
    font-family: monospace;
    font-size: 13px;
    white-space: pre-wrap;
    max-height: 200px;
    overflow: auto;
    display: none;
    color: var(--text-primary);
}
footer {
    text-align: center;
    margin-top: 0;
    padding: 12px;
    font-size: 12px;
    background: var(--footer-bg);
    color: var(--footer-text);
    border-top: 1px solid var(--border-color);
    border-radius: 10px;
    flex-shrink: 0;
}
footer a {
    color: var(--link-color);
    text-decoration: none;
}
.message a {
    color: var(--link-color);
}
.previous-query a {
    color: var(--link-color);
    text-decoration: none;
    font-weight: bold;
    margin-right: 10px;
}
.previous-query a:hover {
    text-decoration: underline;
}
@media (max-width: 768px) {
    .content {
        flex-direction: column;
        height: auto;
    }
}

/* Индикатор загрузки */
.loading-indicator {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid var(--button-bg);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Валидация кадастровых номеров */
.validation-counter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    padding: 6px 14px;
    border-radius: 20px;
    margin-top: 10px;
    font-weight: 500;
}
.validation-counter.valid {
    background: #dcfce7;
    color: #166534;
}
.validation-counter.invalid {
    background: #fee2e2;
    color: #991b1b;
}
.validation-counter.empty {
    background: var(--bg-panel);
    color: var(--text-secondary);
}

.invalid-list {
    background: #fff0f0;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 10px 12px;
    max-height: 180px;
    overflow-y: auto;
}
.invalid-list strong {
    color: #dc3545;
    font-size: 12px;
}
.invalid-list ul {
    margin: 6px 0 0 0;
    padding-left: 18px;
}
.invalid-list li {
    color: #721c24;
    font-size: 12px;
    cursor: pointer;
    padding: 2px 0;
}
.invalid-list li:hover {
    color: #dc3545;
    text-decoration: underline;
}
.invalid-list .more {
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 5px;
}

/* История поиска */
.history-panel {
    display: flex;
    flex-direction: column;
}
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-shrink: 0;
}
.history-header h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-secondary);
    border: none;
    padding: 0;
}
.history-clear-btn {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
    border-radius: 4px;
    margin: 0;
}
.history-clear-btn:hover {
    background: var(--error-bg);
    color: var(--error-text);
}

.history-list {
    flex: 1;
    overflow-y: auto;
}
.history-empty {
    color: var(--text-secondary);
    font-size: 13px;
    text-align: center;
    padding: 20px;
}

.history-group {
    margin-bottom: 14px;
}
.history-time {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 8px;
    padding-left: 4px;
}

.history-item {
    background: var(--bg-container);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color 0.2s;
}
.history-item:hover {
    border-color: var(--button-bg);
}
.history-text {
    font-family: monospace;
    font-size: 12px;
    color: var(--text-primary);
    word-break: break-all;
    margin-bottom: 8px;
    line-height: 1.4;
}
.history-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.history-count {
    font-size: 11px;
    color: var(--text-secondary);
}
.history-duration {
    font-size: 11px;
    color: var(--text-secondary);
}
.cached-badge {
    font-size: 10px;
    background: #e9d5ff;
    color: #6b21a8;
    padding: 2px 6px;
    border-radius: 4px;
}
.history-actions {
    display: flex;
    gap: 6px;
    margin-left: auto;
}

/* Текстовые кнопки истории */
.history-btn {
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 6px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    line-height: 1.4;
    font-family: inherit;
    display: inline-block;
}
.history-btn:hover {
    border-color: var(--button-bg);
    color: var(--button-bg);
    background: var(--bg-panel);
}
.history-delete:hover {
    border-color: #ef4444;
    color: #ef4444;
}

/* Прогресс-бар */
.progress-container {
    margin-top: 20px;
    padding: 12px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}
.progress-bar-wrapper {
    width: 100%;
    height: 10px;
    background: var(--bg-body);
    border-radius: 5px;
    overflow: hidden;
}
.progress-bar {
    display: block;
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--button-bg), #818cf8);
    border-radius: 5px;
    transition: width 0.3s ease;
}

.progress-skeleton {
    padding: 0;
}
.progress-skeleton .skeleton-line {
    border-radius: 5px;
    position: relative;
    overflow: hidden;
    background: var(--bg-body);
}
.progress-skeleton .skeleton-line::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(79, 70, 229, 0.08), transparent);
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
}
.skeleton-line-bar { height: 10px; }
.skeleton-line-text { height: 14px; width: 60%; margin-top: 8px; }
@keyframes skeleton-shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.progress-text {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 8px;
    text-align: center;
}
.progress-eta {
    font-size: 12px;
    color: var(--button-bg);
    margin-top: 4px;
    text-align: center;
    font-weight: 600;
}

.cancel-btn {
    font-size: 13px;
    padding: 4px 16px;
    margin-top: 8px;
    background: transparent;
    border: 1px solid #ef4444;
    color: #ef4444;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    display: block;
    margin-left: auto;
    margin-right: auto;
    box-shadow: none;
}
.cancel-btn:hover {
    background: #ef4444;
    color: white;
    box-shadow: none;
}

/* Бейдж предупреждений */
.warnings-badge {
    font-size: 11px;
    background: #fef3c7;
    color: #92400e;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

/* Expandable список ненайденных */
.warnings-details {
    display: inline-block;
    vertical-align: middle;
}
.warnings-details summary {
    cursor: pointer;
    font-size: 11px;
    background: #fef3c7;
    color: #92400e;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 500;
    user-select: none;
    list-style: none;
}
.warnings-details summary::-webkit-details-marker {
    display: none;
}
.warnings-details summary::after {
    content: ' ▸';
    font-size: 10px;
}
.warnings-details[open] summary::after {
    content: ' ▾';
}
.warnings-list {
    position: absolute;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12px;
    font-family: monospace;
    white-space: nowrap;
    z-index: 10;
    margin-top: 4px;
    line-height: 1.6;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.warnings-details[open] {
    position: relative;
}

/* Модальные окна */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 17, 23, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}
.modal-overlay.modal-open {
    opacity: 1;
    visibility: visible;
}
.modal {
    background: var(--bg-container);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    max-width: 480px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    transform: scale(0.95) translateY(10px);
    transition: transform 0.2s ease;
}
.modal-overlay.modal-open .modal {
    transform: scale(1) translateY(0);
}
.modal-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}
.modal-text {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}
.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
}
.modal-actions button,
.modal-actions a {
    margin-top: 0;
    font-size: 14px;
    font-family: inherit;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-danger {
    background: #ef4444;
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: none;
}
.btn-danger:hover {
    background: #dc2626;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 20px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: none;
}
.btn-outline:hover {
    background: var(--bg-panel);
}

.btn-primary {
    background: var(--button-bg);
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
}
.btn-primary:hover {
    background: var(--button-hover);
}

/* Dev-баннер */
.dev-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: linear-gradient(90deg, #dc2626, #ef4444);
    color: #fff;
    text-align: center;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.4);
    animation: dev-pulse 2s ease-in-out infinite;
}
@keyframes dev-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.85; }
}

.history-save-label {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    font-size: 11px;
    color: var(--text-secondary);
}
.history-save-label input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
    accent-color: #4f46e5;
}
