/* CustomColorAI — 공통 디자인 시스템 (다크 기본 · 라이트 토글) */
:root,
[data-theme="dark"] {
  --bg-deep: #050508;
  --bg-panel: rgba(255, 255, 255, 0.025);
  --bg-elevated: rgba(255, 255, 255, 0.04);
  --text-primary: #f5f5f7;
  --text-muted: rgba(245, 245, 247, 0.52);
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --border: rgba(255, 255, 255, 0.09);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 24px;
  --shadow-soft: 0 24px 64px rgba(0, 0, 0, 0.45);
  --glow: 0 0 80px rgba(59, 130, 246, 0.1);
  --sidebar-w: 260px;
  --topbar-h: 64px;
  --font: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="light"] {
  --bg-deep: #f5f5f7;
  --bg-panel: rgba(255, 255, 255, 0.85);
  --bg-elevated: rgba(0, 0, 0, 0.04);
  --text-primary: #1d1d1f;
  --text-muted: rgba(29, 29, 31, 0.52);
  --accent: #0071e3;
  --accent-soft: rgba(0, 113, 227, 0.1);
  --border: rgba(0, 0, 0, 0.1);
  --shadow-soft: 0 20px 48px rgba(0, 0, 0, 0.08);
  --glow: 0 0 60px rgba(0, 113, 227, 0.1);
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* 배경 */
.cca-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 100% 70% at 50% -25%, rgba(59, 130, 246, 0.16), transparent 55%),
    radial-gradient(ellipse 60% 45% at 100% 40%, rgba(120, 90, 200, 0.06), transparent 45%),
    var(--bg-deep);
}

[data-theme="light"] .cca-bg {
  background:
    radial-gradient(ellipse 100% 70% at 50% -25%, rgba(0, 113, 227, 0.1), transparent 55%),
    radial-gradient(ellipse 60% 45% at 100% 40%, rgba(100, 80, 200, 0.05), transparent 45%),
    var(--bg-deep);
}

.cca-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.4;
  background-image: linear-gradient(rgba(128, 128, 128, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(128, 128, 128, 0.06) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 75% 55% at 50% 35%, black, transparent);
  pointer-events: none;
}

/* 로그인 게이트 */
.cca-gate {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.95rem;
  letter-spacing: 0.03em;
}

.cca-gate[hidden] {
  display: none !important;
}

/* 레이아웃: 앱 셸 */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.app-shell[hidden] {
  display: none !important;
}

