/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:         #f4f6f9;
    --bg-white:   #ffffff;
    --text:       #1a1a2e;
    --text-muted: #6b7280;
    --border:     #e5e7eb;
    --accent:     #4f46e5;
    --accent-h:   #4338ca;
    --danger:     #ef4444;
    --success:    #22c55e;
    --warning:    #f59e0b;
    --radius:     8px;
    --shadow:     0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:  0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --shadow-lg:  0 10px 25px rgba(0,0,0,.12);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

/* ===== Header ===== */
.header {
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}
.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.header-logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -.3px;
}
.header-right { display: flex; align-items: center; gap: 12px; }
.header-user { font-size: 13px; color: var(--text-muted); }

/* ===== Main layout ===== */
.main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* ===== Page header ===== */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 20px;
}
.page-title { font-size: 22px; font-weight: 700; color: var(--text); }
.page-sub   { font-size: 13px; color: var(--text-muted); margin-top: 2px; display: block; }

/* ===== Toolbar ===== */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

/* ===== Inputs ===== */
.input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    color: var(--text);
    background: var(--bg-white);
    transition: border-color .15s;
    outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.1); }
.input::placeholder { color: #9ca3af; }
.textarea { resize: vertical; min-height: 80px; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background .15s, opacity .15s, transform .1s;
    text-decoration: none;
    white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }

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

.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .85; }

.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }

/* ===== Alerts ===== */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 14px;
}
.alert-error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

/* ===== Table ===== */
.table-wrap {
    background: var(--bg-white);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
    overflow-x: auto;
}
.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px;
}
.table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .4px;
    background: #f9fafb;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #f9fafb; }

