/* =========================================================
   AI 智慧筆記摘要與重點整理助手 - 現代感主題與響應式樣式
   ========================================================= */

:root {
  --bg-main: #0b0f19;
  --bg-card: rgba(23, 29, 45, 0.75);
  --bg-card-hover: rgba(30, 38, 59, 0.85);
  --bg-input: rgba(15, 20, 32, 0.85);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: #6366f1;
  --border-glow: rgba(99, 102, 241, 0.35);

  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #818cf8;
  --accent-purple: #a855f7;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;

  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-card: 0 16px 36px -10px rgba(0, 0, 0, 0.5), 0 0 1px 1px rgba(255, 255, 255, 0.05);
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.35);

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

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

body {
  font-family: 'Plus Jakarta Sans', 'Noto Sans TC', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
  position: relative;
  -webkit-font-smoothing: antialiased;
}

/* 背景光暈效果 */
.background-decor {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.35;
  animation: float 20s infinite alternate ease-in-out;
}

.blob-1 {
  width: 450px;
  height: 450px;
  background: radial-gradient(circle, #4f46e5 0%, #312e81 70%);
  top: -100px;
  right: -50px;
}

.blob-2 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, #7e22ce 0%, #431407 70%);
  bottom: -150px;
  left: -100px;
  animation-delay: -5s;
}

.blob-3 {
  width: 380px;
  height: 380px;
  background: radial-gradient(circle, #0e7490 0%, #064e3b 70%);
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.2;
  animation-delay: -10s;
}

@keyframes float {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(30px, 40px) scale(1.08); }
  100% { transform: translate(-20px, -30px) scale(0.95); }
}

/* 主容器 */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 1480px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 2.5rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* 頁頭 */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand-icon {
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 50px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.25), rgba(168, 85, 247, 0.25));
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.brand-text h1 {
  font-size: 1.45rem;
  font-weight: 700;
  background: linear-gradient(135deg, #ffffff 40%, #c7d2fe 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.01em;
}

.brand-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.status-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #f59e0b; /* 橘黃 (尚未設定) */
}

.status-badge.ready {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.3);
  color: #a7f3d0;
}
.status-badge.ready .dot {
  background-color: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
}

/* 主面板網格 (桌機左右排列，手機上下排列) */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  flex: 1;
}

/* 面板通用樣式 */
.panel {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: border-color var(--transition-fast);
}

.panel:focus-within {
  border-color: rgba(99, 102, 241, 0.4);
}

.panel-header {
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.02);
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
}

.panel-title svg {
  color: var(--primary-light);
}

.char-count {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
}

/* 設定區塊 (API Key & Model) */
.config-bar {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--border-subtle);
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.input-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.input-with-button {
  display: flex;
  position: relative;
  align-items: center;
}

.input-with-button input,
.config-bar select {
  width: 100%;
  padding: 0.6rem 0.85rem;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.88rem;
  outline: none;
  transition: all var(--transition-fast);
}

.input-with-button input {
  padding-right: 2.5rem;
  font-family: 'JetBrains Mono', monospace;
}

.input-with-button input:focus,
.config-bar select:focus,
.textarea-wrapper textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--border-glow);
}

.ghost-btn {
  position: absolute;
  right: 6px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  opacity: 0.65;
  transition: opacity var(--transition-fast);
}

.ghost-btn:hover {
  opacity: 1;
}

/* 摘要模式與長度控制項 */
.options-bar {
  padding: 0.85rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.015);
}

.option-pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.pill {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.pill:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.pill.active {
  background: linear-gradient(135deg, var(--primary), var(--accent-purple));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

.length-selector {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.length-selector label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
}

.length-selector input[type="radio"] {
  accent-color: var(--primary);
  cursor: pointer;
}

/* 文本輸入區 */
.textarea-wrapper {
  padding: 1.25rem 1.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 280px;
}

.textarea-wrapper textarea {
  width: 100%;
  flex: 1;
  min-height: 220px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem;
  color: var(--text-main);
  font-size: 0.95rem;
  line-height: 1.7;
  resize: vertical;
  outline: none;
  font-family: inherit;
  transition: all var(--transition-fast);
}

.textarea-wrapper textarea::placeholder {
  color: var(--text-dim);
  line-height: 1.6;
}

/* 快速範本與輔助按鈕 */
.quick-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.quick-title {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.quick-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 0.3rem 0.65rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.quick-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.2);
}

/* 提交按鈕 */
.submit-actions {
  padding: 1rem 1.5rem 1.5rem;
}

.primary-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.85rem 1.5rem;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #d946ef 100%);
  background-size: 200% auto;
  border: none;
  color: #fff;
  font-size: 1.02rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(99, 102, 241, 0.4);
  transition: all var(--transition-normal);
}

