/* Design System & CSS Variables */
:root {
  --primary-h: 214;
  --primary-s: 100%;
  --primary-l: 50%;
  --primary-color: hsl(var(--primary-h), var(--primary-s), var(--primary-l));
  --primary-hover: hsl(var(--primary-h), var(--primary-s), 42%);
  --primary-bg: hsl(var(--primary-h), 100%, 97%);

  --accent-gold: #f59e0b;
  --accent-green: #10b981;
  --accent-purple: #8b5cf6;

  --bg-gradient: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  --card-bg: rgba(255, 255, 255, 0.85);
  --card-border: rgba(226, 232, 240, 0.8);
  --text-main: #0f172a;
  --text-muted: #64748b;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 24px rgba(149, 157, 165, 0.1);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--card-border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

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

.logo-badge {
  background: linear-gradient(135deg, #0866ff, #00d2ff);
  color: white;
  font-weight: 700;
  font-size: 14px;
  padding: 6px 14px;
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 12px rgba(8, 102, 255, 0.3);
}

.logo-title {
  font-family: 'Outfit', sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
}

.logo-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  gap: 8px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: var(--radius-md);
}

.nav-btn {
  border: none;
  background: transparent;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-btn:hover {
  color: var(--text-main);
}

.nav-btn.active {
  background: white;
  color: var(--primary-color);
  box-shadow: var(--shadow-sm);
}

.admin-btn.active {
  color: #d97706;
}

/* Main Container */
.app-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 24px;
  width: 100%;
  flex: 1;
}

.tab-content {
  display: none;

}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Hero Section */
.search-hero {
  text-align: center;
  margin-bottom: 32px;
}

.search-hero h2 {
  font-family: 'Outfit', sans-serif;
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}

.search-hero p {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 24px;
}

.search-box-wrapper {
  max-width: 680px;
  margin: 0 auto 20px;
  display: flex;
  gap: 8px;
  background: white;
  padding: 6px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--card-border);
}

.search-box-wrapper input {
  flex: 1;
  border: none;
  outline: none;
  padding: 12px 18px;
  font-size: 16px;
}

.search-box-wrapper button {
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 0 28px;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.2s ease;
}

.search-box-wrapper button:hover {
  background: var(--primary-hover);
}

/* Filter Chips */
.filter-chips-container {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 900px;
  margin: 0 auto;
}

.chip {
  border: 1px solid var(--card-border);
  background: white;
  color: var(--text-muted);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chip:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.chip.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* Stats Bar */
.stats-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: var(--radius-md);
  border: 1px solid var(--card-border);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}

.patch-filter-dropdown select {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-border);
  outline: none;
  font-size: 14px;
}

/* Cards Grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 20px;
}

.symptom-card {
  background: var(--card-bg);
  backdrop-filter: blur(8px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
}

.symptom-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.card-expand-btn {
  background: none;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 12px;
  color: #64748b;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}
.card-expand-btn:hover {
  background: #f1f5f9;
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.other-patches-section {
  margin-top: 12px;
  border-top: 1px dashed #e2e8f0;
  padding-top: 10px;
}
.other-patches-label {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 8px;
}
.patch-item-other {
  opacity: 0.8;
  border-left-color: #94a3b8;
}

.card-category-tag {
  background: #e0f2fe;
  color: #0369a1;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
}

.card-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
}

.card-aliases {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.patches-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
}

.patch-item {
  background: white;
  padding: 12px;
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--primary-color);
  font-size: 14px;
}

.patch-item-name {
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
}

.patch-item-acu {
  color: #0284c7;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
}

.patch-item-note {
  font-size: 12px;
  color: var(--text-muted);
}

/* AI Chat TAB */
.ai-chat-container {
  max-width: 800px;
  margin: 0 auto;
}

.ai-hero {
  text-align: center;
  margin-bottom: 24px;
}

.ai-hero h2 {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 8px;
}

.chat-input-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--card-border);
  margin-bottom: 20px;
}

.chat-input-card textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  font-size: 15px;
  padding: 8px;
  color: var(--text-main);
}

.chat-action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #f1f5f9;
}

.tip {
  font-size: 12px;
  color: var(--text-muted);
}

#ai-analyze-btn {
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.3);
  transition: transform 0.2s ease;
}

#ai-analyze-btn:hover {
  transform: scale(1.02);
}

.prompt-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 24px;
  font-size: 13px;
  color: var(--text-muted);
}

.example-btn {
  background: white;
  border: 1px solid var(--card-border);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-main);
  transition: background 0.2s ease;
}

.example-btn:hover {
  background: #f1f5f9;
}

.ai-result-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--card-border);
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f1f5f9;
}

.status-tag {
  background: #dcfce7;
  color: #15803d;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
}

.result-content {
  font-size: 15px;
  line-height: 1.8;
}

