:root {
    --navy: #0f2a5e;
    --navy-dark: #0a1f47;
    --blue: #1f4fa8;
    --blue-light: #e8f0fd;
    --accent: #2563eb;
    --text: #1b2433;
    --text-muted: #6b7585;
    --border: #e4e8f0;
    --bg: #f4f6fb;
    --success-bg: #e3f7e9;
    --success-text: #1f9d4d;
    --pending-bg: #fdf3da;
    --pending-text: #b8860b;
    --danger-bg: #fde8e8;
    --danger-text: #d33b3b;
    --gold-bg: #fdf6e3;
    --gold-border: #f0dca0;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a { color: inherit; text-decoration: none; }

.header {
    background: linear-gradient(90deg, var(--navy-dark), var(--navy));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 36px;
}

.header-left { display: flex; align-items: center; gap: 16px; }

.header-logo {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: var(--navy);
    font-size: 15px;
}

.header-title-block { display: flex; align-items: center; gap: 12px; }

.header-brand { font-weight: 700; font-size: 20px; letter-spacing: 1px; }

.header-titles { line-height: 1.35; }
.header-titles .title { font-size: 19px; font-weight: 700; }
.header-titles .subtitle { font-size: 13px; color: #b9c6e6; }

.header-right { display: flex; align-items: center; gap: 20px; font-size: 13px; color: #cfe0ff; }
.header-right .badge-line { display: flex; align-items: center; gap: 6px; }

.header-cell-number {
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 600;
}

.layout {
    display: flex;
    align-items: flex-start;
    gap: 22px;
    padding: 22px 24px;
    max-width: 1680px;
    margin: 0 auto;
}

.main { flex: 1; display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.content-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }

.card {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(20,30,60,0.06);
}

.card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 700;
    margin: 0 0 14px 0;
}

.search-tabs { display: flex; gap: 22px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.search-tab {
    padding-bottom: 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    cursor: pointer;
}
.search-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.search-tab:hover { color: var(--accent); }

.inn-choice-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px;
    margin-bottom: 8px; text-decoration: none; color: inherit;
}
.inn-choice-item:hover { border-color: var(--accent); background: var(--blue-light); }
.inn-choice-item .full-name { font-weight: 600; }

.search-row { display: flex; gap: 12px; }

.input {
    flex: 1;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
}
.input:focus { border-color: var(--accent); }

.btn {
    border: none;
    border-radius: 8px;
    padding: 11px 22px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4fc4; }

.btn-secondary { background: var(--blue-light); color: var(--accent); }
.btn-secondary:hover { background: #d8e6fb; }

.btn-danger { background: var(--danger-bg); color: var(--danger-text); }

.search-hint { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

.info-card {
    background: var(--blue-light);
    border-radius: 12px;
    padding: 18px;
}
.info-card .card-title { color: var(--blue); }

.info-card-gold {
    background: var(--gold-bg);
    border: 1px solid var(--gold-border);
}

.data-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.data-row:last-of-type { border-bottom: none; }
.data-row .label { color: var(--text-muted); }
.data-row .value { font-weight: 600; text-align: right; }

.cell-card {
    background: linear-gradient(135deg, var(--navy), #1d3f8c);
    color: #fff;
    border-radius: 12px;
    padding: 20px;
}
.cell-card .card-title { color: #fff; }
.cell-stats { display: flex; justify-content: space-between; gap: 18px; margin-top: 8px; }
.cell-stat .stat-label { font-size: 12px; color: #b9c6e6; margin-bottom: 4px; }
.cell-stat .stat-value { font-size: 18px; font-weight: 700; }
.cell-stat .stat-value.balance { font-size: 24px; }
.cell-status-row { margin-top: 16px; }
.cell-status-row .label { font-size: 12px; color: #b9c6e6; margin-bottom: 6px; }

.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.badge-success { background: var(--success-bg); color: var(--success-text); }
.badge-pending { background: var(--pending-bg); color: var(--pending-text); }
.badge-danger { background: var(--danger-bg); color: var(--danger-text); }

.table-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--text-muted); font-weight: 600; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 12px 10px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }

.op-row { display: flex; align-items: center; gap: 8px; }
.op-icon { width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; }
.op-icon-in { background: var(--success-bg); color: var(--success-text); }
.op-icon-out { background: var(--danger-bg); color: var(--danger-text); }

.amount-positive { color: var(--success-text); font-weight: 600; }
.amount-negative { color: var(--danger-text); font-weight: 600; }

.doc-list { display: flex; flex-direction: column; gap: 10px; }
.doc-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
}
.doc-icon {
    width: 36px; height: 36px; border-radius: 8px;
    background: var(--blue-light); color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.doc-name { flex: 1; font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { font-size: 12px; color: var(--text-muted); }

.doc-item-clickable { cursor: pointer; }
.doc-item-clickable:hover { border-color: var(--accent); background: var(--blue-light); }

.modal-box.doc-preview-box { width: 96vw; max-width: 1600px; max-height: 96vh; }
.doc-preview-header {
    display: flex; justify-content: space-between; align-items: center;
    gap: 16px; margin-bottom: 14px; font-weight: 600;
}
.doc-preview-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 200px; max-height: 88vh; overflow: auto;
    background: var(--bg); border-radius: 10px;
}
.doc-preview-body img {
    max-width: 100%; max-height: 88vh; display: block;
    transition: transform .15s ease; transform-origin: center top; cursor: zoom-in;
}
.doc-preview-body iframe { width: 100%; height: 88vh; border: none; border-radius: 10px; }
.doc-preview-fallback { padding: 40px; text-align: center; color: var(--text-muted); font-size: 14px; }

.doc-zoom-controls { display: flex; align-items: center; gap: 4px; }
.doc-zoom-controls .btn { padding: 6px 12px; min-width: 36px; text-align: center; }
#doc-zoom-reset { min-width: 56px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 32px; margin-bottom: 10px; }

.footer {
    max-width: 1680px;
    margin: 0 auto;
    padding: 18px 28px 30px;
    display: flex;
    justify-content: space-between;
    color: var(--text-muted);
    font-size: 13px;
    flex-wrap: wrap;
    gap: 8px;
}
.footer a { color: var(--accent); margin-left: 18px; }

@media (max-width: 980px) {
    .layout { flex-direction: column; }
    .content-grid { grid-template-columns: 1fr; }
}

/* ===== Admin ===== */
.admin-body { background: var(--bg); }
.admin-header {
    background: linear-gradient(90deg, var(--navy-dark), var(--navy));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 28px;
}
.admin-wrap { max-width: 1200px; margin: 0 auto; padding: 24px 28px; display: flex; flex-direction: column; gap: 20px; }
.admin-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-card { background: #fff; padding: 36px; border-radius: 14px; width: 360px; box-shadow: 0 4px 20px rgba(20,30,60,0.08); }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card p { color: var(--text-muted); font-size: 13px; margin-bottom: 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field .input { width: 100%; }
.error-text { color: var(--danger-text); font-size: 13px; margin-bottom: 12px; }
.success-text { color: var(--success-text); font-size: 13px; margin-bottom: 12px; }

.modal-overlay {
    position: fixed; inset: 0; background: rgba(10,20,40,0.45);
    display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal-box { background: #fff; border-radius: 14px; padding: 26px; width: 480px; max-width: 92vw; max-height: 88vh; overflow-y: auto; }
.modal-box h2 { margin-top: 0; font-size: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.results-table-wrap { overflow-x: auto; }
.link-btn { color: var(--accent); font-weight: 600; cursor: pointer; }

.section-title { font-size: 15px; font-weight: 700; margin: 0; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }

.inline-form { display: grid; grid-template-columns: repeat(4, 1fr) auto; gap: 8px; align-items: end; margin-bottom: 16px; }
.inline-form .field { margin-bottom: 0; }

.upload-row { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }

.toast {
    position: fixed; bottom: 24px; right: 24px;
    background: var(--navy); color: #fff;
    padding: 12px 18px; border-radius: 10px; font-size: 14px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    z-index: 200;
}

/* ===== Иконки (SVG вместо emoji) ===== */
.icon { vertical-align: -3px; flex-shrink: 0; }
.card-title .icon { vertical-align: -4px; }

/* ===== Переход между страницами ===== */
.page-fade { animation: pageFadeIn 0.25s ease-out; }
@keyframes pageFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Горизонтальная навигация публичных страниц ===== */
.site-nav {
    background: #fff;
    border-bottom: 1px solid var(--border);
}
.site-nav-inner {
    max-width: 1680px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    gap: 4px;
    overflow-x: auto;
}
.site-nav-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 14px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}
.site-nav-item:hover { color: var(--accent); }
.site-nav-item.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ===== Скелетоны загрузки ===== */
.skeleton-line {
    height: 14px;
    border-radius: 6px;
    margin-bottom: 10px;
    background: linear-gradient(90deg, #e9edf5 25%, #f4f6fb 37%, #e9edf5 63%);
    background-size: 400% 100%;
    animation: skeletonShimmer 1.4s ease infinite;
}
@keyframes skeletonShimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

/* ===== Кнопка копирования ===== */
.copy-btn {
    border: none; background: rgba(255,255,255,0.15); color: inherit;
    border-radius: 6px; padding: 4px 6px; cursor: pointer; margin-left: 6px;
    display: inline-flex; align-items: center; vertical-align: middle;
}
.copy-btn:hover { background: rgba(255,255,255,0.3); }

/* ===== Связанные ячейки ===== */
.related-cell-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; font-weight: 600;
}
.related-cell-item:last-child { border-bottom: none; }
.related-cell-item:hover { color: var(--accent); }

/* ===== Миниатюры документов ===== */
.doc-thumb { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }

/* ===== Фильтры истории + пагинация ===== */
.filter-row { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin-bottom: 18px; }
.filter-row .field { margin-bottom: 0; min-width: 160px; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 16px; }
.pagination-total { font-size: 13px; color: var(--text-muted); }

/* ===== Чат поддержки ===== */
.chat-thread {
    display: flex; flex-direction: column; gap: 10px;
    max-height: 480px; overflow-y: auto;
    padding: 16px; background: var(--bg); border-radius: 10px; margin-bottom: 16px;
}
.chat-empty { text-align: center; color: var(--text-muted); font-size: 14px; padding: 30px; }
.chat-bubble { max-width: 70%; padding: 10px 14px; border-radius: 12px; font-size: 14px; line-height: 1.5; }
.chat-bubble-client { align-self: flex-end; background: #fff; border: 1px solid var(--border); }
.chat-bubble-admin { align-self: flex-start; background: var(--accent); color: #fff; }
.chat-bubble-text { white-space: pre-wrap; word-break: break-word; }
.chat-bubble-time { font-size: 11px; opacity: 0.7; margin-top: 4px; }
.chat-form { display: flex; gap: 10px; align-items: flex-end; }
.chat-form textarea { flex: 1; resize: vertical; }

.thread-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px;
}
.thread-item:hover { border-color: var(--accent); background: var(--blue-light); }
.thread-item-title { font-weight: 600; font-size: 14px; }
.thread-item-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ===== Drag-and-drop загрузка документов ===== */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: 10px;
    padding: 28px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
}
.dropzone:hover, .dropzone-active { border-color: var(--accent); background: var(--blue-light); color: var(--accent); }

/* ===== Живая валидация форм ===== */
.field-hint { display: block; font-size: 12px; color: var(--danger-text); margin-top: 4px; min-height: 14px; }
.input-invalid { border-color: var(--danger-text) !important; }

/* ===== Спиннер на кнопках ===== */
.btn-loading { opacity: 0.7; cursor: wait; position: relative; }

/* ===== Админ-навигация ===== */
.admin-nav { display: flex; gap: 6px; }
.admin-nav-item {
    display: flex; align-items: center; gap: 7px;
    padding: 9px 14px; border-radius: 8px;
    font-size: 14px; font-weight: 500; color: #cfe0ff;
}
.admin-nav-item:hover { background: rgba(255,255,255,0.1); }
.admin-nav-item.active { background: rgba(255,255,255,0.16); color: #fff; font-weight: 600; }
.admin-brand { display: flex; align-items: center; gap: 8px; }

.nav-badge {
    background: var(--danger-text); color: #fff;
    border-radius: 999px; font-size: 11px; font-weight: 700;
    padding: 1px 7px; margin-left: 2px;
}

/* ===== Мобильная адаптация ===== */
@media (max-width: 980px) {
    .header { flex-wrap: wrap; gap: 12px; padding: 16px 20px; }
    .header-right { font-size: 12px; flex-wrap: wrap; gap: 10px; }
    .site-nav-inner { padding: 0 12px; }
    .admin-header { flex-wrap: wrap; gap: 10px; padding: 14px 16px; }
    .admin-nav { overflow-x: auto; width: 100%; }
    .layout { padding: 16px; }
    .form-grid { grid-template-columns: 1fr; }
    .inline-form { grid-template-columns: 1fr; }
    .modal-box { width: 94vw; padding: 18px; }
    .filter-row { flex-direction: column; align-items: stretch; }
    .filter-row .field { min-width: 0; }
    .chat-bubble { max-width: 88%; }
}
