/* === ЦВЕТОВЫЕ ПЕРЕМЕННЫЕ === */
:root {
    --bg: #f8fafc;
    --card-bg: white;
    --text: #2d3748;
    --text-secondary: #4a5568;
    --border: #e2e8f0;
    --button-bg: #3182ce;
    --button-hover: #2c5282;
    --status-valid-bg: #f0fff4;
    --status-valid-text: #2f855a;
    --status-invalid-bg: #fff5f5;
    --status-invalid-text: #c53030;
    --tab-bg: #edf2f7;
    --tab-active-bg: #3182ce;
    --tab-active-text: white;
    --footer-bg: white;
    --loader-text: #3182ce;
}

:root.dark {
    --bg: #1a202c;
    --card-bg: #2d3748;
    --text: #e2e8f0;
    --text-secondary: #a0aec0;
    --border: #4a5568;
    --button-bg: #4299e1;
    --button-hover: #3182ce;
    --status-valid-bg: #2f3b34;
    --status-valid-text: #68d391;
    --status-invalid-bg: #4d3235;
    --status-invalid-text: #fc8181;
    --tab-bg: #2d3748;
    --tab-active-bg: #4299e1;
    --tab-active-text: white;
    --footer-bg: #2d3748;
    --loader-text: #63b3ed;
}

/* ОБЩИЕ СТИЛИ */
body {
    font-family: Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    transition: background 0.3s, color 0.3s;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    padding-bottom: 80px; /* отступ под футбар */
}

h1 {
    text-align: center;
    color: var(--text);
    margin: 20px 0;
    font-size: 24px;
}

/* ТАБЫ */
.tabs {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 25px;
    flex-wrap: wrap;
}

.tab {
    padding: 10px 8px;
    background: var(--tab-bg);
    border-radius: 8px;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
    text-align: center;
    flex: 1;
    min-width: 90px;
    max-width: 180px;
    box-sizing: border-box;
    color: var(--text);
}

@media (min-width: 768px) {
    .tab {
        flex: none;
        padding: 12px 14px;
        font-size: 15px;
    }
}

.tab.active {
    background: var(--tab-active-bg);
    color: var(--tab-active-text);
}

.tab:hover:not(.active) {
    background: var(--border);
}

/* СОДЕРЖИМОЕ */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ФОРМЫ */
.search-form {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    margin-bottom: 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.mode-row {
    width: 100%;
    margin-bottom: 12px;
}

.mode-row > label {
    font-weight: bold;
    margin-bottom: 6px;
    display: block;
    color: var(--text);
}

.mode-row > select {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--card-bg);
    color: var(--text);
}

.date-number-row {
    display: flex;
    gap: 12px;
    width: 100%;
    margin-bottom: 16px;
}

.date-number-row > input:nth-child(1) {
    flex: 0 0 15%;
    min-width: 100px;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--card-bg);
    color: var(--text);
    text-align: center;
}

.date-number-row > input:nth-child(2) {
    flex: 1;
    min-width: 200px;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--card-bg);
    color: var(--text);
}

.simple-number-row {
    width: 100%;
    margin-bottom: 16px;
}

.simple-number-row > input {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--card-bg);
    color: var(--text);
    box-sizing: border-box;
}

/* КНОПКА */
.search-btn {
    min-width: 220px;
    padding: 12px 24px;
    background: var(--button-bg);
    color: white;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.search-btn:hover:not(:disabled) {
    background: var(--button-hover);
}

.search-btn:disabled {
    background: #a0aec0;
    cursor: not-allowed;
}

/* ЗАГРУЗКА */
.loader {
    text-align: center;
    margin: 15px 0;
    font-weight: bold;
    color: var(--loader-text);
    min-height: 24px;
}

/* РЕЗУЛЬТАТЫ */
.results {
    margin-top: 20px;
}

.result-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    font-size: 14px;
    line-height: 1.5;
}

.card-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

.doc-number {
    font-size: 18px;
    font-weight: bold;
    color: var(--text);
    word-break: break-word;
    min-width: 0;
}

.country-code {
    font-size: 16px;
    font-weight: bold;
    color: var(--button-bg);
    background: var(--status-valid-bg);
    padding: 2px 10px;
    border-radius: 6px;
    white-space: nowrap;
}

.registry {
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 12px;
}

.period-status {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

.period {
    color: var(--text);
    font-weight: 500;
}

.status-badge {
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: bold;
    display: inline-block;
    white-space: nowrap;
}

.status-valid {
    background: var(--status-valid-bg);
    color: var(--status-valid-text);
}

.status-invalid {
    background: var(--status-invalid-bg);
    color: var(--status-invalid-text);
}

.applicant {
    color: var(--text);
    font-weight: 500;
}

.error {
    color: var(--status-invalid-text);
    font-weight: bold;
    margin-top: 15px;
}

.info-text {
    color: var(--text);
    font-weight: bold;
    margin-bottom: 8px;
}

.info-sub {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 10px;
}

/* === ИСТОРИЯ ПОИСКА === */
.search-history {
    width: 100%;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.history-header h3 {
    font-size: 16px;
    color: var(--text);
    margin: 0;
}

.clear-btn {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.clear-btn:hover {
    background: var(--status-valid-bg);
    color: var(--status-invalid-text);
}

.history-empty {
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
    padding: 10px 0;
}

.history-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--status-valid-bg);
    border-radius: 8px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.history-item:hover {
    background: #ebf8ff;
}

.history-query {
    font-weight: 500;
    color: var(--text);
    word-break: break-word;
}

.history-date {
    color: var(--text-secondary);
    font-size: 12px;
    white-space: nowrap;
}

/* === FOOTER BAR === */
.footer-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--footer-bg);
    padding: 10px 20px;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1000;
    box-sizing: border-box;
}

.footer-left,
.footer-right {
    display: flex;
    align-items: center;
    min-width: 0;
}

/* Кнопка "Переключить тему" */
.theme-toggle-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s, color 0.2s;
}

.theme-toggle-btn:hover {
    background: var(--button-bg);
    color: white;
}

/* Кнопка истории — по центру ВСЕГО ЭКРАНА */
.center-btn {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
}

/* Кнопка "История поиска" */
.history-toggle-btn {
    background: var(--button-bg);
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 20px;
    font-weight: bold;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
}

.history-toggle-btn:hover {
    background: var(--button-hover);
}

/* Версия */
.version-label {
    color: var(--text-secondary);
    font-size: 12px;
    white-space: nowrap;
    text-align: right;
}

/* === MODAL === */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    color: var(--text);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    margin: 0;
    color: var(--text);
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-close:hover {
    color: var(--status-invalid-text);
}

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
    color: var(--text);
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    text-align: right;
}

.clear-history-btn {
    background: var(--status-invalid-text);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
}

.clear-history-btn:hover {
    background: #c53030;
}

/* Элемент истории внутри модального окна */
.modal-history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}

.modal-history-item:hover {
    background: var(--status-valid-bg);
}

.modal-history-query {
    font-weight: 500;
    color: var(--text);
    word-break: break-word;
    text-align: left;
}

.modal-history-registry {
    color: var(--text-secondary);
    font-size: 12px;
    white-space: nowrap;
    text-align: right;
}

/* ФЛАГИ */
.tab-flag {
    width: 20px;
    height: 15px;
    vertical-align: middle;
    margin-left: 6px;
    border: 1px solid var(--border);
    border-radius: 2px;
}