/* ==========================================================================
   301cell — Base: reset, typography, form controls, utilities
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  font-size: 16px;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-base);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "tnum" 0;
  /* 한글은 어절 단위로 줄바꿈 — 단어 중간에서 끊기지 않게 */
  word-break: keep-all;
  overflow-wrap: break-word;
  transition: background-color var(--dur-base) var(--ease), color var(--dur-base) var(--ease);
}

/* 테마 전환 순간의 전역 트랜지션 (theme.js 가 잠깐 붙였다 뗀다) */
.theme-transition, .theme-transition * {
  transition: background-color var(--dur-base) var(--ease),
              border-color var(--dur-base) var(--ease),
              color var(--dur-base) var(--ease),
              fill var(--dur-base) var(--ease) !important;
}

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: var(--fw-semibold); line-height: var(--lh-tight); }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
p  { margin: 0 0 var(--sp-3); }
p:last-child { margin-bottom: 0; }

a { color: var(--text-link); text-decoration: none; }
a:hover { text-decoration: underline; }

small { font-size: var(--fs-xs); }
code, kbd, pre, samp { font-family: var(--font-mono); font-size: 0.92em; }
code {
  background: var(--surface-3); padding: 0.1em 0.36em;
  border-radius: var(--r-xs); color: var(--text-secondary);
}
hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-5) 0; }

ul, ol { margin: 0; padding-left: 1.2em; }
img, svg, video, canvas { max-width: 100%; display: block; }

/* ---------- 포커스 링 (접근성 필수) ---------- */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

::selection { background: var(--primary-ring); color: var(--text); }

/* ---------- 스크롤바 ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: var(--r-full);
  border: 2px solid transparent; background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }

/* ==========================================================================
   Form controls
   ========================================================================== */
input, select, textarea, button { font: inherit; color: inherit; }

.field { display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; }
.field-label {
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
  color: var(--text-secondary); display: flex; align-items: center; gap: var(--sp-1);
}
.field-label .req { color: var(--sig-danger); font-weight: var(--fw-bold); }
.field-hint { font-size: var(--fs-xs); color: var(--text-muted); }
.field-error { font-size: var(--fs-xs); color: var(--sig-danger); display: flex; align-items: center; gap: 4px; }

.input, .select, .textarea {
  width: 100%;
  padding: 0 var(--sp-3);
  height: 36px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: var(--fs-md);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.textarea { height: auto; min-height: 88px; padding: var(--sp-2) var(--sp-3); line-height: var(--lh-base); resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }

.input:hover:not(:disabled), .select:hover:not(:disabled), .textarea:hover:not(:disabled) {
  border-color: var(--text-faint);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring);
}
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--surface-3); color: var(--text-faint); cursor: not-allowed;
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"], .select[aria-invalid="true"] {
  border-color: var(--sig-danger);
}
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px rgba(207, 59, 59, 0.22); }

