:root {
  --primary-color: #2b5c8f;
  --primary-hover: #1e4268;
  --text-main: #333333;
  --text-muted: #666666;
  --bg-color: #f5f7fa;
  --card-bg: #ffffff;
  --border-color: #e2e8f0;
  --border-radius: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Microsoft YaHei", sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.6;
}

/* Header */
.app-header {
  background-color: var(--primary-color);
  color: white;
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
}

.header-content h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.tagline {
  font-size: 0.9rem;
  opacity: 0.8;
}

/* Layout */
.app-container {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1rem;
}

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

@media (min-width: 768px) {
  .layout-grid {
    grid-template-columns: 350px 1fr;
  }
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}

.card h2 {
  margin-bottom: 1.5rem;
  font-size: 1.25rem;
  color: var(--primary-color);
}

.output-card {
  min-height: 500px;
}

/* Forms */
.form-group {
  margin-bottom: 1.25rem;
}

.form-row-parallel {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.form-row-parallel .form-group {
  margin-bottom: 0;
}

.book-hint {
  font-size: 0.85rem;
  padding: 10px 14px;
  border-radius: var(--border-radius);
  margin-bottom: 1.25rem;
  background-color: #f0f7ff;
  color: #1e4268;
  border: 1px solid #c8e1f8;
  line-height: 1.5;
}

.book-hint strong {
  color: #0b4f8a;
}

.book-hint ul {
  margin: 6px 0 2px 18px;
  padding: 0;
}

.book-hint li {
  margin-bottom: 3px;
  color: #334155;
}

:root[data-theme="dark"] .book-hint {
  background-color: #1e293b;
  color: #93c5fd;
  border: 1px solid #3b82f6;
}

:root[data-theme="dark"] .book-hint strong {
  color: #60a5fa;
}

:root[data-theme="dark"] .book-hint li {
  color: #cbd5e1;
}

.flex-1 {
  flex: 1;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

input[type="text"],
input[type="password"],
select {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-family: inherit;
  font-size: 1rem;
  transition: border-color 0.2s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary-color);
}

/* Collapsible */
.collapsible {
  margin-bottom: 1.5rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.5rem;
}

summary {
  cursor: pointer;
  font-weight: 600;
  padding: 0.5rem;
}

/* Buttons */
button {
  cursor: pointer;
  font-family: inherit;
  border: none;
  border-radius: 4px;
  transition: background-color 0.2s, color 0.2s;
}

.btn-primary {
  width: 100%;
  background-color: var(--primary-color);
  color: white;
  padding: 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

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

.btn-primary:disabled {
  background-color: var(--text-muted);
  cursor: not-allowed;
}

.btn-secondary {
  background-color: white;
  color: var(--primary-color);
  border: 1px solid var(--primary-color);
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}

.btn-secondary:hover {
  background-color: var(--bg-color);
}

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
}

.tab-btn {
  background: none;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  border-radius: 0;
}

.tab-btn.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
  font-weight: 600;
}

.tab-content {
  display: none;
}

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

/* Utilities */
.hidden {
  display: none !important;
}

/* Status Spinner */
#status-container {
  text-align: center;
  padding: 3rem 0;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 1rem;
}

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

#status-text {
  color: var(--text-muted);
  font-weight: 500;
}

/* Report Output */
.report-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.source-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background-color: #e0f2fe;
  color: #0369a1;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
}

.badge-success {
  background-color: #dcfce7;
  color: #15803d;
}

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

.badge-error, .badge-danger {
  background-color: #fee2e2;
  color: #b91c1c;
}

.badge-neutral {
  background-color: #f1f5f9;
  color: #64748b;
}

.badge-info {
  background-color: #e0f2fe;
  color: #0369a1;
}

.btn-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.75rem;
  margin-bottom: 0.5rem;
}

.btn-row button {
  flex: 1;
  text-align: center;
}

