/* RAI - GitHub Dark 테마 */
:focus-visible { outline: 2px solid var(--accent, #58a6ff); outline-offset: 2px; }
:root {
  --bg-base:    #0d1117;
  --bg-surface: #161b22;
  --bg-card:    #1c2128;
  --bg-overlay: #21262d;
  --bg-hover:   #30363d;
  --border:     #30363d;
  --border-muted: #21262d;
  --text:       #e6edf3;
  --text-muted: #8b949e;
  --text-dim:   #484f58;
  --accent:     #58a6ff;
  --accent-hover:#79c0ff;
  --color-green: #3fb950;
  --color-orange:#f0883e;
  --color-error: #f85149;
  --color-purple:#bc8cff;
  --sidebar-w:  240px;
  --topbar-h:   52px;
  --radius:     6px;
  --radius-lg:  10px;
  /* 별칭 */
  --danger:        #f85149;
  --bg-secondary:  #161b22;
  --text-secondary:#8b949e;
  --color-success: #3fb950;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg-base);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

/* 스크롤바 */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
* { scrollbar-color: var(--bg-hover) var(--bg-base); scrollbar-width: thin; }

/* ── 레이아웃 ─────────────────────────────────────── */
#sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 100;
  transition: transform .2s;
  overflow-y: auto;
}
#sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); }

#main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
  transition: margin-left .2s;
}
#main-content.sidebar-collapsed { margin-left: 0; }

#topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1.25rem;
  position: sticky; top: 0; z-index: 50;
  flex-shrink: 0;
}

#sidebar-toggle {
  background: none; border: none; color: var(--text-muted);
  font-size: 1.1rem; cursor: pointer; padding: .25rem .5rem;
  border-radius: var(--radius);
}
#sidebar-toggle:hover { background: var(--bg-hover); color: var(--text); }

#topbar-title {
  font-weight: 600; font-size: .95rem; color: var(--text);
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#topbar-actions { display: flex; gap: .5rem; align-items: center; flex-shrink: 0; }

#page-body {
  flex: 1 1 0; min-height: 0;
  padding: 1.5rem 2rem;
  width: 100%; min-width: 0;
}

/* ── 사이드바 ─────────────────────────────────────── */
#sidebar-logo {
  padding: 1rem 1rem .75rem;
  border-bottom: 1px solid var(--border-muted);
  flex-shrink: 0;
}
.logo-link {
  display: flex; align-items: center; gap: .5rem;
  text-decoration: none; color: var(--text);
  font-size: 1.1rem; font-weight: 700;
}
.logo-img { border-radius: 8px; vertical-align: middle; flex-shrink: 0; }
.logo-icon { color: var(--accent); font-size: 1.2rem; }

.nav-section { padding: .75rem .5rem .25rem; }
.nav-label {
  font-size: .7rem; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .08em;
  padding: 0 .5rem .4rem;
}
.nav-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .45rem .75rem; border-radius: var(--radius);
  color: var(--text-muted); text-decoration: none;
  font-size: .875rem; transition: background .15s, color .15s;
  white-space: nowrap; border-left: 2px solid transparent;
}
.nav-item:hover { background: var(--bg-overlay); color: var(--text); }
.nav-item.active { background: var(--bg-overlay); color: var(--accent); font-weight: 500; border-left-color: var(--accent); }
.nav-icon { font-size: 1rem; flex-shrink: 0; }
.nav-bottom { margin-top: auto; border-top: 1px solid var(--border-muted); }
.nav-bottom .nav-item { font-size: .78rem; color: var(--text-dim); }

.sidebar-search {
  display: flex; gap: .25rem; padding: .25rem .5rem;
}
.sidebar-search input {
  flex: 1; background: var(--bg-overlay); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius); padding: .35rem .6rem;
  font-size: .8rem; min-width: 0;
}
.sidebar-search input:focus { outline: none; border-color: var(--accent); }
.sidebar-search button {
  background: var(--bg-overlay); border: 1px solid var(--border);
  color: var(--text-muted); border-radius: var(--radius);
  padding: .35rem .5rem; cursor: pointer; flex-shrink: 0;
}
.sidebar-search button:hover { border-color: var(--accent); color: var(--accent); }

/* ── 버튼 ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .45rem .9rem; border-radius: var(--radius);
  font-size: .875rem; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; text-decoration: none;
  white-space: nowrap; flex-shrink: 0; transition: opacity .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--bg-overlay); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-ghost { background: none; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-overlay); color: var(--text); }
.btn-danger { background: none; color: var(--color-error); border-color: var(--color-error); }
.btn-danger:hover { background: var(--color-error); color: #fff; }
.btn-danger-fill { background: var(--color-error); color: #fff; border-color: var(--color-error); }
.btn-danger-fill:hover { background: #f85149; border-color: #f85149; }
.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }

/* ── 터치 인터랙션 전역 ───────────────────────────── */
a, button, label[for], [role="button"],
.prompt-card, .cat-chip, .nav-item, .mbn-item,
.model-radio-item, .quality-radio-item, .amount-btn,
.history-card, .upload-zone {
  touch-action: manipulation;
}
.prompt-card:active  { opacity: .82; }
.cat-chip:active     { opacity: .7; }
.history-card:active { opacity: .82; }
.mbn-item:active     { opacity: .65; }

/* ── 플래시 메시지 ────────────────────────────────── */
.flash {
  padding: .75rem 1rem; border-radius: var(--radius);
  margin-bottom: 1rem; font-size: .875rem;
}
.flash-success { background: rgba(63,185,80,.15); border: 1px solid rgba(63,185,80,.4); color: var(--color-green); }
.flash-error   { background: rgba(248,81,73,.15);  border: 1px solid rgba(248,81,73,.4);  color: var(--color-error); }

/* ── 페이지 헤더 ─────────────────────────────────── */
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: .35rem; }
.subtitle { color: var(--text-muted); }

/* ── 사이드바 오버레이 (모바일) ──────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 150;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
#sidebar-overlay.active { display: block; }

/* ── 탑바 모바일 크레딧 위젯 ─────────────────────── */
.topbar-credit {
  display: none;
  align-items: center;
  gap: .35rem;
  margin-left: auto;
  font-size: .82rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.topbar-credit-icon { font-size: .9rem; }
.topbar-charge-btn {
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  background: var(--accent); color: #000;
  border-radius: 50%; font-weight: 700; font-size: .78rem;
  text-decoration: none; flex-shrink: 0;
}

/* ── 탑바 GIS 인라인 로그인 버튼 ───────────────────── */
.topbar-gsi-btn {
  margin-left: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
/* 모바일: 아이콘 버튼만, 데스크탑: 텍스트 버튼만 */
.topbar-gsi-mobile { display: none; }
@media (max-width: 768px) {
  .topbar-gsi-desktop { display: none !important; }
  .topbar-gsi-mobile { display: flex !important; margin-left: 0; }
}

/* ── 카테고리 바 ──────────────────────────────────── */
#category-bar {
  display: flex; gap: .5rem; flex-wrap: nowrap;
  overflow-x: auto; margin-bottom: 1.5rem;
  padding-bottom: .25rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
#category-bar::-webkit-scrollbar { display: none; }
.cat-chip {
  padding: .3rem .8rem; border-radius: 20px;
  font-size: .8rem; white-space: nowrap; flex-shrink: 0;
  background: var(--bg-overlay); color: var(--text-muted);
  border: 1px solid var(--border); text-decoration: none;
  transition: all .15s;
  min-height: 36px; display: inline-flex; align-items: center;
}
.cat-chip:hover { border-color: var(--accent); color: var(--accent); }
.cat-chip.active { background: var(--accent); color: #000; border-color: var(--accent); }

/* ── 프롬프트 카드 그리드 ────────────────────────── */
#prompt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.prompt-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); text-decoration: none; color: var(--text);
  display: flex; flex-direction: column;
  transition: border-color .15s, box-shadow .15s;
  overflow: hidden;
}
.prompt-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.prompt-card.featured { border-color: var(--color-purple); }
.prompt-card.featured:hover { box-shadow: 0 0 0 1px var(--color-purple); }

.card-thumb {
  height: 160px; overflow: hidden;
  background: var(--bg-overlay);
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.placeholder-thumb {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--bg-overlay), var(--bg-hover));
}
.thumb-icon { font-size: 3rem; opacity: .4; }

.card-body { padding: 1rem; flex: 1; }
.card-title { font-weight: 600; margin: .5rem 0 .4rem; font-size: .95rem; }
.card-desc { color: var(--text-muted); font-size: .82rem; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .5rem; }

.card-footer {
  padding: .75rem 1rem; border-top: 1px solid var(--border-muted);
  display: flex; justify-content: space-between; align-items: center;
}
.card-model { font-size: .75rem; color: var(--text-dim); font-family: monospace; }
.card-btn { font-size: .8rem; color: var(--accent); font-weight: 500; }

/* ── 배지 ─────────────────────────────────────────── */
.badge {
  display: inline-block; padding: .15rem .5rem;
  border-radius: 20px; font-size: .72rem; font-weight: 600;
  margin-right: .3rem;
}
.badge-category { background: var(--bg-hover); color: var(--text-muted); }
.badge-featured { background: rgba(188,140,255,.15); color: var(--color-purple); border: 1px solid rgba(188,140,255,.3); }
.badge-model { background: rgba(88,166,255,.1); color: var(--accent); border: 1px solid rgba(88,166,255,.25); }

.tag {
  display: inline-block; font-size: .72rem; color: var(--text-dim);
  background: var(--bg-overlay); padding: .1rem .4rem;
  border-radius: 3px;
}

/* ── 빈 상태 ──────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 4rem 1rem; color: var(--text-muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h3 { font-size: 1.1rem; margin-bottom: .5rem; }

/* ── 프롬프트 상세 (단일 컬럼) ──────────────────── */
.prompt-page {
  max-width: 600px;
  margin: 0 auto;
}
.prompt-desc-compact {
  font-size: .875rem; color: var(--text-dim);
  margin-bottom: .875rem; line-height: 1.55;
}
.prompt-header { margin-bottom: 1.25rem; }
.prompt-header h1 {
  font-size: 1.5rem; font-weight: 700;
  margin: .25rem 0 .5rem; line-height: 1.3;
}
#prompt-desc {
  color: var(--text-muted); font-size: .9rem;
  line-height: 1.6; margin: 0;
}
.prompt-meta { margin-bottom: .6rem; }

