/* 앱 셸: 사이드바 · 상단바 · 본문. 인라인 스타일 금지(CSP) — 모든 스타일은 이 파일들에 둔다 */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-1);
  background: var(--bg-0);
  word-break: keep-all;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 배경 빛 번짐 — 데이터 위에 올라가지 않도록 맨 뒤 고정 레이어 */
/* 높이는 주소창이 접혔을 때의 큰 화면(lvh) 기준: 휴대폰에서 스크롤 중 주소창이 접히는 동안 아래에 바탕색 띠가 드러나지 않게 */
.bg-glow {
  position: fixed; inset: 0 0 auto 0; height: 100vh; height: 100lvh; z-index: -1; pointer-events: none;
  background:
    radial-gradient(600px 400px at 12% 8%, var(--glow-blue), transparent 70%),
    radial-gradient(520px 380px at 92% 18%, var(--glow-amber), transparent 70%),
    radial-gradient(640px 420px at 70% 100%, var(--glow-teal), transparent 70%),
    var(--bg-1);
}

/* 아이콘: lucide SVG를 mask로 써서 글자색(currentColor)을 따른다 */
.icon {
  display: inline-block; flex: none; width: 18px; height: 18px;
  background-color: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}

/* ── 레이아웃 ── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 180ms ease;
}
.app.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
.main { min-width: 0; display: flex; flex-direction: column; }

/* ── 사이드바 ── */
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: var(--s-4);
  padding: var(--s-4) var(--s-3);
  background: var(--glass);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(var(--blur)); -webkit-backdrop-filter: blur(var(--blur));
  overflow: hidden;
}
.brand { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2); min-height: 40px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: var(--radius-sm); flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-weight: 800; color: var(--on-accent);
}
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--text-2); }

.side-search {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-3); border-radius: var(--radius-sm);
  background: var(--glass); border: 1px solid var(--border); color: var(--text-2);
}
.side-search input { flex: 1; min-width: 0; background: none; border: 0; outline: none; }
.side-search input::placeholder { color: var(--text-3); }

.nav { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; margin: 0 calc(-1 * var(--s-1)); padding: 0 var(--s-1); }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-link {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 9px var(--s-3); margin: 2px 0;
  border-radius: var(--radius-sm);
  color: var(--text-2); text-decoration: none;
  transition: background 120ms ease, color 120ms ease;
}
.nav-link:hover { background: var(--glass-strong); color: var(--text-1); }
.nav-link[aria-current="page"] { background: var(--accent-strong); color: var(--on-accent); }
.nav-label { flex: 1; min-width: 0; }
.nav-badge {
  min-width: 22px; padding: 0 6px; border-radius: 999px; text-align: center;
  font-size: 11px; font-weight: 700; line-height: 20px;
  background: var(--badge-bg); color: var(--badge-fg);
}
.nav-link[aria-current="page"] .nav-badge { background: var(--on-accent); color: var(--accent-strong); }
.nav-ext { color: var(--text-3); }

/* 접고 펼치는 상위 메뉴(2단) */
.nav-parent {
  display: flex; align-items: center; gap: var(--s-3); width: 100%;
  padding: 9px var(--s-3); margin: 2px 0;
  border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--text-2); font: inherit; text-align: left; cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.nav-parent:hover { background: var(--glass-strong); color: var(--text-1); }
.nav-section.has-active > .nav-parent { color: var(--text-1); font-weight: 600; }
.nav-chevron { width: 16px; height: 16px; color: var(--text-3); transition: transform 150ms ease; }
.nav-section.is-open > .nav-parent .nav-chevron { transform: rotate(90deg); }
.nav-sub { list-style: none; margin: 0 0 var(--s-1); padding: 0; }
.nav-sub[hidden] { display: none; }
.nav-sub .nav-link { padding: 7px var(--s-3) 7px calc(var(--s-3) * 2 + 18px); font-size: 13.5px; }

.side-user {
  display: flex; align-items: center; gap: var(--s-3); width: 100%; flex: none;
  padding: var(--s-3); border-radius: var(--radius-md);
  background: var(--glass); border: 1px solid var(--border);
  font: inherit; color: inherit; text-align: left;
}
.side-user:disabled { cursor: default; opacity: 1; }
.side-user-name, .side-user-role { display: block; }
.side-user-more { display: none; flex: none; color: var(--text-2); transition: transform 160ms ease; }
.side-user.is-open .side-user-more { transform: rotate(180deg); }
.side-user.is-open { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
/* 휴대폰: 계정 카드를 누르면 위로 펼쳐지는 메뉴 */
.side-user-wrap { position: relative; flex: none; }
.side-account { position: absolute; left: 0; right: 0; bottom: calc(100% + 8px); z-index: 5;
  display: flex; justify-content: space-around; align-items: center; gap: var(--s-2); padding: var(--s-2); border-radius: var(--radius-md);
  background: var(--tooltip-bg); border: 1px solid var(--border-strong);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.28), 0 2px 8px rgba(0, 0, 0, 0.12);
  animation: side-account-in 140ms ease-out; }