.primary-btn:hover:not(:disabled) {
  background-position: right center;
  box-shadow: 0 6px 24px rgba(139, 92, 246, 0.55);
  transform: translateY(-1px);
}

.primary-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.primary-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

/* 輸出面板動作工具列 */
.action-buttons {
  display: flex;
  gap: 0.5rem;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.82rem;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

/* 輸出顯示區 */
.output-content-area {
  padding: 1.5rem;
  flex: 1;
  overflow-y: auto;
  min-height: 480px;
  max-height: 720px;
  position: relative;
}

/* 空狀態 */
.empty-state {
  height: 100%;
  min-height: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 3.5rem;
  margin-bottom: 1rem;
  opacity: 0.85;
}

.empty-state h3 {
  font-size: 1.25rem;
  color: #fff;
  margin-bottom: 0.6rem;
  font-weight: 600;
}

.empty-state p {
  max-width: 440px;
  font-size: 0.92rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.feature-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
}

.ftag {
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-full);
  color: var(--text-muted);
}

/* 載入動畫 */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 380px;
  padding: 2rem;
  gap: 1.5rem;
}

.spinner {
  width: 46px;
  height: 46px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--primary);
  border-right-color: var(--accent-purple);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

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

.loading-text {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 500;
}

.skeleton-lines {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 1rem;
}

.skeleton-line {
  height: 14px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.04) 25%, rgba(255, 255, 255, 0.09) 50%, rgba(255, 255, 255, 0.04) 75%);
  background-size: 200% 100%;
  border-radius: 6px;
  animation: shimmer 1.8s infinite;
}

.line-1 { width: 90%; }
.line-2 { width: 75%; }
.line-3 { width: 85%; }
.line-4 { width: 60%; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Markdown 排版樣式 */
.markdown-body {
  color: #e5e7eb;
  font-size: 0.98rem;
  line-height: 1.75;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  color: #fff;
  margin-top: 1.6rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
  line-height: 1.35;
}

.markdown-body h1:first-child,
.markdown-body h2:first-child,
.markdown-body h3:first-child {
  margin-top: 0;
}

.markdown-body h1 {
  font-size: 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.5rem;
}

.markdown-body h2 {
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.markdown-body h3 {
  font-size: 1.1rem;
  color: #c7d2fe;
}

.markdown-body p {
  margin-bottom: 1rem;
  color: #d1d5db;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.5rem;
  margin-bottom: 1.2rem;
}

.markdown-body li {
  margin-bottom: 0.45rem;
}

.markdown-body li strong {
  color: #fff;
}

.markdown-body blockquote {
  border-left: 4px solid var(--primary);
  padding: 0.6rem 1rem;
  background: rgba(99, 102, 241, 0.08);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 1.2rem 0;
  color: #c7d2fe;
}

.markdown-body code {
  font-family: 'JetBrains Mono', monospace;
  background: rgba(255, 255, 255, 0.08);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.88em;
  color: #f43f5e;
}

.markdown-body pre {
  background: #090d16;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 1rem;
  overflow-x: auto;
  margin: 1.2rem 0;
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
  color: #e2e8f0;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.2rem 0;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border-subtle);
  padding: 0.65rem 0.9rem;
  text-align: left;
}

.markdown-body th {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}

/* 頁尾 */
.app-footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.82rem;
  color: var(--text-dim);
}

/* 浮動提示 Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 0.8rem 1.4rem;
  background: #1f2937;
  color: #fff;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 1000;
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.toast-error {
  background: #7f1d1d;
  border-color: #ef4444;
  color: #fee2e2;
}

.toast.toast-success {
  background: #064e3b;
  border-color: #10b981;
  color: #d1fae5;
}

/* =========================================================
   行動版響應式設計 (Responsive Mobile Design)
   ========================================================= */

@media (max-width: 960px) {
  .app-container {
    padding: 1rem 0.75rem 2rem;
    gap: 1rem;
  }

  .app-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 1rem;
  }

  .header-badges {
    align-self: flex-start;
  }

  .main-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .config-bar {
    grid-template-columns: 1fr;
    padding: 1rem;
    gap: 0.85rem;
  }

  .options-bar {
    padding: 0.85rem 1rem;
    flex-direction: column;
    align-items: flex-start;
  }

  .textarea-wrapper {
    padding: 1rem;
    min-height: 220px;
  }

  .textarea-wrapper textarea {
    min-height: 180px;
  }

  .output-content-area {
    padding: 1rem;
    min-height: 360px;
    max-height: none;
  }

  .brand-text h1 {
    font-size: 1.25rem;
  }

  .toast {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    text-align: center;
  }
}