.info-box {
  background: var(--bg-overlay); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem; margin: 1rem 0;
}
.info-row {
  display: flex; justify-content: space-between;
  padding: .3rem 0; font-size: .875rem;
}
.info-row span { color: var(--text-muted); }

.prompt-preview {
  margin-top: 1rem;
  border: 1px solid var(--border); border-radius: var(--radius);
}
.prompt-preview summary {
  padding: .6rem .75rem; cursor: pointer; color: var(--text-muted);
  font-size: .85rem; user-select: none;
}
.prompt-template {
  padding: .75rem; font-size: .78rem; color: var(--text-muted);
  white-space: pre-wrap; word-break: break-word;
  border-top: 1px solid var(--border); max-height: 300px; overflow-y: auto;
  background: var(--bg-base);
}

/* ── 생성 패널 ───────────────────────────────────── */
.panel-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.5rem;
  position: sticky; top: calc(var(--topbar-h) + 1rem);
}
.panel-card h2 { font-size: 1.1rem; margin-bottom: .35rem; }
.panel-hint { color: var(--text-muted); font-size: .83rem; margin-bottom: 1.25rem; }

/* ── 생성 카드 (prompt 단일 컬럼, sticky 없음) ── */
.generate-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.5rem;
}

/* ── 폼 ───────────────────────────────────────────── */
.form-group { margin-bottom: .875rem; }
.form-label {
  display: block; font-weight: 500; margin-bottom: .4rem; font-size: .875rem;
}
.required { color: var(--color-error); margin-left: .2rem; }
.label-hint { font-weight: 400; color: var(--text-muted); font-size: .78rem; margin-left: .5rem; }
.field-hint { color: var(--text-muted); font-size: .78rem; margin-top: .35rem; line-height: 1.4; }
.field-error-msg { color: #f85149; font-size: .82rem; margin-top: .35rem; font-weight: 500; }
/* 로그인 유도 말풍선 툴팁 */
.login-tooltip {
  position: fixed;
  background: var(--bg-surface, #161b22);
  border: 1px solid rgba(88,166,255,.5);
  border-radius: 10px;
  padding: .7rem 1rem;
  font-size: .88rem;
  color: var(--text, #e6edf3);
  z-index: 9999;
  max-width: 240px;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,.5);
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.login-tooltip::before,
.login-tooltip::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: var(--arrow-left, 50%);
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
}
.login-tooltip::before {
  border-top: 8px solid rgba(88,166,255,.5);
  bottom: -9px;
}
.login-tooltip::after {
  border-top: 8px solid var(--bg-surface, #161b22);
  bottom: -8px;
}
.login-tooltip-close {
  position: absolute; top: 3px; right: 6px;
  background: none; border: none;
  color: var(--text-dim); cursor: pointer;
  font-size: .8rem; line-height: 1; padding: 2px 4px;
}
.login-tooltip-link { color: var(--accent, #58a6ff); font-weight: 600; text-decoration: none; display: inline-block; margin-top: .3rem; }
.login-tooltip-link:hover { text-decoration: underline; }

/* 모델 호환성 체크박스 (관리자) */
.model-compat-section { margin-top: 1.25rem; }
.model-compat-list { display: flex; flex-direction: column; gap: .4rem; margin-top: .5rem; }
.model-compat-item { display: flex; align-items: center; gap: .55rem; padding: .4rem .6rem; border-radius: 6px; background: var(--bg-overlay); border: 1px solid var(--border); font-size: .85rem; cursor: pointer; }
.model-compat-item:hover { border-color: var(--accent); }
.model-compat-item input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); flex-shrink: 0; cursor: pointer; }
.model-compat-badge { margin-left: auto; font-size: .75rem; padding: .1rem .4rem; border-radius: 4px; flex-shrink: 0; }
.badge-ok  { background: rgba(63,185,80,.15); color: #3fb950; }
.badge-warn{ background: rgba(227,179,65,.15); color: #e3b341; }
.badge-no  { background: rgba(248,81,73,.12);  color: #f85149; }

/* 관리자 메타 바 (프롬프트 페이지) */
.admin-meta-bar { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem .75rem; padding: .5rem .75rem; margin-bottom: .75rem; background: rgba(88,166,255,.07); border: 1px solid rgba(88,166,255,.2); border-radius: 8px; font-size: .8rem; color: var(--text-muted); }
.admin-meta-badge { font-weight: 600; color: var(--accent); }
.admin-meta-item code { font-size: .78rem; background: var(--bg-overlay); padding: .1rem .3rem; border-radius: 4px; }
.admin-meta-status.status-on  { color: #3fb950; font-weight: 600; }
.admin-meta-status.status-off { color: #f85149; font-weight: 600; }

.form-control {
  width: 100%; background: var(--bg-overlay); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius); padding: .6rem .85rem;
  font-size: 1rem; font-family: inherit; transition: border-color .15s;
  min-height: 46px;
}
.form-control:focus { outline: none; border-color: var(--accent); }
textarea.form-control { resize: vertical; min-height: 100px; }
select.form-control { cursor: pointer; }

/* ── 생성 버튼 ──────────────────────────────────── */
#btn-generate {
  min-height: 54px; font-size: 1.05rem; font-weight: 700;
  letter-spacing: .01em;
}
.code-input { font-family: 'SFMono-Regular', Consolas, monospace; font-size: .8rem; }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 1rem; }

.form-checkboxes { display: flex; gap: 1.5rem; margin: 1rem 0; }
.checkbox-label {
  display: flex; align-items: center; gap: .5rem; cursor: pointer;
  font-size: .875rem;
}
.checkbox-label input { accent-color: var(--accent); }

.form-actions { display: flex; gap: .75rem; margin-top: 1.5rem; }
.input-with-btn { display: flex; gap: .5rem; }
.input-with-btn .form-control { flex: 1; min-width: 0; }

/* ── 업로드 존 ───────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius-lg);
  padding: 1.5rem; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s; position: relative;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent); background: rgba(88,166,255,.05);
}
.upload-placeholder { display: flex; flex-direction: column; gap: .35rem; color: var(--text-muted); }
.upload-icon { font-size: 1.8rem; }
.upload-hint { font-size: .75rem; color: var(--text-dim); }
.upload-preview {
  max-width: 100%; max-height: 220px; border-radius: var(--radius);
  object-fit: contain;
}

.notice-box {
  background: var(--bg-overlay); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem 1rem;
  color: var(--text-muted); font-size: .85rem; margin-bottom: 1rem;
}

/* ── 생성 오버레이 ───────────────────────────────── */
#generating-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 999;
}
#generating-box {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 2.5rem;
  text-align: center; max-width: 380px; width: 90%;
}
#generating-box h3 { margin: 1rem 0 .5rem; font-size: 1.1rem; }
#gen-status-sub { color: var(--text-muted); font-size: .85rem; }

.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid var(--bg-overlay);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress-dots { display: flex; justify-content: center; gap: .5rem; margin-top: 1.25rem; }
.progress-dots span {
  width: 8px; height: 8px; border-radius: 50%; background: var(--border);
  animation: pulse 1.4s ease-in-out infinite;
}
.progress-dots span:nth-child(2) { animation-delay: .2s; }
.progress-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes pulse { 0%,80%,100%{opacity:.3;} 40%{opacity:1;} }

/* ── 결과 페이지 ─────────────────────────────────── */
.result-page { max-width: 900px; margin: 0 auto; }
.result-header { text-align: center; margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.result-success-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.result-header h1 { font-size: 1.5rem; margin-bottom: .35rem; }
.result-meta { color: var(--text-muted); font-size: .85rem; }

#result-files-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 1.5rem; margin-bottom: 2rem;
}
.result-file-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
}
.result-image-wrap { background: var(--bg-overlay); }
.result-image {
  width: 100%; display: block; cursor: zoom-in;
  transition: opacity .15s;
}
.result-image:hover { opacity: .9; }
.result-text-wrap { padding: 1rem; }
.result-text {
  font-family: inherit; white-space: pre-wrap; word-break: break-word;
  max-height: 300px; overflow-y: auto; font-size: .85rem;
  color: var(--text-muted); line-height: 1.7;
}
.result-file-actions {
  display: flex; gap: .5rem; flex-wrap: nowrap;
  padding: .75rem 1rem; border-top: 1px solid var(--border);
}
.result-actions-bar {
  display: flex; gap: .75rem; justify-content: center; margin-top: 1rem;
}
.result-pending { text-align: center; padding: 3rem; }
.result-pending .spinner { margin: 0 auto 1rem; }
.result-error { text-align: center; padding: 3rem; }
.error-icon { font-size: 2.5rem; margin-bottom: 1rem; }
.result-error h2 { margin-bottom: .5rem; }
.error-detail {
  color: var(--color-error); font-size: .85rem; margin: 1rem auto;
  max-width: 480px; background: rgba(248,81,73,.08);
  border: 1px solid rgba(248,81,73,.25); border-radius: var(--radius);
  padding: .75rem; word-break: break-all;
}
.error-actions { display: flex; gap: .75rem; justify-content: center; margin-top: 1.5rem; }

#lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.9);
  display: flex; align-items: center; justify-content: center; z-index: 9999;
  cursor: zoom-out;
}
#lightbox-inner { position: relative; max-width: 95vw; max-height: 95vh; }
#lightbox-img { max-width: 95vw; max-height: 95vh; border-radius: var(--radius); display: block; }
#lightbox-close {
  position: absolute; top: -2rem; right: 0;
  background: none; border: none; color: var(--text-muted);
  font-size: 1.2rem; cursor: pointer;
}