.td-empty { text-align: center; color: var(--text-muted); padding: 40px; }
.td-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* Бейдж API */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
}
.badge-ok  { background: #d1fae5; color: #065f46; }
.badge-no  { background: #fee2e2; color: #991b1b; }

/* ===== Pagination ===== */
.pagination {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
    justify-content: center;
}
.pagination .btn { min-width: 80px; }
.pagination-info { font-size: 13px; color: var(--text-muted); }

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
    background: var(--bg-white);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: modal-in .18s ease;
}
@keyframes modal-in {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 17px; font-weight: 700; }
.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body {
    padding: 20px 22px;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    padding: 14px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ===== Form ===== */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.required   { color: var(--danger); }
.field-hint { font-size: 11px; font-weight: 400; color: var(--text-muted); margin-left: 4px; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
@media (max-width: 520px) { .form-row { grid-template-columns: 1fr; } }

/* ===== Autocomplete ===== */
.field-autocomplete { position: relative; }
.autocomplete-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 300;
    max-height: 200px;
    overflow-y: auto;
}
.autocomplete-dropdown.open { display: block; }
.autocomplete-item {
    padding: 9px 12px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.autocomplete-item:hover { background: #f3f4f6; }
.autocomplete-item .city-name { font-weight: 600; }
.autocomplete-item .city-meta { font-size: 11px; color: var(--text-muted); }

/* ===== JSON button ===== */
.btn-json {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}
.btn-json:hover { background: #dbeafe; }

/* ===== Кнопка перегенерации JSON через API ===== */
.btn-regenerate {
    background: #f0fdf4;
    color: #15803d;
    border: 1px solid #bbf7d0;
}
.btn-regenerate:hover   { background: #dcfce7; }
.btn-regenerate:disabled { opacity: .6; cursor: not-allowed; }

/* ===== Модалка ошибки API ===== */
.modal-api-error { max-width: 680px; }

.modal-header-error { background: #fef2f2; border-bottom-color: #fecaca; }
.modal-header-error .modal-title { color: #b91c1c; }

.api-error-msg-box {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 14px 16px;
    color: #b91c1c;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 16px;
    line-height: 1.5;
}

.api-debug-section { margin-top: 4px; }

.api-debug-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    margin: 14px 0 6px;
}

.api-debug-grid {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 4px 12px;
    font-size: 13px;
    align-items: start;
}
.debug-key { color: var(--text-muted); font-weight: 600; padding: 3px 0; }
.debug-val { color: var(--text); padding: 3px 0; word-break: break-all; }
.debug-val-ok  { color: #15803d; font-weight: 700; }
.debug-val-err { color: #b91c1c; font-weight: 700; }

.api-debug-pre {
    font-family: 'Menlo', 'Consolas', monospace;
    font-size: 12px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 180px;
    overflow-y: auto;
    color: #1e293b;
    margin-bottom: 4px;
}
.api-debug-pre-response { color: #7c3aed; }

/* ===== JSON modal ===== */
.modal-json { max-width: 780px; }

.json-viewer {
    font-family: 'Menlo', 'Consolas', 'Monaco', monospace;
    font-size: 12.5px;
    line-height: 1.6;
    color: #1e293b;
    background: #f8fafc;
    border-top: 1px solid var(--border);
    padding: 18px 22px;
    margin: 0;
    white-space: pre;
    overflow: auto;
    max-height: 60vh;
}

.json-copy-hint {
    font-size: 13px;
    color: var(--text-muted);
    margin-right: auto;
    transition: color .2s;
}
.json-copy-hint.copy-ok { color: var(--success); font-weight: 600; }

/* ===== Login page ===== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.login-wrap { width: 100%; max-width: 380px; padding: 20px; }
.login-box {
    background: var(--bg-white);
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    padding: 32px 28px;
}
.login-title { font-size: 24px; font-weight: 800; color: var(--accent); margin-bottom: 4px; }
.login-sub   { font-size: 13px; color: var(--text-muted); margin-bottom: 24px; }

/* ===== Navigation ===== */
.nav {
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 56px;
    z-index: 90;
}
.nav-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    gap: 2px;
}
.nav-link {
    display: inline-flex;
    align-items: center;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    transition: color .15s, border-color .15s;
}
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ===== Games — Filters ===== */
.games-filter {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.filter-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg);
    border-radius: var(--radius);
    padding: 3px;
    border: 1px solid var(--border);
}
.filter-btn {
    padding: 6px 16px;
    border-radius: 6px;
    border: none;
    background: none;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: background .15s, color .15s;
}
.filter-btn:hover  { background: var(--bg-white); color: var(--text); }
.filter-btn.active { background: var(--bg-white); color: var(--accent); font-weight: 600; box-shadow: var(--shadow); }

/* ===== Games — Date groups ===== */
.date-group { margin-bottom: 28px; }
.date-group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}
.date-group-label {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}
.badge-today {
    background: #dbeafe;
    color: #1d4ed8;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 20px;
}

/* ===== Games — Grid ===== */
.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 14px;
}

/* ===== Game Card ===== */
.game-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    transition: box-shadow .15s;
    overflow: hidden;
}
.game-card:hover { box-shadow: var(--shadow-md); }
.game-card.past  { opacity: .72; }
.game-card.past:hover { opacity: 1; }

.game-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 14px 14px 10px;
    gap: 8px;
}
.game-card-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
}
.game-status {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    display: inline-block;
    margin-bottom: 2px;
    width: fit-content;
}
.game-status.upcoming { background: #ede9fe; color: #5b21b6; }
.game-status.today    { background: #d1fae5; color: #065f46; }
.game-status.past     { background: #f3f4f6; color: #6b7280; }

.game-location {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.game-time-dur {
    font-size: 12px;
    color: var(--text-muted);
}
.game-card-actions {
    display: flex;
    gap: 5px;
    flex-shrink: 0;
}

.game-card-body {
    padding: 4px 14px 12px;
}

.game-card-foot {
    padding: 10px 14px 14px;
    border-top: 1px solid var(--border);
    background: #fafafa;
}

/* ===== Progress Bar ===== */
.progress-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.progress-bar {
    flex: 1;
    height: 8px;
    background: #e5e7eb;
    border-radius: 99px;
    overflow: hidden;
    min-width: 60px;
}
.progress-fill {
    height: 100%;
    border-radius: 99px;
    transition: width .3s ease;
}
.progress-fill.low  { background: #ef4444; }
.progress-fill.mid  { background: #f59e0b; }
.progress-fill.full { background: #22c55e; }

.progress-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    min-width: 36px;
}
.progress-label.full { color: var(--success); }
.progress-status { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.progress-status.ok { color: var(--success); font-weight: 600; }

.pinned-badge {
    font-size: 11px;
    background: #fff7ed;
    color: #92400e;
    padding: 2px 7px;
    border-radius: 20px;
    white-space: nowrap;
}
.over-norm {
    font-size: 11px;
    color: var(--danger);
    font-weight: 600;
    white-space: nowrap;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 15px;
}
.empty-icon { font-size: 48px; margin-bottom: 12px; }

/* ===== Game Modal — Tabs ===== */
.modal-game { max-width: 660px; }

.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: #fafafa;
    padding: 0 6px;
}
.tab-btn {
    padding: 10px 18px;
    border: none;
    background: none;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color .15s, border-color .15s;
    display: flex;
    align-items: center;
    gap: 6px;
}
.tab-btn:hover  { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    background: var(--accent);
    color: #fff;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 700;
    padding: 0 5px;
}

/* Показ/скрытие панелей */
.tab-pane        { display: none; }
.tab-pane.active { display: block; }

/* Заметки — выровнять высоту редактора */
.tab-notes-pane.active { display: flex; flex-direction: column; }
.tab-notes-pane .ql-container { flex: 1; }

/* ===== Participants Tab ===== */
.part-header { margin-bottom: 14px; }

.part-search-wrap { position: relative; margin-bottom: 16px; }

.participants-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 320px;
    overflow-y: auto;
}
.part-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 24px;
    font-size: 13px;
}
.part-section-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    padding: 8px 4px 4px;
}
.part-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-radius: var(--radius);
    background: #f9fafb;
    border: 1px solid var(--border);
    gap: 8px;
}
.part-row:hover { background: #f3f4f6; }

.part-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}
.part-name  { font-size: 13px; font-weight: 600; color: var(--text); }
.part-phone { font-size: 12px; color: var(--text-muted); }

.part-actions { display: flex; gap: 5px; flex-shrink: 0; }

.btn-pin { background: #f3f4f6; color: #9ca3af; border: 1px solid var(--border); }
.btn-pin:hover  { background: #fff7ed; color: #92400e; border-color: #fed7aa; }
.btn-pin.active { background: #fff7ed; color: #92400e; border-color: #fed7aa; }

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 22px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    z-index: 9999;
    box-shadow: var(--shadow-lg);
    white-space: nowrap;
}
.toast-ok    { background: #052e16; color: #bbf7d0; }
.toast-error { background: #450a0a; color: #fecaca; }

/* ===== Quill overrides ===== */
.ql-container { font-size: 14px; border-radius: 0 0 var(--radius) var(--radius); }
.ql-toolbar   { border-radius: var(--radius) var(--radius) 0 0; background: #f9fafb; }
.ql-editor    { min-height: 220px; }
