:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: #1a2035;
    --bg-input: #0f1629;
    --border: #1e2a45;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #6c5ce7;
    --accent-hover: #7c6ff7;
    --accent-glow: rgba(108, 92, 231, 0.3);
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --sidebar-bg: #0d1224;
    --sidebar-border: #1a2540;
    --sidebar-active: rgba(108, 92, 231, 0.15);
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
    --transition: 0.2s ease;
}

[data-theme="light"] {
    --bg-primary: #f1f5f9;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #f8fafc;
    --border: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --sidebar-bg: #ffffff;
    --sidebar-border: #e2e8f0;
    --sidebar-active: rgba(108, 92, 231, 0.08);
    --shadow: 0 4px 24px rgba(0,0,0,0.06);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* Stars Background */
.stars-bg {
    position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
}
[data-theme="light"] .stars-bg { display: none; }

.star {
    position: absolute; width: 2px; height: 2px; background: #fff; border-radius: 50%;
    animation: twinkle var(--duration) infinite;
}
.star.large { width: 3px; height: 3px; box-shadow: 0 0 6px rgba(255,255,255,0.5); }

@keyframes twinkle {
    0%, 100% { opacity: 0.2; }
    50% { opacity: 1; }
}

.shooting-star {
    position: absolute; width: 80px; height: 1px;
    background: linear-gradient(90deg, rgba(108,92,231,0.8), transparent);
    animation: shoot var(--duration) linear infinite;
    opacity: 0;
}

@keyframes shoot {
    0% { transform: translateX(0) translateY(0); opacity: 0; }
    5% { opacity: 1; }
    20% { transform: translateX(300px) translateY(150px); opacity: 0; }
    100% { opacity: 0; }
}

/* Layout */
.app-layout {
    display: flex; min-height: 100vh; position: relative; z-index: 1;
}

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

.sidebar-brand {
    padding: 1.5rem; display: flex; align-items: center; gap: 12px;
    border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-brand .logo {
    width: 36px; height: 36px; background: linear-gradient(135deg, var(--accent), #a855f7);
    border-radius: 10px; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px; color: #fff;
}
.sidebar-brand h2 { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }

.sidebar-nav { flex: 1; padding: 1rem 0.75rem; overflow-y: auto; }

.nav-item {
    display: flex; align-items: center; gap: 12px; padding: 0.7rem 1rem;
    border-radius: var(--radius-sm); color: var(--text-secondary);
    text-decoration: none; font-size: 0.9rem; font-weight: 500;
    transition: all var(--transition); margin-bottom: 2px;
}
.nav-item:hover { background: var(--sidebar-active); color: var(--text-primary); }
.nav-item.active {
    background: var(--sidebar-active); color: var(--accent);
    border-left: 3px solid var(--accent);
}
.nav-item i { width: 20px; text-align: center; font-size: 1rem; }

.nav-section {
    font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-muted); padding: 1.2rem 1rem 0.5rem;
}

.sidebar-footer {
    padding: 1rem; border-top: 1px solid var(--sidebar-border);
    display: flex; align-items: center; gap: 10px;
}
.sidebar-footer .user-avatar {
    width: 34px; height: 34px; border-radius: 50%; background: var(--accent);
    display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; font-size: 0.8rem;
}
.sidebar-footer .user-info { flex: 1; }
.sidebar-footer .user-info .name { font-size: 0.85rem; font-weight: 600; color: var(--text-primary); }
.sidebar-footer .user-info .role { font-size: 0.72rem; color: var(--text-muted); }

/* Main content */
.main-content {
    flex: 1; margin-left: 260px; display: flex; flex-direction: column; min-height: 100vh;
}

.topbar {
    padding: 1rem 1.5rem; display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border); background: var(--bg-secondary);
    position: sticky; top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left h1 { font-size: 1.2rem; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.menu-toggle {
    display: none; background: none; border: none; color: var(--text-primary);
    font-size: 1.3rem; cursor: pointer; padding: 4px;
}

.content { flex: 1; padding: 1.5rem; }

/* Footer */
.app-footer {
    padding: 1rem 1.5rem; border-top: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.78rem; color: var(--text-muted);
}

/* Cards */
.card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.card-header {
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 {
    font-size: 0.95rem; font-weight: 600; display: flex; align-items: center; gap: 8px;
}
.card-body { padding: 1.25rem; }

/* Grid */
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block; font-size: 0.82rem; font-weight: 600; color: var(--text-secondary);
    margin-bottom: 0.4rem;
}
.form-control {
    width: 100%; padding: 0.6rem 0.9rem; background: var(--bg-input);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text-primary); font-size: 0.88rem; transition: border-color var(--transition);
    outline: none;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.form-control::placeholder { color: var(--text-muted); }

.input-icon {
    position: relative;
}
.input-icon i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 0.85rem; }
.input-icon input { padding-left: 2.4rem; }
.input-icon .toggle-pass {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--text-muted); cursor: pointer;
}

select.form-control { appearance: none; cursor: pointer; }

.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }

.form-check {
    display: flex; align-items: center; gap: 8px;
}
.form-check input[type="checkbox"] {
    width: 16px; height: 16px; accent-color: var(--accent);
}
.form-check label { font-size: 0.85rem; color: var(--text-secondary); margin: 0; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 8px; padding: 0.55rem 1.2rem;
    border: none; border-radius: var(--radius-sm); font-size: 0.85rem; font-weight: 600;
    cursor: pointer; transition: all var(--transition); text-decoration: none;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); box-shadow: 0 4px 12px var(--accent-glow); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #000; }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-input); color: var(--text-primary); }
.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.78rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { padding: 0.5rem; width: 34px; height: 34px; justify-content: center; }

/* Badges */
.badge {
    display: inline-flex; align-items: center; gap: 4px; padding: 0.25rem 0.6rem;
    border-radius: 20px; font-size: 0.72rem; font-weight: 600;
}
.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-info { background: rgba(59,130,246,0.15); color: var(--info); }

/* Tables */
.table-wrap { overflow-x: auto; }
table {
    width: 100%; border-collapse: collapse; font-size: 0.85rem;
}
table th {
    padding: 0.75rem 1rem; text-align: left; font-weight: 600; font-size: 0.78rem;
    text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}
table td {
    padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); color: var(--text-secondary);
}
table tr:hover td { background: var(--bg-input); }

/* Status dots */
.status-dot {
    width: 8px; height: 8px; border-radius: 50%; display: inline-block;
}
.status-dot.online { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.offline { background: var(--danger); }

/* Login page */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 1rem;
}
.login-container { position: relative; z-index: 1; width: 100%; max-width: 400px; }
.login-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.login-header {
    padding: 2.5rem 2rem; text-align: center;
    background: linear-gradient(135deg, var(--accent), #a855f7);
}
.login-header .login-logo {
    width: 56px; height: 56px; margin: 0 auto 1rem;
    background: rgba(255,255,255,0.2); border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 1.2rem; color: #fff;
}
.login-header h1 { color: #fff; font-size: 1.4rem; font-weight: 700; }
.login-header p { color: rgba(255,255,255,0.7); font-size: 0.88rem; margin-top: 0.3rem; }
.login-body { padding: 2rem; }
.login-footer { padding: 0 2rem 1.5rem; text-align: center; }

.theme-btn {
    background: var(--bg-input); border: 1px solid var(--border); border-radius: 50%;
    width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
    color: var(--text-secondary); cursor: pointer; transition: all var(--transition);
}
.theme-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 1000;
    display: none; align-items: center; justify-content: center; padding: 1rem;
    backdrop-filter: blur(4px);
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); width: 100%; max-width: 500px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4); animation: modalIn 0.2s ease;
}
.modal-header {
    padding: 1.25rem; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close {
    background: none; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer;
}
.modal-body { padding: 1.25rem; }
.modal-footer {
    padding: 1rem 1.25rem; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 0.5rem;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(-10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Toast */
.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 2000; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
    padding: 0.75rem 1.25rem; border-radius: var(--radius-sm);
    font-size: 0.85rem; font-weight: 500; color: #fff;
    animation: toastIn 0.3s ease; box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--info); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Stats */
.stat-card {
    padding: 1.25rem; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius);
}
.stat-card .stat-icon {
    width: 40px; height: 40px; border-radius: 10px; display: flex;
    align-items: center; justify-content: center; font-size: 1.1rem; margin-bottom: 0.75rem;
}
.stat-card .stat-value { font-size: 1.4rem; font-weight: 700; color: var(--text-primary); }
.stat-card .stat-label { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.2rem; }

/* PPPoE list items */
.pppoe-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.85rem 1rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
    margin-bottom: 0.5rem; transition: all var(--transition);
}
.pppoe-item:hover { border-color: var(--accent); background: var(--bg-input); }
.pppoe-item .pppoe-info { display: flex; align-items: center; gap: 12px; }
.pppoe-item .pppoe-name { font-weight: 600; font-size: 0.88rem; }
.pppoe-item .pppoe-ip { font-size: 0.8rem; color: var(--text-muted); font-family: monospace; }
.pppoe-item .pppoe-actions { display: flex; gap: 6px; }

/* Code blocks */
code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 0.82rem;
    background: var(--bg-input); padding: 0.2rem 0.5rem; border-radius: 4px;
    color: var(--accent);
}
.code-block {
    background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 1rem; font-family: monospace; font-size: 0.82rem; overflow-x: auto;
    color: var(--text-secondary);
}

/* Loading */
.spinner {
    width: 20px; height: 20px; border: 2px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
    background: linear-gradient(90deg, var(--bg-input) 25%, var(--border) 50%, var(--bg-input) 75%);
    background-size: 200% 100%; animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm); height: 20px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Utility */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-center { text-align: center; }
.fw-600 { font-weight: 600; }
.hidden { display: none !important; }

/* Responsive */
@media (max-width: 1024px) {
    .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.3); }
    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; }
    .topbar { padding: 0.75rem 1rem; }
    .content { padding: 1rem; }
}

@media (max-width: 480px) {
    .login-card { border-radius: var(--radius-sm); }
    .login-header { padding: 2rem 1.5rem; }
    .login-body { padding: 1.5rem; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