@keyframes side-account-in { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .side-account { animation: none; } }
.side-account[hidden] { display: none; }
.side-account .side-account-item { width: 48px; height: 48px; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700;
  background: var(--glass-strong); border: 1px solid var(--border-strong);
}
.side-user-text { flex: 1; min-width: 0; }
.side-user-name { font-weight: 600; }
.side-user-role { font-size: 12px; color: var(--text-2); }

/* 접힌 사이드바: 아이콘만 */
.app.is-collapsed .brand-text,
.app.is-collapsed .side-search,
.app.is-collapsed .nav-group,
.app.is-collapsed .nav-label,
.app.is-collapsed .nav-ext,
.app.is-collapsed .side-user-text { display: none; }
.app.is-collapsed .nav-link { justify-content: center; position: relative; }
.app.is-collapsed .nav-badge { position: absolute; top: 2px; right: 4px; min-width: 16px; line-height: 16px; font-size: 10px; padding: 0 4px; }
.app.is-collapsed .side-user { justify-content: center; padding: var(--s-2); }
.app.is-collapsed .brand { justify-content: center; }

/* 레일(아이콘만, .is-rail은 shell.js가 붙임): 상위 메뉴는 아이콘만, 누르면 옆에 하위 메뉴 창 */
.app.is-rail .nav-parent { justify-content: center; position: relative; }
.app.is-rail .nav-chevron { display: none; }
.app.is-rail .nav-parent .nav-badge { position: absolute; top: 2px; right: 4px; min-width: 16px; line-height: 16px; font-size: 10px; padding: 0 4px; }
.nav-flyout {
  position: fixed; z-index: 60; min-width: 220px; padding: var(--s-2);
  background: var(--bg-1); border: 1px solid var(--border-strong); border-radius: var(--radius-md); box-shadow: var(--shadow);
}
.nav-flyout[hidden] { display: none; }
.nav-flyout-title { padding: var(--s-1) var(--s-3) var(--s-2); font-size: 12px; font-weight: 600; color: var(--text-3); }
.nav-flyout .nav-sub { margin: 0; }
.app .nav-flyout .nav-sub .nav-link { justify-content: flex-start; padding: 8px var(--s-3); }
.app .nav-flyout .nav-sub .nav-label,
.app .nav-flyout .nav-sub .nav-ext { display: revert; }
.app .nav-flyout .nav-sub .nav-badge { position: static; }

/* ── 상단바 ── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: var(--s-3);
  height: var(--topbar-h); padding: 0 var(--s-6);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(var(--blur)); -webkit-backdrop-filter: blur(var(--blur));
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .topbar { background: var(--glass-strong); }
}
.topbar-search {
  flex: 1; max-width: 420px;
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-3); border-radius: var(--radius-sm);
  background: var(--glass); border: 1px solid var(--border); color: var(--text-2);
}
.topbar-search input { flex: 1; min-width: 0; background: none; border: 0; outline: none; }
.topbar-search input::placeholder { color: var(--text-3); }
.topbar-spacer { flex: 1; }

.icon-btn {
  position: relative; display: inline-grid; place-items: center;
  width: 38px; height: 38px; border-radius: var(--radius-sm); flex: none;
  background: var(--glass); border: 1px solid var(--border); color: var(--text-2);
  cursor: pointer; transition: border-color 120ms ease, color 120ms ease, filter 120ms ease;
}
.icon-btn:hover { border-color: var(--border-strong); color: var(--text-1); filter: brightness(1.08); }
.icon-btn:disabled { cursor: not-allowed; opacity: .5; }
.icon-btn .dot { position: absolute; top: 8px; right: 9px; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); }
.only-mobile { display: none; }
@media (max-width: 767px) { .hide-mobile { display: none !important; } }

.profile { display: flex; align-items: center; gap: var(--s-2); padding: 3px var(--s-3) 3px 3px; border-radius: 999px; background: var(--glass); border: 1px solid var(--border); }
.profile-name { font-weight: 600; max-width: 140px; }

/* ── 본문 ── */
.content { flex: 1; padding: var(--s-6); min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; margin-bottom: var(--s-6); }
.crumbs { display: flex; align-items: center; gap: var(--s-1); font-size: 12px; color: var(--text-2); margin-bottom: var(--s-1); flex-wrap: wrap; }
.crumbs .icon { width: 12px; height: 12px; }
.page-title { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.page-desc { margin: var(--s-1) 0 0; color: var(--text-2); }
.page-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }

