/* ============================================================
   Obsidian - Unified Design System
   ============================================================ */

:root {
  --bg:        #0f0f12;
  --bg2:       #1a1a1f;
  --bg3:       #22222a;
  --border:    #2a2a33;
  --border2:   #333340;
  --text:      #9ca3af;
  --text-h:    #f3f4f6;
  --muted:     #6b7280;
  --accent:    #7c3aed;
  --accent2:   #a855f7;
  --green:     #10b981;
  --red:       #ef4444;
  --yellow:    #f59e0b;
  --blue:      #3b82f6;
  --radius:    8px;
  --radius-lg: 12px;
  --transition: 0.2s ease;
}

/* ---- Reset & Base ---- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input { font-family: inherit; }

/* ---- Layout ---- */
.page-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ---- Header ---- */
.top-header {
  height: 56px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-title { color: var(--text-h); font-size: 16px; font-weight: 600; }
.menu-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  background: var(--bg2);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-h);
  font-size: 18px;
}
.btn-logout {
  background: var(--red);
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 12px;
}
.btn-logout:hover { background: #dc2626; }

/* ---- Drawer ---- */
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 40;
  display: none;
}
.drawer-overlay.open { display: block; }
.drawer {
  position: fixed;
  top: 0; left: 0;
  width: 240px; height: 100%;
  background: var(--bg);
  border-right: 1px solid var(--border);
  z-index: 50;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
@media (min-width: 769px) {
  .drawer { transform: translateX(0); }
  .drawer-overlay { display: none !important; }
}

.drawer-header {
  height: 56px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
}
.drawer-logo {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 14px;
  flex-shrink: 0;
}
.drawer-brand { color: var(--text-h); font-size: 16px; font-weight: 700; }
.drawer-nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.drawer-section-title {
  padding: 8px 16px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.06em;
}
.drawer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 14px;
  transition: background var(--transition), color var(--transition);
}
.drawer-item:hover { background: var(--bg3); color: var(--text-h); }
.drawer-item.active {
  background: rgba(124,58,237,0.12);
  color: var(--accent2);
}
.drawer-item-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
  flex-shrink: 0;
}
.drawer-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
}
.drawer-footer-info { display: flex; align-items: center; gap: 10px; }
.drawer-footer-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 13px; font-weight: 600;
  flex-shrink: 0;
}
.drawer-footer-logout {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s;
  position: absolute;
  right: 16px;
  bottom: 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
}
.drawer-footer-logout:hover {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}
.drawer-footer-name { color: var(--text-h); font-size: 13px; font-weight: 600; }
.drawer-footer-role { color: var(--muted); font-size: 11px; }

/* ---- Header Profile ---- */
.header-profile {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 20px;
  transition: background 0.2s;
}
.header-profile:hover { background: var(--bg2); }
.header-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 11px; font-weight: 600;
}
.header-username { color: var(--text-h); font-size: 13px; font-weight: 500; }


/* ---- Main ---- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
@media (max-width: 768px) {
  .main-content { overflow-y: auto; }
}

/* ---- Cards ---- */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-h);
  margin-bottom: 12px;
}

/* ---- Stats Grid ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
}
.stat-label { color: var(--text); font-size: 12px; margin-bottom: 4px; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text-h); }
.stat-sub { font-size: 11px; margin-top: 4px; }
.stat-sub.positive { color: var(--green); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-danger { background: rgba(239,68,68,0.15); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }
.btn-secondary { background: var(--border); color: var(--text-h); }
.btn-secondary:hover { background: var(--border2); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; }

/* ---- Form ---- */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-h);
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: #fff;
  font-size: 14px;
  transition: border-color var(--transition);
}
.form-input:focus { outline: none; border-color: var(--accent); }
.form-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }
.required { color: var(--red); }

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}
.badge-active  { background: rgba(16,185,129,0.15); color: var(--green); }
.badge-inactive { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-admin   { background: rgba(124,58,237,0.15); color: var(--accent2); }

/* ---- User Row ---- */
.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.user-row:last-child { border-bottom: none; }
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 14px;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { color: var(--text-h); font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ---- Stat Rows ---- */
.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.stat-row:last-child { border-bottom: none; }
.stat-row-label { color: var(--text); }
.stat-row-value { color: var(--text-h); font-weight: 500; }
.stat-row-value.positive { color: var(--green); }
.stat-row-value.negative { color: var(--red); }

/* ---- Toast ---- */
.toast {
  position: fixed;
  top: 16px;
  right: 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  color: var(--text-h);
  font-size: 13px;
  z-index: 200;
  display: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 400px;
  max-width: 90vw;
  padding: 24px;
}
.modal-title { color: var(--text-h); font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }
.modal-field { margin-bottom: 12px; }
.modal-field label { display: block; font-size: 12px; color: var(--text); margin-bottom: 4px; }
.modal-field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: #fff;
  font-size: 14px;
}
.modal-field input:focus { outline: none; border-color: var(--accent); }

/* ---- Loading / Empty ---- */
.loading-state { text-align: center; padding: 40px 16px; color: var(--muted); font-size: 13px; }

/* ---- Grid helpers ---- */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 640px) { .grid-4 { grid-template-columns: repeat(4, 1fr); } }

/* ---- Animations ---- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 0.4s ease-out; }

/* ---- Focus ---- */
*:focus, *:focus-visible { outline: none; }
.form-input:focus, .btn:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
