:root {
  --app-bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #eef2f7;
  --text: #172033;
  --muted: #697386;
  --line: #dce3ee;
  --brand: #2f80ed;
  --success: #17a673;
  --warning: #f2994a;
  --danger: #eb5757;
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.08);
}

[data-bs-theme="dark"] {
  --app-bg: #101319;
  --surface: #171c24;
  --surface-soft: #202734;
  --text: #eef3fb;
  --muted: #a9b3c3;
  --line: #2b3444;
  --brand: #66a6ff;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(47, 128, 237, 0.06), transparent 280px),
    var(--app-bg);
  font-family: Arial, "Noto Sans KR", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

body.unauthenticated .app-shell {
  grid-template-columns: 1fr;
}

body.unauthenticated .sidebar,
body.unauthenticated .topbar {
  display: none;
}

body.unauthenticated .content {
  min-height: 100vh;
  display: grid;
  align-items: center;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 24px 16px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 8px;
  background: var(--success);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.sidebar-foot span,
.eyebrow,
.metric-card span,
.panel p,
.panel small {
  color: var(--muted);
}

.main-nav {
  display: grid;
  gap: 8px;
}

.main-nav button {
  width: 100%;
  min-height: 44px;
  padding: 11px 12px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  font-weight: 800;
}

.main-nav button.active,
.main-nav button:hover {
  color: var(--text);
  background: var(--surface-soft);
}

.sidebar-foot {
  margin-top: auto;
  padding: 14px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.sidebar-foot strong {
  display: block;
  margin-top: 4px;
}

.main-area {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 30px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
}

.topbar h1,
.page-head h2 {
  margin: 0;
  font-size: clamp(1.35rem, 2vw, 1.9rem);
  font-weight: 800;
}

.topbar-actions,
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.theme-switch {
  min-width: 118px;
}

.content {
  padding: 30px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.page-head {
  margin-bottom: 22px;
}

.metric-grid,
.dashboard-grid,
.stats-grid,
.settings-grid {
  display: grid;
  gap: 16px;
}

.metric-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.dashboard-grid {
  grid-template-columns: 1.25fr 1fr;
}

.stats-grid {
  grid-template-columns: minmax(0, 1.4fr) minmax(300px, 0.75fr);
}

.settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metric-card,
.panel,
.pipeline-column,
.login-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 20px;
}

.metric-card strong {
  display: block;
  margin: 10px 0 5px;
  font-size: 2rem;
  line-height: 1;
}

.panel {
  padding: 22px;
}

.panel.wide,
.timeline-panel {
  grid-column: span 2;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-head h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
}

.status.success {
  color: #0d7a53;
  background: rgba(23, 166, 115, 0.14);
}

.status.pending {
  color: #a66300;
  background: rgba(242, 153, 74, 0.16);
}

.status.danger {
  color: #b42318;
  background: rgba(235, 87, 87, 0.15);
}

.hero-panel {
  min-height: 350px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background:
    linear-gradient(140deg, color-mix(in srgb, var(--brand) 14%, transparent), transparent),
    var(--surface);
}

.load-value {
  display: block;
  font-size: 3.5rem;
  line-height: 1;
}

.soft-meter {
  height: 12px;
  margin: 24px 0;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.soft-meter i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--success), var(--brand));
}

.mini-bars,
.timeline,
.rank-list,
.account-list,
.policy-grid {
  display: grid;
  gap: 12px;
}

.mini-bars div {
  display: grid;
  grid-template-columns: 74px 1fr 70px;
  gap: 12px;
  align-items: center;
}

.mini-bars i {
  display: block;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--success), var(--brand));
}

.timeline div,
.rank-list div,
.account-list div,
.token-box {
  display: grid;
  gap: 6px;
  padding: 13px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.timeline div {
  grid-template-columns: 62px 1fr;
}

.timeline b,
.rank-list b {
  color: var(--brand);
}

.filter-panel {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 12px;
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.stats-filter {
  grid-template-columns: 0.8fr 1fr 1fr 1fr auto;
}

.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--text);
  margin-bottom: 0;
}

.pipeline-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.pipeline-column {
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: 360px;
  padding: 16px;
  background: color-mix(in srgb, var(--surface) 84%, var(--surface-soft));
}

.column-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-weight: 800;
}

.column-head strong {
  color: var(--text);
}

.pipeline-column article {
  display: grid;
  gap: 6px;
  padding: 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: 8px;
  background: var(--surface);
}

.pipeline-column small {
  color: var(--muted);
  font-weight: 700;
}

.log-row {
  display: grid;
  grid-template-columns: 96px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 13px 0;
  border-top: 1px solid var(--line);
}

.log-row span {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.log-row em {
  color: #0d7a53;
  font-style: normal;
  font-weight: 800;
}

.log-row em.warn {
  color: #a66300;
}

.chart-bars {
  display: flex;
  align-items: end;
  gap: 12px;
  height: 280px;
  padding-top: 18px;
}

.chart-bars i {
  flex: 1;
  min-width: 18px;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(180deg, var(--brand), var(--success));
}

.rank-list div {
  grid-template-columns: 42px 1fr auto;
  align-items: center;
}

.account-list div {
  grid-template-columns: 1fr 1.3fr auto;
  align-items: center;
}

.account-list em {
  color: var(--brand);
  font-style: normal;
  font-weight: 800;
}

.token-box code {
  color: var(--text);
  word-break: break-all;
}

.login-page {
  min-height: calc(100vh - 155px);
  align-content: center;
}

.login-page.active {
  display: grid;
}

.login-card {
  width: min(440px, 100%);
  margin: 0 auto;
  padding: 30px;
}

.login-card .brand-mark {
  margin-bottom: 22px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.login-form span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-weight: 800;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .main-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .sidebar-foot {
    display: none;
  }

  .metric-grid,
  .dashboard-grid,
  .stats-grid,
  .settings-grid,
  .pipeline-board {
    grid-template-columns: 1fr 1fr;
  }

  .pipeline-board {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar,
  .topbar-actions,
  .page-head {
    align-items: stretch;
    flex-direction: column;
  }

  .content,
  .topbar,
  .sidebar {
    padding: 18px;
  }

  .main-nav,
  .metric-grid,
  .dashboard-grid,
  .stats-grid,
  .settings-grid,
  .filter-panel,
  .stats-filter,
  .mini-bars div,
  .timeline div,
  .rank-list div,
  .account-list div,
  .log-row,
  .topbar-actions {
    grid-template-columns: 1fr;
  }

  .panel.wide,
  .timeline-panel {
    grid-column: auto;
  }
}
