/* ── Variables ── */
:root {
    --bg: #0d1117;
    --bg2: #161b22;
    --surface: #1c2333;
    --surface2: #242d3d;
    --border: rgba(255,255,255,.08);
    --border2: rgba(255,255,255,.14);
    --text: #e6edf3;
    --muted: #8b949e;
    --accent: #58a6ff;
    --accent2: #1f6feb;
    --green: #3fb950;
    --green-bg: rgba(63,185,80,.12);
    --red: #f85149;
    --red-bg: rgba(248,81,73,.12);
    --yellow: #d29922;
    --yellow-bg: rgba(210,153,34,.12);
    --purple: #bc8cff;
    --sidebar-w: 252px;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0,0,0,.4);
    --font: 'DM Sans', system-ui, sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* ── Layout ── */
.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Brand ── */
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 8px 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.brand-icon {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, #1f6feb, #388bfd);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.brand h1 { font-size: 1.05rem; font-weight: 700; letter-spacing: -.02em; }
.brand p { font-size: .75rem; color: var(--muted); margin-top: 1px; }

/* ── Nav ── */
.nav-label {
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    padding: 0 10px;
    margin-bottom: 6px;
}

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted);
    font-family: var(--font);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: background .15s, color .15s;
}

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

.nav-item.active {
    background: rgba(88,166,255,.15);
    color: var(--accent);
    font-weight: 600;
}

.nav-icon { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }

/* ── Sidebar footer ── */
.sidebar-footer {
    border-top: 1px solid var(--border);
    padding-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sync-status { font-size: .72rem; color: var(--muted); text-align: center; }

/* ── Header ── */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 28px 0;
    gap: 16px;
}

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

.header h2 { font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em; }
.page-desc { font-size: .85rem; color: var(--muted); margin-top: 2px; }

.header-meta {
    padding: 6px 28px 0;
    font-size: .78rem;
    color: var(--muted);
}

.header-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.menu-toggle {
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    cursor: pointer;
    font-size: 1rem;
}

/* ── Page content ── */
.page-content { padding: 20px 28px 40px; flex: 1; }
.page { display: none; }
.page.active { display: block; }

/* ── Cards ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 16px;
}

.card-flush { overflow: visible; }
.card-head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,.02);
}
.card-head.row { display: flex; align-items: center; justify-content: space-between; }
.card-head h3 { font-size: .9rem; font-weight: 600; }
.card-body { padding: 18px; }

/* ── Stat grid ── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: border-color .15s;
}

.stat-card:hover { border-color: var(--border2); }
.stat-card.highlight { border-color: rgba(88,166,255,.4); background: rgba(88,166,255,.06); }
.stat-card.success { border-color: rgba(63,185,80,.3); background: var(--green-bg); }

.stat-icon { font-size: 1.3rem; }
.stat-label { font-size: .75rem; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.stat-value.sm { font-size: 1rem; font-weight: 600; }

/* ── Split grid ── */
.split-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.team-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

/* ── Info banner ── */
.info-banner {
    background: rgba(88,166,255,.08);
    border: 1px solid rgba(88,166,255,.2);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: .85rem;
    color: #9ec5ff;
    margin-bottom: 16px;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-family: var(--font);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .1s;
    white-space: nowrap;
}