/* ── 에러 배너 ───────────────────────────────────── */
.error-banner {
  background: rgba(248,81,73,.12); border: 1px solid rgba(248,81,73,.35);
  color: var(--color-error); border-radius: var(--radius);
  padding: .75rem 1rem; margin-bottom: 1rem; font-size: .875rem;
}

/* ── 에러 페이지 (404 / 500) ─────────────────────── */
.error-page {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center;
  padding: 4rem 1.5rem; min-height: 60vh;
}
.error-code {
  font-size: 6rem; font-weight: 800; line-height: 1;
  color: var(--accent); opacity: .35; letter-spacing: -.05em;
  margin-bottom: .25rem;
}
.error-page .error-icon {
  font-size: 3rem; margin-bottom: 1rem;
}
.error-title {
  font-size: 1.5rem; font-weight: 700; margin-bottom: .75rem;
}
.error-desc {
  color: var(--text-muted); font-size: .95rem; line-height: 1.7;
  max-width: 480px; margin-bottom: 2rem;
}

/* ── 관리자 ──────────────────────────────────────── */
.stats-row {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr));
  gap: 1rem; margin-bottom: 2rem;
}
.stat-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-top: 2px solid var(--accent);
  border-radius: var(--radius-lg); padding: 1.25rem; text-align: center;
  transition: border-color .15s, box-shadow .15s;
}
.stat-card:hover { box-shadow: 0 2px 12px rgba(88,166,255,.1); }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1.2; }
.stat-label { color: var(--text-muted); font-size: .8rem; margin-top: .25rem; }

.section-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: .75rem;
}
.section-header h2 { font-size: 1rem; }

.health-banner {
  display: flex; align-items: center; gap: 1rem;
  margin-bottom: 1rem; padding: .6rem 1rem;
  background: var(--bg-overlay); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .85rem;
}

.table-wrap { overflow-x: auto; margin-bottom: 1.5rem; }
.data-table {
  width: 100%; border-collapse: collapse;
  font-size: .875rem;
}
.data-table th {
  background: var(--bg-overlay); color: var(--text-muted);
  font-weight: 500; text-align: left;
  padding: .6rem .9rem; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: .6rem .9rem; border-bottom: 1px solid var(--border-muted);
}
.data-table tbody tr:nth-child(even) { background: rgba(255,255,255,.02); }
.data-table tbody tr:hover { background: var(--bg-overlay); }
.table-empty { text-align: center; color: var(--text-dim); padding: 2rem; }
.action-btns { display: flex; gap: .4rem; flex-wrap: nowrap; }

.status-badge {
  display: inline-block; padding: .15rem .55rem;
  border-radius: 20px; font-size: .72rem; font-weight: 600;
}
.status-pending  { background:rgba(240,136,62,.15); color:var(--color-orange); }
.status-processing{ background:rgba(88,166,255,.15); color:var(--accent); }
.status-done     { background:rgba(63,185,80,.15); color:var(--color-green); }
.status-error    { background:rgba(248,81,73,.15); color:var(--color-error); }

.toggle-btn {
  padding: .25rem .65rem; border-radius: 20px; font-size: .75rem;
  border: 1px solid var(--border); cursor: pointer;
  background: var(--bg-overlay); color: var(--text-muted);
  transition: all .15s;
}
.toggle-btn.active { background: rgba(63,185,80,.15); color: var(--color-green); border-color: rgba(63,185,80,.3); }

.admin-form { max-width: 900px; margin: 0 auto; }
.admin-nav-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 1rem; margin-top: 1.5rem;
}
.admin-nav-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.25rem;
  text-align: center; text-decoration: none; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  transition: border-color .15s, background .15s;
}
.admin-nav-card:hover { border-color: var(--accent); background: var(--bg-overlay); color: var(--accent); }
.nav-card-icon { font-size: 1.5rem; }

/* ── 설정 페이지 ─────────────────────────────────── */
.settings-section {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-top: 2px solid var(--accent);
  border-radius: var(--radius-lg); padding: 1.5rem; margin-bottom: 1.25rem;
}
.settings-section h2 {
  font-size: 1rem; margin-bottom: 1rem;
  padding-bottom: .625rem; border-bottom: 1px solid var(--border);
  color: var(--text);
}
.test-result { margin-top: .5rem; font-size: .875rem; }
.test-ok { color: var(--color-green); }
.test-fail { color: var(--color-error); }

/* ── 페이지네이션 ────────────────────────────────── */
.pagination { display: flex; gap: .4rem; margin-top: 1rem; }
.page-btn {
  display: inline-block; padding: .35rem .65rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text-muted); text-decoration: none; font-size: .8rem;
  background: var(--bg-overlay);
}
.page-btn:hover { border-color: var(--accent); color: var(--accent); }
.page-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }

/* ── 로그인 페이지 ───────────────────────────────── */
body.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg-base);
}
.login-container { width: 100%; max-width: 360px; padding: 1rem; }
.login-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-top: 2px solid var(--accent);
  border-radius: var(--radius-lg); padding: 2rem;
  box-shadow: 0 4px 20px rgba(0,0,0,.3);
}
.login-logo { font-size: 1.5rem; font-weight: 700; text-align: center; margin-bottom: 1rem; }
.login-card h2 { text-align: center; margin-bottom: 1.5rem; font-size: 1rem; color: var(--text-muted); }
.link-muted  { color: var(--text-muted); text-decoration: none; font-size: .85rem; }
.link-muted:hover  { color: var(--accent); }
.link-accent { color: var(--accent); }
.link-accent:hover { text-decoration: underline; }

/* ── 태그 행 ─────────────────────────────────────── */
.tags-row { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }

/* ── 텍스트 유틸 ─────────────────────────────────── */
.text-error { color: var(--color-error); font-size: .8rem; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-1 { margin-top: 1rem; }
.clr-accent { color: var(--accent); }
.clr-error  { color: var(--color-error); }
.clr-green  { color: var(--color-green); }
.clr-orange { color: var(--color-orange); }
.clr-muted  { color: var(--text-muted); }

/* ── 모달 공통 ───────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6); z-index: 9999;
  align-items: center; justify-content: center;
}
.modal-box {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 2rem; max-width: 420px; width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}
.modal-body-text { font-size: .9rem; line-height: 1.6; color: var(--text-muted); margin-bottom: 1.25rem; }
.modal-actions    { display: flex; gap: .75rem; justify-content: flex-end; }
.withdraw-credit-warning {
  background: rgba(224,82,82,.1); border: 1px solid rgba(224,82,82,.3);
  border-radius: 8px; padding: .8rem 1rem; margin-bottom: 1.2rem;
  font-size: .875rem; color: var(--color-error);
}

/* ── 테이블 유틸 ─────────────────────────────────── */
.td-date { font-size: .78rem; white-space: nowrap; }
.td-sm   { font-size: .78rem; color: var(--text-muted); }
.td-link { color: var(--text); text-decoration: none; }
.td-right { text-align: right; }

/* ── 차트 영역 ───────────────────────────────────── */
.chart-area { height: 220px; }
code { font-family: 'SFMono-Regular', Consolas, monospace; font-size: .82em;
       background: var(--bg-overlay); padding: .1em .35em; border-radius: 3px; }

/* ── 모델 라디오 선택 ────────────────────────────── */
.model-group-label {
  font-size: .75rem; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .06em;
  margin: .75rem 0 .35rem;
}
.model-group-label:first-child { margin-top: 0; }

.model-radio-row {
  display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .2rem;
}

.model-radio-item {
  display: flex; flex-direction: row; align-items: center; gap: .3rem;
  padding: .3rem .55rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-overlay);
  cursor: pointer; transition: border-color .15s, background .15s;
  min-width: 0;
}
/* 관리자 — 가격행 있으므로 column 레이아웃 */
.model-radio-item.has-price { flex-direction: column; gap: .08rem; padding: .35rem .6rem; }
.model-radio-item input[type="radio"] { display: none; }
.model-radio-item:hover { border-color: var(--accent); background: var(--bg-hover); }
.model-radio-item.selected {
  border-color: var(--accent);
  background: rgba(88,166,255,.1);
}
.mri-id {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: .75rem; color: var(--text); white-space: nowrap;
}
.mri-name { font-size: .68rem; color: var(--text-muted); white-space: nowrap; }
.mri-price {
  font-size: .67rem; color: var(--color-green);
  white-space: nowrap; margin-top: .02rem;
}
.mri-price small { color: var(--text-dim); font-size: .63rem; }

/* ── 사이드바 사용자 정보 ──────────────────────────── */
.nav-user-info {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .75rem; margin-bottom: .25rem;
}
.nav-user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid var(--border); object-fit: cover; flex-shrink: 0;
}
.nav-user-name {
  font-size: .8rem; color: var(--text); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
/* .nav-credit-balance → line 1070 에서 정의 */
.credit-icon { font-size: .85rem; }

/* ── 사이드바 하단 계정 버튼 & 팝업 ──────────────────── */
#sidebar-account {
  position: relative;
  padding: .45rem .6rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#sac-btn {
  display: flex; align-items: center; gap: .6rem;
  width: 100%; padding: .45rem .5rem;
  background: transparent; border: none; border-radius: 8px;
  cursor: pointer; color: var(--text); text-align: left;
  transition: background .15s;
}
#sac-btn:hover { background: var(--bg-hover); }
.sac-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0;
  border: 1px solid var(--border);
}
.sac-avatar-fb {
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff;
  font-size: .85rem; font-weight: 700;
}
.sac-btn-text { flex: 1; min-width: 0; }
.sac-btn-name {
  display: block; font-size: .82rem; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
}
.sac-btn-sub {
  display: block; font-size: .7rem; color: var(--text-muted); margin-top: .05rem;
}
.sac-ellipsis { flex-shrink: 0; color: var(--text-muted); opacity: .7; }

/* 팝업 */
#sac-popup {
  position: absolute;
  bottom: calc(100% + 6px); left: .6rem; right: .6rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 -4px 16px rgba(0,0,0,.25), 0 8px 24px rgba(0,0,0,.35);
  overflow: hidden; z-index: 300;
}
.sac-popup-head {
  display: flex; align-items: center; gap: .65rem;
  padding: .8rem .85rem;
}
.sac-popup-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0;
  border: 1px solid var(--border);
}
.sac-popup-info { flex: 1; min-width: 0; }
.sac-popup-name {
  font-size: .85rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
}
.sac-popup-credits { font-size: .73rem; color: var(--text-muted); margin-top: .08rem; }
.sac-charge-pill {
  flex-shrink: 0; font-size: .7rem; font-weight: 700;
  padding: .18rem .55rem; border-radius: 20px;
  background: var(--accent); color: #fff; text-decoration: none;
  letter-spacing: .02em; transition: opacity .12s;
}
.sac-charge-pill:hover { opacity: .82; }
.sac-sep { height: 1px; background: var(--border); margin: .2rem 0; }
.sac-item {
  display: flex; align-items: center; gap: .55rem;
  padding: .48rem .85rem; font-size: .83rem;
  color: var(--text); text-decoration: none; transition: background .12s;
}
.sac-item:hover { background: var(--bg-hover); }
.sac-item-active { color: var(--accent); }
.sac-item-icon { font-size: .88rem; width: 1.1rem; text-align: center; flex-shrink: 0; }
.sac-logout { color: #f85149; }
.sac-logout:hover { background: rgba(248,81,73,.08); }

/* ── 테마 선택 칩 ──────────────────────────────────────── */
.sac-theme-row {
  display: flex; align-items: center; gap: .5rem;
  padding: .35rem .6rem;
}
.sidebar-theme-picker, .theme-chips {
  display: flex; flex-wrap: nowrap; gap: .35rem;
}
.sidebar-theme-picker { padding: 0 .5rem; }
.theme-chip {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; border: 2px solid var(--border-muted);
  background: var(--bg-overlay); cursor: pointer;
  font-size: .8rem; padding: 0;
  flex-shrink: 0;
}
.theme-chip:hover { border-color: var(--accent); }
.theme-chip.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

/* ── 크레딧 비용 (프롬프트 페이지) ───────────────────── */
.credit-cost-wrap {
  display: flex; align-items: center; gap: .4rem;
  padding: .5rem .75rem;
  background: rgba(240,136,62,.08);
  border: 1px solid rgba(240,136,62,.25);
  border-radius: var(--radius);
  font-size: .85rem; color: var(--color-orange);
  margin-bottom: .5rem;
}
.credit-cost-wrap .credit-icon { font-size: 1rem; }
.credit-balance-hint { color: var(--text-muted); font-size: .8rem; }
.credit-balance-hint a { color: var(--accent); }
.credit-balance-hint strong { color: var(--color-orange); }
.admin-price-hint {
  font-size: .78rem; color: var(--accent); opacity: .85;
  font-variant-numeric: tabular-nums;
}
.quality-radio-row {
  display: flex; flex-wrap: nowrap; gap: .4rem;
}
.quality-radio-item {
  display: flex; align-items: center; gap: .3rem;
  padding: .35rem .7rem; border-radius: var(--radius);
  border: 1px solid var(--border); cursor: pointer;
  font-size: .85rem; white-space: nowrap;
  background: var(--bg-card);
}
.quality-radio-item input[type="radio"] { display: none; }
.quality-radio-item:hover { border-color: var(--accent); background: var(--bg-hover); }
.quality-radio-item.selected {
  border-color: var(--accent);
  background: rgba(88,166,255,.1);
  color: var(--accent);
  font-weight: 500;
}
.nav-item-google {
  background: rgba(88,166,255,.08);
  border: 1px solid rgba(88,166,255,.2);
}
.nav-item-google:hover { background: rgba(88,166,255,.15); color: var(--accent); }

/* ── 마이페이지 ──────────────────────────────────── */
.mypage-count {
  font-size: .82rem; color: var(--text-dim);
  margin-bottom: .75rem;
}
.mypage-header {
  display: flex; align-items: center; gap: 1rem;
  margin-bottom: 1.5rem;
}
.user-avatar {
  width: 56px; height: 56px; border-radius: 50%;
  border: 2px solid var(--border); object-fit: cover;
}
.mypage-header h2 { font-size: 1.2rem; margin-bottom: .2rem; }

#history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.history-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
  display: flex; flex-direction: column;
}
.history-card:hover { border-color: var(--accent); box-shadow: 0 2px 12px rgba(88,166,255,.08); }

