@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800&display=swap');

:root {
  --bg-primary: #070913;
  --bg-secondary: #0c0f1d;
  --surface-color: rgba(13, 17, 34, 0.7);
  --surface-border: rgba(255, 255, 255, 0.06);
  --accent-color: #6366f1;
  --accent-secondary: #a855f7;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  --accent-glow: rgba(99, 102, 241, 0.35);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #475569;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 12px 40px rgba(0, 0, 0, 0.7);
  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --glass-blur: blur(16px);
  --input-bg: rgba(0, 0, 0, 0.25);
  /* CH06 設計權杖：微間距系統（禁止 >24px 留白）*/
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px;  --sp-4: 16px;  --sp-5: 24px;
  --control-h: 36px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --t-fast: 0.15s;  --t-base: 0.2s;
  --header-h: 61px;
}

[data-theme="light"] {
  --bg-primary: #f1f3f9;
  --bg-secondary: #ffffff;
  --surface-color: rgba(255, 255, 255, 0.75);
  --surface-border: rgba(0, 0, 0, 0.06);
  --accent-color: #4f46e5;
  --accent-secondary: #9333ea;
  --accent-gradient: linear-gradient(135deg, #4f46e5 0%, #9333ea 100%);
  --accent-glow: rgba(79, 70, 229, 0.15);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 12px 40px rgba(79, 70, 229, 0.08);
  --input-bg: rgba(0, 0, 0, 0.05);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition: var(--transition-smooth);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Typography */
h1, h2, h3, h4 {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Header */
header {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--surface-border);
  padding: 10px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: var(--glass-blur);
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 38px;
  height: 38px;
  background: var(--accent-gradient);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
  box-shadow: 0 0 15px var(--accent-glow);
}

header h1 {
  font-size: 24px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

header p {
  font-size: 12px;
  color: var(--text-secondary);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Layout container */
.container {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 24px;
  flex: 1;
}

@media (max-width: 1024px) {
  .container {
    grid-template-columns: 1fr;
  }
}

/* Glassmorphic panels */
.panel {
  background: var(--surface-color);
  border: 1px solid var(--surface-border);
  backdrop-filter: var(--glass-blur);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: fit-content;
}

.panel h2 {
  font-size: 20px;
  position: relative;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--surface-border);
  color: var(--text-primary);
}

.panel h2::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 50px;
  height: 2px;
  background: var(--accent-gradient);
  border-radius: 2px;
}

/* Inputs & Form styling */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

input[type="text"], select, textarea {
  width: 100%;
  padding: 12px 16px;
  background-color: var(--input-bg);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  transition: var(--transition-smooth);
}

select option {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

input[type="text"]:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 10px var(--accent-glow);
}

.row-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Custom Checkbox Grid */
.checks {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  transition: var(--transition-smooth);
}

.check-label:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(99, 102, 241, 0.3);
}

.check-label input {
  accent-color: var(--accent-color);
  width: 16px;
  height: 16px;
}

/* Buttons */
button {
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition-smooth);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid var(--surface-border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border: 1px solid var(--surface-border);
  font-size: 16px;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--accent-color);
}

.btn-danger {
  background-color: var(--error);
  color: white;
}

.btn-danger:hover {
  background-color: #dc2626;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* Tab navigation container */
.tabs-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.tab-nav {
  display: flex;
  gap: 8px;
  background: rgba(0, 0, 0, 0.2);
  padding: 6px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--surface-border);
}

.tab-btn {
  flex: 1;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 14px;
  box-shadow: none;
}

.tab-btn.active {
  background: var(--surface-color);
  color: var(--text-primary);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow-sm);
}

/* Tab panes */
.tab-pane {
  display: none;
}

.tab-pane.active {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Output Cards */
.output-card {
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.output-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.output-header h3 {
  font-size: 15px;
  color: var(--text-secondary);
}

.prompt-textarea {
  min-height: 120px;
  resize: vertical;
  background: rgba(0, 0, 0, 0.3);
  font-family: 'Courier New', Courier, monospace;
  font-size: 14px;
  line-height: 1.6;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

/* Image Generator Pane Styles */
.generation-setup {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

@media (max-width: 600px) {
  .generation-setup {
    grid-template-columns: 1fr;
  }
}

/* AI 智能擴寫卡片 */
.ai-expand-card {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(168, 85, 247, 0.06));
  border: 1px solid rgba(99, 102, 241, 0.2);
}

.ai-expand-card h3 i {
  color: var(--accent-color);
}

.inline-select {
  width: auto;
  padding: 6px 10px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.hint-text {
  font-size: 12px;
  color: var(--text-secondary);
  background: rgba(99, 102, 241, 0.06);
  border: 1px solid rgba(99, 102, 241, 0.12);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  line-height: 1.5;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hint-text i {
  color: var(--accent-color);
}

.preview-container {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: rgba(0, 0, 0, 0.3);
  border: 2px dashed var(--surface-border);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.preview-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 14px;
}

.preview-placeholder i {
  font-size: 40px;
}

.preview-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Generation Status Overlay */
.gen-status-container {
  padding: 16px;
  background: rgba(99, 102, 241, 0.05);
  border: 1px solid rgba(99, 102, 241, 0.15);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gen-status-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  font-size: 14px;
}

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  width: 0%;
  height: 100%;
  background: var(--accent-gradient);
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* Gallery styles */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.gallery-card {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  group: hover;
  aspect-ratio: 1;
  cursor: pointer;
}

.gallery-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: var(--transition-smooth);
}

.gallery-card:hover img {
  transform: scale(1.05);
}

.gallery-card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.2) 60%, transparent 100%);
  opacity: 0;
  transition: var(--transition-smooth);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 12px;
  gap: 8px;
}

.gallery-card:hover .gallery-card-overlay {
  opacity: 1;
}

.gallery-card-meta {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.gallery-card-actions {
  display: flex;
  gap: 6px;
}

.gallery-card-actions button {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  flex: 1;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: var(--transition-smooth);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  transform: translateY(20px);
  transition: var(--transition-smooth);
}

.modal-overlay.active .modal-content {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--surface-border);
  padding-bottom: 12px;
}

.modal-header h2 {
  font-size: 20px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  border-top: 1px solid var(--surface-border);
  padding-top: 16px;
}

/* Custom Workflow Textarea */
.workflow-textarea {
  min-height: 200px;
  font-family: monospace;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.4);
}

