:root { --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; }
:root[data-theme="dark"] { --s1: #3987e5; --s2: #d95926; --s3: #199e70; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 32px; }
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.bar { height: 64px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 8px; flex: none; }
.brand small { font-size: 13px; font-weight: 600; color: var(--text-3); padding-top: 2px; }
.tabs { display: flex; gap: 4px; margin-right: auto; }
.tabs a { height: 36px; padding: 0 14px; border-radius: 10px; display: flex; align-items: center; font-size: 15px; font-weight: 600; color: var(--text-3); transition: background .15s, color .15s; }
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--text); background: var(--surface); }
.right { display: flex; align-items: center; gap: 6px; flex: none; }
.user { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 6px 0 4px; border-radius: 22px; background: var(--surface); }
.avatar { width: 36px; height: 36px; border-radius: 50%; overflow: hidden; flex: none; background: var(--blue-soft); color: var(--blue); display: grid; place-items: center; font-weight: 700; font-size: 15px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.logout { height: 32px; padding: 0 12px; border-radius: 16px; font-size: 13px; font-weight: 600; color: var(--text-2); background: var(--surface-2); }
.logout:hover { background: var(--hover); color: var(--text); }

.page { padding-top: 16px; padding-bottom: 96px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0; }
.h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; margin: 40px 0 12px; }
.tbox { background: var(--surface); border-radius: 20px; padding: 8px 20px; min-width: 0; overflow-x: auto; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 12px; }

.btn { height: 40px; padding: 0 16px; border-radius: 12px; font-size: 14px; font-weight: 600; background: var(--surface-2); color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: background .15s, transform .15s, opacity .15s; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .35; pointer-events: none; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.sm { height: 32px; padding: 0 12px; border-radius: 10px; font-size: 13px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue) 60%, transparent); outline-offset: 2px; }