.select {
  appearance: none;
  padding-right: var(--sp-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%23667a90' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--sp-3) center;
  cursor: pointer;
}
:root[data-theme="dark"] .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%238b9bad' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.input-sm, .select-sm { height: 30px; font-size: var(--fs-sm); padding-inline: var(--sp-2); }
.input-lg, .select-lg { height: 44px; font-size: var(--fs-lg); }

/* 검색 인풋 */
.input-search { padding-left: var(--sp-8); }
.search-wrap { position: relative; display: flex; align-items: center; }
.search-wrap > .icon { position: absolute; left: var(--sp-3); color: var(--text-faint); pointer-events: none; }

/* 체크박스 / 라디오 */
.check, .radio {
  appearance: none; width: 16px; height: 16px; flex: 0 0 16px; margin: 0;
  border: 1.5px solid var(--border-strong); background: var(--surface);
  cursor: pointer; position: relative;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.check { border-radius: var(--r-xs); }
.radio { border-radius: 50%; }
.check:checked, .radio:checked { background: var(--primary); border-color: var(--primary); }
.check:checked::after {
  content: ""; position: absolute; inset: 0;
  background: no-repeat center / 11px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='11' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2 4.8 8.5 9.5 3.8' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
:root[data-theme="dark"] .check:checked::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='11' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2 4.8 8.5 9.5 3.8' fill='none' stroke='%2304202a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.check:indeterminate { background: var(--primary); border-color: var(--primary); }
.check:indeterminate::after {
  content: ""; position: absolute; left: 3px; right: 3px; top: 50%;
  height: 2px; margin-top: -1px; background: var(--primary-fg); border-radius: 1px;
}
.radio:checked::after {
  content: ""; position: absolute; inset: 3.5px; border-radius: 50%; background: var(--primary-fg);
}
.check:focus-visible, .radio:focus-visible { box-shadow: 0 0 0 3px var(--primary-ring); }

.check-label { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; font-size: var(--fs-md); }

/* 스위치 */
.switch { appearance: none; width: 36px; height: 20px; border-radius: var(--r-full);
  background: var(--border-strong); position: relative; cursor: pointer; flex: none;
  transition: background var(--dur-fast) var(--ease); }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: var(--sh-xs);
  transition: transform var(--dur-fast) var(--ease); }
.switch:checked { background: var(--primary); }
.switch:checked::after { transform: translateX(16px); }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: 36px; padding: 0 var(--sp-4);
  border: 1px solid transparent; border-radius: var(--r-sm);
  background: var(--surface); color: var(--text);
  font-size: var(--fs-md); font-weight: var(--fw-medium); white-space: nowrap;
  cursor: pointer; user-select: none;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn .icon { flex: none; }

.btn-primary   { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn-primary:hover  { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-primary:active { background: var(--primary-active); }

.btn-default   { background: var(--surface); border-color: var(--border-strong); }
.btn-default:hover { background: var(--surface-hover); border-color: var(--text-faint); }

.btn-ghost     { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn-soft      { background: var(--primary-soft); color: var(--primary-soft-fg); }
.btn-soft:hover{ background: var(--primary-soft); filter: brightness(0.96); }

.btn-danger    { background: var(--sig-danger); color: #fff; border-color: var(--sig-danger); }
.btn-danger:hover { filter: brightness(0.92); }

.btn-outline-danger { background: transparent; color: var(--sig-danger); border-color: var(--tone-danger-bd); }
.btn-outline-danger:hover { background: var(--tone-danger-bg); }

.btn-sm  { height: 30px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }
.btn-xs  { height: 26px; padding: 0 var(--sp-2); font-size: var(--fs-xs); gap: var(--sp-1); }
.btn-lg  { height: 44px; padding: 0 var(--sp-6); font-size: var(--fs-lg); }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }
.btn-icon.btn-xs { width: 26px; }
.btn-block { width: 100%; }

/* 배양실 태블릿 장갑 모드 — body.glove-mode 로 전역 확대 */
body.glove-mode .btn { min-height: var(--touch-min); padding-inline: var(--sp-5); font-size: var(--fs-lg); }
body.glove-mode .input, body.glove-mode .select { height: var(--touch-min); font-size: var(--fs-lg); }
body.glove-mode .check, body.glove-mode .radio { width: 22px; height: 22px; flex-basis: 22px; }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); margin-left: 0; }
.btn-group .btn:last-child  { border-radius: 0 var(--r-sm) var(--r-sm) 0; }

/* ==========================================================================
   Utilities
   ========================================================================== */
.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;
}
.skip-link {
  position: absolute; left: var(--sp-3); top: -60px; z-index: var(--z-tooltip);
  background: var(--primary); color: var(--primary-fg);
  padding: var(--sp-2) var(--sp-4); border-radius: var(--r-sm);
  transition: top var(--dur-fast) var(--ease);
}
.skip-link:focus { top: var(--sp-3); }

.stack   { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-2 { display: flex; flex-direction: column; gap: var(--sp-2); }
.stack-6 { display: flex; flex-direction: column; gap: var(--sp-6); }
.row     { display: flex; align-items: center; gap: var(--sp-3); }
.row-2   { display: flex; align-items: center; gap: var(--sp-2); }
.wrap    { flex-wrap: wrap; }
.spacer  { flex: 1 1 auto; }
.grow    { flex: 1 1 auto; min-width: 0; }

.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.num  { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.fw-medium { font-weight: var(--fw-medium); }
.fw-semibold { font-weight: var(--fw-semibold); }

.hidden { display: none !important; }
/* display:flex/grid 를 가진 컴포넌트에서도 [hidden] 이 확실히 먹도록 */
[hidden] { display: none !important; }
@media (max-width: 900px)  { .hide-md { display: none !important; } }
@media (max-width: 640px)  { .hide-sm { display: none !important; } }
@media (min-width: 901px)  { .only-md { display: none !important; } }

.grid { display: grid; gap: var(--sp-4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px)  { .grid-3, .grid-2 { grid-template-columns: 1fr; }
                             .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px)  { .grid-4 { grid-template-columns: 1fr; } }

/* 정의 목록 (상세화면 기본정보 표시용) */
.dl { display: grid; grid-template-columns: minmax(120px, 168px) 1fr; gap: var(--sp-3) var(--sp-4); margin: 0; }
.dl dt { font-size: var(--fs-sm); color: var(--text-muted); }
.dl dd { margin: 0; font-size: var(--fs-md); color: var(--text); word-break: break-word; }
@media (max-width: 560px) { .dl { grid-template-columns: 1fr; gap: var(--sp-1) 0; }
                            .dl dd { margin-bottom: var(--sp-3); } }
