:root {
    --bg:              #f0f2f5;
    --sidebar-bg:      #ffffff;
    --sidebar-w:       250px;
    --header-bg:       #ffffff;
    --card-bg:         #ffffff;
    --border:          #e4e8ed;
    --text:            #2c3e50;
    --text-muted:      #8492a6;
    --accent:          #5b8dee;
    --accent-hover:    #4a7cdc;
    --accent-light:    #eef3fd;
    --success:         #28a96a;
    --danger:          #e55353;
    --warning:         #f5a623;
    --shadow-sm:       0 1px 3px rgba(0,0,0,.07);
    --shadow:          0 2px 8px rgba(0,0,0,.09);
    --radius:          8px;
    --sidebar-item-h:  40px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
}

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

/* ─── Sidebar ────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand .brand-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -.3px;
    margin: 0;
}

.sidebar-brand .brand-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin: 2px 0 0;
}

.sidebar-nav {
    padding: 12px 0;
    flex: 1;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--text-muted);
    padding: 12px 20px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--sidebar-item-h);
    padding: 0 20px;
    color: var(--text);
    text-decoration: none;
    border-radius: 0;
    transition: background .15s, color .15s;
    font-size: 13.5px;
}

.nav-item:hover {
    background: var(--bg);
    color: var(--accent);
}

.nav-item.active {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 600;
    border-left: 3px solid var(--accent);
}

.nav-item .nav-icon {
    width: 18px;
    text-align: center;
    opacity: .7;
    flex-shrink: 0;
}

.nav-item.active .nav-icon { opacity: 1; }

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 12px 0;
}

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

/* ─── Topbar ─────────────────────────────── */
.topbar {
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    height: 56px;
    display: flex;
    align-items: center;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.topbar-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-user {
    font-size: 13px;
    color: var(--text-muted);
}

/* ─── Content ────────────────────────────── */
.content {
    padding: 28px;
    flex: 1;
}

/* ─── Cards ──────────────────────────────── */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.card-body {
    padding: 20px;
}

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

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
}

.stat-card .stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .5px;
}

.stat-card .stat-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.stat-card .stat-icon {
    float: right;
    font-size: 20px;
    opacity: .18;
    margin-top: -34px;
}

.stat-card.accent  { border-left: 3px solid var(--accent); }
.stat-card.success { border-left: 3px solid var(--success); }
.stat-card.danger  { border-left: 3px solid var(--danger); }
.stat-card.warning { border-left: 3px solid var(--warning); }

/* ─── Tables ─────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
}

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

thead th {
    background: #f8f9fb;
    border-bottom: 1px solid var(--border);
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .4px;
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background .1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

td {
    padding: 10px 14px;
    vertical-align: middle;
}

/* ─── Buttons ────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    transition: all .15s;
    white-space: nowrap;
}

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

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

.btn-outline {
    background: transparent;
    color: var(--accent);
    border-color: var(--accent);
}

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

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.btn-danger:hover { opacity: .88; color: #fff; }

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

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

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 2px 8px;  font-size: 11px; }

/* ─── Badges ─────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .2px;
}

.badge-success { background: #e8f7ef; color: #1a7a47; }
.badge-danger  { background: #fdecea; color: #c0392b; }
.badge-warning { background: #fef8e7; color: #996a00; }
.badge-info    { background: var(--accent-light); color: var(--accent); }
.badge-neutral { background: #f0f2f5; color: var(--text-muted); }

/* ─── Forms ──────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 5px;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13.5px;
    color: var(--text);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}

.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(91,141,238,.12);
}

select.form-control { cursor: pointer; }

.form-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.form-row .form-group { flex: 1; min-width: 160px; }

/* ─── Filter bar ─────────────────────────── */
.filter-bar {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 18px;
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.filter-bar .form-group { margin-bottom: 0; }

/* ─── Pagination ─────────────────────────── */
.pagination {
    display: flex;
    gap: 4px;
    align-items: center;
    list-style: none;
    padding: 0;
    margin: 18px 0 0;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    color: var(--text);
    text-decoration: none;
    background: var(--card-bg);
    transition: all .15s;
}

.page-link:hover { border-color: var(--accent); color: var(--accent); }
.page-link.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.page-link.disabled { opacity: .4; pointer-events: none; }

/* ─── Alerts / Flash ─────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13.5px;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success { background: #e8f7ef; color: #1a7a47; border: 1px solid #b8e6d0; }
.alert-danger  { background: #fdecea; color: #c0392b; border: 1px solid #f5c6c6; }
.alert-warning { background: #fef8e7; color: #996a00; border: 1px solid #f5e199; }
.alert-info    { background: var(--accent-light); color: var(--accent); border: 1px solid #c8d9f8; }

/* ─── Page header ────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.page-header h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

/* ─── Service health dots ────────────────── */
.health-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

.health-dot.ok    { background: var(--success); box-shadow: 0 0 0 3px rgba(40,169,106,.2); }
.health-dot.error { background: var(--danger);  box-shadow: 0 0 0 3px rgba(229,83,83,.2); }
.health-dot.warn  { background: var(--warning); box-shadow: 0 0 0 3px rgba(245,166,35,.2); }

/* ─── Log output ─────────────────────────── */
.log-output {
    background: #1e2433;
    color: #c9d1d9;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.6;
    padding: 16px 18px;
    border-radius: var(--radius);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 360px;
    overflow-y: auto;
}

/* ─── Tower config tabs ─────────────────── */
.tower-tabs-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.race-tabs {
    display: flex;
    gap: 0;
    background: #f8f9fb;
    border-bottom: 1px solid var(--border);
    padding: 0 8px;
    overflow-x: auto;
    flex-shrink: 0;
}

.race-tab {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 13px 18px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    cursor: pointer;
    transition: color .15s, border-color .15s;
    white-space: nowrap;
    outline: none;
}

.race-tab:hover {
    color: var(--text);
    background: rgba(0,0,0,.03);
}

.race-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.race-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 18px;
    padding: 0 5px;
    background: var(--border);
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    transition: background .15s, color .15s;
}

.race-tab.active .race-count {
    background: var(--accent-light);
    color: var(--accent);
}

.race-panel {
    display: none;
}

.race-panel.active {
    display: block;
}

/* ─── Tower config table ─────────────────── */
.tower-table input[type=number],
.tower-table select {
    width: 90px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
    color: var(--text);
    background: #fff;
}

.tower-table input[type=number]:focus,
.tower-table select:focus {
    border-color: var(--accent);
    outline: none;
}

/* ─── Progress bar (loot weights) ───────── */
.prob-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.prob-bar-fill {
    height: 6px;
    border-radius: 3px;
    background: var(--accent);
    min-width: 2px;
    transition: width .3s;
}

.prob-bar-label {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ─── Login page ─────────────────────────── */
.login-wrap {
    min-height: 100vh;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 40px;
    width: 360px;
}

.login-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 6px;
    text-align: center;
}

.login-sub {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 28px;
}

/* ─── Misc ───────────────────────────────── */
.text-muted   { color: var(--text-muted); }
.text-accent  { color: var(--accent); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.fw-600       { font-weight: 600; }
.gap-2        { gap: 8px; }
.d-flex       { display: flex; }
.align-center { align-items: center; }
.mt-1  { margin-top: 4px; }
.mt-2  { margin-top: 8px; }
.mt-3  { margin-top: 16px; }
.mb-0  { margin-bottom: 0; }
.mb-3  { margin-bottom: 16px; }
.ms-auto { margin-left: auto; }
