:root {
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f5f9;
  --border-color: #e2e8f0;
  --border-focus: #0f172a;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  
  --primary: #0f172a;
  --primary-hover: #1e293b;
  --primary-light: #f1f5f9;
  
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;
  --success-text: #065f46;
  
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  --warning-text: #92400e;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.04);
}

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

body {
  font-family: 'Plus Jakarta Sans', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.5rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* 頂部導覽列 */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

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

.brand-badge {
  background: var(--primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  letter-spacing: 0.05em;
}

.brand-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.brand-text .subtitle {
  font-size: 0.825rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg-subtle);
  padding: 0.4rem 0.75rem;
  border-radius: 20px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
}

/* 主佈局：雙欄自適應 */
.main-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  flex: 1;
}

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

/* 通用面板樣式 */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: #fafafa;
}

.panel-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-subtle);
  color: var(--text-muted);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
}

.form-content {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* 表單元件 */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tip {
  font-size: 0.775rem;
  color: var(--text-muted);
  font-weight: normal;
}

.form-control {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-size: 0.9rem;
  color: var(--text-main);
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  font-family: inherit;
}

.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.08);
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

.hook-select {
  font-size: 0.85rem;
  background-color: #f8fafc;
}

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

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

.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }

/* Tabs 切換按鈕 */
.tab-group {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  background: #fafafa;
}

.tab-buttons {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab-btn {
  flex: 1;
  padding: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--border-color);
  background: #fff;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* 按鈕樣式 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: #e2e8f0;
}

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

.btn-outline:hover {
  background: var(--bg-subtle);
}

.btn-text {
  background: none;
  border: none;
  font-size: 0.8rem;
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
}

.btn-text:hover {
  text-decoration: underline;
}

.btn-block {
  width: 100%;
  padding: 0.85rem;
  font-size: 0.95rem;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

/* 右側預覽區 */
.tabs-preview {
  display: flex;
  gap: 0.5rem;
}

.preview-tab {
  background: none;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}

.preview-tab.active {
  color: var(--text-main);
  border-bottom-color: var(--primary);
}

.preview-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.char-count {
  font-size: 0.8rem;
  color: var(--text-subtle);
}

.preview-body {
  display: none;
  padding: 1.25rem;
  flex: 1;
  flex-direction: column;
  gap: 1rem;
}

.preview-body.active {
  display: flex;
}

/* 零幻覺驗證條 */
.validation-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  font-size: 0.85rem;
}

/* 即時聯網比對開關 */
.live-search-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
}

.toggle-container {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-container input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #cbd5e1;
  transition: .3s;
  border-radius: 24px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .toggle-slider {
  background-color: #10b981;
}

input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

.toggle-label {
  display: flex;
  flex-direction: column;
}

.toggle-label strong {
  font-size: 0.85rem;
  color: #065f46;
}

.toggle-label small {
  font-size: 0.75rem;
  color: #047857;
}

/* 即時聯網來源清單 */
.live-sources-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 0.75rem;
}

.live-sources-box.hidden {
  display: none;
}

.sources-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #334155;
}

.sources-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.source-item {
  font-size: 0.775rem;
  padding: 0.35rem 0.5rem;
  background: #ffffff;
  border: 1px solid #edf2f7;
  border-radius: 4px;
}

.source-item a {
  color: #2563eb;
  text-decoration: none;
  font-weight: 500;
}

.source-item a:hover {
  text-decoration: underline;
}

.source-item .source-meta {
  font-size: 0.7rem;
  color: #94a3b8;
  margin-top: 0.15rem;
}

.validation-bar.valid {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success-text);
}

.validation-bar.has-warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning-text);
}

.val-icon {
  font-size: 1.2rem;
}

.val-text {
  display: flex;
  flex-direction: column;
}

.val-text strong {
  font-size: 0.85rem;
}

.val-text span {
  font-size: 0.775rem;
  opacity: 0.9;
}

/* 輸出文字區域 */
.content-wrapper {
  flex: 1;
  display: flex;
  min-height: 380px;
}

.output-textarea {
  width: 100%;
  height: 100%;
  min-height: 380px;
  padding: 1rem;
  font-size: 0.925rem;
  line-height: 1.65;
  color: var(--text-main);
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: inherit;
  resize: vertical;
  white-space: pre-wrap;
}

/* 詳細檢核報告 */
.validation-report {
  border-top: 1px dashed var(--border-color);
  padding-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.validation-report.hidden {
  display: none;
}

.validation-report h4 {
  font-size: 0.85rem;
  color: var(--text-main);
}

.val-list {
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.val-list.passed {
  color: var(--success-text);
}

.val-list.warnings {
  color: #b91c1c;
}

/* LINE 模擬器 */
.line-mock-container {
  display: flex;
  flex-direction: column;
  height: 520px;
  background: #849ebf;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.line-header {
  background: #273246;
  color: #fff;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.line-avatar {
  font-size: 1.25rem;
  background: #3b4b66;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.line-user-info {
  display: flex;
  flex-direction: column;
}

.line-user-info strong {
  font-size: 0.875rem;
}

.line-user-info span {
  font-size: 0.7rem;
  opacity: 0.8;
}

.line-chat-box {
  flex: 1;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.line-bubble {
  max-width: 80%;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}

.line-bubble.bot {
  align-self: flex-start;
  background: #ffffff;
  color: #0f172a;
  border-top-left-radius: 2px;
}

.line-bubble.user {
  align-self: flex-end;
  background: #5ac463;
  color: #000;
  border-top-right-radius: 2px;
}

.line-input-area {
  padding: 0.75rem;
  background: #ffffff;
  display: flex;
  gap: 0.5rem;
}

.line-input-area input {
  flex: 1;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
}

/* Modal 彈窗 */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: #fff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

.modal-content.modal-lg {
  max-width: 800px;
}

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

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

.alert-box {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.825rem;
}

.alert-box.info {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  color: #0369a1;
}

/* 法規卡片 */
.policy-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  background: #fafafa;
}

.policy-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}

.policy-badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: #e0f2fe;
  color: #0284c7;
  font-weight: 600;
}

.policy-badge.draft {
  background: #fef3c7;
  color: #b45309;
}

.policy-rules {
  margin-left: 1.25rem;
  font-size: 0.85rem;
  color: var(--text-main);
}
