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

:root {
    --sidebar-bg: #1a1d23;
    --sidebar-hover: #2a2d35;
    --sidebar-active: #3b82f6;
    --sidebar-text: #a0a3ab;
    --sidebar-width: 240px;
    --content-bg: #f3f4f6;
    --card-bg: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #10b981;
    --warning: #f59e0b;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

html { font-size: 14px; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', sans-serif; background: var(--content-bg); color: var(--text-primary); line-height: 1.5; }

.app-wrapper { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar { width: var(--sidebar-width); background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; z-index: 100; }
.sidebar-brand { padding: 20px 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.brand-icon { font-size: 1.4rem; }
.brand-text { font-size: 1.1rem; font-weight: 700; color: #fff; letter-spacing: -0.02em; }
.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 6px; color: var(--sidebar-text); text-decoration: none; font-size: 0.93rem; transition: all 0.15s; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-icon { width: 20px; text-align: center; font-size: 0.95rem; }
.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,0.06); }
.user-info { font-size: 0.85rem; color: #9ca3af; margin-bottom: 8px; }
.btn-logout { display: inline-block; padding: 5px 12px; background: rgba(255,255,255,0.08); color: #d1d5db; border-radius: 4px; text-decoration: none; font-size: 0.8rem; transition: background 0.15s; }
.btn-logout:hover { background: rgba(255,255,255,0.15); }

/* Main Content */
.main-content { flex: 1; margin-left: var(--sidebar-width); }
.content-header { padding: 24px 32px 0; }
.content-header h1 { font-size: 1.5rem; font-weight: 700; color: var(--text-primary); }
.content-body { padding: 20px 32px 32px; }

/* Cards */
.card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card-title { font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 12px; }

/* Stats Grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.stat-label { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--text-primary); }
.stat-sub { font-size: 0.8rem; color: var(--text-secondary); margin-top: 2px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead th { background: #f9fafb; padding: 10px 12px; text-align: left; font-weight: 600; color: var(--text-secondary); border-bottom: 2px solid var(--border); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
thead th a { color: inherit; text-decoration: none; }
thead th a:hover { color: var(--accent); }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: #f0f4ff; }
tbody tr:nth-child(even) { background: #fafbfc; }
tbody tr:nth-child(even):hover { background: #f0f4ff; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; border: none; font-size: 0.85rem; font-weight: 500; cursor: pointer; text-decoration: none; transition: all 0.15s; line-height: 1.4; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-secondary { background: #e5e7eb; color: var(--text-primary); }
.btn-secondary:hover { background: #d1d5db; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }

/* Toggle Switch */
.toggle { position: relative; display: inline-block; width: 42px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: #d1d5db; border-radius: 24px; transition: 0.2s; }
.toggle-slider::before { content: ''; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: 0.2s; }
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* Master switch */
.master-switches { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.master-switch { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 24px; display: flex; align-items: center; gap: 16px; min-width: 260px; }
.master-switch-label { font-weight: 600; font-size: 0.95rem; }
.master-switch-status { font-size: 0.8rem; padding: 2px 8px; border-radius: 10px; font-weight: 500; }
.status-on { background: #d1fae5; color: #065f46; }
.status-off { background: #fee2e2; color: #991b1b; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; }
.form-control { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem; font-family: inherit; transition: border 0.15s; background: #fff; }
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
textarea.form-control { min-height: 80px; resize: vertical; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }

.search-bar { display: flex; gap: 8px; margin-bottom: 20px; }
.search-bar .form-control { max-width: 320px; }

/* Usage bar */
.usage-bar { width: 100%; height: 6px; background: #e5e7eb; border-radius: 3px; overflow: hidden; }
.usage-bar-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }
.usage-ok .usage-bar-fill { background: var(--success); }
.usage-warn .usage-bar-fill { background: var(--warning); }
.usage-danger .usage-bar-fill { background: var(--danger); }
.usage-text { font-size: 0.75rem; color: var(--text-secondary); margin-top: 2px; }

/* Badge */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 0.75rem; font-weight: 500; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-gray { background: #f3f4f6; color: #374151; }

/* Toast */
.toast { position: fixed; bottom: 24px; right: 24px; background: #1f2937; color: #fff; padding: 12px 20px; border-radius: 8px; font-size: 0.9rem; z-index: 9999; opacity: 0; transform: translateY(10px); transition: all 0.3s; box-shadow: var(--shadow-md); }
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { background: var(--danger); }

/* Login page */
.login-wrapper { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: linear-gradient(135deg, #1a1d23 0%, #2d3748 100%); }
.login-box { background: #fff; border-radius: 12px; padding: 40px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-box h1 { font-size: 1.4rem; margin-bottom: 8px; color: var(--text-primary); }
.login-box p { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 24px; }
.login-box .form-group { margin-bottom: 16px; }
.login-box .btn { width: 100%; justify-content: center; padding: 10px; font-size: 0.95rem; }
.login-error { background: #fee2e2; color: #991b1b; padding: 8px 12px; border-radius: 6px; font-size: 0.85rem; margin-bottom: 16px; }

/* Top groups table highlight */
.rank-cell { font-weight: 700; color: var(--accent); }

/* IP list */
.ip-tag { display: inline-flex; align-items: center; gap: 6px; background: #eef2ff; padding: 4px 10px; border-radius: 6px; font-size: 0.85rem; margin: 2px 4px 2px 0; }
.ip-tag .remove-ip { cursor: pointer; color: var(--danger); font-weight: 700; font-size: 0.9rem; line-height: 1; }

/* Audit log */
.audit-list { max-height: 400px; overflow-y: auto; }
.audit-item { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.audit-item .audit-time { color: var(--text-secondary); font-size: 0.75rem; }
.audit-item .audit-action { font-weight: 600; }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { width: 60px; overflow: hidden; }
    .brand-text, .nav-item span:not(.nav-icon), .sidebar-footer .user-info { display: none; }
    .nav-item { justify-content: center; padding: 12px; }
    .main-content { margin-left: 60px; }
    .content-header, .content-body { padding-left: 16px; padding-right: 16px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .master-switches { flex-direction: column; }
}

/* Flex utilities */
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.justify-between { justify-content: space-between; }
.mb-16 { margin-bottom: 16px; }
.mb-8 { margin-bottom: 8px; }
.mt-16 { margin-top: 16px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-secondary); }
.text-sm { font-size: 0.8rem; }
