/* AIFA Mobile UI Stylesheet */
:root {
  --bg: #f4f6fb;
  --bg-card: #ffffff;
  --bg-card-sub: #f8fafc;
  --border: #e2e8f0;
  --border-focus: #3b82f6;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-sub: #eff6ff;
  --success: #10b981;
  --success-sub: #ecfdf5;
  --warning: #f59e0b;
  --warning-sub: #fffbeb;
  --danger: #ef4444;
  --danger-sub: #fef2f2;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, 0.08);
  --font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[x-cloak] { display: none !important; }

/* Main App Shell */
.mobile-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: calc(72px + var(--safe-bottom));
}

/* Sticky Mobile Topbar */
.mobile-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge .logo {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge .sub-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-card-sub);
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
  display: inline-block;
}

.refresh-icon-btn, .icon-btn {
  background: none;
  border: 1px solid var(--border);
  padding: 8px;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  min-width: 44px;
  min-height: 44px;
}

.refresh-icon-btn:active, .icon-btn:active {
  background: var(--bg-card-sub);
  transform: scale(0.96);
}

.auth-badge-btn {
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-sub);
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: 14px;
  padding: 4px 10px;
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Content Container */
.mobile-content {
  padding: 14px 14px 20px;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
}

/* Card Container */
.m-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 14px;
}

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

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

.m-card-title::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 16px;
  background: var(--primary);
  border-radius: 2px;
}

.m-card-badge {
  font-size: 12px;
  font-weight: 500;
  color: var(--primary);
  background: var(--primary-sub);
  padding: 2px 8px;
  border-radius: 10px;
}

/* Stat Grid */
.stat-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.stat-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.stat-box {
  background: var(--bg-card-sub);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  text-align: center;
}

.stat-box .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-box .stat-val {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.stat-box .stat-sub {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 4px;
}

/* Chip list for engines / vendors - Min Touch Height 44px */
.chips-flex {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chip-item {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-card-sub);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 44px;
}

.chip-item .chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
}

.chip-item .chip-val {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 12px;
}

.chip-item.is-active, .chip-item.is-selected {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.chip-item.is-active .chip-dot, .chip-item.is-selected .chip-dot {
  background: #fff;
}

.chip-item.is-active .chip-val, .chip-item.is-selected .chip-val {
  color: #fff;
}

/* Form Controls - Input / Select / Textarea Font Size >= 16px and Min Height >= 44px */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

input, select, textarea, .m-input, .m-textarea, .m-select {
  font-size: 16px !important;
  font-family: inherit;
}

.m-input, .m-select {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px !important;
  color: var(--text-main);
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  min-height: 44px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.m-input:focus, .m-textarea:focus, .m-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.m-textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px !important;
  color: var(--text-main);
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  resize: vertical;
  min-height: 88px;
  line-height: 1.5;
  transition: border-color 0.15s, box-shadow 0.15s;
}

/* Action Buttons - Min Touch Height >= 44px */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.m-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 44px;
}

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

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

.m-btn-outline {
  background: #fff;
  border-color: var(--border);
  color: var(--text-main);
}

.m-btn-outline:active {
  background: var(--bg-card-sub);
}

.m-btn-stop {
  background: var(--danger-sub);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.3);
}

.m-btn-stop:active {
  background: var(--danger);
  color: #fff;
}

.m-btn-ghost {
  background: transparent;
  color: var(--primary);
  border-color: transparent;
  padding: 8px 12px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.m-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* Distill Word Tags - Touch Friendly */
.word-pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 380px;
  overflow-y: auto;
  padding: 4px;
}

.word-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card-sub);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.4;
  min-height: 44px;
}

.word-pill:active {
  border-color: var(--primary);
  background: var(--primary-sub);
  color: var(--primary);
}

.word-pill .jump-icon {
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  background: var(--primary-sub);
  padding: 3px 6px;
  border-radius: 4px;
}

/* Distill relation view */
.distill-view-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 4px 0 12px;
}

.distill-toggle-btn {
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card-sub);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.distill-toggle-btn.is-active {
  border-color: var(--primary);
  background: var(--primary-sub);
  color: var(--primary);
}

.distill-tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.distill-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card-sub);
  color: var(--text-main);
  font-size: 13px;
  cursor: pointer;
  max-width: 100%;
}

.distill-tag-chip span:first-child {
  overflow-wrap: anywhere;
}

.distill-tag-chip.is-active {
  border-color: #22d3ee;
  background: rgba(34, 211, 238, 0.12);
  color: var(--text-main);
}

.distill-tag-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-light);
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 7px;
  border-radius: 999px;
}

.distill-graph-wrap {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  margin-bottom: 12px;
}

.distill-graph-svg-host {
  width: 100%;
  overflow: hidden;
  border-radius: 16px;
  background: linear-gradient(160deg, #122039, #0a1222);
  border: 1px solid #253650;
}

.distill-focus-svg {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  touch-action: manipulation;
}

.distill-edge {
  stroke: rgba(148, 163, 184, 0.35);
  stroke-width: 1.5;
}

.distill-hit {
  fill: transparent;
  pointer-events: all;
}

.distill-face {
  stroke-width: 1.5;
}

.distill-node.kind-center .distill-face {
  fill: #2563eb;
  stroke: #93c5fd;
}

.distill-node.kind-tag .distill-face {
  fill: #0e7490;
  stroke: #67e8f9;
}

.distill-node.kind-question .distill-face {
  fill: #15803d;
  stroke: #86efac;
}

.distill-node.is-selected .distill-face {
  fill: #ea580c;
  stroke: #fdba74;
}

.distill-node-label,
.distill-node-count {
  fill: #e2e8f0;
  font-size: 14px;
  pointer-events: none;
}

.distill-node-count {
  font-size: 13px;
  font-weight: 700;
  fill: #f8fafc;
}

.distill-empty {
  color: var(--text-light);
  font-size: 13px;
  padding: 16px 8px;
  text-align: center;
  line-height: 1.5;
}

.distill-linked-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.distill-q-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card-sub);
  overflow: hidden;
}

