/*
  Пастельная тема админки. Одна светлая палитра без переключателя: панель
  смотрят на рабочем мониторе, а два набора цветов означали бы вдвое больше
  мест, где графики могут разъехаться с интерфейсом.

  Цвета графиков вынесены в те же переменные, что и интерфейс: ряд «рыба»
  обязан быть одного оттенка на всех экранах, иначе легенду приходится читать
  заново на каждом блоке.
*/

:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-soft: #eef3fa;
    --surface-sunken: #f8fafd;
    --border: #e0e8f3;
    --border-strong: #ccd9ea;

    --text: #263449;
    --text-muted: #6d7e96;
    --text-faint: #96a4b8;

    --accent: #4a90e2;
    --accent-strong: #3878c4;
    --accent-soft: #e8f1fd;

    --mint: #7fcfbb;
    --lilac: #b0a5e3;
    --peach: #f4b49a;
    --sand: #f0d296;
    --rose: #eaa3b6;
    --sky: #8cc4ee;

    --success: #6cbf8f;
    --warning: #e0b060;
    --danger: #e08a8a;

    --shadow-sm: 0 1px 2px rgba(38, 52, 73, 0.06);
    --shadow: 0 6px 20px rgba(38, 52, 73, 0.08);
    --shadow-lg: 0 18px 48px rgba(38, 52, 73, 0.16);

    --radius: 14px;
    --radius-sm: 9px;
    --sidebar-width: 232px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

/*
  Атрибут hidden обязан побеждать раскладку.

  Экран входа, каркас панели и карточка игрока задают display своими классами
  (flex/grid), а правило класса специфичнее, чем display:none из стилей браузера.
  Без этой строки `element.hidden = true` молча не срабатывал: вход проходил
  успешно, токен сохранялся, дашборд рисовался — но экран входа оставался на
  экране, а панель уезжала ниже него. Снаружи это выглядело как «жму войти и
  ничего не происходит».
*/
[hidden] {
    display: none !important;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
    margin: 0;
    font-weight: 650;
    letter-spacing: -0.01em;
}

h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

p { margin: 0; }

/* ---------- Вход ---------- */