/* Toast Notification System */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
}

.toast {
  background: var(--bg-secondary);
  border-left: 4px solid var(--accent-color);
  border-top: 1px solid var(--surface-border);
  border-right: 1px solid var(--surface-border);
  border-bottom: 1px solid var(--surface-border);
  color: var(--text-primary);
  padding: 16px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
  transform: translateX(100%);
  opacity: 0;
  transition: var(--transition-smooth);
}

.toast.active {
  transform: translateX(0);
  opacity: 1;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--error); }
.toast.warning { border-left-color: var(--warning); }

.toast-icon {
  font-size: 18px;
}
.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon { color: var(--error); }
.toast.warning .toast-icon { color: var(--warning); }

/* Spinners */
.spinner {
  animation: spin 1s linear infinite;
  display: inline-block;
}

@keyframes spin {
  100% { transform: rotate(360deg); }
}

/* Lightbox Modal */
.lightbox-modal {
  width: 95%;
  max-width: 900px;
  background: transparent;
  box-shadow: none;
  border: none;
  padding: 0;
}

.lightbox-body {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--surface-border);
  overflow: hidden;
  max-height: 80vh;
}

@media (max-width: 768px) {
  .lightbox-body {
    grid-template-columns: 1fr;
    max-height: 90vh;
    overflow-y: auto;
  }
}

.lightbox-image-container {
  display: flex;
  align-items: center;
  justify-content: center;
  background: black;
  max-height: 60vh;
}

.lightbox-image-container img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lightbox-details {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.lightbox-details h3 {
  font-size: 18px;
  border-bottom: 1px solid var(--surface-border);
  padding-bottom: 8px;
}

.lightbox-detail-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.lightbox-detail-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
}

.lightbox-detail-value {
  font-size: 13px;
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.2);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  word-break: break-all;
  max-height: 120px;
  overflow-y: auto;
}

/* Animations */
.pulse-glow {
  animation: pulse-glow 2s infinite ease-in-out;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 10px var(--accent-glow); }
  50% { box-shadow: 0 0 20px var(--accent-color); }
}

.mode-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-gradient);
  color: white;
}

/* ══════════════════════════════════════════
   CH06 UI 精實排版強化 (20260621)
   ══════════════════════════════════════════ */

/* 極細捲軸：6px，半透明 */
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.32); }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: rgba(0,0,0,.22); }

/* 高密度控制項：select / input 統一 36px 高度 */
.panel select,
.panel input[type="text"],
.panel input[type="password"],
.generation-setup select,
.inline-select {
  height: var(--control-h);
  padding: 0 var(--sp-3);
  transition: border-color var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease);
}

/* 膠囊式分頁 */
.tab-nav {
  border-radius: 999px;
  padding: 4px;
  height: 44px;
  align-items: center;
}
.tab-btn {
  border-radius: 999px;
  padding: 7px var(--sp-3);
  transition: background var(--t-base) var(--ease), color var(--t-base) var(--ease);
  font-size: 13px;
}
.tab-btn.active {
  border-radius: 999px;
}

/* 桌面版（≥1025px）：雙欄獨立滾動，調整左欄時右欄提示詞恆在視線內 */
@media (min-width: 1025px) {
  .container {
    height: calc(100vh - var(--header-h));
    align-items: stretch;
  }
  .container > .panel {
    height: 100%;
    overflow-y: auto;
  }
  .container > .tabs-container {
    height: 100%;
    overflow-y: auto;
  }
}

/* 平板（768–1024px）：收緊間距，品質標籤流式換行 */
@media (max-width: 1024px) {
  .container { gap: var(--sp-3); padding: var(--sp-3); }
  .checks { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
}

/* 手機（<768px）：單欄堆疊，拇指熱區，分頁可橫向滑動 */
@media (max-width: 767px) {
  .container { padding: var(--sp-2); }
  .container > .panel { margin-bottom: var(--sp-3); }
  .row-grid { grid-template-columns: 1fr; }
  .panel { padding: var(--sp-3); gap: var(--sp-3); }
  #buildBtn, #genBtn, #comfyGenBtn, #videoGenBtn, #copyBothBtn { width: 100%; }
  .tab-nav { overflow-x: auto; flex-wrap: nowrap; border-radius: var(--radius-lg); height: auto; padding: 6px; }
  .tab-btn { flex-shrink: 0; border-radius: var(--radius-md); }
  .generation-setup { grid-template-columns: 1fr 1fr; }
}

/* 畫廊精實網格：間距收緊至 8px */
.gallery-grid {
  gap: 8px;
}

/* 影片畫廊徽章 */
.video-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 99px;
  letter-spacing: .02em;
}

/* AI 影片分頁：運鏡/時間控制三欄網格 */
.video-controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--sp-3);
}
@media (max-width: 767px) {
  .video-controls-grid { grid-template-columns: 1fr 1fr; }
}

/* 影片預覽容器 */
.video-preview-container {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: rgba(0,0,0,.35);
  border: 2px dashed var(--surface-border);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.video-preview-container video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* 秒數提示小字 */
.length-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: var(--sp-2);
}