.history-thumb {
  height: 160px; background: var(--bg-overlay);
  overflow: hidden; position: relative; cursor: pointer;
}
.history-thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.thumb-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .15s;
  font-size: .875rem; color: #fff;
}
.history-thumb:hover .thumb-overlay { opacity: 1; }

.history-thumb-text,
.history-thumb-error,
.history-thumb-pending {
  display: flex; align-items: center; justify-content: center;
  font-size: 2.5rem; cursor: default;
}
.history-thumb-error { background: rgba(248,81,73,.08); }
.history-thumb-pending { background: var(--bg-overlay); }

.spinner-sm {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--bg-hover);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}

.history-card-body {
  padding: .75rem; flex: 1;
}
.history-title {
  font-weight: 500; font-size: .875rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-bottom: .3rem;
}
.history-meta { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

.history-card-actions {
  display: flex; gap: .4rem; padding: .6rem .75rem;
  border-top: 1px solid var(--border-muted);
  flex-wrap: nowrap;
}

/* ── 설정 페이지 추가 스타일 ─────────────────────── */
.settings-desc {
  color: var(--text-muted); font-size: .85rem;
  margin-bottom: 1rem; line-height: 1.6;
}
.settings-desc a { color: var(--accent); text-decoration: none; }
.settings-desc a:hover { text-decoration: underline; }
.settings-desc code { font-size: .82em; }

.model-chips {
  display: flex; gap: .5rem; flex-wrap: wrap;
}
.model-chip {
  background: var(--bg-overlay); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .35rem .65rem;
  display: flex; flex-direction: column; gap: .1rem;
}
.model-chip-id {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: .78rem; color: var(--accent);
}
.model-chip-name { font-size: .75rem; color: var(--text-muted); }

.model-list {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; max-height: 260px; overflow-y: auto;
}
.model-list-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .45rem .75rem; font-size: .83rem;
  border-bottom: 1px solid var(--border-muted);
}
.model-list-item:last-child { border-bottom: none; }
.model-list-item:nth-child(even) { background: rgba(255,255,255,.02); }
.model-id {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: .78rem; color: var(--text); flex: 1;
}

/* ===== NAV CREDIT & CHARGE ===== */
.nav-credit-balance {
  display: flex; align-items: center; gap: .4rem;
  padding: .45rem .75rem; font-size: .85rem;
  color: var(--color-orange); font-weight: 600;
  background: rgba(240,136,62,.08); border-radius: var(--radius);
  margin-bottom: .25rem;
}
.credit-icon { font-size: 1rem; }
#nav-credit-amount { flex: 1; }
.nav-charge-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 1.1rem; font-weight: 700; line-height: 1;
  text-decoration: none; flex-shrink: 0;
  transition: background .15s;
}
.nav-charge-btn:hover { background: var(--accent-hover); }

/* ===== CHARGE PAGE ===== */
.charge-layout {
  max-width: 600px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 1rem;
}
.charge-balance-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-left: 3px solid var(--color-orange, #e3b341);
  border-radius: var(--radius-lg); padding: 1.25rem 1.5rem;
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
}
.cb-label { font-size: .82rem; color: var(--text-muted); flex-basis: 100%; }
.cb-amount {
  font-size: 1.8rem; font-weight: 700; color: var(--color-orange); line-height: 1;
}
.cb-unit { font-size: .9rem; color: var(--text-muted); align-self: flex-end; padding-bottom: .2rem; }
.charge-section {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.25rem 1.5rem;
}
.charge-section-title {
  font-size: .85rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .05em; margin-bottom: .5rem;
}
.charge-section-desc { font-size: .8rem; color: var(--text-muted); margin-bottom: 1rem; }
.amount-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem;
}
.amount-btn {
  background: var(--bg-overlay); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: .75rem .5rem;
  cursor: pointer; text-align: center; transition: border-color .15s, background .15s;
  display: flex; flex-direction: column; align-items: center; gap: .2rem;
  -webkit-tap-highlight-color: transparent; min-height: 64px;
}
.amount-btn:hover { border-color: var(--accent); background: rgba(88,166,255,.06); }
.amount-btn.selected {
  border-color: var(--accent); background: rgba(88,166,255,.12);
}
.ab-credits {
  font-size: 1.05rem; font-weight: 700; color: var(--text);
}
.ab-unit { font-size: .72rem; color: var(--text-muted); }
.ab-price { font-size: .8rem; color: var(--accent); margin-top: .1rem; }
#charge-widget-area {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.25rem 1.5rem;
  display: none;
}
#charge-widget-area.visible { display: block; }
.charge-summary {
  display: flex; flex-direction: column; gap: .4rem;
  padding: .75rem 1rem; background: var(--bg-overlay);
  border-radius: var(--radius); margin-bottom: 1rem;
  font-size: .88rem;
}
.cs-row {
  display: flex; align-items: center; gap: .35rem;
  color: var(--text-muted);
}
.cs-row strong { color: var(--accent); font-weight: 700; margin: 0 .1rem; }
.charge-info { font-size: .8rem; color: var(--text-muted); line-height: 1.7; }
.charge-info h3 { font-size: .82rem; font-weight: 600; color: var(--text); margin-bottom: .5rem; }
.charge-info ul { padding-left: 1.1rem; }
.charge-info li { margin-bottom: .2rem; }
#toss-payment-widget, #toss-agreement-widget { min-height: 80px; }
#btn-pay {
  width: 100%; margin-top: 1rem; padding: .85rem;
  font-size: 1rem; font-weight: 600;
}

