:root {
  /* Primitive tokens */
  --sidebar-width: 264px;
  --cellaheal: #161616;
  --cellaheal-red-dark: #ff0000;
  --cellaheal-red-light: #ffbbbb;
  --cellaheal-spotless-dark: #991B1B;
  --cellaheal-spotless-light: #fff2f2;
  --cellaheal-poreless-dark: #92400E;
  --cellaheal-poreless-light: #fffbec;
  --cellaheal-stressless-dark: #065F46;
  --cellaheal-stressless-light: #f1ffe1;
  --cellaheal-flawless-dark: #ffd50b;
  --cellaheal-flawless-light: #fffbec;
  --cellaheal-dryless-dark: #0071cf;
  --cellaheal-timeless-dark: #bd4ad0;
  --cellaheal-black: #000;
  --cellaheal-white: #fff;
  --cellaheal-050: #fbfbfb;
  --cellaheal-100: #f5f5f5;
  --cellaheal-200: #d5d5d5;
  --cellaheal-300: #b5b5b5;
  --cellaheal-400: #959595;
  --cellaheal-500: #767676;
  --cellaheal-600: #565656;
  --cellaheal-700: #363636;
  --cellaheal-800: #161616;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  /* Semantic tokens */
  --bg: var(--cellaheal-050);
  --surface: var(--cellaheal-white);
  --surface-strong: var(--cellaheal-white);
  --surface-muted: var(--cellaheal-100);
  --line: var(--cellaheal-200);
  --line-strong: var(--cellaheal-300);
  --text: var(--cellaheal-800);
  --muted: var(--cellaheal-600);
  --accent: var(--cellaheal-800);
  --accent-strong: var(--cellaheal-black);
  --accent-soft: var(--cellaheal-100);
  --good: var(--cellaheal-stressless-dark);
  --warn: var(--cellaheal-poreless-dark);
  --bad: var(--cellaheal-spotless-dark);
  --focus-ring: var(--cellaheal-black);
  --page-section-gap: var(--space-4);
  --layout-cluster-gap: var(--space-2);
  --layout-grid-gap: var(--space-3);
  --duration-fast: 150ms;
  --z-popover: 20;
  --z-nav: 30;
  --z-backdrop: 40;
  --z-drawer: 50;
  --z-stacked-backdrop: 60;
  --z-stacked-drawer: 70;
  --z-tooltip: 80;
  --z-toast: 90;
  --z-modal: 100;
  --z-skip-link: 110;
  --shadow: 0 16px 40px rgba(0, 0, 0, .08);
  --shadow-raised: 0 18px 50px rgba(0, 0, 0, .16);

  /* Component tokens. Contexts change these variables instead of overriding base declarations. */
  --control-height-compact: 32px;
  --control-height-default: 40px;
  --control-height-touch: 44px;
  --control-height-large: 48px;
  --control-height-hero: 56px;
  --control-padding-compact: 10px;
  --control-padding-default: 14px;
  --control-font-compact: 13px;
  --control-font-default: 14px;
  --card-padding: var(--space-5);
  --card-padding-compact: var(--space-3);
  --card-radius: var(--radius-md);
  --card-background: var(--surface);
  --card-border: var(--line);
  --card-shadow: 0 1px 2px rgba(0, 0, 0, .03);
  --panel-padding: var(--space-3);
  --panel-radius: var(--radius-sm);
  --tooltip-max-width: 280px;
  --tooltip-padding-block: var(--space-2);
  --tooltip-padding-inline: 10px;
  --tooltip-radius: 7px;
}

* { box-sizing: border-box; }

html { font-size: 15px; }