.result-content p { margin: 0 0 8px; }
.result-content h3 { font-size: 17px; color: var(--primary-color); margin: 16px 0 8px; }
.result-content h4 { font-size: 15px; color: #0369a1; margin: 14px 0 6px; }
.result-content ul, .result-content ol { padding-left: 20px; margin: 6px 0 10px; }
.result-content li { margin-bottom: 4px; }
.result-content hr { border: none; border-top: 1px solid #e2e8f0; margin: 12px 0; }
.result-content code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 13px; }

/* AI 回覆內的表格 */
.result-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 16px;
  font-size: 14px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.result-content th {
  background: #0ea5e9;
  color: white;
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
}
.result-content td {
  padding: 8px 12px;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: top;
}
.result-content tr:nth-child(even) td { background: #f8fafc; }
.result-content tr:last-child td { border-bottom: none; }

/* Protocols Grid */
.protocols-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.protocol-card {
  background: white;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.protocol-card h3 {
  font-size: 18px;
  color: var(--primary-color);
  margin-bottom: 8px;
}

.detox-section-card {
  background: linear-gradient(135deg, #fff7ed, #fff);
  border: 1px solid #fed7aa;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

/* Admin CMS Table */
.admin-header-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
  background: white;
  padding: 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--card-border);
}

.admin-actions-bar {
  display: flex;
  gap: 10px;
}

.btn-primary { background: var(--primary-color); color: white; border: none; padding: 10px 18px; border-radius: var(--radius-sm); font-weight: 600; cursor: pointer; }
.btn-success { background: #10b981; color: white; border: none; padding: 10px 18px; border-radius: var(--radius-sm); font-weight: 600; cursor: pointer; }
.btn-warning { background: #f59e0b; color: white; border: none; padding: 10px 18px; border-radius: var(--radius-sm); font-weight: 600; cursor: pointer; }
.btn-secondary { background: #e2e8f0; color: var(--text-main); border: none; padding: 10px 18px; border-radius: var(--radius-sm); font-weight: 600; cursor: pointer; }

.admin-table-wrapper {
  background: white;
  border-radius: var(--radius-md);
  border: 1px solid var(--card-border);
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  text-align: left;
}

.admin-table th, .admin-table td {
  padding: 14px 18px;
  border-bottom: 1px solid #f1f5f9;
}

.admin-table th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
}

.admin-table tr:hover {
  background: #f8fafc;
}

/* Modals & Toast */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.hidden { display: none !important; }

.modal-card {
  background: white;
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 600px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

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

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 14px;
}

.form-group input, .form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  outline: none;
  font-size: 14px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: #0f172a;
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 2000;
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 24px;
  border-top: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.6);
  font-size: 13px;
  color: var(--text-muted);
}

.disclaimer-text {
  max-width: 900px;
  margin: 8px auto 0;
  font-size: 12px;
  color: #94a3b8;
}

/* AI Engine Config Card (Admin Tab) */
.ai-config-card {
  background: white;
  border-radius: var(--radius-md);
  padding: 24px;
  margin-bottom: 24px;
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-md);
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 8px;
}

.card-title-row h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* Toggle Switch */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.toggle-switch input {
  display: none;
}

.slider {
  width: 46px;
  height: 24px;
  background-color: #cbd5e1;
  border-radius: 24px;
  position: relative;
  transition: 0.3s;
}

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

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

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

.toggle-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

/* Config Grid & Form Fields */
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.config-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.config-group.full-width {
  grid-column: 1 / -1;
}

.config-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.config-group input[type="text"],
.config-group input[type="password"],
.config-group textarea {
  padding: 10px 14px;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.config-group input:focus, .config-group textarea:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(8, 102, 255, 0.1);
}

.input-with-btn {
  display: flex;
  gap: 8px;
}

.input-with-btn input {
  flex: 1;
}

.btn-sm {
  padding: 8px 12px;
  font-size: 12px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

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

.field-hint {
  font-size: 12px;
  color: #64748b;
}

.preset-links {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.preset-links span {
  font-size: 12px;
  color: var(--text-muted);
}

.preset-btn {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 12px;
  color: #334155;
  cursor: pointer;
  transition: all 0.2s;
}

.preset-btn:hover {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.config-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px dashed #e2e8f0;
}

/* Chat Buttons Group */
.chat-btn-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-secondary-sm {
  background: #e2e8f0;
  color: #334155;
  border: none;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-secondary-sm:hover {
  background: #cbd5e1;
}

.engine-tag-llm {
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  color: white;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.engine-tag-rule {
  background: #0284c7;
  color: white;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

/* Blurred Overlay for Unauthenticated Main Content */
.app-main.blurred {
  filter: blur(8px);
  pointer-events: none;
  user-select: none;
}

/* Provider Pipeline Item Card */
.provider-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 16px;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.provider-card:hover {
  border-color: #cbd5e1;
  box-shadow: var(--shadow-sm);
}

.provider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
}

.provider-priority-badge {
  background: linear-gradient(135deg, #0284c7, #2563eb);
  color: white;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 12px;
}

.provider-priority-badge.backup {
  background: linear-gradient(135deg, #f59e0b, #d97706);
}

.provider-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-icon {
  background: white;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}

.btn-icon:hover {
  background: #f1f5f9;
}


