/* =============================================================================
   계이득 스튜디오 /studio (WSC)
   토큰은 site.css :root 그대로 사용 — 새 색·폰트 발명 금지 (DESIGN.md)
   데스크톱: 좌측 사이드바 / 모바일(<900px): 하단 탭 4개
   ========================================================================== */

.studio-body {
  background: var(--page);
  color: var(--primary);
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.studio-body .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;
}

/* --- 게이트 (로딩/온보딩/에러) ------------------------------------------- */

.studio-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.studio-gate[hidden] {
  display: none;
}

.gate-box {
  width: min(460px, 100%);
  padding: 32px 28px;
  border: 1px solid var(--gw-border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

.gate-box h1 {
  margin: 0 0 10px;
  font-size: 1.45rem;
  line-height: 1.25;
}

.gate-box p {
  margin: 0 0 18px;
  color: var(--secondary);
}

.gate-note {
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.92rem;
}

/* --- 셸 레이아웃 ----------------------------------------------------------- */

.studio-shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.studio-shell[hidden] {
  display: none;
}

.studio-side {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px 14px;
  border-right: 1px solid var(--gw-border);
  background: var(--surface);
}

.side-brand img {
  width: 132px;
  height: 44px;
  object-fit: contain;
  object-position: left center;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.side-nav button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  color: var(--secondary);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.side-nav button:hover {
  color: var(--primary);
  background: var(--surface-2);
}

.side-nav button.active {
  color: var(--primary);
  background: var(--surface-2);
  border-color: var(--gw-border);
  box-shadow: inset 3px 0 0 var(--blue);
}

.nav-lock {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  border: 1px solid var(--gw-border);
  border-radius: 999px;
  padding: 1px 8px;
  white-space: nowrap;
}

.side-foot {
  margin-top: auto;
  padding: 0 12px;
}

.side-foot a {
  color: var(--secondary);
  font-size: 0.92rem;
  text-decoration: none;
}

.side-foot a:hover {
  color: var(--primary);
}

/* --- 메인 ------------------------------------------------------------------ */

.studio-main {
  min-width: 0;
  width: 100%;
  max-width: 1100px;
  padding: 26px clamp(16px, 3.5vw, 40px) 60px;
}

.studio-mainhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.studio-mainhead h1 {
  margin: 0;
  font-size: 1.6rem;
  line-height: 1.2;
}

.mainhead-side {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.mock-badge {
  padding: 3px 10px;
  border: 1px solid var(--yellow);
  border-radius: 999px;
  color: var(--yellow);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.conn-chip {
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--gw-border);
  background: var(--surface-2);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.conn-chip.conn-on {
  color: var(--green);
  border-color: var(--green);
}

.conn-chip.conn-off {
  color: var(--muted);
}

.studio-view[hidden] {
  display: none;
}

/* --- 패널·카드 --------------------------------------------------------------- */

.panel {
  padding: 20px 22px;
  border: 1px solid var(--gw-border);
  border-radius: var(--radius);
  background: var(--surface);
  margin: 0 0 16px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.08rem;
}

.panel-sub {
  color: var(--muted);
  font-size: 0.88rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.stat-card {
  padding: 18px 20px;
  border: 1px solid var(--gw-border);
  border-radius: var(--radius);
  background: var(--surface);
  min-width: 0;
}

.stat-label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.stat-value {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1.15;
}

.stat-value.conn-on {
  color: var(--green);
}

.stat-sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.dash-cols {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

/* --- 피드 ------------------------------------------------------------------- */

.feed-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 520px;
  overflow-y: auto;
}

.feed-list li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.feed-list li:last-child {
  border-bottom: none;
}

.feed-time {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 0.82rem;
  width: 74px;
}

.feed-main {
  min-width: 0;
  flex: 1;
}

.feed-main .feed-name {
  font-weight: 700;
}

.feed-main .feed-msg {
  display: block;
  color: var(--secondary);
  font-size: 0.9rem;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.feed-amount {
  flex-shrink: 0;
  font-weight: 800;
}

.feed-badge {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 8px;
  border: 1px solid var(--gw-border);
  white-space: nowrap;
}

.feed-badge.b-auto {
  color: var(--green);
  border-color: var(--green);
}

.feed-badge.b-manual {
  color: var(--blue-2);
  border-color: var(--blue-2);
}

.feed-badge.b-unmatched {
  color: var(--yellow);
  border-color: var(--yellow);
}

/* --- QR -------------------------------------------------------------------- */

.qr-panel {
  text-align: center;
}

.page-link-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
  min-width: 0;
}

.page-link-row a {
  color: var(--blue-2);
  text-decoration: none;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.qr-box {
  display: inline-block;
  padding: 12px;
  border-radius: var(--radius);
  background: #ffffff;
  margin-bottom: 12px;
}

.qr-box canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.qr-hint {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0 0 14px;
}

/* --- 바로가기 카드 (페이지 설정) — 모바일 퍼스트: 세로 스택, ≥900px에서 가로 배치 --- */

.shortcut-card .shortcut-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.shortcut-qr {
  padding: 10px;
  border-radius: var(--radius);
  background: #ffffff;
  flex-shrink: 0;
}

.shortcut-qr canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.shortcut-info {
  min-width: 0;
  width: 100%;
}

.shortcut-url {
  margin: 0 0 12px;
  font-weight: 700;
  color: var(--blue-2);
  overflow-wrap: anywhere;
  word-break: break-all;
}

.shortcut-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.shortcut-actions .btn {
  min-height: 44px;
}

@media (min-width: 900px) {
  .shortcut-card .shortcut-body {
    flex-direction: row;
    align-items: center;
    text-align: left;
  }

  .shortcut-actions {
    justify-content: flex-start;
  }
}

/* --- 버튼·입력 ---------------------------------------------------------------- */

.studio-body .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--gw-border);
  background: var(--surface-2);
  color: var(--primary);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
}

.studio-body .btn-primary {
  background: var(--blue);
  border-color: var(--blue);
  color: var(--on-blue);
}

.studio-body .btn-primary:hover {
  filter: brightness(1.08);
}

.studio-body .btn-ghost:hover {
  background: var(--surface-3);
}

.studio-body .btn-sm {
  padding: 5px 12px;
  font-size: 0.85rem;
}

.studio-body .btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.linklike {
  padding: 0;
  border: none;
  background: none;
  color: var(--blue-2);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.studio-body input[type="text"],
.studio-body input[type="url"],
.studio-body input[type="number"],
.studio-body select,
.studio-body textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gw-border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--primary);
  min-width: 0;
}

.studio-body input:focus-visible,
.studio-body select:focus-visible,
.studio-body textarea:focus-visible,
.studio-body button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

.studio-body input[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

/* --- 설정 폼 ------------------------------------------------------------------ */

.settings-form fieldset.panel {
  border: 1px solid var(--gw-border);
}

.settings-form legend {
  padding: 0 6px;
  font-weight: 800;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field:last-child {
  margin-bottom: 0;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--secondary);
}

.field-hint {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.84rem;
}

.field-hint-inline {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
  font-style: normal;
}

.handle-row {
  display: flex;
  align-items: center;
  gap: 0;
}

.handle-prefix {
  flex-shrink: 0;
  padding: 10px 8px 10px 12px;
  border: 1px solid var(--gw-border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  background: var(--surface-3);
  color: var(--muted);
  font-size: 0.92rem;
  white-space: nowrap;
}

.handle-row input {
  border-radius: 0 var(--radius) var(--radius) 0;
}

.preset-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.radio-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radio-row,
.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  margin-bottom: 10px;
}

.radio-row input,
.toggle-row input {
  margin-top: 4px;
  flex-shrink: 0;
}

.subfields {
  padding: 12px;
  border: 1px dashed var(--gw-border);
  border-radius: var(--radius);
  margin-bottom: 14px;
}

/* --- 팀코드 (프로그램 공유 코드) — 연결 코드와 같은 모노 표기, 44px 이상 터치 타깃 --- */

.teamcode-input {
  min-height: 44px;
  font-family: "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.06em;
}

.teamcode-result {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px dashed var(--gw-border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--secondary);
  font-size: 0.88rem;
}

.teamcode-result[hidden] {
  display: none;
}

.teamcode-result.ok {
  border-style: solid;
  border-color: var(--green);
  color: var(--green);
  font-weight: 700;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.mobile-quicklinks {
  display: none;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.mobile-quicklinks button {
  padding: 7px 14px;
  border: 1px solid var(--gw-border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--secondary);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
}

/* --- 시그니처 테이블 ------------------------------------------------------------ */

.sync-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.sync-banner p {
  margin: 0;
}

.table-scroll {
  overflow-x: auto;
  padding: 8px 10px;
}

.sig-table,
.don-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

.sig-table th,
.sig-table td,
.don-table th,
.don-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 0.92rem;
}

.sig-table th,
.don-table th {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.sig-table tbody tr:last-child td,
.don-table tbody tr:last-child td {
  border-bottom: none;
}

.sig-thumb {
  width: 56px;
  height: 42px;
  border-radius: 6px;
  border: 1px solid var(--gw-border);
  background: var(--surface-2);
  object-fit: cover;
  display: block;
}

.sig-thumb-fallback {
  width: 56px;
  height: 42px;
  border-radius: 6px;
  border: 1px solid var(--gw-border);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.sig-title-cell {
  min-width: 200px;
}

.sig-local-title {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
}

.sig-media-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border: 1px solid var(--gw-border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  vertical-align: 1px;
}

.pin-btn {
  border: 1px solid var(--gw-border);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px 12px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.pin-btn.on {
  color: var(--yellow);
  border-color: var(--yellow);
}

.sort-btns {
  display: inline-flex;
  gap: 4px;
}

.sort-btns button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--gw-border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--secondary);
  cursor: pointer;
  line-height: 1;
}

.sort-btns button[disabled] {
  opacity: 0.35;
  cursor: default;
}

/* --- 후원 내역 ------------------------------------------------------------------ */

.filter-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.chip {
  padding: 7px 16px;
  border: 1px solid var(--gw-border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--secondary);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.chip.active {
  color: var(--on-blue);
  background: var(--blue);
  border-color: var(--blue);
}

.don-msg {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.don-nick {
  color: var(--secondary);
  font-size: 0.85rem;
}

.block-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 8px;
  margin-bottom: 14px;
}

.block-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.block-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.block-list li:last-child {
  border-bottom: none;
}

.block-value {
  font-weight: 700;
}

.block-reason {
  color: var(--muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

/* --- 프로그램 연동 ---------------------------------------------------------------- */

.relay-status {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 10px;
}

.connect-code-box {
  margin: 16px 0;
  padding: 18px;
  border: 1px dashed var(--gw-border);
  border-radius: var(--radius);
  background: var(--surface-2);
  text-align: center;
}

.connect-code {
  margin: 0 0 6px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: clamp(1.7rem, 7vw, 2.6rem);
  font-weight: 800;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: var(--blue-2);
  overflow-wrap: anywhere;
}

.guide-steps {
  margin: 14px 0 0;
  padding-left: 20px;
  color: var(--secondary);
}

.guide-steps li {
  margin-bottom: 8px;
}

/* --- 잠금 카드([예약]) -------------------------------------------------------------- */

.locked-card {
  text-align: center;
  padding: 40px 24px;
}

.locked-card h2 {
  margin: 0 0 10px;
}

.locked-card p {
  margin: 0;
  color: var(--secondary);
}

.locked-badge {
  display: inline-block;
  margin: 0 0 14px;
  padding: 3px 12px;
  border: 1px solid var(--yellow);
  border-radius: 999px;
  color: var(--yellow);
  font-size: 0.8rem;
  font-weight: 800;
}

.account-list {
  margin: 0;
}

.account-list > div {
  display: flex;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.account-list > div:last-child {
  border-bottom: none;
}

.account-list dt {
  width: 90px;
  flex-shrink: 0;
  color: var(--muted);
  font-weight: 700;
}

.account-list dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* --- 상태 공통(빈/스켈레톤/토스트/모달) ------------------------------------------------ */

.empty-box {
  padding: 26px 20px;
  text-align: center;
  color: var(--secondary);
}

.empty-box p {
  margin: 0 0 10px;
}

.empty-box .guide-steps {
  text-align: left;
  display: inline-block;
}

.skeleton-rows {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
}

.skeleton-bar {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: studio-shimmer 1.4s infinite linear;
}

.skeleton-bar.w90 { width: 90%; }
.skeleton-bar.w75 { width: 75%; }
.skeleton-bar.w60 { width: 60%; }

@keyframes studio-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.toast-root {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  width: min(420px, calc(100% - 32px));
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--gw-border);
  background: var(--surface-2);
  color: var(--primary);
  box-shadow: var(--shadow);
  font-size: 0.92rem;
  text-align: center;
}

.toast.err {
  border-color: var(--danger);
  color: var(--danger);
}

.toast.okv {
  border-color: var(--green);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 55%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(440px, 100%);
  padding: 24px 22px;
  border: 1px solid var(--gw-border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

/* --- 모바일 하단 탭 -------------------------------------------------------------- */

.studio-tabbar {
  display: none;
}

@media (max-width: 899px) {
  .studio-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .studio-side {
    display: none;
  }

  .studio-main {
    padding-bottom: 92px;
  }

  .studio-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border-top: 1px solid var(--gw-border);
    background: var(--header);
    backdrop-filter: blur(18px);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
  }

  .studio-tabbar[hidden] {
    display: none;
  }

  .studio-tabbar button {
    padding: 10px 4px;
    border: none;
    border-radius: var(--radius);
    background: none;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
  }

  .studio-tabbar button.active {
    color: var(--primary);
    background: var(--surface-2);
  }

  .stat-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .dash-cols {
    grid-template-columns: minmax(0, 1fr);
  }

  .mobile-quicklinks {
    display: flex;
  }

  .preset-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .block-form {
    grid-template-columns: minmax(0, 1fr);
  }

  .don-msg {
    max-width: 180px;
  }
}