.distill-q-card.is-active {
  border-color: #fb923c;
}

.report-material-item {
  display: block;
  padding: 12px 14px;
  min-height: 44px;
}

.report-material-item.is-muted {
  opacity: 0.78;
}

.report-material-item.is-locked {
  pointer-events: none;
  opacity: 0.65;
}

.report-material-check {
  width: 20px;
  height: 20px;
  min-width: 20px;
  margin-top: 2px;
  flex-shrink: 0;
}

.report-material-answer {
  margin-top: 6px;
  max-height: 4.5em;
  overflow: hidden;
  overflow-wrap: anywhere;
  white-space: normal;
}

.report-cite-line {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.report-materials-list .distill-q-text {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.distill-q-main {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: inherit;
  padding: 12px 14px;
  min-height: 44px;
  cursor: pointer;
}

.distill-q-text {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-main);
  overflow-wrap: anywhere;
  white-space: normal;
}

.distill-q-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.distill-mini-tag {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
}

.distill-mini-tag.muted {
  background: rgba(148, 163, 184, 0.12);
  color: #94a3b8;
}

.distill-q-actions {
  display: flex;
  gap: 8px;
  padding: 0 12px 12px;
  flex-wrap: wrap;
}

.distill-q-actions .m-btn {
  flex: 1;
  min-width: 120px;
}

/* Probing Animation */
.probe-loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px 20px;
  background: var(--bg-card-sub);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
  text-align: center;
  margin: 14px 0;
}

.probe-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 14px;
}

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

.probe-pulse-bar {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin: 12px 0;
  position: relative;
}

.probe-pulse-bar::after {
  content: "";
  position: absolute;
  left: -30%;
  width: 40%;
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  animation: pulseMove 1.4s infinite ease-in-out;
}

@keyframes pulseMove {
  0% { left: -30%; }
  100% { left: 100%; }
}

/* Citations Result List */
.citation-card {
  background: var(--bg-card-sub);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  transition: border-color 0.15s;
}

.citation-card:active {
  border-color: var(--primary);
}

.citation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.citation-idx {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-sub);
  padding: 1px 6px;
  border-radius: 4px;
}

.citation-domain {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.citation-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.4;
  margin-bottom: 4px;
}

.citation-link {
  font-size: 13px;
  color: var(--primary);
  word-break: break-all;
  text-decoration: none;
  display: block;
  min-height: 24px;
}

/* Answer Excerpt Card */
.answer-box {
  background: var(--bg-card-sub);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
}

/* Report View Specific Styles */
.report-banner {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  color: #fff;
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 14px;
}

.report-banner h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
  line-height: 1.3;
}

.report-banner .banner-sub {
  font-size: 12px;
  color: #94a3b8;
  margin-bottom: 10px;
}

.report-banner .banner-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
}

.report-banner .banner-stat-chip {
  background: rgba(255, 255, 255, 0.1);
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

/* Next Sample Scheduling Box */
.scheduling-box {
  background: var(--primary-sub);
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 14px;
}

.scheduling-box .task-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

.scheduling-box .task-desc {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  word-break: break-all;
}

/* Tables and Mobile Scroll Containers */
.table-scroll-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 10px -16px;
  padding: 0 16px;
}

.m-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
}

.m-table th, .m-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.m-table th {
  background: var(--bg-card-sub);
  font-weight: 600;
  color: var(--text-muted);
}

.m-table tr:last-child td {
  border-bottom: none;
}

/* byEngine Cards */
.engine-card {
  background: var(--bg-card-sub);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 12px;
}

.engine-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-weight: 700;
  font-size: 14px;
  color: var(--text-main);
}

/* Collapsible Sample Items */
details.sample-details {
  background: var(--bg-card-sub);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
}

details.sample-details summary {
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 32px;
}

details.sample-details summary::-webkit-details-marker {
  display: none;
}

details.sample-details[open] {
  border-color: var(--primary);
}

details.sample-details[open] summary {
  margin-bottom: 10px;
  color: var(--primary);
}

/* Toast Message */
.m-toast {
  position: fixed;
  top: calc(56px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: rgba(15, 23, 42, 0.9);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  transition: opacity 0.2s;
  white-space: nowrap;
}

/* Auth Modal Overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 440px;
  padding: 20px;
}

/* Bottom Navigation Bar - Height and Touch Target */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 999;
  height: calc(60px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.03);
}

.nav-tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 100%;
  min-height: 44px;
  color: var(--text-muted);
  text-decoration: none;
  border: none;
  background: none;
  cursor: pointer;
  padding: 4px 0;
  transition: color 0.15s ease, transform 0.15s ease;
}

.nav-tab-item .nav-icon {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-tab-item .nav-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-tab-item .nav-label {
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
}

.nav-tab-item.active {
  color: var(--primary);
}

.nav-tab-item:active {
  transform: scale(0.92);
}

/* Simple Trend Sparkline on Mobile */
.trend-summary-chart {
  width: 100%;
  height: 160px;
  margin-top: 8px;
}

/* Responsive tweaks */
@media (min-width: 640px) {
  .mobile-content {
    padding: 20px 24px;
  }
  .stat-grid-2 {
    grid-template-columns: repeat(4, 1fr);
  }
}

.distill-node:focus-visible .distill-face { stroke: #fff; stroke-width: 3; }
.distill-toggle-btn:focus-visible, .distill-tag-chip:focus-visible, .distill-q-main:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
