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

:root {
  --bg: #0d1117;
  --bg-alt: #161b22;
  --bg-card: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --green: #3fb950;
  --red: #f85149;
  --orange: #d29922;
  --purple: #bc8cff;
  --radius: 8px;
  --sidebar: 240px;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-alt: #f6f8fa;
  --bg-card: #f6f8fa;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #656d76;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --green: #1a7f37;
  --red: #cf222e;
  --orange: #9a6700;
  --purple: #8250df;
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* Layout */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar); flex-shrink: 0;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; height: 100vh;
  overflow-y: auto; z-index: 100;
}

.sidebar-header { padding: 20px 16px; border-bottom: 1px solid var(--border); }
.sidebar-header h1 { font-size: 16px; font-weight: 600; color: var(--accent); }
.sidebar-header .subtitle { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: var(--radius);
  color: var(--text-muted); cursor: pointer; font-size: 13px;
  transition: all .15s; border: none; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--bg-card); color: var(--text); }
.nav-item.active { background: var(--bg-card); color: var(--accent); font-weight: 500; }
.nav-item .icon { width: 18px; text-align: center; font-size: 14px; }

.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); }
.sidebar-footer .user-info { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.sidebar-footer .role-badge { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 10px; font-weight: 500; text-transform: uppercase; background: var(--bg-card); color: var(--purple); margin-left: 4px; }

.main { flex: 1; margin-left: var(--sidebar); padding: 24px 32px; max-width: calc(100vw - var(--sidebar)); }

.page-header { margin-bottom: 24px; }
.page-header h2 { font-size: 20px; font-weight: 600; margin-bottom: 4px; }
.page-header p { color: var(--text-muted); font-size: 13px; }

/* Cards */
.card { background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-header h3 { font-size: 14px; font-weight: 600; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card { background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat-card .value { font-size: 24px; font-weight: 600; color: var(--accent); }
.stat-card .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-top: 4px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
thead th { position: sticky; top: 0; background: var(--bg-alt); font-weight: 600; color: var(--text-muted); text-transform: uppercase; font-size: 11px; letter-spacing: .5px; }
tr:hover td { background: var(--bg-card); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-alt);
  color: var(--text); cursor: pointer; font-size: 12px; font-weight: 500;
  transition: all .15s; white-space: nowrap;
}
.btn:hover { background: var(--bg-card); border-color: var(--text-muted); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 3px 8px; font-size: 11px; }
.btn-group { display: flex; gap: 6px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); margin-bottom: 4px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text); font-size: 13px;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--accent); }
.form-group textarea { min-height: 100px; font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace; font-size: 12px; resize: vertical; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }

/* Badge */
.badge { display: inline-block; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 600; text-transform: uppercase; }
.badge-green { background: rgba(63, 185, 80, .15); color: var(--green); }
.badge-red { background: rgba(248, 81, 73, .15); color: var(--red); }
.badge-orange { background: rgba(210, 153, 34, .15); color: var(--orange); }
.badge-purple { background: rgba(188, 140, 255, .15); color: var(--purple); }
.badge-gray { background: var(--bg-card); color: var(--text-muted); }

/* Search */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-bar input { flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--text); font-size: 13px; }
.search-bar input:focus { outline: none; border-color: var(--accent); }
.search-bar select { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--text); font-size: 13px; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 16px; }
.pagination .info { font-size: 12px; color: var(--text-muted); }

/* Overlay/modal */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.5); z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal { background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; width: 90%; max-width: 600px; max-height: 80vh; overflow-y: auto; }
.modal h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  padding: 12px 20px; border-radius: var(--radius);
  background: var(--bg-alt); border: 1px solid var(--border);
  font-size: 13px; z-index: 300;
  opacity: 0; transform: translateY(10px);
  transition: all .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: var(--red); }
.toast.success { border-color: var(--green); }

/* Login */
.login-wrap {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card { background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; width: 100%; max-width: 380px; }
.login-card h1 { font-size: 20px; font-weight: 600; margin-bottom: 4px; color: var(--accent); }
.login-card p { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
.login-card .form-group { margin-bottom: 16px; }
.login-card .btn { width: 100%; justify-content: center; padding: 10px; }
.login-card .error-msg { color: var(--red); font-size: 12px; margin-bottom: 12px; display: none; }

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

.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state .icon { font-size: 32px; margin-bottom: 8px; }

/* Code */
pre, code { font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace; }
.code-block { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; font-size: 12px; overflow-x: auto; white-space: pre-wrap; max-height: 400px; }

/* Tabs */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab { padding: 8px 16px; border: none; background: none; color: var(--text-muted); cursor: pointer; font-size: 13px; border-bottom: 2px solid transparent; transition: all .15s; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Checkbox */
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.checkbox-label input[type="checkbox"] { width: auto; accent-color: var(--accent); }

/* Mobile */
@media (max-width: 768px) {
  .sidebar { width: 100%; position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .main { margin-left: 0; padding: 16px; max-width: 100%; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { flex-direction: column; gap: 0; }
  .search-bar { flex-wrap: wrap; }
  .search-bar select { flex: 1; }
}