/* ===== CHARGE RESULT PAGE ===== */
.result-center {
  max-width: 480px; margin: 0 auto; text-align: center;
  padding: 1.5rem 1rem; min-height: 50vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.result-icon { font-size: 2.5rem; margin-bottom: .5rem; }
.result-title { font-size: 1.5rem; font-weight: 700; margin-bottom: .5rem; }
.result-desc { color: var(--text-muted); font-size: .9rem; margin-bottom: 1.25rem; }
.result-amount-badge {
  display: inline-block; background: rgba(88,166,255,.12);
  border: 1px solid var(--accent); border-radius: var(--radius);
  padding: .5rem 1.25rem; font-size: 1.1rem; font-weight: 700;
  color: var(--accent); margin-bottom: 1.5rem;
}
.result-expires { color: var(--text-muted); font-size: .82rem; margin-bottom: 1.25rem; }
.result-expires strong { color: var(--color-yellow, #e3b341); }
.result-actions { display: flex; gap: .75rem; justify-content: center; flex-wrap: wrap; }

/* ===== ADMIN STATS ===== */
.stats-filter-bar {
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin-bottom: 1.25rem;
}
.stats-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: .75rem; margin-bottom: 1.25rem;
}
.kpi-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-lg); padding: 1rem;
  display: flex; flex-direction: column; align-items: flex-start; gap: .3rem;
  transition: box-shadow .15s;
}
.kpi-card:hover { box-shadow: 0 2px 10px rgba(88,166,255,.08); }
.kpi-icon { font-size: 1.3rem; }
.kpi-value {
  font-size: 1.4rem; font-weight: 700; color: var(--text);
  line-height: 1.2; word-break: break-all;
}
.kpi-label { font-size: .75rem; color: var(--text-muted); }
.kpi-green .kpi-value { color: var(--color-green); }
.kpi-green { border-left-color: var(--color-green); }
.kpi-red .kpi-value { color: var(--color-error); }
.kpi-red { border-left-color: var(--color-error); }
.kpi-orange .kpi-value { color: var(--color-orange); }
.kpi-orange { border-left-color: var(--color-orange); }
.kpi-purple .kpi-value { color: #bc8cff; }
.kpi-purple { border-left-color: #bc8cff; }
.stats-chart-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: .75rem;
  margin-bottom: 1.25rem;
}
.stats-chart-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1rem;
}
.chart-title {
  font-size: .85rem; font-weight: 600; color: var(--text-muted);
  margin-bottom: .75rem;
}
.stats-section {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}
.stats-section .chart-title { margin-bottom: .75rem; }
.stats-table-wrap { overflow-x: auto; }

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 768px) {
  /* ── 기본 폰트 크기 + 앱 셸 레이아웃 (네이티브 앱 UX) ── */
  html, body { font-size: 16px; overflow: hidden; overscroll-behavior: none; }
  #main-content { height: 100dvh; min-height: unset; overflow: hidden; }
  #page-body { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

  /* ── 사이드바: 슬라이드 오버레이 */
  #sidebar {
    position: fixed; left: -85vw; top: 0; height: 100%;
    z-index: 200; transition: left .25s ease; width: 85vw; max-width: 300px;
  }
  #sidebar.open { left: 0; }
  #main-content { margin-left: 0 !important; }
  #sidebar-toggle { display: flex !important; }

  /* ── 사이드바 내부: 더 큰 텍스트/터치 타겟 */
  .nav-label { font-size: .8rem; padding: .6rem 1rem .2rem; }
  .nav-item {
    font-size: 1rem; padding: .8rem 1rem;
    min-height: 52px; display: flex; align-items: center;
  }
  .nav-user-name { font-size: .95rem; }
  #nav-credit-amount { font-size: .95rem; }
  .nav-credit-balance { font-size: .95rem; padding: .5rem 1rem; }
  .nav-charge-btn { width: 28px; height: 28px; font-size: .9rem; }
  .nav-user-avatar { width: 34px; height: 34px; }
  .logo-link { font-size: 1.25rem; }

  /* ── 탑바: safe area + 크기 */
  #topbar {
    height: calc(48px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) .625rem 0;
    gap: .4rem;
  }
  .topbar-icon-btn { display: flex; }
  #topbar-title { font-size: 1rem; }
  #sidebar-toggle { font-size: 1.3rem; padding: .4rem .6rem; }
  .topbar-credit {
    display: flex; gap: .35rem; font-size: .9rem;
  }
  .topbar-credit-icon { font-size: 1rem; }
  #topbar-credit-amount { font-size: .9rem; }
  .topbar-charge-btn { width: 26px; height: 26px; font-size: .85rem; }

  /* ── 페이지 본문 패딩 (하단 탭바 + safe area 여백 확보) */
  #page-body { padding: .625rem .625rem calc(52px + env(safe-area-inset-bottom, 0px) + .5rem); }

  /* ── 카드 그리드: 모바일 2열 (App Store 스타일) */
  #prompt-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: .5rem;
  }
  /* 홀수 마지막 카드: 전체 너비 (카드 1개일 때 좌우 꽉 채움) */
  #prompt-grid .prompt-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
  /* 2열 카드: 태그 숨김, 설명 2줄 */
  #prompt-grid .card-tags { display: none; }
  #prompt-grid .card-desc {
    -webkit-line-clamp: 2;
    font-size: .78rem;
  }
  #prompt-grid .card-title { font-size: .9rem; }
  #prompt-grid .card-body { padding: .45rem .6rem .35rem; gap: .2rem; }
  #prompt-grid .card-footer { padding: .3rem .6rem; font-size: .72rem; }
  .card-thumb { height: 120px; }
  /* 전체너비 단일 카드: 썸네일 더 높게 */
  #prompt-grid .prompt-card:last-child:nth-child(odd) .card-thumb { height: 180px; }
  .card-title { font-size: .875rem; margin: .4rem 0 .3rem; }
  .card-desc { font-size: .78rem; line-height: 1.5; -webkit-line-clamp: 2; }
  .card-body { padding: .625rem .75rem; }
  .card-footer { padding: .5rem .75rem; }
  .card-btn { font-size: .75rem; }

  /* ── 배지/태그 */
  .badge { font-size: .78rem; padding: .2rem .55rem; }
  .card-tags .tag { font-size: .78rem; }

  /* ── 버튼: 최소 터치 타겟 48px */
  .btn, button {
    min-height: 48px; font-size: 1rem; padding: .65rem 1.1rem;
  }
  .btn-sm { min-height: 40px; font-size: .9rem; }
  .btn-ghost { min-height: 44px; }

  /* ── 카테고리 바 */
  .category-bar { margin-bottom: .5rem; gap: .35rem; }
  .category-btn {
    font-size: .85rem; padding: .35rem .75rem; min-height: 36px;
  }

  /* ── 금액 그리드: 2열, 더 큰 버튼 */
  .amount-grid { grid-template-columns: repeat(2, 1fr); gap: .75rem; }
  .amount-btn { padding: 1.1rem .75rem; }
  .ab-credits { font-size: 1.15rem; }
  .ab-unit { font-size: .8rem; }
  .ab-price { font-size: .85rem; }

  /* ── 충전 페이지 */
  .charge-layout { padding: 0; gap: .625rem; }
  .charge-section { padding: .875rem; }
  .charge-balance-card { padding: .875rem; }
  .cb-amount { font-size: 1.8rem; }
  .cb-label { font-size: .88rem; }
  .charge-section-title { font-size: .95rem; margin-bottom: .5rem; }
  .charge-section-desc { font-size: .85rem; }
  .cs-row { font-size: .88rem; }

  /* ── 약관 페이지 */
  .terms-toc { display: none; }
  .terms-wrap, .terms-layout { padding: 1rem .875rem 3rem; gap: 0; }
  .terms-body h1 { font-size: 1.5rem; }
  .terms-body h2 { font-size: 1.15rem; }
  .terms-body h3 { font-size: 1rem; }
  .terms-body p, .terms-body li { font-size: .95rem; line-height: 1.7; }

  /* ── 결과 페이지 */
  .result-center { padding: 1rem .75rem; }
  .result-icon { font-size: 2.5rem; }
  .result-title { font-size: 1.15rem; }
  .result-desc { font-size: .88rem; }
  .result-actions { gap: .5rem; }
  .result-actions .btn { width: 100%; }

  /* ── 플래시 메시지 */
  .flash { font-size: .88rem; padding: .5rem .75rem; margin-bottom: .5rem; }

  /* ── 테이블 스크롤 */
  .table-wrap, .stats-table-wrap { overflow-x: auto; }
  table { font-size: .88rem; }

  /* ── 통계 */
  .stats-chart-row { grid-template-columns: 1fr; }
  .stats-kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-value { font-size: 1.3rem; }

  /* ── 관리자 */
  .stats-row { grid-template-columns: repeat(2, 1fr); gap: .625rem; margin-bottom: 1.25rem; }
  .stat-card { padding: .875rem .75rem; }
  .stat-value { font-size: 1.6rem; }
  .admin-nav-cards { grid-template-columns: repeat(2, 1fr); gap: .625rem; }
  .admin-nav-card { padding: 1rem .75rem; }
  .settings-section { padding: 1rem; }

  /* ── 프롬프트 상세 페이지 (모바일) */
  .prompt-header { margin-bottom: .375rem; }
  .prompt-header h1 { font-size: 1.1rem; margin-bottom: .25rem; }
  .prompt-desc-compact { font-size: .82rem; color: var(--text-muted); }
  .generate-card { padding: .75rem; }
  .form-group { margin-bottom: .5rem; }
  .form-label { font-size: .82rem; margin-bottom: .25rem; }
  #btn-generate { min-height: 48px; font-size: 1rem; }
  .form-control { font-size: .95rem; min-height: 44px; padding: .4rem .6rem; }
  textarea.form-control { min-height: 90px; }
  /* 업로드 존 — 터치 타겟 강화 */
  .upload-zone {
    padding: .75rem;
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .2rem;
    text-align: center;
  }
  .upload-icon { font-size: 1.5rem; }
  .upload-placeholder > span:nth-child(2) { font-size: .8rem; color: var(--text-muted); }
  .upload-hint { font-size: .68rem; }
  .model-radio-item { padding: .28rem .5rem; }
  .model-radio-item.has-price { padding: .32rem .55rem; }
  .mri-id { font-size: .78rem; }
  .credit-cost-wrap { font-size: .92rem; }

  /* ── 크레딧 잔액 히어로 (credits.html) */
  .credit-balance-hero { padding: .75rem 1rem; margin-bottom: .625rem; gap: .5rem; }
  .cbh-amount { font-size: 1.5rem; }
  .cbh-label { margin-bottom: -.35rem; font-size: .78rem; }
  .cbh-sub { font-size: .72rem; }
  .cbh-expires { font-size: .72rem; margin-top: -.3rem; }

  /* ── 크레딧 필터 탭 */
  .credit-filter-tabs { margin-bottom: .625rem; gap: .35rem; }
  .cft { padding: .3rem .65rem; font-size: .78rem; }

  /* ── 크레딧 테이블 */
  .credit-table .cr-desc { max-width: 160px; font-size: .8rem; }
  .credit-badge { font-size: .7rem; padding: .1rem .4rem; }

  /* ── 충전 안내/사업자 정보 */
  .charge-info { font-size: .75rem; line-height: 1.5; }
  .charge-info h3 { font-size: .78rem; margin-bottom: .3rem; }
  .charge-info ul { padding-left: .9rem; }
  .charge-info li { margin-bottom: .1rem; }
  .charge-biz-info { padding: .625rem !important; }
  .biz-dl { grid-template-columns: 90px 1fr; gap: .15rem .35rem; font-size: .75rem; }

  /* ── 결제 버튼 */
  #btn-pay { margin-top: .625rem; padding: .7rem; }
  #toss-payment-widget, #toss-agreement-widget { min-height: 60px; }
}

