:root {
    --bg: #1e1e1e;
    --surface: #2a2a2a;
    --surface-hover: #333333;
    --border: #3e3e3e;
    --text: #e0e0e0;
    --text-muted: #999999;
    --primary: #5ba0d6;
    --primary-hover: #4a90c6;
    --success: #5cb85c;
    --success-bg: rgba(92,184,92,.15);
    --warning: #f0ad4e;
    --warning-bg: rgba(240,173,78,.15);
    --danger: #d9534f;
    --danger-hover: #c9302c;
    --danger-bg: rgba(217,83,79,.15);
    --sidebar-width: 220px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --mono: "SF Mono", "Cascadia Code", "Consolas", monospace;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* ---------- Sidebar ---------- */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease, width 0.2s ease;
    z-index: 100;
}
#sidebar.collapsed {
    transform: translateX(calc(-1 * var(--sidebar-width)));
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    font-size: 16px;
}
.sidebar-logo { height: 32px; width: auto; }
.sidebar-toggle {
    position: fixed;
    top: 1.65rem;
    left: calc(var(--sidebar-width) - 2.5rem);
    z-index: 101;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    transition: left 0.2s ease;
}
body.sidebar-collapsed .sidebar-toggle {
    left: 0.75rem;
}
.sidebar-toggle:hover { color: var(--text); }

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0;
    overflow-y: auto;
}
.sidebar-nav a {
    display: block;
    padding: 0.6rem 1.25rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    border-left: 3px solid transparent;
    transition: background 0.15s, color 0.15s;
}
.sidebar-nav a:hover {
    background: var(--surface-hover);
    color: var(--text);
}
.sidebar-nav a.active {
    color: var(--primary);
    border-left-color: var(--primary);
    background: var(--surface-hover);
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}
.sidebar-user { color: var(--text-muted); }
.sidebar-footer a { color: var(--text-muted); text-decoration: none; }
.sidebar-footer a:hover { color: var(--danger); }

/* ---------- Main content ---------- */
main {
    margin-left: var(--sidebar-width);
    padding: 1.5rem 2rem;
    min-height: 100vh;
    transition: margin-left 0.2s ease;
}
body.sidebar-collapsed main {
    margin-left: 0;
    padding-left: 3.5rem;
}

/* ---------- Flash ---------- */
.flash-container { margin-bottom: 1rem; }
.flash {
    padding: 0.75rem 1rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    font-size: 14px;
}
.flash-success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success); }
.flash-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.flash-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning); }
.flash-info { background: rgba(74,158,255,.15); color: var(--primary); border: 1px solid var(--primary); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    padding: 0.4rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    line-height: 1.5;
}
.btn:hover { background: var(--surface-hover); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-secondary { background: #555; color: #fff; border-color: #555; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 0.2rem 0.5rem; font-size: 12px; }
.btn-full { width: 100%; }

/* ---------- Badge ---------- */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; margin: 1rem 0; background: var(--surface); border-radius: 6px; overflow: hidden; }
th, td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
th { background: var(--surface-hover); font-weight: 600; position: sticky; top: 0; color: var(--text-muted); }
tbody tr:hover { background: var(--surface-hover); }
.cell-truncate { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-mono { font-family: var(--mono); font-size: 12px; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.25rem; color: var(--text-muted); }
input[type="text"], input[type="password"], input[type="email"],
input[type="number"], select, textarea {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(74,158,255,.2); }

.inline-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0.5rem 0; }
.inline-form input { width: auto; }
.input-xs { width: 60px !important; }
.input-sm { width: 120px !important; }
.input-lg { width: 250px !important; }
.checkbox-label { display: flex; align-items: center; gap: 0.25rem; font-size: 13px; white-space: nowrap; }
.inline { display: inline; }

.search-bar, .filter-bar { display: flex; gap: 0.5rem; align-items: center; margin: 1rem 0; }
.search-bar input, .filter-bar input { width: 250px; }
.filter-bar select { width: 150px; }

/* ---------- Login ---------- */
.login-container {
    max-width: 360px;
    margin: 4rem auto;
    background: var(--surface);
    padding: 2rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.login-logo { display: block; margin: 0 auto 1.5rem; max-width: 200px; height: auto; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; margin-bottom: 1rem; }
.card-header { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); background: var(--surface-hover); }
.card-body { padding: 1rem; }
.card-body p { margin-bottom: 0.35rem; }

/* ---------- Sections ---------- */
.section { margin-bottom: 2rem; }
.section-header { display: flex; justify-content: space-between; align-items: center; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }

/* ---------- Kill switch ---------- */
.kill-switch-row { display: flex; gap: 1rem; margin: 0.75rem 0; }

/* ---------- Stats ---------- */
.stats-row { display: flex; gap: 1rem; margin: 1rem 0; }
.stat-card {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1.25rem;
    text-align: center;
}
.stat-value { font-size: 2rem; font-weight: 700; }
.stat-label { color: var(--text-muted); font-size: 13px; margin-top: 0.25rem; }

/* ---------- Detail card ---------- */
.detail-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
    margin: 1rem 0;
}
.detail-card p { margin-bottom: 0.35rem; }
.detail-card a { color: var(--primary); }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; gap: 1rem; margin: 1rem 0; }

/* ---------- Misc ---------- */
a { color: var(--primary); }
h1, h2, h3 { color: var(--text); }
.muted { color: var(--text-muted); }
.actions { white-space: nowrap; }
.actions form { display: inline-block; }
details { margin-top: 0.75rem; }
details summary { cursor: pointer; color: var(--primary); font-size: 13px; }
.cred-form { margin-top: 0.75rem; max-width: 400px; }
.cred-form .form-group { margin-bottom: 0.5rem; }
.cred-form input { width: 100%; }

/* ---------- File drop ---------- */
.file-drop {
    border: 2px dashed var(--border);
    border-radius: 6px;
    padding: 2rem;
    text-align: center;
    margin: 1rem 0;
    cursor: pointer;
    transition: border-color 0.2s;
}
.file-drop:hover, .file-drop.dragover { border-color: var(--primary); background: rgba(74,158,255,.05); }
.file-drop input[type="file"] { display: none; }
.import-form pre { background: var(--surface-hover); padding: 1rem; border-radius: 4px; font-size: 13px; overflow-x: auto; color: var(--text); }

/* ---------- Edit rows ---------- */
.edit-row td { background: var(--surface-hover); }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    #sidebar { transform: translateX(calc(-1 * var(--sidebar-width))); }
    #sidebar.open { transform: translateX(0); }
    main { margin-left: 0; padding: 1rem; }
    body.sidebar-collapsed main { margin-left: 0; }
    .stats-row { flex-direction: column; }
    .inline-form { flex-direction: column; align-items: stretch; }
    .inline-form input { width: 100% !important; }
    table { font-size: 12px; }
    th, td { padding: 0.35rem 0.5rem; }
    .cell-truncate { max-width: 120px; }
}