body { margin: 0; color: var(--text); font-family: "Figtree", "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, system-ui, Roboto, "Helvetica Neue", "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", sans-serif; background: var(--bg); line-height: 1.5; }

a,
button,
input,
select,
textarea { font: inherit; }

.shell { min-height: 100vh; }

.shell-fixed-sidebar { position: relative; }

.sidebar { position: fixed; top: 0; left: 0; z-index: var(--z-nav); display: flex; flex-direction: column; width: var(--sidebar-width); height: 100dvh; overflow: hidden; padding: var(--space-5) var(--space-3); border-right: 1px solid var(--line); background: var(--surface); }

.brand { display: flex; margin-bottom: 24px; flex-direction: column; align-items: center; }

.brand-mark { display: inline-flex; align-items: center; width: fit-content; }

.brand-logo { display: block; width: 48px; height: auto; margin-bottom: 16px; }

.brand small { display: block; margin-bottom: 8px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; font-size: 11px; font-weight: 600; }

.brand .clh { font-size: 20px; font-weight: 700; }

.brand .crp { font-size: 18px; font-weight: 500; color: var(--cellaheal-600); }

.sidebar-user { border: 1px solid var(--line); border-radius: 8px; margin-top: 24px; padding: 14px; font-size: 14px; width: 100%; }

.sidebar-user-name { font-weight: 600; font-size: 16px; margin-right: 4px; }

.sidebar-nav { display: grid; flex: 1 1 auto; align-content: start; gap: 4px; min-height: 0; margin-bottom: 124px; overflow-y: auto; }

.nav-item { display: grid; gap: 6px; }

.nav-link,
.subnav-link { text-decoration: none; transition: 140ms ease; }

.nav-link { display: flex; align-items: center; justify-content: space-between; min-height: 44px; padding: 10px 12px; border: 1px solid transparent; border-radius: var(--radius-sm); color: var(--text); font-size: 14px; font-weight: 600; }

.nav-link:hover { border-color: var(--line); background: var(--surface-muted); }
.nav-link.active { border-color: var(--line-strong); background: var(--accent-soft); color: var(--accent-strong); }

.nav-toggle { width: 100%; background: transparent; cursor: pointer; }

.nav-toggle::before { content: none; }

.nav-toggle::after { content: "+"; display: block; line-height: 1; font-size: 16px; font-weight: 500; color: var(--muted); }

.nav-toggle:hover,
.nav-toggle.is-open { border-color: var(--line); background: var(--surface-muted); }

.nav-toggle:hover::after,
.nav-toggle.is-open::after { color: var(--text); }

.nav-toggle.is-open::after { content: "-"; }

.subnav { display: none; gap: 4px; margin-left: 10px; padding-left: 10px; border-left: 1px solid var(--line); }

.subnav.is-open { display: grid; }

.subnav-static { display: grid; }

.subnav-link { min-height: 36px; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--muted); font-size: 13px; }

.subnav-action { width: 100%; border: 0; background: transparent; text-align: left; cursor: pointer; }

