:root {
  --bg: #F6F7FB;
  --surface: #FFFFFF;
  --border: #E5E7EB;
  --border-strong: #D1D5DB;
  --text: #111827;
  --text-muted: #6B7280;
  --text-dim: #9CA3AF;
  --brand: #5443EF;
  --brand-soft: #EEEBFF;
  --accent: #FFBA08;
  --danger: #EF4444;
  --danger-soft: #FEE2E2;
  --success: #10B981;
  --success-soft: #D1FAE5;
  --warning: #F59E0B;
  --info: #3B82F6;
  --sidebar-bg: #111827;
  --sidebar-text: #9CA3AF;
  --sidebar-text-active: #FFFFFF;
  --sidebar-active: rgba(84, 67, 239, 0.15);
  --sidebar-hover: rgba(255, 255, 255, 0.05);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow: 0 4px 12px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  --radius-sm: 8px;
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans KR', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ========== Layout ========== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  padding: 20px 20px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar .brand .logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), #7A6CF5);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.5px;
}
.sidebar .brand .brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.sidebar .brand .brand-name { color: #fff; font-size: 14px; font-weight: 700; }
.sidebar .brand .brand-sub { color: var(--sidebar-text); font-size: 11px; }

.sidebar .nav-group { padding: 16px 12px 8px; }
.sidebar .nav-group-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 0 8px 8px;
  text-transform: uppercase;
}
.sidebar .nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--sidebar-text);
  margin-bottom: 2px;
  transition: background 0.12s, color 0.12s;
}
.sidebar .nav a:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar .nav a.active {
  background: var(--sidebar-active);
  color: var(--sidebar-text-active);
  font-weight: 600;
}
.sidebar .nav a .icon {
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  opacity: 0.9;
}
.sidebar .sidebar-footer {
  margin-top: auto;
  padding: 8px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar .sidebar-footer .sf-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--sidebar-text);
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background 0.12s, color 0.12s;
}
.sidebar .sidebar-footer .sf-item:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar .sidebar-footer .sf-item.active {
  background: var(--sidebar-active);
  color: var(--sidebar-text-active);
  font-weight: 600;
}
.sidebar .sidebar-footer .sf-item .icon {
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  opacity: 0.9;
}

/* Main panel */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.topbar .page-title { font-size: 16px; font-weight: 700; color: var(--text); }
.topbar .spacer { flex: 1; }
.topbar .user {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px; border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.topbar .user .avatar {
  width: 28px; height: 28px; border-radius: 999px;
  background: linear-gradient(135deg, var(--brand), #7A6CF5);
  color: #fff; font-weight: 700; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.topbar .user .info { display: flex; flex-direction: column; line-height: 1.2; }
.topbar .user .info .name { font-size: 12px; font-weight: 600; }
.topbar .user .info .role { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.topbar #logoutBtn { margin-left: 4px; }

.content {
  padding: 24px 28px 40px;
  width: 100%;
}

/* ========== Components ========== */
h1, h2, h3 { color: var(--text); margin: 0 0 12px; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-header h3 { margin: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn.primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.btn.primary:hover { background: #4735D6; border-color: #4735D6; }
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn.ghost:hover { background: var(--bg); color: var(--text); }
.btn.danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn.danger:hover { background: #DC2626; }
.btn.sm { padding: 5px 10px; font-size: 12px; }

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  transition: border-color 0.12s, box-shadow 0.12s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(84, 67, 239, 0.15);
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar input, .toolbar select { min-width: 180px; }

/* Table */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  font-size: 13px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.table th, .table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.table th {
  background: #FAFAFB;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--bg); }
.table td a { color: var(--brand); font-weight: 500; }
.table td a:hover { text-decoration: underline; }

/* Pager */
.pager {
  display: flex; align-items: center; gap: 4px;
  justify-content: center; margin: 20px 0 0;
  flex-wrap: wrap;
}
.pager .btn {
  min-width: 32px;
  justify-content: center;
}
.pager .btn[disabled] { opacity: 0.4; cursor: not-allowed; }

/* KPIs — 가용 폭을 모두 나눠 쓰도록 auto-fit */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

/* 대시보드 2열 섹션 */
.dash-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}
.dash-grid .dash-col {
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
}
@media (max-width: 1100px) {
  .dash-grid { grid-template-columns: 1fr; }
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
  background: var(--brand);
  opacity: 0.85;
}
.kpi:nth-child(5n+2)::before { background: var(--success); }
.kpi:nth-child(5n+3)::before { background: var(--accent); }
.kpi:nth-child(5n+4)::before { background: var(--info); }
.kpi:nth-child(5n+5)::before { background: var(--danger); }
.kpi .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 6px;
  font-weight: 600;
}
.kpi .val {
  font-size: 24px;
  font-weight: 800;
  margin: 0;
  color: var(--text);
  letter-spacing: -0.02em;
}

/* Key-value list */
.kv {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px 20px;
  margin: 0;
}
.kv dt {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  align-self: start;
}
.kv dd {
  margin: 0;
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}

/* Badges (pill) */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.pill.success { background: var(--success-soft); color: #065F46; }
.pill.danger { background: var(--danger-soft); color: #991B1B; }
.pill.warn { background: #FEF3C7; color: #92400E; }
.pill.info { background: #DBEAFE; color: #1E40AF; }
.pill.brand { background: var(--brand-soft); color: var(--brand); }
.pill.neutral { background: #F3F4F6; color: #374151; }

.muted { color: var(--text-muted); }
.error { color: var(--danger); font-size: 12px; min-height: 16px; }
.section-gap { margin-top: 24px; }

/* ========== Login ========== */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(800px at 20% 0%, rgba(84, 67, 239, 0.25), transparent 60%),
    radial-gradient(600px at 90% 100%, rgba(255, 186, 8, 0.15), transparent 50%),
    linear-gradient(135deg, #0f172a, #1e293b);
  padding: 24px;
}
.auth-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 36px 32px 28px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.auth-card .brand-block {
  text-align: center;
  margin-bottom: 24px;
}
.auth-card .brand-block .logo {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), #7A6CF5);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.5px;
  box-shadow: 0 8px 20px rgba(84, 67, 239, 0.35);
  margin-bottom: 12px;
}
.auth-card h1 {
  font-size: 18px;
  margin: 0 0 4px;
  text-align: center;
  color: var(--text);
}
.auth-card .sub {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 20px;
}
.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-card label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.auth-card input {
  padding: 11px 12px;
  font-size: 14px;
  border-radius: 10px;
}
.auth-card .btn.primary {
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  justify-content: center;
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
  .sidebar { width: 64px; }
  .sidebar .brand-text,
  .sidebar .nav-group-title,
  .sidebar .nav a span.label,
  .sidebar .sidebar-footer { display: none; }
  .sidebar .nav a { justify-content: center; padding: 10px; }
  .kv { grid-template-columns: 1fr; gap: 4px 0; }
  .content { padding: 20px 16px; }
  .topbar { padding: 12px 16px; }
}
