/* ============================================================
   WT Tracker — стили
   ============================================================ */

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #1a1a1a;
    color: #e0e0e0;
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 15px; width: 100%; }

header { background: #2a2a2a; padding: 15px 0; border-bottom: 1px solid #333; margin-bottom: 20px; }
header h1 { font-size: 1.4rem; margin-bottom: 10px; }

nav { display: flex; gap: 10px; flex-wrap: wrap; }
nav a { color: #aaa; text-decoration: none; padding: 6px 12px; border-radius: 5px; transition: background 0.2s, color 0.2s; }
nav a:hover { background: #333; color: #fff; }

main { flex: 1; padding-bottom: 30px; }
footer { text-align: center; padding: 20px 0; color: #666; font-size: 0.9rem; border-top: 1px solid #333; margin-top: 30px; }

h2 { font-size: 1.2rem; margin-bottom: 15px; color: #e0e0e0; }
h3 { font-size: 1rem; color: #e0e0e0; }

.card { background: #2a2a2a; border-radius: 10px; padding: 20px; margin-bottom: 20px; border: 1px solid #333; }
.card h2 { margin-bottom: 15px; }

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin-bottom: 20px; }
.summary-item { background: #2a2a2a; padding: 15px; border-radius: 10px; border: 1px solid #333; }
.summary-item .label { font-size: 0.85rem; color: #888; margin-bottom: 5px; }
.summary-item .value { font-size: 1.3rem; font-weight: bold; color: #4a9eff; word-break: break-word; }

button, .btn { background: #4a9eff; color: #fff; border: none; padding: 10px 20px; border-radius: 5px; font-size: 1rem; cursor: pointer; text-decoration: none; display: inline-block; transition: background 0.2s; font-family: inherit; }
button:hover, .btn:hover { background: #3a8eef; }
.btn-danger { background: #e74c3c; }
.btn-danger:hover { background: #d73c2c; }
.btn-secondary { background: #555; color: #fff; text-decoration: none; padding: 10px 20px; border-radius: 5px; display: inline-block; transition: background 0.2s; border: none; cursor: pointer; font-size: 1rem; font-family: inherit; }
.btn-secondary:hover { background: #666; }
.btn-small { padding: 5px 12px; font-size: 0.85rem; }

input, select { background: #1a1a1a; color: #e0e0e0; border: 1px solid #444; padding: 10px 15px; border-radius: 5px; font-size: 1rem; width: 100%; font-family: inherit; }
input:focus, select:focus { outline: none; border-color: #4a9eff; }

.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; color: #aaa; font-size: 0.9rem; }
.form-row { display: flex; gap: 15px; align-items: flex-end; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 150px; margin-bottom: 0; }

.filter-section { display: flex; flex-direction: column; gap: 15px; }
.filter-group label { display: block; margin-bottom: 8px; color: #888; font-size: 0.85rem; text-transform: uppercase; }

.tabs { display: flex; gap: 5px; flex-wrap: wrap; }
.tabs-small .tab { padding: 5px 10px; font-size: 0.85rem; }
.tab { background: #333; color: #aaa; border: 1px solid #444; padding: 8px 16px; border-radius: 5px; cursor: pointer; text-decoration: none; font-size: 0.95rem; transition: background 0.2s, color 0.2s; font-family: inherit; display: inline-block; }
.tab:hover { background: #3a3a3a; color: #fff; }
.tab.active { background: #4a9eff; color: #fff; border-color: #4a9eff; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px; text-align: left; border-bottom: 1px solid #333; }
th { color: #888; font-size: 0.85rem; text-transform: uppercase; font-weight: normal; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #333; }
.value-small { color: #4a9eff; font-weight: bold; }

.progress-bar { background: #333; border-radius: 5px; overflow: hidden; height: 8px; margin: 10px 0; }
.progress-fill { background: linear-gradient(90deg, #4a9eff, #6ab0ff); height: 100%; transition: width 0.3s; border-radius: 5px; }

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }

.tank-item { padding: 15px 0; border-bottom: 1px solid #333; }
.tank-item:last-child { border-bottom: none; }
.tank-card { padding: 15px 20px; }
.tank-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; flex-wrap: wrap; gap: 10px; }
.tank-header a { color: #4a9eff; text-decoration: none; font-size: 1.05rem; }
.tank-header a:hover { text-decoration: underline; }
.nation { color: #888; font-size: 0.9rem; }
.tank-stats { display: flex; justify-content: space-between; font-size: 0.9rem; color: #aaa; flex-wrap: wrap; gap: 10px; }
.tank-info { margin-top: 15px; color: #888; font-size: 0.9rem; }
.tank-info div { margin-bottom: 5px; }
.tank-actions { margin-top: 15px; display: flex; gap: 10px; flex-wrap: wrap; }

.nation-group { margin-bottom: 25px; }
.nation-title { color: #4a9eff; font-size: 1rem; margin-bottom: 10px; padding-left: 5px; letter-spacing: 1px; }

.empty { color: #666; font-style: italic; text-align: center; padding: 20px; }
.empty a { color: #4a9eff; text-decoration: none; }
.empty a:hover { text-decoration: underline; }

#results { margin-top: 15px; }
#results table { margin-top: 10px; }

/* ============================================================
   АНАЛИТИКА
   ============================================================ */

.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 15px;
}

.analytics-item {
    background: #1f1f1f;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 12px;
    text-align: center;
}

.analytics-label {
    font-size: 0.75rem;
    color: #888;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.analytics-value {
    font-size: 1.1rem;
    font-weight: bold;
    color: #4a9eff;
    word-break: break-word;
}

.forecast-box {
    background: linear-gradient(135deg, #1f2a1f, #2a251f);
    border: 2px solid #ff9800;
    border-radius: 8px;
    padding: 15px;
    margin-top: 15px;
    text-align: center;
}

.forecast-box.done {
    background: linear-gradient(135deg, #1f2a1f, #1f2a1f);
    border-color: #4caf50;
}

.forecast-label {
    font-size: 0.85rem;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.forecast-value {
    font-size: 1.1rem;
    color: #e0e0e0;
}

.forecast-value strong {
    color: #ff9800;
    font-size: 1.3rem;
}

.forecast-box.done .forecast-value strong {
    color: #4caf50;
}

.forecast-value a {
    color: #4a9eff;
    text-decoration: none;
}

.forecast-value a:hover {
    text-decoration: underline;
}

.forecast-date {
    color: #888;
    font-size: 0.9rem;
}

/* График */
.chart {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 120px;
    padding: 10px 0;
    border-bottom: 1px solid #333;
    margin-bottom: 8px;
}

.chart-bar {
    flex: 1;
    height: 100%;
    display: flex;
    align-items: flex-end;
    cursor: pointer;
    position: relative;
}

.chart-bar-fill {
    width: 100%;
    background: linear-gradient(to top, #4a9eff, #6ab0ff);
    border-radius: 2px 2px 0 0;
    min-height: 2px;
    transition: background 0.2s;
}

.chart-bar:hover .chart-bar-fill {
    background: linear-gradient(to top, #ff9800, #ffb74d);
}

.chart-legend {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: #666;
}

/* ============================================================
   СВОРАЧИВАЕМЫЕ БЛОКИ (COLLAPSE)
   ============================================================ */

.collapsible {
    position: relative;
}

.collapsible-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    padding: 5px 0;
    margin: -5px 0 10px 0;
    transition: color 0.2s;
}

.collapsible-header:hover {
    color: #4a9eff;
}

.collapsible-header h2 {
    margin: 0;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.collapsible-arrow {
    font-size: 0.8rem;
    color: #888;
    transition: transform 0.2s;
    margin-left: 10px;
}

.collapsible.collapsed .collapsible-arrow {
    transform: rotate(-90deg);
}

.collapsible.collapsed .collapsible-body {
    display: none;
}

.collapsible-body {
    transition: opacity 0.2s;
}

/* ============================================================
   ДЕРЕВО ИССЛЕДОВАНИЯ
   ============================================================ */

.tree-legend { display: flex; gap: 20px; flex-wrap: wrap; padding: 12px 20px; align-items: center; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; color: #aaa; }

.status-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid transparent; }
.status-dot.status-purchased { background: #4caf50; }
.status-dot.status-progress { background: #ff9800; }
.status-dot.status-locked { background: #555; }
.group-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: #4a9eff; border: 2px solid #2a2a2a; }
.reserve-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: #444; border: 2px solid #2a2a2a; }

.tree-card { padding: 10px; }
.tree-grid-wrap { overflow-x: auto; overflow-y: visible; padding-bottom: 10px; }
.tree-table { border-collapse: separate; border-spacing: 8px; min-width: max-content; }
.rank-header { background: transparent; border: none; }
.branch-header, .premium-header { background: #1f1f1f; color: #888; font-size: 0.7rem; text-transform: uppercase; padding: 8px 6px; text-align: center; border-radius: 6px 6px 0 0; font-weight: normal; letter-spacing: 0.5px; }
.premium-header { color: #ffc107; background: #2a2510; }
.rank-cell { background: #1f1f1f; color: #4a9eff; font-weight: bold; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px; text-align: center; vertical-align: middle; padding: 10px 8px; border-radius: 6px; border: 1px solid #333; min-width: 70px; white-space: nowrap; }
.branch-cell { vertical-align: top; padding: 4px; min-width: 130px; max-width: 150px; }
.premium-cell { vertical-align: top; padding: 4px; min-width: 140px; max-width: 160px; border-left: 2px dashed #444; background: rgba(255, 193, 7, 0.03); }

.tree-node { background: #252525; border: 2px solid #444; border-radius: 6px; padding: 8px 10px; margin-bottom: 4px; text-align: center; transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s; cursor: pointer; position: relative; }
.tree-node:hover { transform: translateY(-2px); box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4); }
.tree-node.status-locked { border-color: #444; background: #1f1f1f; opacity: 0.75; }
.tree-node.status-active { border-color: #ff9800; background: #2a251f; box-shadow: 0 0 10px rgba(255, 152, 0, 0.25); }
.tree-node.status-done { border-color: #4caf50; background: #1f2a1f; }
.tree-node.group-node { border-color: #4a9eff; background: #1f242a; }
.tree-node.group-node:hover { box-shadow: 0 4px 14px rgba(74, 158, 255, 0.3); }
.reserve-node { border-color: #555 !important; background: #1a1a1a !important; opacity: 0.6; }
.reserve-node:hover { opacity: 0.9; }
.premium-node { border-color: #ffc107 !important; background: #2a2510 !important; position: relative; }
.premium-node::before { content: "⭐"; position: absolute; top: 3px; right: 5px; font-size: 0.7rem; opacity: 0.9; }
.premium-node:hover { box-shadow: 0 4px 14px rgba(255, 193, 7, 0.3) !important; }

.node-name { font-size: 0.75rem; font-weight: bold; color: #e0e0e0; line-height: 1.2; word-wrap: break-word; overflow-wrap: break-word; margin-bottom: 2px; }
.node-sub { font-size: 0.65rem; color: #888; }
.node-badge { position: absolute; bottom: 3px; right: 5px; font-size: 0.6rem; background: #444; color: #aaa; padding: 1px 5px; border-radius: 3px; text-transform: uppercase; }
.done-badge { background: #4caf50 !important; color: #fff !important; }
.progress-badge { background: #ff9800 !important; color: #fff !important; }
.node-progress { height: 3px; background: #333; border-radius: 2px; overflow: hidden; margin-top: 4px; }
.node-progress-fill { height: 100%; background: #ff9800; border-radius: 2px; transition: width 0.3s; }

/* ============ Модальное окно ============ */

.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.7); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.modal-content { background: #2a2a2a; border-radius: 10px; border: 1px solid #444; max-width: 600px; width: 100%; max-height: 80vh; overflow-y: auto; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; border-bottom: 1px solid #333; }
.modal-header h3 { color: #4a9eff; font-size: 1.1rem; }
.modal-close { background: none; border: none; color: #aaa; font-size: 1.5rem; cursor: pointer; padding: 0 5px; line-height: 1; }
.modal-close:hover { color: #fff; }
#modal-body { padding: 15px 20px; }
#modal-body .status-locked { color: #888; }
#modal-body .status-progress { color: #ff9800; font-weight: bold; }
#modal-body .status-purchased { color: #4caf50; }

/* ============ Адаптив ============ */

@media (max-width: 768px) {
    .rank-cell { min-width: 50px; font-size: 0.65rem; padding: 6px 4px; }
    .branch-cell { min-width: 100px; max-width: 110px; }
    .premium-cell { min-width: 110px; max-width: 120px; }
    .node-name { font-size: 0.7rem; }
    .node-sub { font-size: 0.6rem; }
    .premium-header { font-size: 0.6rem; padding: 6px 4px; }
}

@media (max-width: 600px) {
    header h1 { font-size: 1.2rem; }
    nav { gap: 5px; }
    nav a { padding: 5px 10px; font-size: 0.9rem; }
    .summary { grid-template-columns: 1fr; }
    .summary-item .value { font-size: 1.1rem; }
    .card { padding: 15px; }
    .form-row { flex-direction: column; align-items: stretch; }
    .form-row .form-group { width: 100%; }
    .form-row button { width: 100%; }
    table { font-size: 0.85rem; }
    th, td { padding: 8px 5px; }
    .tank-header { flex-direction: column; align-items: flex-start; }
    .tank-stats { flex-direction: column; align-items: flex-start; }
    .page-header { flex-direction: column; align-items: stretch; }
    .page-header .btn { width: 100%; text-align: center; }
    .tab { padding: 6px 12px; font-size: 0.85rem; }
    .tree-legend { gap: 10px; font-size: 0.8rem; }
    .analytics-grid { grid-template-columns: repeat(2, 1fr); }
    .analytics-value { font-size: 0.95rem; }
    .chart { height: 80px; }
    .collapsible-header h2 { font-size: 1rem; }
    .collapsible-header { padding: 8px 0; margin: -5px 0 8px 0; }
}

/* ============ Скроллбар ============ */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #1a1a1a; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* ============================================================
   КНОПКИ ДАТ, РЕДАКТИРОВАНИЕ, БЫСТРОЕ ДОБАВЛЕНИЕ
   ============================================================ */

.date-buttons {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.date-btn {
    background: #333;
    color: #aaa;
    border: 1px solid #444;
    padding: 6px 14px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s, color 0.2s;
}

.date-btn:hover {
    background: #4a9eff;
    color: #fff;
    border-color: #4a9eff;
}

.edit-battle-btn {
    margin-right: 5px;
}

/* Кнопка быстрого добавления на узле дерева */
.quick-battle-btn {
    position: absolute;
    top: 3px;
    left: 5px;
    width: 18px;
    height: 18px;
    padding: 0;
    background: #4a9eff;
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 0.85rem;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.2s, background 0.2s;
}

.quick-battle-btn:hover {
    opacity: 1;
    background: #ff9800;
}

@media (max-width: 600px) {
    .quick-battle-btn {
        width: 16px;
        height: 16px;
        font-size: 0.75rem;
        top: 2px;
        left: 3px;
    }

    .date-btn {
        padding: 5px 10px;
        font-size: 0.8rem;
    }
}