.model-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  cursor: pointer;
  padding: 0.6rem 0.85rem;
  background: var(--bg-surface-alt, #f8fafc);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 6px;
  transition: all 0.2s ease;
}

.model-summary:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

details[open] > .model-summary {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.model-summary-main {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
}

.model-summary-title {
  font-weight: 600;
  color: var(--text-color, #1e293b);
}

.model-summary-desc {
  color: var(--primary-color, #2563eb);
  font-weight: 500;
}

.model-summary-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-summary-action {
  font-size: 0.75rem;
  color: var(--text-muted, #64748b);
}

.model-config-body {
  padding: 0.85rem;
  border: 1px solid var(--border-color, #e2e8f0);
  border-top: none;
  border-bottom-left-radius: 6px;
  border-bottom-right-radius: 6px;
  background: var(--bg-surface, #fff);
}

.api-key-status-text {
  font-size: 0.8rem;
  font-weight: normal;
  color: var(--text-muted);
}

.form-help-text {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.auth-switch-link {
  margin-top: 1.25rem;
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.auth-switch-link a {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 600;
  margin-left: 6px;
}

.auth-switch-link a:hover {
  text-decoration: underline;
}

/* In-page Alerts */
.alert-msg {
  padding: 0.75rem 1rem;
  border-radius: var(--border-radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: break-word;
}

.alert-msg.error {
  background-color: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-msg.success {
  background-color: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.alert-msg.warning {
  background-color: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
}

.alert-msg.info {
  background-color: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 380px;
  width: calc(100% - 40px);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 12px 16px;
  border-radius: var(--border-radius);
  font-size: 0.9rem;
  box-shadow: var(--shadow-md);
  background-color: var(--card-bg);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  transition: opacity 0.3s ease, transform 0.3s ease;
  animation: toast-in 0.3s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.toast-success {
  border-left: 4px solid #16a34a;
}

.toast-error {
  border-left: 4px solid #dc2626;
}

.toast-warning {
  border-left: 4px solid #d97706;
}

.toast-info {
  border-left: 4px solid #2563eb;
}

.user-email-text {
  font-size: 0.9rem;
  font-weight: 500;
  color: white;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Markdown Styles */
.markdown-body {
  line-height: 1.8;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3 {
  color: var(--primary-color);
  margin-top: 1.5rem;
  margin-bottom: 1rem;
}

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

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

.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--border-color);
  margin: 2rem 0;
}

#empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 0;
}

/* History List */
.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  margin-bottom: 1rem;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  background-color: var(--card-bg, #ffffff);
}

.history-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  border-color: var(--primary-color);
}

.history-info {
  flex: 1;
  min-width: 0;
}

.history-title {
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 0.25rem;
  word-break: break-word;
}

.history-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.history-download-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--border-radius, 6px);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}

.history-download-btn:hover {
  background-color: var(--primary-color);
  color: #ffffff;
  border-color: var(--primary-color);
}

/* Login Overlay Styles */
.login-overlay {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}
.login-overlay.hidden {
  display: none !important;
}
.login-modal {
  width: 400px;
  max-width: 90vw;
  padding: 30px;
}
.login-modal h2 {
  margin-top: 0;
  text-align: center;
  margin-bottom: 20px;
}
.error-msg {
  color: #d32f2f;
  margin-bottom: 15px;
  font-size: 0.9em;
  text-align: center;
}
.header-titles {
  display: flex;
  flex-direction: column;
}
.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.user-controls {
  display: flex;
  align-items: center;
  gap: 15px;
  color: white;
}
.btn-small {
  padding: 4px 10px;
  font-size: 0.85em;
}

/* Dark Mode */
:root[data-theme="dark"] {
  --primary-color: #3b82f6;
  --primary-hover: #2563eb;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --bg-color: #0f172a;
  --card-bg: #1e293b;
  --border-color: #334155;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.5);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.5);
}

body {
  transition: background-color 0.3s ease, color 0.3s ease;
}

.card {
  transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

:root[data-theme="dark"] .alert-msg.error {
  background-color: #450a0a;
  color: #fca5a5;
  border: 1px solid #7f1d1d;
}

:root[data-theme="dark"] .alert-msg.success {
  background-color: #052e16;
  color: #86efac;
  border: 1px solid #14532d;
}

:root[data-theme="dark"] .alert-msg.warning {
  background-color: #451a03;
  color: #fde047;
  border: 1px solid #78350f;
}

:root[data-theme="dark"] .alert-msg.info {
  background-color: #172554;
  color: #93c5fd;
  border: 1px solid #1e3a8a;
}

:root[data-theme="dark"] .badge-success {
  background-color: #064e3b;
  color: #86efac;
}

:root[data-theme="dark"] .badge-warning {
  background-color: #78350f;
  color: #fcd34d;
}

:root[data-theme="dark"] .badge-error,
:root[data-theme="dark"] .badge-danger {
  background-color: #7f1d1d;
  color: #fca5a5;
}

:root[data-theme="dark"] .badge-neutral {
  background-color: #334155;
  color: #94a3b8;
}

/* Coverage Chart Styles */
.bar {
  fill: var(--primary-color);
}
.bar:hover {
  fill: var(--primary-hover);
}
.axis-label {
  fill: var(--text-main);
  font-size: 12px;
}
.axis path,
.axis line {
  stroke: var(--border-color);
}

.tooltip {
  position: absolute;
  text-align: left;
  padding: 8px;
  font-size: 12px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  pointer-events: none;
  opacity: 0;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
  z-index: 1000;
}

/* Directory Tree Selector Component */
.admin-tree-container {
  border: 1px solid var(--border-color, #cbd5e1);
  border-radius: 6px;
  background: var(--bg-surface, #fff);
  overflow: hidden;
  margin-top: 4px;
}

.admin-tree-filter-box {
  padding: 6px 8px;
  background: var(--bg-muted, #f8fafc);
  border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.admin-tree-search-input {
  width: 100%;
  padding: 6px 10px;
  font-size: 0.8rem;
  border: 1px solid var(--border-color, #cbd5e1);
  border-radius: 4px;
  background: #fff;
  box-sizing: border-box;
}

.admin-tree-viewport {
  max-height: 240px;
  overflow-y: auto;
  padding: 4px 0;
}

.tree-branch-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: #f1f5f9;
  font-size: 0.82rem;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
  border-top: 1px solid #e2e8f0;
  border-bottom: 1px solid #e2e8f0;
  user-select: none;
}

.tree-branch-header:first-child {
  border-top: none;
}

.tree-branch-header:hover {
  background: #e2e8f0;
}

.tree-branch-toggle {
  display: inline-block;
  transition: transform 0.2s ease;
  font-size: 0.72rem;
  margin-right: 6px;
}

.tree-branch-toggle.collapsed {
  transform: rotate(-90deg);
}

.tree-branch-items {
  padding: 2px 0;
}

.tree-branch-items.collapsed {
  display: none;
}

.tree-leaf-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 12px 5px 22px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.tree-leaf-item:hover {
  background: #eff6ff;
}

.tree-leaf-item.selected {
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 600;
  border-left: 3px solid #2563eb;
}

.tree-leaf-badge {
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 10px;
  background: #e2e8f0;
  color: #475569;
}

.tree-leaf-item.selected .tree-leaf-badge {
  background: #bfdbfe;
  color: #1e40af;
}

.admin-tree-selected-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: #f8fafc;
  border-top: 1px solid var(--border-color, #e2e8f0);
  font-size: 0.8rem;
}

.selected-target-hint {
  color: var(--text-muted, #64748b);
  font-size: 0.78rem;
}

.selected-target-pill {
  display: inline-block;
  background: #e0f2fe;
  color: #0369a1;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
  border: 1px solid #bae6fd;
}