.card {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(var(--blur)); -webkit-backdrop-filter: blur(var(--blur));
  padding: var(--s-6);
  transition: border-color 150ms ease;
}
.card:hover { border-color: var(--border-strong); }

.empty { text-align: center; padding: var(--s-8) var(--s-4); color: var(--text-2); }
.empty .icon { width: 36px; height: 36px; color: var(--text-3); margin-bottom: var(--s-3); }
.empty-title { font-size: 16px; font-weight: 600; color: var(--text-1); margin: 0 0 var(--s-1); }
.empty p { margin: 0; }
.empty a { color: var(--accent); }

/* 진입 모션: 페이드 + 살짝 위로 */
.enter { animation: enter 180ms ease-out both; }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* 드로어 덮개 (모바일) */
.scrim { position: fixed; inset: 0; z-index: 40; background: var(--overlay); touch-action: none; overscroll-behavior: none; }
/* 모바일 드로어가 열린 동안 뒤 페이지 고정(js/shell.js lockScroll) */
html.is-scroll-locked body { position: fixed; left: 0; right: 0; width: 100%; overflow: hidden; }
.scrim[hidden] { display: none; }

/* ── 반응형 ── */
@media (max-width: 1199px) {
  .app, .app.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
  .app:not(.is-expanded) .brand-text,
  .app:not(.is-expanded) .side-search,
  .app:not(.is-expanded) .nav-group,
  .app:not(.is-expanded) .nav-label,
  .app:not(.is-expanded) .nav-ext,
  .app:not(.is-expanded) .side-user-text { display: none; }
  .app:not(.is-expanded) .nav-link { justify-content: center; position: relative; }
  .app:not(.is-expanded) .nav-badge { position: absolute; top: 2px; right: 4px; min-width: 16px; line-height: 16px; font-size: 10px; padding: 0 4px; }
  .app:not(.is-expanded) .side-user { justify-content: center; padding: var(--s-2); }
  .app:not(.is-expanded) .brand { justify-content: center; }
  .collapse-btn { display: none; }
}
@media (max-width: 767px) {
  .app, .app.is-collapsed { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; z-index: 50; left: auto; right: 0; top: 0; width: min(var(--sidebar-w), 86vw); /* 오른쪽에서 열림(메뉴 버튼이 오른쪽) */
    transform: translateX(100%); transition: transform 180ms ease;
    background: var(--bg-1);
    height: 100vh; height: 100dvh; overscroll-behavior: contain;  /* 주소창이 있어도 아래 내 정보까지 보이게 */
  }
  .app.is-drawer-open .sidebar { transform: none; }
  /* 드로어 안에서는 항상 펼친 모양 */
  .app .sidebar .brand-text, .app .sidebar .side-search, .app .sidebar .nav-group,
  .app .sidebar .nav-label, .app .sidebar .nav-ext, .app .sidebar .side-user-text { display: revert; }
  .app .sidebar .side-user-text { display: block; }
  .side-user { cursor: pointer; }
  .side-user-more { display: block; }
  .app .sidebar .side-search { display: flex; }
  .app .sidebar .nav-link { justify-content: flex-start; }
  .app .sidebar .nav-badge { position: static; }
  .app .sidebar .side-user { justify-content: flex-start; padding: var(--s-3); }
  .app .sidebar .brand { justify-content: flex-start; }
  .only-mobile { display: inline-grid; }
  .topbar { padding: 0 var(--s-4); }
  .topbar-search { display: none; }
  .profile-name { display: none; }
  .profile { padding: 3px; }
  .content { padding: var(--s-4); }
  .page-title { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* 로그인 전 안내 — 배경은 js/gate-bg.js(점 격자·빛 번짐 캔버스) + 아래 바탕 그라데이션 */
html.is-gate .bg-photo { background: linear-gradient(180deg, #070b16, #0b1222) !important; }
html.is-gate[data-theme="light"] .bg-photo { background: linear-gradient(180deg, #f3f6fc, #e6ecf7) !important; }
html.is-gate .bg-photo::after { display: none; }
.gate-canvas { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; }
.gate { min-height: 100vh; display: grid; place-items: center; padding: var(--s-4); }
.gate-card { width: min(440px, 100%); }

/* 휴대폰: 누를 때 브라우저가 칠하는 파란 사각형(탭 하이라이트)과 길게 누를 때 글자 선택·메뉴 끄기.
   대신 눌린 동안 옅은 배경으로 알려 준다. 키보드 포커스 표시(:focus-visible)는 그대로 */
html { -webkit-tap-highlight-color: transparent; }
button, a, label, summary, [role="button"] { -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
button, .nav-link, .nav-parent, .side-user, .seg-btn, .btn, .icon-btn { -webkit-user-select: none; user-select: none; }
@media (hover: none) {
  .nav-link:active, .nav-parent:active, .side-user:active, .icon-btn:active { background: var(--glass-strong); }
}


/* 로그인 연출(js/login-intro.js): 화면 전체를 덮고, 점 파동 → 글자 줄은 아래로·점은 입자로 → 입자가 흩어진 뒤 배경(.intro-bg)을 걷어 아래 화면을 보인다. 색은 병원 주 색(JS가 넣음) */
.intro { position: fixed; inset: 0; z-index: 2000; }
.intro-bg { position: absolute; inset: 0; background: var(--bg-1); } /* 로그인 화면이 덮개(.gate-veil)로 페이드아웃된 색과 같게 */
.intro-glow {
  position: absolute; inset: 0; opacity: 0;
  background:
    radial-gradient(620px 420px at 14% 10%, var(--intro-glow, rgba(95,212,184,.28)), transparent 70%),
    radial-gradient(640px 440px at 86% 92%, var(--intro-glow-2, rgba(95,212,184,.14)), transparent 70%);
}
.gate-veil { position: fixed; inset: 0; z-index: -1; background: var(--bg-1); opacity: 0; pointer-events: none; } /* 배경 위·로그인 상자 아래(같은 z-index에서 나중 요소가 위) */
.intro canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.intro-box { position: absolute; left: 50%; top: 50%; width: min(360px, calc(100vw - 48px)); transform: translate(-50%, -50%); opacity: 0; text-align: center; }
.intro-name { display: flex; justify-content: center; min-width: 0; margin: 0 0 14px; font-size: 16px; font-weight: 600; color: var(--text-1, inherit); white-space: nowrap; }
.intro-name .ellipsis { min-width: 0; }
.intro-loading { flex: none; margin-left: .35em; color: var(--text-2, inherit); font-weight: 500; }
.intro-dots { display: flex; justify-content: center; align-items: center; gap: 12px; height: 34px; }
.intro-dots span { width: 10px; height: 10px; border-radius: 50%; }

/* ── 스크롤바(PC만: 마우스 + 768px 이상) — 사이드바 메뉴 4px(올렸을 때만 보임), 본문·안쪽 칸 6px, 둥근 반투명 손잡이, 테마 색 따라감 ──
   Chrome·Edge·Safari는 ::-webkit-scrollbar, Firefox는 표준 속성(얇게·색만). Chrome 121+은 표준 속성이 있으면 webkit 모양을 무시하므로 Firefox에만 표준 속성을 준다.
   휴대폰·태블릿(터치)은 기본 스크롤바 그대로. 젠티 콘솔(hq-system public/admin/styles/app.css)과 같은 규칙 — 한쪽을 고치면 같이. */
@media (hover: hover) and (pointer: fine) and (min-width: 768px) {
  :root {
    --sb-thumb: color-mix(in srgb, var(--text-3) 45%, transparent);
    --sb-thumb-hover: color-mix(in srgb, var(--text-2) 75%, transparent);
  }
  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
  ::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
  ::-webkit-scrollbar-thumb { background: var(--sb-thumb); border-radius: 999px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--sb-thumb-hover); }
  .nav::-webkit-scrollbar { width: 4px; }
  .nav::-webkit-scrollbar-thumb { background: transparent; }
  .sidebar:hover .nav::-webkit-scrollbar-thumb { background: var(--sb-thumb); }
  .sidebar:hover .nav::-webkit-scrollbar-thumb:hover { background: var(--sb-thumb-hover); }
  @supports not selector(::-webkit-scrollbar) {
    * { scrollbar-width: thin; scrollbar-color: var(--sb-thumb) transparent; }
    .nav { scrollbar-color: transparent transparent; }
    .sidebar:hover .nav { scrollbar-color: var(--sb-thumb) transparent; }
  }
}
