/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f1117;
    --bg-card: #181b23;
    --bg-input: #1e2230;
    --bg-hover: #242838;
    --border: #2a2e3d;
    --border-focus: #4f8ff7;
    --text: #e1e4ed;
    --text-muted: #8b90a0;
    --text-dim: #5c6070;
    --accent: #4f8ff7;
    --accent-hover: #3a7de6;
    --green: #34d399;
    --green-bg: rgba(52, 211, 153, 0.12);
    --red: #f87171;
    --red-bg: rgba(248, 113, 113, 0.12);
    --yellow: #fbbf24;
    --yellow-bg: rgba(251, 191, 36, 0.12);
    --radius: 8px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
}

html, body { height: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

#app { display: flex; height: 100vh; }

/* === Layout === */
.layout { display: flex; width: 100%; height: 100%; }
.sidebar {
    width: 220px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 32px 40px;
}

/* === Sidebar === */
.sidebar-logo {
    padding: 20px 24px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}
.sidebar-logo span { color: var(--accent); }

.sidebar-nav { padding: 12px 0; flex: 1; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 24px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: color 0.15s, background 0.15s;
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover { color: var(--text); background: var(--bg-hover); }
.sidebar-nav a.active {
    color: var(--accent);
    background: rgba(79, 143, 247, 0.08);
    border-left-color: var(--accent);
}
.sidebar-nav a svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.7; }
.sidebar-nav a.active svg { opacity: 1; }

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sidebar-user {
    font-size: 13px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-user strong { color: var(--text); display: block; font-weight: 600; }

.btn-logout {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    transition: all 0.15s;
}
.btn-logout:hover { border-color: var(--red); color: var(--red); }

/* === Page header === */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
}
.page-header h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.page-header-actions { display: flex; gap: 10px; }

/* === Cards === */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.stat-card-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.stat-card-value {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.stat-card-value.green { color: var(--green); }
.stat-card-value.accent { color: var(--accent); }

/* === Tables === */
.table-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
table {
    width: 100%;
    border-collapse: collapse;
}
thead th {
    text-align: left;
    padding: 12px 16px;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}
tbody td {
    padding: 12px 16px;
    font-size: 13.5px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

.empty-state {
    padding: 48px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* === Badges === */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-blue { background: rgba(79, 143, 247, 0.12); color: var(--accent); }
.badge-gray { background: rgba(91, 96, 112, 0.2); color: var(--text-muted); }

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}
.status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.offline { background: var(--text-dim); }

.tag {
    display: inline-block;
    padding: 1px 7px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
    color: var(--text-muted);
    margin-right: 4px;
    margin-bottom: 2px;
}

.mono { font-family: var(--mono); font-size: 12.5px; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--text-dim); }
.btn-danger { background: var(--red-bg); color: var(--red); border: 1px solid rgba(248, 113, 113, 0.2); }
.btn-danger:hover:not(:disabled) { background: rgba(248, 113, 113, 0.2); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
}
.btn-icon:hover { color: var(--text); background: var(--bg-hover); }
.btn-icon.danger:hover { color: var(--red); }

.action-btns { display: flex; gap: 4px; }

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal h2 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 20px;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
}

/* === Forms === */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13.5px;
    font-family: var(--font);
    transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--border-focus);
}
.form-group textarea {
    min-height: 120px;
    resize: vertical;
    font-family: var(--mono);
    font-size: 13px;
}
.form-group input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
}
.form-hint {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 4px;
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* === Login === */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100%;
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
}
.login-card h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}
.login-card h1 span { color: var(--accent); }
.login-card p {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 28px;
}
.login-card .btn { width: 100%; justify-content: center; padding: 10px; }
.login-error {
    background: var(--red-bg);
    color: var(--red);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
}

/* === Token display === */
.token-display {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-family: var(--mono);
    font-size: 13px;
    word-break: break-all;
    margin: 12px 0;
    position: relative;
}
.token-display .copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
}
.token-warning {
    font-size: 12.5px;
    color: var(--yellow);
    margin-top: 8px;
}

/* === ACL Editor === */
.acl-rule {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    position: relative;
}
.acl-rule-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.acl-rule-num {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}
.acl-rule .form-group { margin-bottom: 10px; }
.acl-rule .form-group label { font-size: 11.5px; }

/* === Toast === */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13.5px;
    font-weight: 500;
    z-index: 200;
    animation: toast-in 0.3s ease;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.toast-success { background: #1a3a2a; color: var(--green); border: 1px solid rgba(52, 211, 153, 0.3); }
.toast-error { background: #3a1a1a; color: var(--red); border: 1px solid rgba(248, 113, 113, 0.3); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-logo span, .sidebar-nav a span, .sidebar-user, .sidebar-footer { display: none; }
    .sidebar-logo { padding: 16px; text-align: center; }
    .sidebar-nav a { justify-content: center; padding: 12px; border-left: none; }
    .main-content { padding: 20px; }
    .card-grid { grid-template-columns: repeat(2, 1fr); }
    .form-row { grid-template-columns: 1fr; }
}
