:root {
  --bg: #0b1220;
  --bg-elev: #131c2e;
  --bg-elev2: #1b2740;
  --border: #26324c;
  --text: #e6ecf7;
  --text-dim: #93a1bd;
  --accent: #4f8cff;
  --accent-dim: #2a4a86;
  --ok: #37c978;
  --warn: #f5b445;
  --err: #ff5f6d;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
}
a { color: var(--accent); }
button { font: inherit; }

.app-loading { display: grid; place-items: center; height: 100vh; color: var(--text-dim); }

/* ── layout ── */
.layout { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 700; font-size: 16px; padding: 6px 10px 14px; letter-spacing: .3px; }
.brand small { display: block; color: var(--text-dim); font-weight: 400; font-size: 11px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px; color: var(--text-dim);
  text-decoration: none; cursor: pointer; border: 0; background: none; width: 100%; text-align: left;
}
.nav-link:hover { background: var(--bg-elev2); color: var(--text); }
.nav-link.active { background: var(--accent-dim); color: #fff; }
.nav-icon { font-size: 15px; line-height: 1; }
.nav-spacer { flex: 1; }
.nav-user { font-size: 12px; color: var(--text-dim); padding: 8px 10px; border-top: 1px solid var(--border); word-break: break-all; }
.nav-user b { color: var(--text); }

.main { padding: 24px clamp(16px, 4vw, 40px); max-width: 1180px; width: 100%; }
.page-title { margin: 0 0 4px; font-size: 20px; }
.page-sub { margin: 0 0 20px; color: var(--text-dim); font-size: 13px; }

/* ── cards / grid ── */
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 14px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.stat { font-size: 26px; font-weight: 700; }
.stat small { font-size: 13px; color: var(--text-dim); font-weight: 400; }

/* ── table ── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-dim); font-weight: 600; background: var(--bg-elev); position: sticky; top: 0; }
tbody tr:hover { background: var(--bg-elev2); }
tbody tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── badges / buttons ── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.ok { background: rgba(55,201,120,.15); color: var(--ok); }
.badge.warn { background: rgba(245,180,69,.15); color: var(--warn); }
.badge.err { background: rgba(255,95,109,.15); color: var(--err); }
.badge.dim { background: var(--bg-elev2); color: var(--text-dim); }

.btn {
  border: 1px solid var(--border); background: var(--bg-elev2); color: var(--text);
  padding: 7px 13px; border-radius: 8px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: rgba(255,95,109,.12); border-color: var(--err); color: var(--err); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.meter { height: 6px; background: var(--bg-elev2); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.meter > span { display: block; height: 100%; background: var(--accent); }
.meter.warn > span { background: var(--warn); }
.meter.err > span { background: var(--err); }

/* ── forms ── */
label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-dim); border-color: var(--accent); }
.field { margin-bottom: 14px; }
.form-error { color: var(--err); font-size: 13px; margin: 8px 0; }
.form-hint { color: var(--text-dim); font-size: 12px; margin-top: 4px; }

/* ── auth screen ── */
.auth-wrap { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 24px; }
.auth-card { width: 100%; max-width: 360px; }
.auth-title { margin: 0 0 18px; font-size: 22px; font-weight: 700; text-align: center; letter-spacing: .5px; }

/* ── misc ── */
.muted { color: var(--text-dim); }
.mono { font-family: var(--mono); font-size: 12px; }
.section { margin-bottom: 28px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.chart-box { position: relative; height: 300px; }
.mini-chart { position: relative; height: 90px; }
details.report { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; background: var(--bg-elev); }
details.report > summary { padding: 12px 14px; cursor: pointer; font-weight: 600; }
details.report .report-body { padding: 0 14px 14px; }
.guide { color: var(--warn); font-size: 12px; margin: 6px 0 12px; }
.feed-item { border-bottom: 1px solid var(--border); padding: 12px 0; }
.feed-item:last-child { border-bottom: 0; }
.feed-item pre { white-space: pre-wrap; margin: 6px 0 0; font-family: var(--mono); font-size: 12px; color: var(--text-dim); }

#toast-host {
  position: fixed; right: 16px; left: 16px; bottom: 16px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
  z-index: 999; pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--bg-elev2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  padding: 10px 14px; border-radius: 8px; max-width: 340px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.toast.err { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }

/* ── 모바일 ── */
@media (max-width: 760px) {
  .layout { display: block; }

  .sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    height: auto; width: 100%;
    flex-direction: row; align-items: stretch; gap: 0;
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border); border-right: 0;
    overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
    z-index: 100;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .brand, .nav-spacer, .nav-user { display: none; }

  .nav-link {
    width: auto; flex: 0 0 auto;
    flex-direction: column; gap: 3px;
    min-width: 60px; padding: 8px 10px;
    font-size: 10px; text-align: center; white-space: nowrap;
    border-radius: 10px;
    -webkit-tap-highlight-color: transparent;
  }
  .nav-icon { font-size: 18px; }
  .nav-link.active { background: var(--accent-dim); }

  .main {
    max-width: none;
    padding: 16px 14px calc(76px + env(safe-area-inset-bottom));
  }
  .page-title { font-size: 18px; }

  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  .row-between { gap: 8px; }
  .chart-box { height: 240px; }

  /* iOS 입력 시 자동 확대 방지 */
  input, select, textarea { font-size: 16px; }

  #toast-host { bottom: calc(72px + env(safe-area-inset-bottom)); }

  th, td { padding: 8px 10px; }
}

@media (hover: none) {
  .nav-link:hover { background: none; color: var(--text-dim); }
  .nav-link.active:hover { background: var(--accent-dim); color: #fff; }
}