@media (max-width: 480px) {
  html, body { font-size: 16px; }

  /* 카드 1열 유지, 내용 더 읽기 쉽게 */
  .amount-grid { grid-template-columns: repeat(2, 1fr); gap: .5rem; }
  .stats-kpi-grid { grid-template-columns: repeat(2, 1fr); gap: .5rem; }
  .kpi-value { font-size: 1.15rem; }

  /* 결과 액션 버튼 세로 정렬 */
  .result-actions { flex-direction: column; }
  .result-actions .btn { width: 100%; min-height: 52px; font-size: 1.05rem; }

  /* 카드 설명 3줄까지 */
  .card-desc { -webkit-line-clamp: 3; }

  /* 탑바 버튼 더 크게 */
  #sidebar-toggle { font-size: 1.4rem; }
}

/* ── 크레딧 거래내역 ──────────────────────────── */
.credit-balance-hero {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-top: 2px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
}
.cbh-label { color: var(--text-muted); font-size: .82rem; flex-basis: 100%; margin-bottom: -.25rem; }
.cbh-amount { font-size: 1.75rem; font-weight: 700; color: var(--accent); line-height: 1; }
.cbh-unit  { font-size: .85rem; color: var(--text-muted); align-self: flex-end; padding-bottom: .15rem; }
.cbh-sub   { color: var(--text-muted); font-size: .78rem; margin-left: auto; }
.cbh-expires { color: var(--text-muted); font-size: .78rem; flex-basis: 100%; margin-top: -.2rem; }
.cbh-expires strong { color: var(--color-yellow, #e3b341); }

.credit-filter-tabs {
  display: flex; gap: .5rem; margin-bottom: 1rem;
  flex-wrap: nowrap; overflow-x: auto;
}
.cft {
  padding: .35rem .8rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  color: var(--text-muted);
  text-decoration: none;
  font-size: .82rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.cft:hover { border-color: var(--accent); color: var(--accent); }
.cft.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.credit-table .cr-date { color: var(--text-muted); font-size: .8rem; white-space: nowrap; }
.credit-table .cr-desc { color: var(--text); max-width: 260px; }
.credit-table .cr-amount { font-weight: 600; text-align: right; white-space: nowrap; }
.credit-table .cr-plus   { color: var(--color-green); }
.credit-table .cr-minus  { color: var(--color-error); }
.credit-table .cr-balance{ text-align: right; color: var(--text-muted); white-space: nowrap; }

.credit-badge {
  display: inline-block; padding: .15rem .5rem;
  border-radius: 4px; font-size: .75rem; font-weight: 600;
}
.badge-charge { background: rgba(88,166,255,.15); color: var(--accent); }
.badge-deduct { background: rgba(248,81,73,.12);  color: var(--color-error); }
.badge-refund { background: rgba(63,185,80,.15);  color: var(--color-green); }
.badge-grant   { background: rgba(188,140,255,.15);color: var(--color-purple); }
.badge-expired { background: rgba(139,148,158,.15); color: var(--text-muted); }

.refund-section {
  margin-top: 2rem;
  border: 1px solid rgba(224,82,82,.3);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  background: rgba(224,82,82,.05);
}
.refund-section-title { margin: 0 0 .75rem; color: var(--color-error); font-size: .95rem; }
.refund-section-desc  { font-size: .8rem; color: var(--text-muted); margin: 0 0 1rem; }


/* ── 충전 사업자 정보 ───────────────────────────── */
.charge-biz-info {
  border-color: var(--border-muted) !important;
}
.biz-dl { display: grid; grid-template-columns: 110px 1fr; gap: .25rem .5rem; font-size: .8rem; }
.biz-dl dt { color: var(--text-dim); }
.biz-dl dd { color: var(--text-muted); }
.biz-info-title { font-size: .85rem; color: var(--text-muted); margin-bottom: .6rem; }
.biz-info-note  { font-size: .75rem; color: var(--text-dim); margin-top: .6rem; }

/* ── 이용약관 ───────────────────────────────────── */
.terms-wrap,
.terms-layout {
  display: flex;
  gap: 2rem;
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
  align-items: flex-start;
}
.terms-toc {
  position: sticky;
  top: 1rem;
  width: 180px;
  flex-shrink: 0;
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-size: .8rem;
}
.terms-toc .toc-title {
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 .5rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-size: .72rem;
}
.terms-toc ol {
  margin: 0;
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.terms-toc a {
  color: var(--text-dim);
  text-decoration: none;
  transition: color .15s;
}
.terms-toc a:hover,
.terms-toc a.active {
  color: var(--accent);
}
.terms-toc .toc-date {
  margin: .8rem 0 0;
  color: var(--text-dim);
  font-size: .72rem;
}
.terms-body {
  flex: 1;
  min-width: 0;
}
.terms-main-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0 0 .3rem;
  color: var(--text);
}
.terms-effective {
  font-size: .8rem;
  color: var(--text-dim);
  margin-bottom: 2rem;
}
.terms-body section {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.terms-body section:last-of-type { border-bottom: none; }
.terms-body h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 .75rem;
  padding-left: .5rem;
  border-left: 3px solid var(--accent);
}
.terms-body p, .terms-body li {
  font-size: .875rem;
  color: var(--text-muted);
  line-height: 1.75;
}
.terms-body ol, .terms-body ul {
  padding-left: 1.4rem;
  margin: .5rem 0;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.terms-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
  margin: .75rem 0;
}
.terms-table th, .terms-table td {
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  text-align: left;
}
.terms-table th {
  background: var(--bg-overlay);
  color: var(--text-muted);
  font-weight: 600;
}
.terms-table td { color: var(--text-dim); }
.terms-table tr:hover td { background: var(--bg-hover); }
.terms-table .tr-highlight td {
  color: var(--text-muted);
  background: rgba(255,90,90,.04);
}
.terms-note {
  font-size: .8rem;
  color: var(--text-dim);
  margin-top: .6rem;
  padding: .5rem .75rem;
  background: var(--bg-overlay);
  border-radius: var(--radius-sm, 4px);
  border-left: 3px solid var(--border);
}
.terms-date {
  font-size: .8rem;
  color: var(--text-dim);
  margin-bottom: 1.5rem;
}
.terms-highlight {
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  margin: .5rem 0 1rem;
}
.terms-body h3 {
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 1rem 0 .4rem;
}
.terms-biz-section,
.terms-biz-info {
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
  margin-top: 1rem;
}
.terms-biz-section h2,
.terms-biz-info h3 {
  font-size: .85rem;
  color: var(--text-muted);
  border-left: none;
  padding-left: 0;
  margin-bottom: .6rem;
}
.terms-biz-info dl { display: grid; grid-template-columns: 140px 1fr; gap: .3rem .6rem; font-size: .82rem; }
.terms-biz-info dt { color: var(--text-dim); }
.terms-biz-info dd { color: var(--text-muted); }
/* 모바일: 목차 숨김 */
@media (max-width: 700px) {
  .terms-toc { display: none; }
  .terms-wrap,
  .terms-layout { padding: 1rem .75rem 3rem; gap: 0; }
}

/* ── Toss 인앱 로그인 페이지 ─────────────────────────── */
.toss-login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px);
  padding: 2rem 1rem;
}
.toss-login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-top: 2px solid var(--accent);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  box-shadow: 0 4px 24px rgba(0,0,0,.3);
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  text-align: center;
}
.toss-logo {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.toss-logo img { border-radius: 16px; }
.toss-logo .logo-text { font-size: 1.8rem; font-weight: 700; color: var(--text); }
.toss-login-desc {
  font-size: .95rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0;
}
.toss-gsi-wrapper {
  display: flex;
  justify-content: center;
  margin: .5rem 0;
}
.toss-channel-badge {
  font-size: .78rem;
  color: var(--text-dim);
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: .25rem .75rem;
  margin: 0;
}
.toss-login-notice {
  font-size: .78rem;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.5;
}

/* ═══════════════════════════════════════════════════════
   TOPBAR ICON BUTTONS (설치 / 전체화면)
   ═══════════════════════════════════════════════════════ */
.topbar-icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); border-radius: var(--radius);
  flex-shrink: 0; -webkit-tap-highlight-color: transparent;
  transition: background .15s, color .15s;
}
.topbar-icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.topbar-icon-btn svg { display: block; pointer-events: none; stroke: currentColor; fill: none; width: 18px; height: 18px; flex-shrink: 0; }