.subnav-link:hover,
.subnav-link.active { color: var(--text); background: var(--surface-muted); }
.notification-badge { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; padding: 0; background: #dc2626; color: #fff; border-radius: 50%; font-size: 11px; font-variant-numeric: tabular-nums; line-height: 1; text-align: center; }
.nav-notification-badge { margin-left: 4px; color: var(--cellaheal-spotless-dark); font: inherit; font-variant-numeric: tabular-nums; }
.sidebar-bottom-card { position: fixed; bottom: 18px; left: 18px; width: calc(var(--sidebar-width) - 36px); border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: linear-gradient(145deg, #fff, #f7f7f7); box-shadow: 0 10px 22px rgba(0,0,0,.05); }
.sidebar-account { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.sidebar-account-avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--cellaheal-800); color: #fff; font-weight: 700; }
.sidebar-account-copy { display: grid; gap: 2px; min-width: 0; }
.sidebar-account-copy strong { font-size: 14px; }
.sidebar-account-copy span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-notification-summary { display: flex; align-items: center; gap: 6px; margin-top: 12px; color: var(--text); font-size: 13px; font-weight: 700; text-decoration: none; }
.sidebar-notification-summary-empty { color: var(--muted); font-size: 12px; font-weight: 400; }
.notification-badge:not(.is-hidden) + .sidebar-notification-summary-empty { display: none; }

.main { min-height: 100dvh; margin-left: var(--sidebar-width); padding: var(--space-6); }

/* Every admin route gets the same vertical rhythm through the layout renderer. */
.page-content { display: flex; min-width: 0; flex-direction: column; gap: var(--page-section-gap); }
.main .page-content > * { margin-block: 0; }

.page-header {
  position: sticky;
  top: 0;
  z-index: var(--z-nav);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin: 0;
  padding: 12px 0;
  border-bottom: 1px solid transparent;
  background: var(--bg);
  overflow-anchor: none;
  transition: padding 220ms cubic-bezier(.22, 1, .36, 1), border-color 220ms ease, box-shadow 220ms ease;
}

.page-header h1 { margin: 0 0 8px; font-size: 32px; line-height: 1.08; letter-spacing: -0.05em; font-weight: 700; transition: margin 220ms cubic-bezier(.22, 1, .36, 1), font-size 220ms cubic-bezier(.22, 1, .36, 1); }
/* 헤더 우측에 보조 링크(설정 등)와 기본 액션 버튼을 나란히 둘 때 쓴다. */
.page-header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.page-header .eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.page-header .eyebrow a { color: inherit; text-decoration: none; }
.page-header .eyebrow a:hover { color: var(--text); }

.page-header p { max-height: 96px; margin: 0; overflow: hidden; opacity: 1; transform: translateY(0); transition: max-height 220ms cubic-bezier(.22, 1, .36, 1), margin 220ms cubic-bezier(.22, 1, .36, 1), opacity 150ms ease, transform 220ms cubic-bezier(.22, 1, .36, 1); }
.page-header p,
.muted,
p { color: var(--muted); }

.page-header.is-measuring,
.page-header.is-measuring *,
.record-detail-header.is-measuring,
.record-detail-header.is-measuring * { transition: none !important; }

/* 헤더가 충분히 화면 밖으로 올라간 뒤에만 작아진다. 복원은 스크롤 최상단에서만 한다. */
.page-header.is-compact { align-items: center; padding: 8px 0; border-color: var(--line); background: var(--bg); box-shadow: 0 6px 12px rgba(0, 0, 0, .035); }
.page-header.is-compact h1 { margin: 0; font-size: 20px; }
.page-header.is-compact .eyebrow,
.page-header.is-compact p { max-height: 0; margin: 0; opacity: 0; transform: translateY(-4px); }

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active { -webkit-box-shadow: 0 0 0px 1000px var(--cellaheal-white) inset !important; -webkit-text-fill-color: var(--text) !important; transition: background-color 5000s ease-in-out 0s; }

input:-webkit-autofill:focus { -webkit-box-shadow: 0 0 0px 1000px var(--cellaheal-white) inset, 0 0 10px 2px var(--accent-soft) !important; }

.grid { display: grid; gap: var(--layout-grid-gap); }

.grid.cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.grid.two { grid-template-columns: 1.2fr 0.8fr; }

.card {
  --card-current-padding: var(--card-padding);
  --card-current-radius: var(--card-radius);
  --card-current-background: var(--card-background);
  --card-current-border: var(--card-border);
  --card-current-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  padding: var(--card-current-padding);
  border: 1px solid var(--card-current-border);
  border-radius: var(--card-current-radius);
  background: var(--card-current-background);
  box-shadow: var(--card-current-shadow);
}

.card-compact { --card-current-padding: var(--card-padding-compact); }
.card-flush { --card-current-padding: 0; overflow: hidden; }
.card-muted { --card-current-background: var(--surface-muted); --card-current-shadow: none; }
.card-interactive { color: inherit; text-decoration: none; transition: border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease, background-color var(--duration-fast) ease; }
.card-interactive:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.card-interactive:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.card-status { --card-status-color: var(--line-strong); border-left: 6px solid var(--card-status-color); }
.card-status.good { --card-status-color: var(--good); --card-current-background: var(--cellaheal-stressless-light); }
.card-status.warn { --card-status-color: var(--warn); --card-current-background: var(--cellaheal-poreless-light); }
.card-status.bad { --card-status-color: var(--bad); --card-current-background: var(--cellaheal-spotless-light); }

/* Reusable secondary grouping inside a card. It is deliberately flatter than a card. */
.inset-panel { padding: var(--panel-padding); border: 1px solid var(--line); border-radius: var(--panel-radius); background: var(--surface-muted); }
.inset-panel.is-selected,
.inset-panel-emphasis { border-color: var(--accent); background: var(--accent-soft); }

.dropzone { padding: var(--space-4); border: 1px dashed var(--line-strong); border-radius: var(--panel-radius); background: var(--surface-muted); cursor: pointer; transition: border-color var(--duration-fast) ease, background-color var(--duration-fast) ease; }
.dropzone:hover,
.dropzone.is-active { border-color: var(--accent); background: var(--accent-soft); }

/* Reusable feedback container. Tone modifiers carry meaning; pages only own placement. */
.status-panel { display: flex; gap: var(--space-2); padding: var(--space-3) var(--space-4); border: 1px solid var(--line); border-radius: var(--panel-radius); background: var(--surface-muted); color: var(--text); line-height: 1.6; }
.status-panel.good { border-color: var(--good); background: var(--cellaheal-stressless-light); color: var(--good); }
.status-panel.warn { border-color: var(--warn); background: var(--cellaheal-poreless-light); color: var(--warn); }
.status-panel.bad { border-color: var(--bad); background: var(--cellaheal-spotless-light); color: var(--bad); }

.notice,
.notice-error {
  display: flex;
  flex-direction: column;
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background: var(--surface-muted);
  box-shadow: none;
}
.notice-error { border-color: var(--bad); background: var(--cellaheal-spotless-light); }

.radio-card-group,
.checkbox-card-group { display: flex; gap: var(--layout-grid-gap); align-items: center; flex-wrap: wrap; }

.radio-card,
.checkbox-card { display: inline-flex; min-height: var(--control-height-default); align-items: center; gap: var(--space-2); padding: 9px var(--space-3); border: 1px solid var(--line); border-radius: var(--panel-radius); background: var(--surface); color: var(--text); font-size: var(--control-font-default); font-weight: 600; cursor: pointer; transition: border-color var(--duration-fast) ease, background-color var(--duration-fast) ease; }
.radio-card:hover,
.checkbox-card:hover { border-color: var(--line-strong); background: var(--surface-muted); }

.radio-card input[type="radio"] { appearance: none; -webkit-appearance: none; width: 22px; height: 22px; margin: 0; padding: 0; border: 0; border-radius: 0; background: transparent url("/assets/icons/radiobutton-unchecked.svg") center / 22px 22px no-repeat; box-shadow: none; cursor: pointer; }
.radio-card input[type="radio"]:checked { background-image: url("/assets/icons/radiobutton-checked.svg"); }
.radio-card input[type="radio"]:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.toast { position: fixed; left: 50%; bottom: var(--space-6); z-index: var(--z-toast); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--accent); color: var(--surface); box-shadow: var(--shadow); transform: translateX(-50%); }

.card h2,
.card h3,
h2,
h3 { margin: 0 0 14px; letter-spacing: -0.03em; }

.metric { margin: 8px 0 2px; font-size: 2rem; line-height: 1.05; letter-spacing: -0.05em; font-weight: 600; }

/* 숫자 요약 카드는 제목과 설명을 분리한다. 설명은 정보 버튼에만 두고, 비용 조건만 짧은 배지로 남긴다. */
.metric-card { --card-current-padding: var(--space-4); gap: 0; }
.metric-card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-height: 16px; }
.metric-card-label { color: var(--muted); font-size: 12px; font-weight: 600; line-height: 1.35; }
.metric-card .metric { margin: 6px 0 0; }
/* 일반 button의 모바일 최소 높이(44px)를 물려받으면 카드 헤더가 아이콘 높이만큼 커진다. 정보 아이콘은
   카드 안의 보조 컨트롤이므로 실제 아이콘 크기와 같은 20px로 독립시킨다. */
.metric-card-info { display: inline-flex; flex: 0 0 auto; align-items: center; justify-content: center; width: 20px; min-height: 20px; height: 20px; margin: 0; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: help; }
.metric-card-info:hover,
.metric-card-info:focus-visible { background: var(--surface-muted); color: var(--text); outline: none; }
.metric-card-info img { width: 16px; height: 16px; }
.metric-card-info:focus::after { opacity: 1; visibility: visible; }
.metric-card-badge { display: inline-flex; align-self: flex-start; margin-top: 10px; padding: 3px 7px; border-radius: 999px; background: var(--surface-muted); color: var(--muted); font-size: 10px; font-weight: 700; line-height: 1.2; }

.pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 6px 10px; font-size: 11px; font-weight: 700; white-space: nowrap; gap: 4px; }

