/* 접속통계 관리 대시보드 — 차트 색: 검증된 기본 팔레트 (순방문자=slot1 파랑, 페이지뷰=slot2 주황) */
.viz-root {
  color-scheme: light;
  --page:           #f4f4f1;
  --surface-1:      #fcfcfb;
  --border:         #e3e2dc;
  --grid:           #e9e8e3;
  --axis:           #c9c8c0;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #7a7973;
  --accent:         #2a78d6;
  --series-1:       #2a78d6;
  --series-2:       #eb6834;
  --seq-bg:         #cde2fb;   /* 순위표 막대 (sequential blue 100) */
  --ok-bg:          #e6f4e6;  --ok-tx:  #006300;
  --err-bg:         #fbe9e9;  --err-tx: #b02a2a;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --page:           #121211;
    --surface-1:      #1a1a19;
    --border:         #2e2e2c;
    --grid:           #2a2a28;
    --axis:           #4a4a46;
    --text-primary:   #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted:     #94938a;
    --accent:         #3987e5;
    --series-1:       #3987e5;
    --series-2:       #d95926;
    --seq-bg:         #1c3556;
    --ok-bg:          #13301a;  --ok-tx:  #7fd77f;
    --err-bg:         #3a1616;  --err-tx: #f19a9a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--text-primary);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--grid); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

/* ---------- 상단 ---------- */
.top {
  display: flex; align-items: center; gap: 20px; padding: 0 24px; height: 56px;
  background: var(--surface-1); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 16px; color: var(--text-primary); letter-spacing: -.3px; }
.top nav { display: flex; align-items: center; gap: 4px; flex: 1; }
.top nav > a { padding: 6px 12px; border-radius: 6px; color: var(--text-secondary); }
.top nav > a.on, .top nav > a:hover { background: var(--grid); color: var(--text-primary); text-decoration: none; }
.sitepick select { height: 32px; }
.me { color: var(--text-muted); font-size: 13px; white-space: nowrap; }

main { max-width: 1240px; margin: 0 auto; padding: 24px; }
.page-head { margin-bottom: 16px; }
.page-head h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.4px; }
.page-head p { margin: 0; }

