/* ===== 스프레드시트 ===== */

.sh {
  --cell: #12241E;
  --head: #1A3029;
  --grid-line: #263D35;
  --pick: #4D96D9;
  max-width: 96rem;
  margin-inline: auto;
  padding: clamp(1rem, 3vw, 1.75rem) var(--gutter) 1rem;
  font-size: 0.875rem;
}
:root[data-theme="light"] .sh { --cell: #FFFFFF; --head: #E6EEE9; --grid-line: #D3DFD8; --pick: #2F6FB3; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* 저장 위치 고르기 */
.sh-store {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule);
}
.sh-seg { display: inline-flex; flex: none; padding: 3px; border: 1px solid var(--rule); border-radius: 10px; }
.sh-seg button {
  padding: 0.35rem 0.9rem;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}
.sh-seg button:hover { color: var(--ink); }
.sh-seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.sh-store__text { flex: 1 1 22rem; max-width: 52rem; color: var(--ink-soft); font-size: 0.8125rem; line-height: 1.6; }

/* 문서 머리 */
.sh-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1rem;
  margin-bottom: 0.75rem;
}
.sh-head__doc { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; min-width: 0; }
.sh-head__actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.sh-title {
  max-width: 24rem;
  padding: 0.15rem 0.4rem;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: clamp(1.125rem, 2.4vw, 1.375rem);
  font-weight: 800;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: text;
}
.sh-title:hover:not(.is-static) { border-color: var(--rule); }
.sh-title.is-static { cursor: default; }
.sh-title[hidden], .sh-title-input[hidden] { display: none; }
.sh-title-input {
  width: min(24rem, 70vw);
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--seal);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: clamp(1.125rem, 2.4vw, 1.375rem);
  font-weight: 800;
}
.sh-badge {
  flex: none;
  padding: 0.05rem 0.55rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: none;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
}
.sh-badge[hidden] { display: none; }
.sh-badge.is-edit { border-color: var(--seal); color: var(--seal); }
.sh-badge--toggle { cursor: pointer; }
.sh-badge--toggle:hover { border-color: var(--ink-soft); color: var(--ink); }
.sh-badge--toggle[aria-pressed="true"] { border-color: var(--seal); color: var(--seal); }
.sh-status { color: var(--ink-soft); font-size: 0.75rem; }

.sh-btn {
  padding: 0.38rem 0.8rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}
.sh-btn[hidden] { display: none; }
.sh-btn:hover:not(:disabled) { border-color: var(--ink-soft); }
.sh-btn:disabled { opacity: 0.5; cursor: default; }
.sh-btn--primary { border-color: var(--seal); background: var(--seal); color: #fff; }
.sh-btn--primary:hover:not(:disabled) { border-color: var(--seal); filter: brightness(1.08); }
.sh-btn--danger { color: var(--seal); }

.sh-select {
  max-width: 16rem;
  padding: 0.32rem 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 0.8125rem;
}
.sh-select[hidden] { display: none; }
.sh-select--small { max-width: 9.5rem; padding-block: 0.22rem; font-size: 0.75rem; }
.sh-select:disabled { opacity: 0.5; }

.sh-notice {
  margin-bottom: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--seal);
  border-radius: 10px;
  background: color-mix(in srgb, var(--seal) 8%, transparent);
}
.sh-notice[hidden] { display: none; }
.sh-notice__actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }

/* 서식 도구 */
.sh-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem;
  border: 1px solid var(--rule);
  border-bottom: 0;
  border-radius: 10px 10px 0 0;
  background: var(--tile);
}
.sh-tool {
  display: inline-grid;
  place-items: center;
  min-width: 1.9rem;
  height: 1.9rem;
  padding: 0 0.35rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
}
.sh-tool[hidden] { display: none; }
.sh-tool:hover:not(:disabled) { border-color: var(--rule); }
.sh-tool:disabled { opacity: 0.4; cursor: default; }
.sh-tool[aria-pressed="true"] { border-color: var(--seal); background: color-mix(in srgb, var(--seal) 14%, transparent); }
.sh-tool svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sh-tool--text { font-family: Georgia, "Times New Roman", serif; font-size: 0.95rem; }
.sh-tool--wide { padding-inline: 0.55rem; font-size: 0.75rem; font-weight: 600; }
.sh-sep { width: 1px; height: 1.2rem; margin-inline: 0.2rem; background: var(--rule); }
.sh-color { display: inline-flex; align-items: center; gap: 0.25rem; color: var(--ink-soft); font-size: 0.6875rem; }