/* 좋고 나쁨이 아직 안 정해진 중립 상태(예: 평가 대기·발송 후보)용 — 색으로 판단을 주지 않되, 배지 모양은
   good/bad와 똑같이 유지해 같은 컬럼 안에서 글자만 떠 보이지 않게 한다. */
.pill.neutral { color: var(--cellaheal-600); background-color: var(--cellaheal-100); border: 1px solid var(--cellaheal-300); }
.pill.good { color: var(--cellaheal-stressless-dark); background-color: var(--cellaheal-stressless-light); border: 1px solid var(--cellaheal-stressless-dark); }
.pill.warn { color: var(--cellaheal-poreless-dark); background-color: var(--cellaheal-poreless-light); border: 1px solid var(--cellaheal-poreless-dark); }
.pill.bad { color: var(--cellaheal-spotless-dark); background-color: var(--cellaheal-spotless-light); border: 1px solid var(--cellaheal-spotless-dark); }

.table-scroll,
.data-table-scroll { width: 100%; min-width: 0; overflow-x: auto; overscroll-behavior-inline: contain; }

.data-table-scroll:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; border-radius: var(--radius-sm); }

.table,
.data-table { width: 100%; table-layout: fixed; border-collapse: collapse; }

.table th,
.table td,
.data-table th,
.data-table td { padding: 10px; overflow-wrap: anywhere; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); font-size: 14px; }