/* 사이드바 */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: 24px 16px;
  border-right: 1px solid var(--border);
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-brand {
  padding: 8px 12px 20px;
  text-decoration: none;
  color: var(--text-primary);
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.sidebar-brand span.ai {
  color: var(--accent);
  font-weight: 500;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-nav a:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.sidebar-nav a.is-active {
  background: var(--accent-soft);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.sidebar-nav .nav-ico {
  width: 1.25rem;
  text-align: center;
  opacity: 0.85;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* 메인 컬럼 */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-h);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(5, 5, 8, 0.4);
  backdrop-filter: blur(12px);
}

[data-theme="light"] .topbar {
  background: rgba(255, 255, 255, 0.72);
}

.page-inner {
  padding: 28px 32px 48px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.page-title {
  margin: 0 0 8px;
  font-size: clamp(1.5rem, 3vw, 1.85rem);
  font-weight: 600;
  letter-spacing: -0.035em;
}

.page-desc {
  margin: 0 0 32px;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.55;
  max-width: 52ch;
}

/* 버튼 */
.btn {
  appearance: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.88rem;
  padding: 10px 18px;
  border-radius: 999px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn-ghost {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: rgba(128, 128, 128, 0.12);
}

.btn-theme {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
}

.btn-logout {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-logout:hover {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.06);
}

.btn-primary {
  background: linear-gradient(180deg, #4f8fff 0%, var(--accent) 100%);
  color: #fff;
  border: none;
  font-weight: 600;
  padding: 12px 22px;
  border-radius: var(--radius-md);
  box-shadow: var(--glow);
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  font-weight: 600;
  padding: 12px 22px;
  border-radius: var(--radius-md);
}

/* 카드 / 패널 */
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  backdrop-filter: blur(16px);
}

.card + .card {
  margin-top: 20px;
}

/* 테이블 */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 14px 18px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-weight: 600;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.data-table a:hover {
  text-decoration: underline;
}

/* 로그인 전용 */
.auth-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px;
}

.auth-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 420px;
  margin: 0 auto;
  width: 100%;
  padding: 8px 0 24px;
}

.auth-card {
  max-width: 420px;
  margin: 0 auto;
  width: 100%;
  padding: 36px 32px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-soft);
}

.auth-card h1 {
  margin: 0 0 8px;
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.auth-card .sub {
  margin: 0 0 28px;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-full {
  width: 100%;
  margin-top: 6px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 22px 0;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.link-muted {
  color: var(--text-muted);
  font-size: 0.88rem;
  text-decoration: none;
}

.link-muted:hover {
  color: var(--accent);
}

/* 시각화: 업로드 + 컬러 */
.viz-grid {
  display: grid;
  gap: 24px;
  grid-template-columns: 1fr;
}

@media (min-width: 900px) {
  .viz-grid {
    grid-template-columns: 1.1fr 0.9fr;
  }
}

.dropzone {
  position: relative;
  min-height: 280px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-xl);
  padding: 40px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--bg-elevated);
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.dropzone input[type="file"] {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 10px;
  max-width: 100%;
}

.color-swatch {
  aspect-ratio: 1;
  border-radius: 12px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.color-swatch:hover {
  transform: scale(1.06);
}

.color-swatch.is-picked {
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px var(--accent);
}

/* 시각화 워크스페이스 (캔버스 + 컨트롤) */
.page-inner--viz {
  max-width: 1280px;
}

.viz-workspace {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

@media (min-width: 1024px) {
  .viz-workspace {
    flex-direction: row;
    align-items: flex-start;
  }

  .viz-canvas-column {
    flex: 1;
    min-width: 0;
  }

  .viz-controls-column {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
}

.viz-canvas-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: min(62vh, 560px);
  padding: 20px;
  background: var(--bg-elevated);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  position: relative;
}

.viz-canvas-placeholder {
  margin: 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.6;
}

#paintCanvas {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
}

.viz-control-card {
  padding: 20px;
}

.viz-card-title {
  margin: 0 0 6px;
  font-size: 0.95rem;
  font-weight: 600;
}

.viz-card-desc {
  margin: 0 0 14px;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.dropzone--compact {
  min-height: 140px;
  padding: 20px 16px;
}

.viz-drop-ico {
  font-size: 1.75rem;
  display: block;
  margin-bottom: 10px;
}

.viz-custom-color {
  margin-top: 16px;
}

.viz-custom-color label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.viz-color-input {
  width: 100%;
  height: 44px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-deep);
  cursor: pointer;
}

.viz-color-input.is-picked-custom {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.viz-picked-label {
  margin: 12px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.viz-slider-row {
  margin-bottom: 16px;
}

.viz-slider-row:last-of-type {
  margin-bottom: 0;
}

.viz-slider-row label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
  gap: 8px;
}

.viz-slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.viz-hint {
  margin: 10px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* 실시간 AR (model-viewer) */
.ar-card {
  padding: 20px;
}

.ar-color-bar label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.ar-color-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.ar-model-viewer {
  display: block;
  width: 100%;
  height: min(68vh, 520px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}

.ar-ar-custom-btn {
  padding: 12px 20px;
  font-size: 0.95rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: linear-gradient(180deg, #4f8fff 0%, var(--accent) 100%);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.ar-hint {
  margin-top: 16px;
  line-height: 1.55;
}

/* 임베드 · 영역 지정 UI */
.cca-embed .sidebar {
  display: none !important;
}

.cca-embed .app-shell {
  flex-direction: column;
}

.cca-embed .app-main {
  width: 100%;
  max-width: 100%;
}

.viz-canvas--interactive {
  cursor: crosshair;
  touch-action: none;
}

.viz-radio {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 0.88rem;
  color: var(--text-primary);
  cursor: pointer;
}

.viz-radio input {
  accent-color: var(--accent);
}

.viz-select {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
}

.viz-product-banner {
  padding: 14px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--accent-soft);
  color: var(--text-primary);
  font-size: 0.9rem;
  line-height: 1.45;
}

.embed-snippet {
  margin: 0;
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-deep);
  font-size: 0.78rem;
  line-height: 1.5;
  overflow-x: auto;
  color: var(--text-muted);
}

/* 설정 폼 */
.form-row {
  margin-bottom: 20px;
}

.form-row label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.form-row input[type="text"],
.form-row input[type="url"] {
  width: 100%;
  max-width: 400px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: inherit;
}

.logo-preview {
  width: 120px;
  height: 120px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  object-fit: contain;
  margin-top: 12px;
}

footer.page-foot {
  text-align: center;
  padding: 32px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

footer.page-foot a {
  color: var(--text-muted);
}

@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .sidebar-brand {
    flex: 1;
    min-width: 0;
  }

  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    gap: 6px;
  }

  .sidebar-nav a {
    flex: 1 1 auto;
    min-width: 44%;
    justify-content: center;
  }

  .sidebar-foot {
    width: 100%;
    border-top: none;
    padding-top: 8px;
  }
}