.btn:hover { border-color: var(--border2); background: #2d3748; }
.btn:active { transform: scale(.98); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 5px 12px; font-size: .8rem; }

.btn-primary {
    background: linear-gradient(135deg, var(--accent2), #388bfd);
    border-color: transparent;
    color: #fff;
    font-weight: 600;
}
.btn-primary:hover { background: linear-gradient(135deg, #388bfd, #58a6ff); }

.btn-secondary { background: var(--surface2); }
.btn-danger { background: var(--red-bg); border-color: rgba(248,81,73,.3); color: #ffa198; }
.btn-danger:hover { background: rgba(248,81,73,.2); }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* ── Form elements ── */
.field-label {
    display: block;
    font-size: .8rem;
    font-weight: 500;
    color: var(--muted);
    margin-bottom: 6px;
    margin-top: 12px;
}
.field-label:first-child { margin-top: 0; }
.field-hint { font-weight: 400; opacity: .7; }

input, select, textarea {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: .875rem;
    padding: 9px 12px;
    transition: border-color .15s;
    outline: none;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(88,166,255,.15);
}

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

.toggle-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 99px;
    padding: 6px 14px;
    font-size: .82rem;
    cursor: pointer;
    color: var(--muted);
    user-select: none;
}

.toggle-pill:has(input:checked) {
    background: rgba(88,166,255,.12);
    border-color: rgba(88,166,255,.3);
    color: var(--accent);
}

.toggle-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }

.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ── Filter bar ── */
.filter-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.filter-bar input, .filter-bar select { max-width: 280px; }

/* ── Table ── */
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table th {
    text-align: left;
    padding: 10px 16px;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,.02);
    white-space: nowrap;
}
.data-table td {
    padding: 11px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,.02); }

.warn { color: var(--yellow); font-weight: 600; }

/* ── Tags & badges ── */
.team-tag {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 99px;
    font-size: .75rem;
    font-weight: 600;
    background: rgba(88,166,255,.12);
    border: 1px solid rgba(88,166,255,.25);
    color: #9ec5ff;
}

.team-tag.team-rouge { background: rgba(231,76,60,.12); border-color: rgba(231,76,60,.3); color: #ff8a7a; }
.team-tag.team-bleu  { background: rgba(52,152,219,.12); border-color: rgba(52,152,219,.3); color: #79c4ff; }
.team-tag.team-vert  { background: rgba(46,204,113,.12); border-color: rgba(46,204,113,.3); color: #6dffa8; }
.team-tag.team-jaune { background: rgba(241,196,15,.12); border-color: rgba(241,196,15,.3); color: #ffe066; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: .72rem;
    font-weight: 600;
    background: var(--surface2);
    color: var(--muted);
}

.status-on  { color: var(--green); }
.status-off { color: var(--red); }

/* ── Team cards ── */
.team-card .card-body { padding: 16px 18px; }
.team-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.team-card-header h3 { font-size: 1rem; font-weight: 700; }
.team-rouge { color: #ff8a7a; }
.team-bleu  { color: #79c4ff; }
.team-vert  { color: #6dffa8; }
.team-jaune { color: #ffe066; }

.member-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.member-chip {
    padding: 3px 9px;
    border-radius: 99px;
    font-size: .75rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--muted);
}
.member-chip.online { background: var(--green-bg); border-color: rgba(63,185,80,.3); color: #6dffa8; }

.team-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.team-actions input { max-width: 130px; flex: 1; min-width: 100px; }
.team-actions .btn { flex-shrink: 0; }

/* ── Events ── */
.event-list { display: flex; flex-direction: column; gap: 8px; }
.event-list.compact .event-item { padding: 8px 12px; }

.event-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
}
.event-item.type-join          { border-left-color: var(--green); }
.event-item.type-quit          { border-left-color: var(--muted); }
.event-item.type-death         { border-left-color: var(--red); }
.event-item.type-team_add      { border-left-color: var(--purple); }
.event-item.type-team_remove   { border-left-color: var(--yellow); }
.event-item.type-broadcast     { border-left-color: #ffa657; }
.event-item.type-content_update{ border-left-color: var(--accent); }

.event-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.event-time { font-size: .75rem; color: var(--muted); }
.event-body { font-size: .875rem; }
.event-detail { font-size: .8rem; color: var(--muted); margin-top: 4px; }

/* ── Bar chart ── */
.bar-row { display: grid; grid-template-columns: 72px 1fr 28px; gap: 8px; align-items: center; margin-bottom: 10px; }
.bar-label { font-size: .82rem; font-weight: 500; }
.bar-track { background: var(--bg); border-radius: 99px; height: 7px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: var(--accent); transition: width .4s ease; }
.bar-fill.team-rouge { background: #e74c3c; }
.bar-fill.team-bleu  { background: #3498db; }
.bar-fill.team-vert  { background: #2ecc71; }
.bar-fill.team-jaune { background: #f1c40f; }
.bar-value { text-align: right; font-size: .82rem; color: var(--muted); font-weight: 600; }

/* ── Config grid ── */
.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
}

.config-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
}
.config-item span { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 500; display: block; margin-bottom: 4px; }
.config-item strong { font-size: .875rem; word-break: break-all; }

/* ── Shops ── */
.shop-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 16px;
    align-items: start;
}

.shop-items { list-style: none; padding: 0 12px 12px; }
.shop-items li {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    margin-bottom: 4px;
    transition: background .15s, border-color .15s;
}
.shop-items li:hover { background: var(--surface2); }
.shop-items li.active { background: rgba(88,166,255,.1); border-color: rgba(88,166,255,.3); }
.shop-items li strong { display: block; font-size: .875rem; }
.shop-items li span { font-size: .75rem; color: var(--muted); display: block; margin-top: 2px; }
.shop-items li .shop-coords {
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: .68rem;
    color: var(--accent);
    margin-top: 4px;
    line-height: 1.35;
    word-break: break-all;
}

.npc-panel { min-height: 48px; }
.npc-empty { font-size: .8rem; color: var(--muted); margin: 0; }
.npc-list { display: flex; flex-direction: column; gap: 8px; }
.npc-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
}
.npc-card-head { font-size: .8rem; font-weight: 600; margin-bottom: 6px; }
.npc-coords {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    margin-bottom: 4px;
}
.npc-world {
    font-size: .72rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
}
.npc-coords code {
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: .85rem;
    color: var(--accent);
    background: rgba(88,166,255,.08);
    padding: 4px 8px;
    border-radius: 6px;
}
.npc-meta { font-size: .72rem; color: var(--muted); }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 14px;
}

.trade-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-bottom: 10px;
}
.trade-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }

/* ── Preview ── */
.mc-preview {
    background: rgba(0,0,0,.4);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    font-family: 'Courier New', monospace;
    font-size: .9rem;
    line-height: 1.7;
    color: #e6edf3;
    min-height: 60px;
}

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--muted);
}
.empty-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: .5; }

/* ── Toast ── */
.toast {
    position: fixed;
    bottom: 24px; right: 24px;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    background: var(--green-bg);
    border: 1px solid rgba(63,185,80,.3);
    color: #6dffa8;
    font-size: .875rem;
    font-weight: 500;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .25s, transform .25s;
    z-index: 999;
    box-shadow: var(--shadow);
    max-width: 360px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red-bg); border-color: rgba(248,81,73,.3); color: #ffa198; }

/* ── Utils ── */
.hidden { display: none !important; }
code {
    background: rgba(255,255,255,.06);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: .82em;
    font-family: 'Courier New', monospace;
}
.hint { font-size: .8rem; color: var(--muted); }
.actions-cell { display: flex; gap: 5px; flex-wrap: wrap; }
.actions-cell .btn, .actions-cell select { padding: 4px 8px; font-size: .78rem; width: auto; }

/* ── Responsive ── */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: var(--shadow);
    }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .menu-toggle { display: block; }
    .split-grid, .shop-layout, .form-grid, .trade-grid { grid-template-columns: 1fr; }
    .header { padding: 16px 16px 0; }
    .header-meta { padding: 6px 16px 0; }
    .page-content { padding: 16px; }
}