.table th,
.data-table th { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.02em; }

/* Quiet links for record names and supporting destinations in operational lists. */
.record-link,
.record-link:visited { color: var(--text); font-weight: 600; text-decoration: none; text-underline-offset: 3px; text-decoration-thickness: 1px; border-radius: var(--radius-sm); }
.record-link:hover,
.record-link:focus-visible { color: var(--accent-strong); text-decoration: underline; }
.record-link:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 3px; }
.record-link--external { font-weight: 400; }
.record-link--external::after { content: " ↗"; color: var(--muted); }

/* Shared contract for operational tables. Pages may choose density or matrix behavior,
   but card, row, selection, sorting, and scroll behavior stay global. */
.data-table-card { min-width: 0; }
.data-table-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-4); }
.data-table-header h2,
.data-table-header h3 { margin-bottom: var(--space-1); }
.data-table-header p { margin-block: 0; }
.data-table--dense th,
.data-table--dense td { padding-block: var(--space-2); font-size: 13px; }
.data-table--matrix { font-variant-numeric: tabular-nums; }
.data-table .is-numeric,
.data-table [data-cell-type="number"] { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .is-status { text-align: center; }
.data-table .is-actions { text-align: right; white-space: nowrap; }
.data-table tbody tr { transition: background-color var(--duration-fast) ease; }
.data-table tbody tr:not(.data-table-empty-row):hover { background: var(--surface-muted); }
.data-table tbody tr.is-selected { background: var(--surface-muted); box-shadow: inset 4px 0 0 var(--accent); }
.data-table tbody tr.is-selected td { border-bottom-color: var(--line-strong); }
.data-table-empty-row td { height: 96px; color: var(--muted); text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.sort-button { display: inline-flex; align-items: center; gap: 8px; width: auto; min-height: 0; padding: 0; border: 0; border-radius: 0; background: transparent; color: inherit; font-size: inherit; font-weight: inherit; letter-spacing: inherit; text-align: left; }
.sort-button:hover { background: transparent; color: var(--text); }
.sort-button.is-active { color: var(--text); }
.sort-indicator { display: inline-flex; flex-direction: column; gap: 2px; }
.sort-caret { width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; opacity: .35; }
.sort-caret-up { border-bottom: 5px solid currentColor; }
.sort-caret-down { border-top: 5px solid currentColor; }
.sort-button.is-asc .sort-caret-up,
.sort-button.is-desc .sort-caret-down { opacity: 1; }

.stack { display: flex; flex-direction: column; gap: var(--space-4); }

.toolbar { display: flex; gap: var(--layout-cluster-gap); }

.toolbar,
.inline-form,
.pagination-nav,
.table,
.compact-controls {
  --control-height: var(--control-height-compact);
  --control-padding-inline: var(--control-padding-compact);
  --control-font-size: var(--control-font-compact);
}

/* 표 셀이나 섹션 하단에 컨트롤 몇 개를 한 줄로 놓는 폼. 전역 input 규칙(width:100%; flex:1)을
   그대로 두면 컨트롤이 세로로 쌓이므로 여기서 폭·신축을 되돌린다. */
.inline-form { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.inline-form input,
.inline-form select { width: auto; flex: 0 1 auto; min-width: 0; padding: 8px 10px; font-size: 13px; }
.inline-form button { padding: 8px 12px; font-size: 13px; white-space: nowrap; }

.field { display: grid; gap: 8px; width: 100%; }
.field.search {width: auto;}

.field label { font-size: 12px; color: var(--muted); font-weight: 600; }

input,
select,
textarea { border: 1px solid var(--line); background: var(--cellaheal-white); color: var(--text); border-radius: var(--radius-sm); width: 100%; flex: 1; }

input:not([type="checkbox"]):not([type="radio"]),
select {
  min-height: var(--control-height, var(--control-height-default));
  padding: 0 var(--control-padding-inline, var(--control-padding-default));
  font-size: var(--control-font-size, var(--control-font-default));
}

textarea { min-height: 96px; padding: var(--space-3) var(--control-padding-default); }

input[type="checkbox"] { width: min-content; }

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus-ring) 40%, transparent); outline-offset: 2px; border-color: var(--focus-ring); }

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-height: var(--control-height, var(--control-height-default));
  padding: 0 var(--control-padding-inline, var(--control-padding-default));
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--cellaheal-white);
  cursor: pointer;
  font-size: var(--control-font-size, var(--control-font-default));
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  touch-action: manipulation;
  transition: background-color var(--duration-fast) ease, border-color var(--duration-fast) ease, color var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
}