/* ═══════════════════════════════════════════════════════
   MOBILE BOTTOM NAV — 모바일 하단 탭바
   ═══════════════════════════════════════════════════════ */
#mobile-bottom-nav { display: none; }

@media (max-width: 768px) {
  #mobile-bottom-nav {
    display: flex !important;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(48px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    z-index: 100;
    flex-wrap: nowrap;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }
}

.mbn-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: .7rem;
  padding: .3rem .25rem;
  touch-action: manipulation;
  transition: color .15s;
}
.mbn-icon  { font-size: 1.2rem; line-height: 1; display: block; }
.mbn-label { font-size: .6rem; letter-spacing: .01em; }
.mbn-active { color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); }
.mbn-active .mbn-label { font-weight: 600; }


/* ── PWA 독립 실행(standalone) 모드 추가 조정 ── */
@media (display-mode: standalone) {
  #topbar {
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(52px + env(safe-area-inset-top, 0px));
  }
  /* 스탠드얼론에서 설치 버튼 숨김 (이미 설치됨) */
  #btn-install-pwa { display: none !important; }
}

/* ═══════════════════════════════════════════════════════
   iOS 설치 안내 토스트
   ═══════════════════════════════════════════════════════ */
#ios-install-toast {
  position: fixed;
  bottom: calc(70px + env(safe-area-inset-bottom, 0px));
  left: 12px; right: 12px;
  z-index: 9000;
  animation: slideUpFade .3s ease;
}
@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
#ios-install-toast-inner {
  display: flex; align-items: center; gap: .75rem;
  background: var(--bg-overlay);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: .85rem 1rem;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}
.iit-icon { font-size: 1.5rem; flex-shrink: 0; }
.iit-text {
  flex: 1; display: flex; flex-direction: column; gap: 2px;
  font-size: .82rem;
}
.iit-text strong { color: var(--text); font-size: .88rem; }
.iit-text span   { color: var(--text-muted); }
.iit-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-dim); font-size: 1rem; padding: .25rem;
  flex-shrink: 0; line-height: 1;
}

/* ── 탑바 설치 버튼 (항상 모바일에서만 표시) ── */
@media (min-width: 769px) {
  /* 데스크톱: 설치 버튼 숨김 (선택사항 — 필요 시 제거) */
  #btn-install-pwa { display: none !important; }
}

/* ── SPA 페이지 전환 트랜지션 ── */
#page-body { transition: opacity .15s ease; }

/* ── 모바일 overflow 방지 (고정 최소폭 그리드 해제) ── */
@media (max-width: 768px) {
  /* 결과 파일 그리드: minmax(360px) → 2열 (이미지 세트 최적화) */
  #result-files-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: .5rem !important;
  }
  .result-file-actions { padding: .4rem .6rem; gap: .3rem; }
  .result-file-actions .btn { flex: 1; padding: .35rem .4rem; font-size: .8rem; text-align: center; min-height: 44px; }
  /* 결과 페이지 액션 버튼 세로 배치 */
  .result-actions-bar { flex-direction: column; gap: .5rem; }
  .result-actions-bar .btn { width: 100%; min-height: 52px; text-align: center; }
  /* 결과 헤더 압축 */
  .result-header { margin-bottom: .875rem; }
  .result-header h1 { font-size: 1.15rem; }
  .result-meta { font-size: .78rem; }
  /* 폼 2·3열 그리드 → 단일 열 */
  .form-grid-2,
  .form-grid-3 {
    grid-template-columns: 1fr !important;
  }
  /* 가로 스크롤 방지 */
  body { overflow-x: hidden; }
  #page-body { overflow-x: hidden; }
  /* 터치 스크롤 부드럽게 */
  #page-body { -webkit-overflow-scrolling: touch; }

  /* ── 모바일 계정 버튼 & 드롭다운 ── */
  #btn-account-mobile { display: flex; }

  #mobile-account-menu {
    position: fixed;
    top: calc(56px + env(safe-area-inset-top, 0px) + 4px);
    right: 8px;
    width: min(260px, calc(100vw - 16px));
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    z-index: 400;
    box-shadow: 0 8px 32px rgba(0,0,0,.5);
    overflow: hidden;
    animation: mam-in .15s ease;
  }
  @keyframes mam-in {
    from { opacity: 0; }
    to   { opacity: 1; }
  }
  .mam-user {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 14px 10px;
  }
  .mam-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    object-fit: cover; flex-shrink: 0;
  }
  .mam-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
  .mam-name {
    font-weight: 600; font-size: .9rem; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .mam-credits { font-size: .78rem; color: var(--text-muted); }
  .mam-sep { height: 1px; background: var(--border); margin: 4px 0; }
  .mam-item {
    display: flex; align-items: center; gap: 10px;
    padding: 11px 14px; font-size: .875rem;
    color: var(--text); text-decoration: none;
  }
  .mam-item:active { background: var(--bg-hover); }
  .mam-logout { color: #f85149; }
}

/* 데스크톱: 계정 버튼 숨김 */
#btn-account-mobile { display: none; }

/* ═══════════════════════════════════════════════════════
   스켈레톤 로딩 shimmer
   ═══════════════════════════════════════════════════════ */
@keyframes skeleton-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-overlay) 25%,
    var(--bg-hover)   50%,
    var(--bg-overlay) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.6s ease-in-out infinite;
  border-radius: var(--radius);
}
.card-skeleton {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  display: flex; flex-direction: column;
}
.skeleton-thumb { flex-shrink: 0; height: 160px; }
.skeleton-body  { padding: 1rem; flex: 1; display: flex; flex-direction: column; gap: .5rem; }
.skeleton-title { height: 16px; width: 75%; }
.skeleton-line  { height: 12px; }
.skeleton-line-short { height: 12px; width: 55%; }
.skeleton-footer {
  height: 40px; margin-top: auto;
  border-top: 1px solid var(--border-muted);
}
@media (max-width: 768px) {
  .skeleton-thumb { height: 130px; }
  .skeleton-body  { padding: .625rem .75rem; }
}

/* ── 카드 썸네일: shimmer → 이미지 페이드인 ─────── */
.card-thumb {
  background: linear-gradient(
    90deg,
    var(--bg-overlay) 25%,
    var(--bg-hover)   50%,
    var(--bg-overlay) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.6s ease-in-out infinite;
}
.card-thumb.loaded { animation: none; background: var(--bg-overlay); }
.card-thumb img {
  width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .35s ease;
}
.card-thumb img.loaded { opacity: 1; }

/* ── 생성 오버레이 — 단계별 진행 표시기 ─────────── */
.gen-steps {
  display: flex; flex-direction: column; gap: .4rem;
  margin-top: 1.25rem; text-align: left; width: 100%;
}
.gen-step {
  display: flex; align-items: center; gap: .6rem;
  font-size: .82rem; color: var(--text-dim);
  padding: .35rem .6rem; border-radius: var(--radius);
  transition: color .3s, background .3s;
}
.gen-step.active {
  color: var(--text);
  background: var(--bg-overlay);
}
.gen-step.done { color: var(--color-green); }
.gen-step-icon { font-size: 1rem; width: 1.2rem; text-align: center; flex-shrink: 0; }
.gen-elapsed {
  font-size: .75rem; color: var(--text-dim);
  margin-top: .75rem; font-variant-numeric: tabular-nums;
}

/* ── 히스토리 그리드 모바일 2열 ──────────────────── */
@media (max-width: 768px) {
  .mypage-header { margin-bottom: .75rem; gap: .625rem; }
  .user-avatar { width: 44px; height: 44px; }
  .mypage-header h2 { font-size: 1.05rem; }
  .mypage-count { margin-bottom: .5rem; }
  #history-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: .5rem;
  }
  .history-thumb { height: 110px; }
  .history-card-body { padding: .4rem .5rem; }
  .history-title { font-size: .78rem; }
  .history-card-actions { padding: .3rem .4rem; gap: .2rem; flex-wrap: nowrap; }
  .history-card-actions .btn { flex: 1; min-width: 0; text-align: center; padding: .25rem .1rem; font-size: .7rem; white-space: nowrap; }
}