.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background:
        radial-gradient(1000px 500px at 15% -10%, #e4eefb 0%, transparent 60%),
        radial-gradient(800px 500px at 110% 110%, #e9f4f0 0%, transparent 60%),
        var(--bg);
}

.login-card {
    width: 100%;
    max-width: 340px;
    padding: 32px 28px 26px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    text-align: center;
}

.login-logo {
    font-size: 40px;
    line-height: 1;
    margin-bottom: 10px;
}

.login-subtitle {
    margin-top: 4px;
    margin-bottom: 22px;
    color: var(--text-muted);
}

.login-card .field {
    text-align: left;
    margin-bottom: 16px;
}

.login-error {
    margin-top: 14px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    background: #fdeeee;
    color: #b45252;
    font-size: 13px;
}

/* ---------- Каркас ---------- */

.app {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px 14px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 0 8px;
    font-size: 16px;
}

.brand-mark { font-size: 20px; }
.brand-text { font-weight: 500; color: var(--text-muted); }
.brand-text b { color: var(--text); font-weight: 650; }

.nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1 1 auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 11px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.nav-item:hover {
    background: var(--surface-soft);
    color: var(--text);
}

.nav-item.active {
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-weight: 600;
}

.nav-badge {
    margin-left: auto;
    min-width: 20px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.online-chip {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 11px;
    border-radius: var(--radius-sm);
    background: var(--surface-soft);
    color: var(--text-muted);
    font-size: 13px;
}

.online-chip .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 3px rgba(108, 191, 143, 0.2);
}

.content {
    min-width: 0;
    padding: 22px 26px 40px;
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.topbar-subtitle {
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 13px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.updated-at {
    color: var(--text-faint);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

/* ---------- Элементы управления ---------- */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 550;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.button.primary {
    background: var(--accent);
    color: #fff;
}

.button.primary:hover:not(:disabled) { background: var(--accent-strong); }

.button.secondary {
    background: var(--surface);
    border-color: var(--border-strong);
    color: var(--text);
}

.button.secondary:hover:not(:disabled) {
    background: var(--surface-soft);
    border-color: var(--accent);
    color: var(--accent-strong);
}

.button.ghost {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border);
}

.button.ghost:hover:not(:disabled) { background: var(--surface-soft); color: var(--text); }

.button.danger {
    background: #fceded;
    color: #b45252;
    border-color: #f3d6d6;
}

.button.danger:hover:not(:disabled) { background: #f8dede; }

.button.wide { width: 100%; }
.button.small { padding: 5px 10px; font-size: 13px; }

.icon-button {
    width: 30px;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}

.icon-button:hover { background: var(--surface-soft); color: var(--text); }

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.field > span {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 550;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="datetime-local"],
select,
textarea {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.15);
}

textarea {
    min-height: 80px;
    resize: vertical;
}

textarea.code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.45;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
}

.checkbox input { width: auto; }

/* ---------- Карточки и сетки ---------- */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 18px;
    margin-bottom: 18px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.panel-hint {
    color: var(--text-muted);
    font-size: 12px;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.kpi {
    padding: 14px 15px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.kpi-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 12px;
}

.kpi-value {
    margin-top: 6px;
    font-size: 24px;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.kpi-note {
    margin-top: 2px;
    color: var(--text-faint);
    font-size: 12px;
}

.kpi.accent { background: linear-gradient(135deg, #eaf2fd, #f4f9ff); border-color: #d8e6f8; }
.kpi.mint { background: linear-gradient(135deg, #e9f7f3, #f5fbf9); border-color: #d5ece5; }
.kpi.lilac { background: linear-gradient(135deg, #f0edfb, #f8f6fd); border-color: #e2dcf5; }
.kpi.peach { background: linear-gradient(135deg, #fdf0ea, #fdf7f4); border-color: #f6ddd0; }

.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.chart-grid .panel { margin-bottom: 0; }

.chart-wrap {
    width: 100%;
    overflow-x: auto;
}

.chart {
    display: block;
    width: 100%;
    height: auto;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 10px;
    color: var(--text-muted);
    font-size: 12px;
}

.legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legend i {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    display: inline-block;
}

.range-tabs {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    background: var(--surface-soft);
    border-radius: var(--radius-sm);
}

.range-tabs button {
    padding: 5px 11px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.range-tabs button.active {
    background: var(--surface);
    color: var(--accent-strong);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

/* ---------- Таблицы ---------- */

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    position: sticky;
    top: 0;
    padding: 9px 12px;
    background: var(--surface-sunken);
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
}

tbody td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-sunken); }
tbody tr.clickable { cursor: pointer; }

td.num, th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.cell-main {
    display: flex;
    align-items: center;
    gap: 8px;
}

.name-strong { font-weight: 600; }

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    color: var(--text-faint);
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--surface-soft);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge.blue { background: var(--accent-soft); color: var(--accent-strong); }
.badge.mint { background: #e5f6f1; color: #3f8f7c; }
.badge.lilac { background: #efecfa; color: #6f60ab; }
.badge.peach { background: #fdeee7; color: #b8724f; }
.badge.sand { background: #fbf1dc; color: #a17c31; }
.badge.rose { background: #fbeaef; color: #ab5c74; }
.badge.grey { background: #eef1f5; color: #7c8a9c; }

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border-strong);
    flex: 0 0 auto;
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 0 3px rgba(108, 191, 143, 0.2);
}

.empty-state {
    padding: 26px;
    text-align: center;
    color: var(--text-faint);
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.toolbar .search { min-width: 240px; flex: 1 1 240px; }

/* ---------- Карточка игрока ---------- */

.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(38, 52, 73, 0.28);
    z-index: 40;
}

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    width: min(560px, 100vw);
    height: 100vh;
    background: var(--bg);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
}

.drawer-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.drawer-subtitle {
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 12px;
}

.drawer-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 18px 20px 40px;
}

.drawer-body .panel { padding: 15px; }

.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
    gap: 10px;
}

.stat-box {
    padding: 9px 11px;
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.stat-box small {
    display: block;
    color: var(--text-muted);
    font-size: 11px;
}

.stat-box strong {
    font-size: 16px;
    font-variant-numeric: tabular-nums;
}

.grant-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    align-items: end;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.chip {
    padding: 4px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
}

.chip:hover { border-color: var(--accent); color: var(--accent-strong); background: var(--accent-soft); }

.item-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.item-pill {
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--surface-soft);
    font-size: 12px;
}

.item-pill b { font-variant-numeric: tabular-nums; }

details.raw {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-sunken);
}

details.raw > summary {
    padding: 9px 12px;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
}

details.raw > div { padding: 0 12px 12px; }

/* ---------- Мелочи ---------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%);
    z-index: 90;
    max-width: min(520px, calc(100vw - 32px));
    padding: 11px 18px;
    border-radius: var(--radius-sm);
    background: #2f3d52;
    color: #fff;
    box-shadow: var(--shadow-lg);
    font-size: 13px;
}

.toast.error { background: #b45252; }
.toast.success { background: #4f9a72; }

.notice {
    padding: 10px 13px;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 12px;
    margin-bottom: 14px;
}

.notice.warn { background: #fdf4e3; color: #9a7433; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}

.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }

.split {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 18px;
}

.split .panel { margin-bottom: 0; }

@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }

    .sidebar {
        position: static;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .nav { flex-direction: row; flex-wrap: wrap; }
    .sidebar-footer { flex-direction: row; }
    .content { padding: 16px 14px 32px; }
    .form-grid .span-2 { grid-column: span 1; }
}