.button-quiet { width: auto; border: 1px solid var(--line-strong); background: var(--cellaheal-white); color: var(--text); font-weight: 600; }

.button-danger { width: auto; border: 1px solid var(--cellaheal-200); background: var(--cellaheal-200); color: var(--text); font-weight: 600; }

.btnWide { width: 100%; }

button:hover,
.button:hover { background: var(--accent-strong); }

.button-quiet:hover { background: var(--cellaheal-100); }
.button-danger:hover { background: var(--cellaheal-300); }

button:disabled,
.button:disabled { border-color: var(--cellaheal-200); background: var(--cellaheal-200); color: var(--cellaheal-500); cursor: not-allowed; }

.list { display: grid; gap: 12px; }

.list-item { padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface-muted); }

.split { display: flex; justify-content: space-between; gap: 16px; }

.ajax-section { position: relative; }

/* AJAX-rendered page fragments own the same vertical rhythm as .page-content.
   Without this contract, sibling cards become attached after initial render or replacement. */
.ajax-section[data-ajax-pagination-root] { display: flex; min-width: 0; flex-direction: column; gap: var(--page-section-gap); }
.main .ajax-section[data-ajax-pagination-root] > * { margin-block: 0; }

.ajax-section.is-loading {
  transition: opacity 160ms ease;
}

.ajax-section.is-loading::before {
  content: "";
  position: absolute;
  inset: 0;
  background: #d5d5d5aa;
  backdrop-filter: blur(1.5px);
  z-index: 10;
  border-radius: 8px;
}

.ajax-section.is-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin-top: -14px;
  margin-left: -14px;
  border: 5px solid rgba(28, 31, 35, 0.16);
  border-top-color: var(--cellaheal-800);
  border-radius: 999px;
  animation: ajax-spinner-rotate 1.2s ease-in-out infinite;
  z-index: 11;
}

.ajax-section.is-loading > * {
  pointer-events: none;
}

@keyframes ajax-spinner-rotate {
  to {
    transform: rotate(360deg);
  }
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.pagination-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.pagination-gap {
  padding: 0 4px;
  color: var(--muted);
}

.empty-page { min-height: 220px; display: grid; place-items: center; text-align: center; }

.range-toggle-group { display: flex; flex-wrap: wrap; gap: 10px; }

.range-toggle { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; padding: 9px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--cellaheal-white); color: var(--muted); text-decoration: none; font-size: 13px; transition: 140ms ease; }