/* 수식 입력줄 */
.sh-fbar {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--rule);
  border-bottom: 0;
  background: var(--cell);
}
.sh-namebox,
.sh-formula {
  min-width: 0;
  padding: 0.35rem 0.55rem;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8125rem;
}
.sh-namebox { flex: none; width: 6.5rem; border-right: 1px solid var(--rule); text-align: center; }
.sh-fx { display: grid; place-items: center; padding-inline: 0.55rem; border-right: 1px solid var(--rule); color: var(--ink-soft); font-style: italic; font-weight: 600; }
.sh-formula { flex: 1; }
.sh-namebox:focus, .sh-formula:focus { outline: 2px solid var(--pick); outline-offset: -2px; }

/* 표 */
.sh-grid-wrap {
  position: relative;
  height: 60vh;
  overflow: auto;
  border: 1px solid var(--rule);
  background: var(--cell);
  overscroll-behavior: contain;
}
.sh-grid-wrap:focus { outline: none; }
.sh-grid {
  position: relative;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  width: max-content;
  font-size: 0.8125rem;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}
.sh-grid col.sh-col-head { width: 46px; }
.sh-grid td,
.sh-grid th {
  height: 26px;
  padding: 0 6px;
  overflow: hidden;
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  text-overflow: clip;
  white-space: pre;
}
.sh-grid td { vertical-align: middle; cursor: cell; }
.sh-grid th {
  position: sticky;
  z-index: 4;
  background: var(--head);
  color: var(--ink-soft);
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
}
.sh-grid thead th { top: 0; }
.sh-grid th.sh-rh { left: 0; z-index: 3; }
.sh-grid th.sh-corner { left: 0; z-index: 5; cursor: pointer; }
.sh-grid th.sh-ch { cursor: s-resize; }
.sh-grid th.sh-rh { cursor: e-resize; }
.sh-grid th.is-on { background: color-mix(in srgb, var(--pick) 26%, var(--head)); color: var(--ink); }
.sh-resize {
  position: absolute;
  top: 0;
  right: -1px;
  width: 7px;
  height: 100%;
  cursor: col-resize;
}
.sh-resize:hover { background: var(--pick); }
body.is-readonly .sh-resize { cursor: default; }
body.is-readonly .sh-resize:hover { background: none; }

.sh-grid td.is-num { text-align: right; font-variant-numeric: tabular-nums; }
.sh-grid td.is-bool,
.sh-grid td.is-err { text-align: center; }
.sh-grid td.is-err { color: var(--seal); font-weight: 600; }
.sh-grid td.al-left { text-align: left; }
.sh-grid td.al-center { text-align: center; }
.sh-grid td.al-right { text-align: right; }
.sh-grid td.is-b { font-weight: 700; }
.sh-grid td.is-i { font-style: italic; }
.sh-grid td.is-u { text-decoration: underline; }

/* 선택 표시: 표 위에 겹쳐 그립니다 (머리글 아래로 지나가게 z-index를 낮게) */
.sh-sel,
.sh-cur,
.sh-copy {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  pointer-events: none;
}
.sh-sel[hidden], .sh-cur[hidden], .sh-copy[hidden] { display: none; }
.sh-sel { border: 1px solid var(--pick); background: color-mix(in srgb, var(--pick) 14%, transparent); }
.sh-cur { border: 2px solid var(--pick); margin: -1px 0 0 -1px; }
.sh-copy { border: 2px dashed var(--pick); margin: -1px 0 0 -1px; animation: sh-ants 1s steps(2) infinite; }
@keyframes sh-ants { 50% { border-color: transparent; } }
@media (prefers-reduced-motion: reduce) { .sh-copy { animation: none; } }