/* ---------- 필터 (차트 위 한 줄) ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 8px 0 16px; }
.seg { display: inline-flex; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg a { padding: 5px 12px; border-radius: 6px; color: var(--text-secondary); font-size: 13px; }
.seg a.on { background: var(--accent); color: #fff; }
.seg a:hover { text-decoration: none; }
.custom { display: flex; gap: 6px; align-items: center; color: var(--text-muted); }

/* ---------- 타일 ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.tl { color: var(--text-secondary); font-size: 13px; }
.tv { font-size: 28px; font-weight: 700; letter-spacing: -.5px; margin: 2px 0; font-variant-numeric: tabular-nums; }
.ts { color: var(--text-muted); font-size: 12px; }

/* ---------- 카드 ---------- */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; min-width: 0; }
.card h3 { font-size: 15px; margin: 0 0 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.grid .card { margin-bottom: 0; }
.grid + * { margin-top: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.empty { color: var(--text-muted); padding: 8px 0; margin: 0; }
.scroll { overflow-x: auto; }

/* ---------- 차트 ---------- */
.ch-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 4px; }
.ch-head h3 { margin: 0; }
.legend { display: flex; gap: 14px; list-style: none; margin: 0; padding: 0; color: var(--text-secondary); font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.sw.s1 { background: var(--series-1); }
.sw.s2 { background: var(--series-2); }
.chart-wrap { position: relative; overflow-x: auto; }
svg.chart { width: 100%; min-width: 680px; height: auto; display: block; overflow: visible; }
svg .grid { stroke: var(--grid); stroke-width: 1; }
svg .grid.base { stroke: var(--axis); }
svg .ax { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
svg .endlab { fill: var(--text-secondary); font-size: 12px; }
svg .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg .line.s1, svg .dot.s1 { stroke: var(--series-1); }
svg .line.s2, svg .dot.s2 { stroke: var(--series-2); }
svg .dot { fill: var(--surface-1); stroke-width: 2; }
svg .bar.s1 { fill: var(--series-1); }
svg .bar.dim { opacity: .35; }
svg .hit { fill: transparent; cursor: crosshair; }
svg .xhair { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
svg .hov { stroke-width: 2; fill: var(--surface-1); pointer-events: none; }
svg .hov.s1 { stroke: var(--series-1); }
svg .hov.s2 { stroke: var(--series-2); }
.note { color: var(--text-muted); font-size: 12px; margin: 6px 0 0; }
details.tbl { margin-top: 8px; }
details.tbl summary { cursor: pointer; color: var(--text-muted); font-size: 12px; }
details.tbl .scroll { max-height: 320px; overflow: auto; margin-top: 8px; }

.tip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12); min-width: 120px;
}
.tip b { display: block; margin-bottom: 4px; }
.tip .r { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tip .r span:first-child { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.tip .r span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- 표 ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 12px; border-bottom: 1px solid var(--border); padding: 6px 8px; white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.list .path { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.sites tr.off td { opacity: .55; }
table.dim td.nm { position: relative; max-width: 0; width: 70%; }
table.dim .bg { position: absolute; left: 0; top: 4px; bottom: 4px; background: var(--seq-bg); border-radius: 0 4px 4px 0; }
table.dim .tx { position: relative; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 4px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--ok-bg); color: var(--ok-tx); vertical-align: middle; }
.badge.gray { background: var(--grid); color: var(--text-secondary); }
.live { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #0ca30c; margin-right: 6px; vertical-align: middle; }

/* ---------- 폼 ---------- */
input, select, button { font: inherit; color: inherit; }
input, select {
  height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-1);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button { height: 34px; padding: 0 14px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-1); cursor: pointer; }
button:hover { background: var(--grid); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.link { border: 0; background: none; height: auto; padding: 0; color: var(--accent); }
button.danger { color: var(--err-tx); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-secondary); }
label.chk { flex-direction: row; align-items: center; gap: 8px; }
label.chk input { height: auto; }
.form-col { display: flex; flex-direction: column; gap: 10px; }
.form-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.form-row input[name=ip] { width: 160px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 14px; align-items: end; padding: 12px 0; }
form.inline { display: inline; }

.site-item { border-top: 1px solid var(--grid); padding: 10px 0; }
.site-item:first-of-type { border-top: 0; }
.site-item summary { cursor: pointer; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.code { background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.code-h { font-size: 12px; color: var(--text-secondary); margin: 6px 0 4px; display: flex; gap: 8px; align-items: center; }
.code pre { margin: 0 0 6px; white-space: pre-wrap; word-break: break-all; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.copy { height: 24px; padding: 0 8px; font-size: 12px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: var(--ok-bg); color: var(--ok-tx); }
.flash.err { background: var(--err-bg); color: var(--err-tx); }

/* ---------- 로그인 ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login { width: min(360px, 92vw); background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0; font-size: 22px; }
.login p { margin: 0 0 6px; }
.login button { height: 40px; margin-top: 6px; }

@media (max-width: 720px) {
  .top { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 8px; }
  .top nav { order: 3; width: 100%; overflow-x: auto; }
  main { padding: 14px; }
  .tv { font-size: 24px; }
  .grid { grid-template-columns: 1fr; }
}

/* 좁은 화면에서 글자가 세로로 쪼개지지 않게 */
.top nav > a, .seg a, button, .legend li, .tl, th { white-space: nowrap; }
.ch-head { flex-wrap: wrap; }
@media (max-width: 720px) {
  .top .brand { order: 1; }
  .top .me { order: 2; margin-left: auto; }
  .seg { max-width: 100%; overflow-x: auto; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile { padding: 12px; }
  .custom input[type=date] { width: 132px; }
}