.range-toggle:hover,
.range-toggle.active { border-color: var(--cellaheal-800); background: var(--cellaheal-800); color: var(--cellaheal-white); }

/* 분석 화면의 기간·계정·보기 단위를 같은 문법으로 모은다. */
.view-controls { display: grid; gap: 12px; padding: var(--space-3) var(--space-4); border: 1px solid var(--line); border-radius: var(--panel-radius); background: var(--surface); }
.view-controls-head { min-width: 0; }
.view-controls-head h2 { margin: 0; font-size: 14px; letter-spacing: -0.02em; }
.view-controls-groups { display: flex; align-items: flex-start; gap: 14px 24px; flex-wrap: wrap; }
.view-control-group { display: grid; gap: 6px; min-width: 0; }
.view-control-label { color: var(--muted); font-size: 11px; font-weight: 700; }
.view-control-options { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.view-control-option,
.view-control-more summary { display: inline-flex; min-height: 30px; align-items: center; justify-content: center; padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 600; line-height: 1.2; text-decoration: none; white-space: nowrap; cursor: pointer; }
.view-control-option:hover,
.view-control-more summary:hover { border-color: var(--line-strong); color: var(--text); }
.view-control-option.is-active { border-color: var(--accent); background: var(--accent); color: var(--surface); }
.view-control-option.is-disabled { background: var(--surface-muted); color: var(--muted); cursor: not-allowed; }
.view-control-more { position: relative; }
.view-control-more summary { list-style: none; }
.view-control-more summary::-webkit-details-marker { display: none; }
.view-control-more[open] summary { border-color: var(--line-strong); color: var(--text); }
.view-control-more-menu { position: absolute; top: calc(100% + 6px); right: 0; z-index: var(--z-popover); display: grid; min-width: 120px; padding: 6px; border: 1px solid var(--line); border-radius: var(--panel-radius); background: var(--surface); box-shadow: var(--shadow); }
.view-control-more-menu .view-control-option { justify-content: flex-start; border-color: transparent; border-radius: 6px; }
.view-controls-custom { padding-top: 10px; border-top: 1px solid var(--line); }
.view-controls-custom:has(.is-hidden) { display: none; }
.view-controls-custom .toolbar { align-items: flex-end; gap: 8px; }
@media (max-width: 640px) { .view-controls { padding: var(--space-3); } .view-controls-groups { display: grid; gap: 12px; } .view-control-more-menu { right: auto; left: 0; } }

.surface-muted { background: var(--surface-muted); }

.compact-stack { display: flex; gap: 8px; flex-wrap: wrap; }

.card-grid-3 { margin-top: 18px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }

.status-chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-muted); white-space: nowrap; }

.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--cellaheal-800); }

.good .status-dot { background: var(--cellaheal-stressless-dark); }

.warn .status-dot { background: var(--cellaheal-poreless-dark); }

.bad .status-dot { background: var(--cellaheal-spotless-dark); }

.status-label { font-size: 12px; font-weight: 700; }

.section-spaced { margin-top: var(--page-section-gap); }

/* Attribute tooltips share one visual and keyboard-focus contract across every domain. */
[data-tooltip] { position: relative; }

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  z-index: var(--z-tooltip);
  left: var(--tooltip-left, 50%);
  bottom: var(--tooltip-bottom, calc(100% + var(--space-2)));
  top: var(--tooltip-top, auto);
  width: max-content;
  max-width: min(var(--tooltip-width, var(--tooltip-max-width)), calc(100vw - 32px));
  padding: var(--tooltip-padding-block) var(--tooltip-padding-inline);
  border-radius: var(--tooltip-radius);
  background: var(--text);
  color: var(--surface);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .18);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
  text-align: left;
  white-space: pre-line;
  overflow-wrap: anywhere;
  transform: var(--tooltip-transform, translateX(-50%));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--duration-fast) ease, visibility var(--duration-fast) ease;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after { opacity: 1; visibility: visible; }

/* JavaScript가 가능한 화면은 툴팁을 body에 한 번만 띄운다. 부모의 overflow나 표 헤더의 경계에
   잘리지 않고, 아래 스크립트가 화면 사방 여백 안으로 위치를 계산한다. */