.chip { display: inline-flex; align-items: center; height: 24px; padding: 0 8px; border-radius: 7px; font-size: 12.5px; font-weight: 600; white-space: nowrap; vertical-align: middle; background: var(--surface-2); color: var(--text-2); }
.chip + .chip { margin-left: 4px; }
.chip.id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0; background: var(--blue-soft); color: var(--blue); }
a.chip.id:hover { filter: brightness(1.12); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { background: var(--surface); border-radius: 20px; padding: 18px 22px; min-width: 0; }
.stat span { display: block; font-size: 13px; font-weight: 600; color: var(--text-3); }
.stat strong { display: block; margin-top: 6px; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat strong small { font-size: 14px; font-weight: 600; color: var(--text-3); margin-left: 3px; }
.stat em { display: block; margin-top: 2px; font-style: normal; font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.grid { border-collapse: separate; border-spacing: 0; font-size: 14px; width: 100%; font-variant-numeric: tabular-nums; }
.grid th { position: sticky; top: 0; z-index: 1; background: var(--surface); text-align: left; padding: 10px 16px 10px 0; font-size: 12.5px; font-weight: 600; color: var(--text-3); white-space: nowrap; border-bottom: 1px solid var(--line); }
.grid td { padding: 11px 16px 11px 0; border-bottom: 1px solid var(--line); white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.grid tr:last-child td { border-bottom: 0; }
.grid .num { text-align: right; }
.grid td.dim, .grid td.null { color: var(--text-3); }
.grid td code { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text-2); letter-spacing: 0; }
.grid .empty { padding: 40px 0; text-align: center; color: var(--text-3); }
.link-rows tbody tr { cursor: pointer; }
.link-rows tbody tr:hover td { background: color-mix(in srgb, var(--surface) 95%, var(--text)); }

.hosp { display: flex; flex-direction: column; gap: 12px; }
.hosp a { background: var(--surface); border-radius: 20px; padding: 18px 22px; display: flex; align-items: center; justify-content: space-between; gap: 12px; transition: background .15s; }
.hosp a:hover { background: color-mix(in srgb, var(--surface) 92%, var(--text)); }
.hosp b { font-size: 16px; font-weight: 700; }
.hosp small { display: block; margin-top: 2px; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text-3); letter-spacing: 0; }
.hosp strong { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hosp strong small { display: inline; font: 600 13px Pretendard Variable, sans-serif; margin-left: 3px; }

.bar2 { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--surface); }
.seg button { height: 34px; padding: 0 16px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--text-3); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }
.seg.sm button { height: 28px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.search { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: 12px; background: var(--surface); color: var(--text-3); width: 220px; margin-left: auto; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font-size: 14px; color: var(--text); }
.pager { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.pager div { display: flex; gap: 6px; }

.back { display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 10px 0 6px; margin-left: -6px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--text-3); }
.back:hover { background: var(--hover); color: var(--text); }
.subj-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 20px; margin: 12px 0 8px; }
.subj-head h1 { font: 700 28px ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0; }
.subj-head dl { display: flex; flex-wrap: wrap; gap: 6px 20px; font-size: 14px; }
.subj-head dt { color: var(--text-3); font-weight: 600; margin-right: 6px; display: inline; }
.subj-head dd { display: inline; font-variant-numeric: tabular-nums; }

.sig { margin-top: 28px; }
.sig-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.sig-head h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.sig-head .meta { font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums; display: flex; gap: 12px; }
.sig-head .seg { margin-left: auto; }
.sig-head .nav { display: flex; gap: 4px; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px; }
.chart { background: var(--surface); border-radius: 20px; padding: 16px 18px 10px; min-width: 0; position: relative; }
.chart-head { display: flex; align-items: baseline; gap: 6px; margin-bottom: 6px; min-height: 22px; }
.chart-head b { font-size: 15px; font-weight: 700; }
.chart-head small { font-size: 12px; color: var(--text-3); }
.legend { margin-left: auto; display: flex; gap: 12px; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 2px; border-radius: 1px; }
.chart svg { display: block; width: 100%; height: 180px; overflow: visible; touch-action: pan-y; }
.chart .axis text { font-size: 11px; fill: var(--text-3); font-variant-numeric: tabular-nums; }
.chart .axis line { stroke: var(--line); }
.chart .cross { stroke: var(--text-4); stroke-width: 1; }
.chart .nodata { display: grid; place-items: center; height: 180px; font-size: 13px; color: var(--text-3); }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface-2); color: var(--text); border-radius: 10px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tip b { display: block; font-weight: 600; color: var(--text-3); margin-bottom: 3px; font-size: 12px; }
.tip div { display: flex; align-items: center; gap: 6px; }
.tip i { width: 8px; height: 8px; border-radius: 50%; }

.sql { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 12px; align-items: start; }
.side { background: var(--surface); border-radius: 20px; padding: 8px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 76px; max-height: calc(100dvh - 100px); overflow: auto; }
.side button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; padding: 9px 12px; border-radius: 12px; text-align: left; }
.side button:hover { background: var(--hover); }
.side button b { font: 600 13.5px ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0; }
.side button small { font: 11.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text-3); letter-spacing: 0; white-space: normal; }
.panel { background: var(--surface); border-radius: 20px; padding: 18px 20px; min-width: 0; }
.examples { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
#sql { width: 100%; min-height: 168px; resize: vertical; border: 0; outline: 0; border-radius: 14px; padding: 14px 16px; background: var(--surface-2); color: var(--text); font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0; tab-size: 2; }
#sql:focus { box-shadow: 0 0 0 2px color-mix(in srgb, var(--blue) 50%, transparent); }
.sql-bar { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.hint { font-size: 12px; color: var(--text-4); }
.sql-meta { margin-left: auto; font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.sql-err { margin-top: 10px; padding: 12px 16px; border-radius: 12px; background: var(--red-soft); color: var(--red); font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0; }
.grid-wrap { margin-top: 12px; overflow: auto; max-height: calc(100dvh - 380px); min-height: 160px; }
.grid-wrap .grid { font-size: 13px; }
.grid-wrap .grid td { padding: 7px 14px 7px 0; }

@media (max-width: 900px) {
  .wrap { padding: 0 16px; }
  .bar { gap: 10px; }
  .brand small, .logout { display: none; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two, .sql { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; max-height: 200px; }
  .charts { grid-template-columns: minmax(0, 1fr); }
  .search { width: auto; flex: 1; }
  .bar2 { flex-wrap: wrap; }
}