/* 칸 입력: 입력하지 않을 때는 보이지 않습니다 */
.sh-editor {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  margin: 0;
  padding: 4px 5px;
  overflow: hidden;
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  font: inherit;
  font-size: 0.8125rem;
  line-height: 18px;
  white-space: pre;
  resize: none;
  opacity: 0;
  pointer-events: none;
}
.sh-editor[hidden] { display: block; }
.sh-editor.is-on {
  z-index: 3;
  outline: 2px solid var(--pick);
  background: var(--cell);
  color: var(--ink);
  caret-color: auto;
  opacity: 1;
  pointer-events: auto;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
.sh-editor.is-b { font-weight: 700; }
.sh-editor.is-i { font-style: italic; }

.sh-loading { position: absolute; inset: 0; display: grid; place-content: center; gap: 0.75rem; justify-items: center; padding: 1rem; color: var(--ink-soft); text-align: center; }
.sh-loading[hidden] { display: none; }

/* 시트 탭과 요약 */
.sh-foot {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.4rem;
  padding: 0.2rem 0.35rem;
  border: 1px solid var(--rule);
  border-top: 0;
  border-radius: 0 0 10px 10px;
  background: var(--tile);
}
.sh-tabs { display: flex; gap: 0.15rem; min-width: 0; overflow-x: auto; scrollbar-width: thin; }
.sh-tab {
  flex: none;
  max-width: 12rem;
  padding: 0.3rem 0.8rem;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.sh-tab:hover { color: var(--ink); }
.sh-tab[aria-selected="true"] { border-color: var(--rule); background: var(--cell); color: var(--ink); box-shadow: inset 0 -2px 0 var(--seal); }
.sh-summary { margin-left: auto; padding-inline: 0.5rem; color: var(--ink-soft); font-size: 0.75rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* 메뉴 */
.sh-menu {
  position: fixed;
  z-index: 50;
  display: grid;
  min-width: 12rem;
  padding: 0.3rem;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
}
.sh-menu[hidden] { display: none; }
.sh-menu button {
  padding: 0.4rem 0.65rem;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.8125rem;
  text-align: left;
  cursor: pointer;
}
.sh-menu button:hover:not(:disabled), .sh-menu button:focus-visible { background: var(--tile); outline: none; }
.sh-menu button:disabled { opacity: 0.45; cursor: default; }
.sh-menu hr { width: 100%; margin: 0.25rem 0; border: 0; border-top: 1px solid var(--rule); }

/* 대화상자 */
.sh-dialog {
  width: min(32rem, calc(100% - 2rem));
  padding: 1.5rem;
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  font-size: 0.9375rem;
}
.sh-dialog--wide { width: min(52rem, calc(100% - 2rem)); }
.sh-dialog::backdrop { background: rgba(5, 12, 10, 0.6); }
.sh-dialog h2 { font-size: 1.0625rem; font-weight: 700; }
.sh-dialog__head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.5rem; }
.sh-dialog__text { margin-top: 0.6rem; color: var(--ink-soft); line-height: 1.6; }
.sh-dialog__list { margin: 0.75rem 0 0; padding-left: 1.1em; color: var(--ink-soft); line-height: 1.6; }
.sh-dialog__list strong { color: var(--ink); }
.sh-dialog__error { margin-top: 0.75rem; color: var(--seal); font-weight: 600; }
.sh-dialog__error[hidden] { display: none; }
.sh-dialog__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; margin-top: 1.5rem; }
.sh-field { display: grid; gap: 0.35rem; margin-top: 1rem; font-size: 0.8125rem; font-weight: 600; }
.sh-field input {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--tile);
  color: var(--ink);
  font: inherit;
  font-weight: 400;
}
.sh-field input:focus { border-color: var(--seal); outline: none; }

.sh-help { display: grid; grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr)); gap: 1.25rem 2rem; font-size: 0.8125rem; }
.sh-help h3 { margin-bottom: 0.4rem; font-size: 0.875rem; }
.sh-help dl { display: grid; gap: 0.3rem; }
.sh-help dl div { display: grid; grid-template-columns: 9.5rem 1fr; gap: 0.5rem; }
.sh-help dt { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.75rem; font-weight: 600; }
.sh-help dd { color: var(--ink-soft); }
.sh-help__funcs { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.75rem; line-height: 1.7; }
.sh-help__note { margin-top: 0.5rem; color: var(--ink-soft); line-height: 1.6; }

.sh-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  z-index: 60;
  max-width: calc(100% - 2rem);
  padding: 0.6rem 1rem;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.8125rem;
  opacity: 0;
  transform: translate(-50%, 0.5rem);
  transition: opacity 160ms, transform 160ms;
  pointer-events: none;
}
.sh-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 640px) {
  .sh-title { max-width: 60vw; }
  .sh-namebox { width: 4.5rem; }
  .sh-summary { display: none; }
  .sh-help dl div { grid-template-columns: 1fr; gap: 0; }
}