html[data-tooltips-managed="true"] [data-tooltip]::after { display: none; }
#app-tooltip { position: fixed; z-index: var(--z-tooltip); display: none; max-width: min(var(--tooltip-max-width), calc(100vw - 32px)); padding: var(--tooltip-padding-block) var(--tooltip-padding-inline); border-radius: var(--tooltip-radius); background: var(--text); color: var(--surface); box-shadow: 0 6px 16px rgba(0, 0, 0, .18); font-size: 12px; font-weight: 500; line-height: 1.45; text-align: left; white-space: pre-line; overflow-wrap: anywhere; pointer-events: none; }
#app-tooltip.is-visible { display: block; }

/* Rich tooltips use real markup but share the same surface tokens. */
.tooltip-surface {
  z-index: var(--z-tooltip);
  display: none;
  width: max-content;
  min-width: 160px;
  max-width: min(var(--tooltip-width, var(--tooltip-max-width)), calc(100vw - 32px));
  padding: var(--tooltip-padding-block) var(--tooltip-padding-inline);
  border: 1px solid var(--line-strong);
  border-radius: var(--tooltip-radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  white-space: normal;
  overflow-wrap: anywhere;
}

.mobile-nav-trigger,
.mobile-nav-backdrop { display: none; }

@media (max-width: 960px) {
  .shell { min-height: auto; }
  .sidebar { width: min(320px, calc(100vw - 56px)); height: 100dvh; padding-top: 72px; transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow-raised); }
  .shell.is-mobile-nav-open .sidebar { transform: translateX(0); }
  .sidebar-nav { flex: 1 1 auto; margin-bottom: 100px; overflow-y: auto; }
  .sidebar-bottom-card { position: fixed; left: 12px; bottom: 12px; width: calc(min(320px, calc(100vw - 56px)) - 24px); }
  .mobile-nav-trigger { position: fixed; top: 12px; left: 12px; z-index: calc(var(--z-nav) + 1); display: inline-flex; align-items: center; justify-content: center; width: 44px; min-height: 44px; padding: 0; background: var(--surface); color: var(--text); border-color: var(--line-strong); box-shadow: var(--shadow); }
  .mobile-nav-backdrop { position: fixed; inset: 0; z-index: calc(var(--z-nav) - 1); background: rgba(0, 0, 0, .42); }
  .shell.is-mobile-nav-open .mobile-nav-backdrop { display: block; }
  .main { min-height: 100dvh; margin-left: 0; padding: 72px 20px 20px; }
  .page-header { top: 56px; }

  .toolbar,
  .inline-form,
  .pagination-nav,
  .table,
  .compact-controls {
    --control-height: var(--control-height-touch);
  }

  button,
  .button,
  input:not([type="checkbox"]):not([type="radio"]),
  select { min-height: max(var(--control-height, var(--control-height-touch)), var(--control-height-touch)); }

  .page-header h1,
  h1 { font-size: 2rem; }

  .grid.two,
  .card-grid-3 { grid-template-columns: 1fr; }

  .pagination-bar { align-items: flex-start; }
}

.skip-link { position: fixed; top: 8px; left: 8px; z-index: var(--z-skip-link); transform: translateY(-150%); padding: 10px 14px; border-radius: var(--radius-sm); background: var(--text); color: #fff; text-decoration: none; }
.skip-link:focus { transform: translateY(0); }

.empty-state { display: grid; min-height: 180px; place-items: center; padding: var(--space-5); border: 1px dashed var(--line-strong); border-radius: var(--radius-md); color: var(--muted); text-align: center; }
.field-error { margin: 0; color: var(--bad); font-size: 13px; }
.form-feedback { min-height: 20px; margin: 0; color: var(--muted); font-size: 13px; }
.toast[role="status"] { z-index: var(--z-toast); }

@media (max-width: 640px) {
  .page-header { flex-direction: column; gap: var(--space-3); }
  .page-header-actions { width: 100%; flex-wrap: wrap; }
  .page-header-actions > .button { flex: 1 1 auto; }
  .toolbar, .split { flex-wrap: wrap; }
  input, select, textarea { font-size: 16px; }
  .table { min-width: 560px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
