:root {
  color-scheme: light;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --accent-strong: #115e59;
  --warning: #92400e;
  --warning-soft: #fffbeb;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(204, 251, 241, 0.7), transparent 32rem),
    #f3f5f7;
  line-height: 1.55;
}

button, input { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 42px 0 64px;
}

.hero { max-width: 780px; margin-bottom: 24px; }
.eyebrow, .section-kicker {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.eyebrow {
  display: inline-flex;
  padding: 5px 9px;
  border: 1px solid #99f6e4;
  border-radius: 999px;
  background: rgba(240, 253, 250, 0.84);
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 12px; font-size: clamp(2rem, 5vw, 4.2rem); line-height: 1.05; letter-spacing: -0.04em; }
h2 { margin-bottom: 4px; font-size: 1.25rem; line-height: 1.2; }
h3 { margin: 0; font-size: 1.05rem; line-height: 1.25; }
.hero-tagline { margin: 0 0 10px; color: var(--accent-strong); font-size: 1.35rem; font-weight: 800; letter-spacing: -0.01em; }
.hero-copy { max-width: 650px; color: var(--muted); font-size: 1.05rem; }

.privacy-note {
  display: flex;
  gap: 12px;
  align-items: baseline;
  margin: 0 0 20px;
  padding: 14px 16px;
  border: 1px solid #99f6e4;
  border-radius: 14px;
  color: #134e4a;
  background: rgba(240, 253, 250, 0.9);
  box-shadow: 0 8px 22px rgba(15, 118, 110, 0.06);
}
.privacy-note strong { white-space: nowrap; }

.panel {
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.source-panel, .cleanup-panel { padding: 22px; }
.panel-heading { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 18px; }
.panel-heading.compact { align-items: center; margin-bottom: 14px; }
.muted, .helper-text { color: var(--muted); }
.muted { margin: 6px 0 0; font-size: 0.9rem; }
.helper-text { margin: 10px 0 0; font-size: 0.86rem; }
.helper-text.error { color: #b91c1c; }

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}
.status-pill.error { color: #991b1b; background: #fee2e2; }

.source-modes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 14px;
  padding: 0;
  border: 0;
}
.source-modes legend { margin-bottom: 8px; color: var(--muted); font-size: 0.82rem; font-weight: 750; }
.mode-option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}
.mode-option:hover, .mode-option:has(input:checked) { border-color: #5eead4; background: #f0fdfa; }
.mode-option:has(input:checked) { box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.1); }
.mode-option.recommended { border-color: #5eead4; background: #f0fdfa; }
.mode-option input { flex: 0 0 auto; margin: 3px 0 0; accent-color: var(--accent); }
.mode-option strong, .mode-option small { display: block; }
.mode-option-title { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.mode-option strong { color: var(--accent-strong); font-size: 0.9rem; }
.mode-option small { margin-top: 2px; color: var(--muted); font-size: 0.78rem; line-height: 1.45; }
.mode-recommended { padding: 2px 6px; border-radius: 999px; color: #0f766e; background: #ccfbf1; font-size: 0.68rem; font-weight: 800; line-height: 1.2; }
.source-mode-guidance { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0 0 14px; }
.source-mode-guidance article { padding: 12px 14px; border-left: 3px solid #bae6fd; border-radius: 0 10px 10px 0; background: #f8fafc; }
.source-mode-guidance strong, .source-mode-guidance span { display: block; }
.source-mode-guidance strong { color: #334155; font-size: 0.82rem; }
.source-mode-guidance span { margin-top: 3px; color: var(--muted); font-size: 0.78rem; line-height: 1.45; }
.source-mode-guidance code { padding: 1px 4px; border-radius: 5px; color: #334155; background: #e2e8f0; font-size: 0.92em; }
.path-hint code { overflow-wrap: anywhere; word-break: break-word; }
.mode-option code, .picker-detail code { padding: 1px 4px; border-radius: 5px; color: #334155; background: #e2e8f0; font-size: 0.92em; }

.folder-picker {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 22px;
  border: 1.5px dashed #5eead4;
  border-radius: 14px;
  color: var(--accent-strong);
  background: #f0fdfa;
  transition: background 160ms ease, border-color 160ms ease;
}
.folder-picker:hover { border-color: var(--accent); background: #ccfbf1; }
.folder-picker:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.14); }
.folder-picker input { margin-top: 10px; color: var(--ink); }
.folder-picker input::file-selector-button {
  margin-right: 10px;
  padding: 8px 12px;
  border: 1px solid #99f6e4;
  border-radius: 8px;
  color: var(--accent-strong);
  background: white;
  font-weight: 750;
  cursor: pointer;
}
.picker-title { font-weight: 800; }
.picker-detail { color: #475569; font-size: 0.9rem; }

.cli-help {
  margin-top: 14px;
  padding: 14px 16px;
  border: 1px solid #bae6fd;
  border-radius: 12px;
  color: #334155;
  background: #f0f9ff;
  font-size: 0.86rem;
  line-height: 1.55;
}
.cli-help strong { color: #075985; }
.cli-help p { margin: 5px 0; }
.cli-help code { padding: 1px 4px; border-radius: 5px; background: #e0f2fe; overflow-wrap: anywhere; }
.cli-help pre {
  margin: 10px 0;
  padding: 12px;
  overflow-x: auto;
  border-radius: 9px;
  color: #e0f2fe;
  background: #0f172a;
  font-size: 0.78rem;
  line-height: 1.55;
}
.cli-help pre code { padding: 0; color: inherit; background: transparent; white-space: pre; }
.cli-help a { color: #0369a1; font-weight: 700; }

.status-area { min-height: 28px; margin-top: 16px; font-size: 0.9rem; }
.status-area.error { color: #b91c1c; }
.progress-track { height: 5px; overflow: hidden; border-radius: 999px; background: #e2e8f0; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width 180ms ease; }

.workspace { margin-top: 22px; }
.feature-section { margin-top: 24px; }
.feature-section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin: 0 0 12px;
  padding: 0 2px;
}
.feature-section-heading .section-kicker { margin-bottom: 4px; }
.feature-section-heading h2 { margin: 0; font-size: 1.4rem; }
.browse-feature-section .content-grid { margin: 0; }
.advanced-feature-section .insight-panel { margin: 0; }
.advanced-feature-section .diff-panel { margin-top: 18px; }
.hidden { display: none !important; }
.diff-panel { margin-top: 18px; padding: 22px; }
.diff-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) auto; gap: 10px; align-items: end; }
.diff-controls .folder-picker { min-height: 0; padding: 14px; }
.diff-controls .button { min-height: 48px; }
.insight-panel { margin-bottom: 18px; padding: 22px; }
.insight-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.insight-card { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-soft); }
.insight-card-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 9px; }
.insight-card-heading h3 { margin: 0; font-size: 0.98rem; }
.mini-badge { padding: 3px 7px; border-radius: 999px; color: #475569; background: #e2e8f0; font-size: 0.7rem; white-space: nowrap; }
.insight-controls { display: flex; gap: 7px; }
.insight-controls input { min-width: 0; flex: 1; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: white; }
.insight-controls .button { padding: 8px 10px; }
.insight-filter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.insight-filter-grid label { display: grid; gap: 4px; color: var(--muted); font-size: .76rem; font-weight: 700; }
.insight-filter-grid select, .insight-filter-grid input { width: 100%; min-width: 0; box-sizing: border-box; }
.insight-results { max-height: 260px; overflow: auto; }
.health-list { display: grid; gap: 5px; margin: 0; font-size: 0.8rem; }
.health-list div { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px solid #e2e8f0; padding-bottom: 4px; }
.health-list dt { color: var(--muted); }
.health-list dd { max-width: 68%; margin: 0; overflow: hidden; text-overflow: ellipsis; text-align: right; white-space: nowrap; }
.health-warning { margin: 9px 0 0; color: var(--warning); font-size: 0.78rem; }
.search-result { display: flex; width: 100%; flex-direction: column; gap: 1px; padding: 8px 9px; border: 0; border-bottom: 1px solid #e2e8f0; color: var(--ink); text-align: left; background: transparent; }
.search-result:hover { background: #ecfdf5; }
.search-result strong { overflow: hidden; color: var(--accent-strong); text-overflow: ellipsis; white-space: nowrap; }
.search-result span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result small, .timeline-event small, .timeline-event em { color: var(--muted); font-size: 0.72rem; }
.schema-select { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--muted); font-size: 0.8rem; }
.schema-select select { min-width: 0; flex: 1; padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.schema-meta, .schema-indexes, .diff-summary { margin: 5px 0 8px; color: var(--muted); font-size: 0.74rem; }
.schema-scroll { overflow: auto; max-height: 188px; }
.schema-table { width: 100%; border-collapse: collapse; font-size: 0.72rem; }
.schema-table th, .schema-table td { max-width: 160px; padding: 5px 6px; border-bottom: 1px solid #e2e8f0; overflow: hidden; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.schema-table th { position: sticky; top: 0; background: var(--surface-soft); }
.chat-evidence { margin-top: 6px; color: var(--muted); font-size: 0.74rem; }
.chat-evidence details { border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.chat-evidence summary { cursor: pointer; padding: 6px 8px; color: var(--ink); font-weight: 650; }
.chat-evidence ul { margin: 0; padding: 0 10px 8px 26px; }
.chat-evidence li { margin-top: 3px; }
.timeline-note { margin: 3px 0 7px; color: var(--muted); font-size: 0.76rem; }
.timeline-event { display: flex; gap: 8px; align-items: flex-start; padding: 7px 0; border-bottom: 1px solid #e2e8f0; }
.timeline-dot { flex: 0 0 auto; width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; background: #f59e0b; }
.timeline-dot.burst { background: #14b8a6; }
.timeline-event div { min-width: 0; }
.timeline-event strong, .timeline-event small, .timeline-event em { display: block; }
.timeline-event em { font-style: normal; }
.duplicate-tools { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.duplicate-group { padding: 9px 0; border-bottom: 1px solid #e2e8f0; font-size: 0.8rem; }
.duplicate-group > div { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.duplicate-group ul { margin: 6px 0 4px; padding-left: 18px; color: #475569; font-size: 0.75rem; }
.duplicate-group small { color: var(--muted); font-size: 0.72rem; }
.diff-item { display: grid; grid-template-columns: 120px minmax(0, 1fr) 160px; gap: 8px; padding: 7px 0; border-bottom: 1px solid #e2e8f0; font-size: 0.78rem; }
.diff-item span, .diff-item small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.diff-item small { color: var(--muted); }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat-card { padding: 16px 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04); }
.stat-card span { display: block; color: var(--muted); font-size: 0.82rem; }
.stat-card strong { display: block; margin-top: 5px; font-size: 1.5rem; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }

.content-grid { display: grid; grid-template-columns: minmax(250px, 320px) minmax(0, 1fr); gap: 18px; align-items: stretch; }
.chat-panel, .messages-panel { height: 720px; min-height: 0; padding: 18px; }
.chat-panel { display: flex; flex-direction: column; }
.search-box input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; outline: none; background: var(--surface-soft); }
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.16); }
.chat-list { display: flex; min-height: 0; flex: 1 1 auto; flex-direction: column; gap: 4px; margin-top: 12px; }
.chat-pagination { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }
.chat-pagination .button { padding: 7px 9px; font-size: 0.8rem; }
.page-info { min-width: 112px; color: var(--muted); font-size: 0.78rem; text-align: center; }
.chat-item { display: block; width: 100%; padding: 10px 11px; border: 0; border-radius: 10px; color: var(--ink); text-align: left; background: transparent; }
.chat-item:hover { background: #f0fdfa; }
.chat-item.selected { color: var(--accent-strong); background: var(--accent-soft); }
.chat-item-title { display: block; overflow: hidden; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 2px; color: var(--muted); font-size: 0.75rem; }
.empty-state { display: grid; min-height: 220px; place-items: center; padding: 22px; color: var(--muted); text-align: center; }

.button-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.button { border: 1px solid transparent; border-radius: 9px; padding: 9px 13px; font-weight: 750; transition: transform 120ms ease, background 120ms ease; }
.button:focus-visible, input:focus-visible { outline: 3px solid rgba(20, 184, 166, 0.35); outline-offset: 2px; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: 0.45; }
.button-primary { color: white; background: var(--accent); }
.button-primary:hover:not(:disabled) { background: var(--accent-strong); }
.button-secondary { border-color: #cbd5e1; color: #334155; background: white; }
.button-secondary:hover:not(:disabled) { background: #f8fafc; }
.button-quiet { padding: 6px 9px; color: var(--muted); background: transparent; }

.message-status { min-height: 26px; color: var(--muted); font-size: 0.84rem; }
.messages-panel { display: flex; flex-direction: column; }
.message-list { min-height: 0; flex: 1 1 auto; overflow: auto; padding: 4px 4px 12px; border-top: 1px solid var(--line); }
.message-row { display: flex; gap: 10px; margin: 12px 4px; }
.message-row.self { justify-content: flex-end; }
.message-row.self .message-card { border-color: #99f6e4; background: #f0fdfa; }
.message-row.system { justify-content: center; }
.message-row.system .message-card { max-width: min(680px, 94%); border-style: dashed; color: var(--muted); background: #f8fafc; }
.message-card { max-width: min(780px, 90%); padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.message-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; color: var(--muted); font-size: 0.74rem; }
.message-sender { color: #334155; font-weight: 750; }
.message-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-text a { color: var(--accent-strong); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.message-call { margin: 0; color: var(--accent-strong); font-weight: 750; }
.message-call.unanswered { color: #b45309; }
.message-kind { margin: 0; color: #92400e; font-size: 0.86rem; }
.message-coordinates { margin: 4px 0 0; color: var(--muted); font-size: 0.78rem; }
.link-previews { display: grid; gap: 8px; margin-top: 9px; }
.link-preview { display: grid; grid-template-columns: minmax(0, 1fr) minmax(120px, 34%); overflow: hidden; border: 1px solid #dbe4ea; border-radius: 10px; color: inherit; text-decoration: none; background: #f8fafc; transition: border-color 120ms ease, transform 120ms ease; }
.link-preview:hover { border-color: #94a3b8; transform: translateY(-1px); }
.link-preview:focus-visible { outline: 3px solid rgba(20, 184, 166, 0.35); outline-offset: 2px; }
.link-preview.no-image { grid-template-columns: minmax(0, 1fr); }
.link-preview-content { display: block; min-width: 0; padding: 9px 10px; }
.link-preview-domain { display: block; overflow: hidden; color: var(--muted); font-size: 0.7rem; font-weight: 750; letter-spacing: 0.04em; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.link-preview-title { display: -webkit-box; overflow: hidden; margin-top: 2px; overflow-wrap: anywhere; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.link-preview-summary { display: -webkit-box; overflow: hidden; margin-top: 3px; color: var(--muted); font-size: 0.76rem; overflow-wrap: anywhere; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.link-preview img { display: block; width: 100%; height: 100%; min-height: 104px; max-height: 150px; object-fit: cover; background: #e2e8f0; }
.message-media { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 8px; margin-top: 9px; }
.message-image { min-width: 0; margin: 0; }
.message-image-button { display: block; width: 100%; overflow: hidden; padding: 0; border: 0; border-radius: 9px; background: #e2e8f0; }
.message-image-button:focus-visible { outline: 3px solid rgba(20, 184, 166, 0.48); outline-offset: 3px; }
.message-image img { display: block; width: 100%; max-width: 520px; max-height: 520px; margin: auto; object-fit: contain; }
.message-image figcaption { margin-top: 4px; color: var(--muted); font-size: 0.72rem; }
.message-image.preview-error img { min-height: 80px; padding: 16px; object-fit: contain; }
.message-attachments { margin: 9px 0 0; padding-left: 20px; color: var(--accent-strong); font-size: 0.84rem; }
.message-attachments a { color: inherit; overflow-wrap: anywhere; }
.message-attachments small { color: var(--muted); }
.load-more { display: block; margin: 12px auto 0; }

.cleanup-panel { margin-top: 18px; }
.cleanup-guide { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 16px; padding: 0; list-style: none; }
.cleanup-guide li { position: relative; min-width: 0; padding: 12px 12px 12px 46px; border: 1px solid #dbe4ea; border-radius: 12px; background: #f8fafc; }
.cleanup-guide li > span { position: absolute; top: 12px; left: 12px; display: grid; width: 25px; height: 25px; place-items: center; border-radius: 50%; color: white; background: var(--accent); font-size: 0.76rem; font-weight: 850; }
.cleanup-guide strong, .cleanup-guide small { display: block; }
.cleanup-guide strong { color: #334155; font-size: 0.84rem; }
.cleanup-guide small { margin-top: 2px; color: var(--muted); font-size: 0.74rem; line-height: 1.4; }
.cleanup-warning { display: flex; gap: 10px; align-items: baseline; margin-bottom: 16px; padding: 12px 14px; border: 1px solid #fde68a; border-radius: 12px; color: var(--warning); background: var(--warning-soft); font-size: 0.86rem; }
.cleanup-warning strong { white-space: nowrap; }
.cleanup-warning code { padding: 1px 4px; border-radius: 5px; background: #fef3c7; font-size: 0.92em; }
.cleanup-toolbar { display: flex; align-items: center; flex-wrap: wrap; justify-content: space-between; gap: 10px 14px; margin-bottom: 12px; }
.cleanup-search { flex: 1 1 auto; max-width: 620px; }
.cleanup-filter, .cleanup-select { display: flex; flex: 0 0 auto; align-items: center; gap: 7px; color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.cleanup-filter select, .cleanup-select select { min-width: 142px; min-height: 42px; padding: 8px 32px 8px 10px; border: 1px solid var(--line); border-radius: 10px; color: #334155; outline: none; background: white; }
.cleanup-filter select:focus, .cleanup-select select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.16); }
.cleanup-summary { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px; color: var(--muted); font-size: 0.84rem; white-space: nowrap; }
.cleanup-summary strong { color: var(--accent-strong); font-variant-numeric: tabular-nums; }
.attachment-category-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-bottom: 12px; }
.attachment-category-card { display: flex; min-height: 62px; flex-direction: column; justify-content: center; gap: 2px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 11px; color: var(--ink); text-align: left; background: var(--surface-soft); }
.attachment-category-card:hover, .attachment-category-card.active { border-color: #5eead4; color: var(--accent-strong); background: #f0fdfa; box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.08); }
.attachment-category-card strong { font-size: 0.82rem; }
.attachment-category-card span { color: var(--muted); font-size: 0.72rem; font-variant-numeric: tabular-nums; }
.attachment-category-card.active span { color: var(--accent); }
.cleanup-result-info { min-height: 20px; margin: 0 0 8px; color: var(--muted); font-size: 0.8rem; }
.attachment-cleanup-list { border: 1px solid var(--line); border-radius: 14px; background: #f8fafc; }
.cleanup-group-list { display: grid; gap: 8px; padding: 10px; }
.cleanup-group-card { overflow: hidden; border: 1px solid #dbe4ea; border-radius: 12px; background: white; box-shadow: 0 3px 10px rgba(15, 23, 42, 0.025); }
.cleanup-group-card.special { border-color: #fbbf24; background: #fffbeb; }
.cleanup-group-card.special.unconfirmed { border-color: #cbd5e1; background: #f8fafc; }
.cleanup-group-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
.cleanup-group-open-button { display: grid; grid-template-columns: auto minmax(0, 1fr); width: 100%; gap: 12px; align-items: center; padding: 13px 8px 13px 14px; border: 0; color: inherit; text-align: left; cursor: pointer; background: transparent; }
.cleanup-group-open-button:hover { background: #f8fafc; }
.cleanup-group-card.special .cleanup-group-open-button:hover { background: rgba(254, 243, 199, 0.54); }
.cleanup-group-open-button:focus-visible { outline: 3px solid rgba(20, 184, 166, 0.32); outline-offset: -3px; }
.cleanup-group-actions { display: flex; gap: 6px; align-items: center; padding: 0 14px 0 0; }
.cleanup-group-action-button, .cleanup-group-view-button { border: 0; cursor: pointer; font: inherit; }
.cleanup-group-action-button.is-delete { color: #b91c1c; background: #fee2e2; }
.cleanup-group-action-button.is-cancel { color: #475569; background: #e2e8f0; }
.cleanup-group-action-button.is-delete:hover { background: #fecaca; }
.cleanup-group-action-button.is-cancel:hover { background: #cbd5e1; }
.cleanup-group-main { display: grid; min-width: 0; gap: 4px; }
.cleanup-group-heading { display: flex; min-width: 0; flex-wrap: wrap; gap: 7px; align-items: center; }
.cleanup-group-heading strong { overflow: hidden; color: #334155; font-size: 0.9rem; text-overflow: ellipsis; white-space: nowrap; }
.cleanup-group-main small { overflow: hidden; color: var(--muted); font-size: 0.72rem; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.cleanup-group-main > span:last-child { color: var(--muted); font-size: 0.75rem; }
.cleanup-group-main b { color: #c2410c; }
.cleanup-group-open { padding: 6px 9px; border-radius: 8px; color: var(--accent-strong); background: var(--accent-soft); font-size: 0.74rem; font-weight: 800; white-space: nowrap; }
.cleanup-chat-group + .cleanup-chat-group { border-top: 6px solid #e2e8f0; }
.cleanup-chat-header { position: sticky; z-index: 3; top: 0; display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; gap: 11px; align-items: center; padding: 13px 14px; border-bottom: 1px solid #dbe4ea; background: rgba(255, 255, 255, 0.97); box-shadow: 0 5px 16px rgba(15, 23, 42, 0.05); backdrop-filter: blur(8px); }
.cleanup-back-button { white-space: nowrap; }
.cleanup-chat-avatar { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 12px; color: var(--accent-strong); background: var(--accent-soft); font-size: 0.82rem; font-weight: 850; }
.cleanup-chat-title { min-width: 0; }
.cleanup-chat-title > div { display: flex; min-width: 0; flex-wrap: wrap; gap: 7px; align-items: center; }
.cleanup-chat-title h3 { overflow: hidden; margin: 0; font-size: 0.98rem; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.cleanup-chat-title p { margin: 3px 0 0; color: var(--muted); font-size: 0.75rem; }
.cleanup-chat-title p strong { color: #c2410c; }
.cleanup-chat-type { padding: 2px 7px; border-radius: 999px; color: #475569; background: #f1f5f9; font-size: 0.68rem; font-weight: 750; }
.cleanup-review-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 12px; }
.cleanup-review-card { display: grid; grid-template-columns: 128px minmax(0, 1fr); min-width: 0; overflow: hidden; border: 1px solid #dbe4ea; border-radius: 13px; background: white; box-shadow: 0 4px 12px rgba(15, 23, 42, 0.035); }
.cleanup-preview { position: relative; display: grid; min-height: 168px; place-items: center; overflow: hidden; color: #64748b; background: linear-gradient(145deg, #e2e8f0, #f8fafc); font-size: 0.72rem; font-weight: 850; letter-spacing: 0.06em; }
.cleanup-preview img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; }
.cleanup-preview .cleanup-preview-fallback { display: grid; width: 56px; height: 56px; place-items: center; border: 1px solid #cbd5e1; border-radius: 13px; background: rgba(255, 255, 255, 0.72); }
.cleanup-preview.preview-error img { display: none; }
.cleanup-review-context { min-width: 0; padding: 12px; }
.cleanup-message-meta { display: flex; min-width: 0; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 0.72rem; }
.cleanup-message-meta span:first-child { overflow: hidden; color: #334155; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.cleanup-message-meta time { flex: 0 0 auto; }
.cleanup-message-meta.uncertain { flex-wrap: wrap; color: #b45309; }
.cleanup-message-meta.uncertain span:first-child { color: #b45309; }
.cleanup-message-summary { display: -webkit-box; overflow: hidden; min-height: 42px; margin: 5px 0 10px; color: #334155; font-size: 0.82rem; line-height: 1.45; overflow-wrap: anywhere; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.cleanup-file-choices { display: grid; gap: 6px; }
.cleanup-file-choice { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: flex-start; padding: 9px; border: 1px solid #e2e8f0; border-radius: 10px; transition: border-color 120ms ease, background 120ms ease; }
.cleanup-file-choice:hover { border-color: #fdba74; }
.cleanup-file-choice:has(input:checked) { border-color: #fb923c; background: #fff7ed; box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.08); }
.cleanup-file-choice input { margin: 4px 0 0; accent-color: #c2410c; }
.cleanup-file-choice-main { min-width: 0; }
.cleanup-file-title { display: flex; min-width: 0; flex-wrap: wrap; gap: 5px; align-items: center; }
.cleanup-file-title strong { overflow: hidden; max-width: 100%; color: #334155; font-size: 0.78rem; text-overflow: ellipsis; white-space: nowrap; }
.cleanup-kind-badge { flex: 0 0 auto; padding: 1px 5px; border-radius: 5px; color: #1e40af; background: #dbeafe; font-size: 0.62rem; font-weight: 800; }
.cleanup-kind-badge.thumbnail { color: #6d28d9; background: #ede9fe; }
.cleanup-file-choice-main > small { display: block; margin-top: 2px; color: var(--muted); font-size: 0.69rem; }
.cleanup-impact { display: block; margin-top: 4px; color: #92400e; font-size: 0.68rem; line-height: 1.35; }
.cleanup-delete-label { align-self: center; color: #c2410c; cursor: pointer; font-size: 0.68rem; font-weight: 800; white-space: nowrap; }
.cleanup-path { margin-top: 5px; color: var(--muted); font-size: 0.66rem; }
.cleanup-path summary { width: max-content; cursor: pointer; }
.cleanup-path code { display: block; max-height: 68px; margin-top: 4px; overflow: auto; padding: 5px 6px; border-radius: 6px; color: #475569; background: #f1f5f9; overflow-wrap: anywhere; white-space: normal; }
.attachment-pagination { margin-top: 0; border-top: 0; }
.cleanup-export-row { margin-top: 16px; }

body.package-modal-open, body.load-modal-open { overflow: hidden; }
body.image-modal-open { overflow: hidden; }

.image-modal {
  position: fixed;
  z-index: 1100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
}
.image-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(5px);
}
.image-modal-card {
  position: relative;
  display: grid;
  max-width: min(1100px, 100%);
  max-height: 100%;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.94);
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.4);
}
.image-modal-card:focus { outline: none; }
.image-modal-card img {
  display: block;
  width: auto;
  max-width: min(100%, 1000px);
  max-height: min(78vh, 820px);
  margin: auto;
  object-fit: contain;
}
.image-modal-close {
  justify-self: end;
  min-height: 36px;
  padding: 7px 11px;
  border: 0;
  border-radius: 8px;
  color: #e2e8f0;
  background: rgba(51, 65, 85, 0.9);
  font: inherit;
}
.image-modal-close:hover { background: #475569; }
.image-modal-caption {
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  color: #cbd5e1;
  font-size: 0.78rem;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.package-modal {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
}
.package-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.56);
  backdrop-filter: blur(5px);
}
.package-modal-card {
  position: relative;
  width: min(100%, 440px);
  padding: 30px;
  border: 1px solid rgba(153, 246, 228, 0.8);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.28);
  text-align: center;
}
.package-modal-card:focus { outline: none; }
.package-modal-state {
  display: grid;
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  place-items: center;
  border-radius: 50%;
  color: var(--accent-strong);
  background: var(--accent-soft);
}
.package-modal-spinner {
  width: 26px;
  height: 26px;
  border: 3px solid rgba(15, 118, 110, 0.22);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: package-modal-spin 760ms linear infinite;
}
.package-modal .section-kicker { margin-bottom: 6px; }
.package-modal h2 { margin-bottom: 8px; font-size: 1.45rem; }
.package-modal-message {
  min-height: 3.15em;
  margin: 0;
  color: var(--muted);
  font-size: 0.94rem;
}
.package-modal-progress-track {
  height: 10px;
  margin-top: 20px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2e8f0;
}
.package-modal-progress {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #2dd4bf);
  transition: width 180ms ease;
}
.package-modal-progress-label {
  margin: 8px 0 0;
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.package-modal-close {
  min-width: 132px;
  margin-top: 22px;
}
.package-modal.is-success .package-modal-card { border-color: #86efac; }
.package-modal.is-success .package-modal-state {
  color: #15803d;
  background: #dcfce7;
}
.package-modal.is-success .package-modal-spinner {
  width: 25px;
  height: 14px;
  border: 0;
  border-bottom: 4px solid currentColor;
  border-left: 4px solid currentColor;
  border-radius: 0;
  transform: translateY(-2px) rotate(-45deg);
  animation: none;
}
.package-modal.is-success .package-modal-progress { background: #22c55e; }
.package-modal.is-success .package-modal-progress-label { color: #15803d; }
.package-modal.is-error .package-modal-card { border-color: #fecaca; }
.package-modal.is-error .package-modal-state {
  color: #b91c1c;
  background: #fee2e2;
}
.package-modal.is-error .package-modal-spinner {
  position: relative;
  width: 26px;
  height: 26px;
  border: 0;
  animation: none;
}
.package-modal.is-error .package-modal-spinner::before,
.package-modal.is-error .package-modal-spinner::after {
  position: absolute;
  top: 11px;
  left: 1px;
  width: 24px;
  height: 4px;
  border-radius: 999px;
  background: currentColor;
  content: "";
}
.package-modal.is-error .package-modal-spinner::before { transform: rotate(45deg); }
.package-modal.is-error .package-modal-spinner::after { transform: rotate(-45deg); }
.package-modal.is-error .package-modal-progress { background: #ef4444; }
.package-modal.is-error .package-modal-progress-label { color: #b91c1c; }

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


.app-footer { display: flex; justify-content: space-between; gap: 16px; width: min(1440px, calc(100% - 32px)); margin: 0 auto; padding: 0 0 30px; color: var(--muted); font-size: 0.8rem; }
.app-footer-credits a { color: var(--accent-strong); text-decoration: none; font-weight: 600; }
.app-footer-credits a:hover { text-decoration: underline; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
  .insight-grid { grid-template-columns: 1fr; }
  .diff-controls { grid-template-columns: 1fr; }
  .content-grid { grid-template-columns: 1fr; }
  .chat-panel { height: auto; min-height: 0; }
  .chat-list { height: 280px; flex: 0 1 auto; max-height: 280px; }
  .messages-panel { height: 560px; min-height: 0; }
  .cleanup-review-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .app-shell { width: min(100% - 20px, 1440px); padding-top: 24px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .source-modes { grid-template-columns: 1fr; }
  .source-mode-guidance { grid-template-columns: 1fr; }
  .panel-heading, .panel-heading.compact, .app-footer { align-items: flex-start; flex-direction: column; }
  .button-row { justify-content: flex-start; }
  .privacy-note { align-items: flex-start; flex-direction: column; gap: 2px; }
  .cleanup-toolbar { align-items: stretch; flex-direction: column; }
  .cleanup-search { max-width: none; }
  .cleanup-guide { grid-template-columns: 1fr; }
  .cleanup-filter, .cleanup-select { justify-content: space-between; }
  .cleanup-filter select, .cleanup-select select { flex: 1 1 auto; }
  .attachment-category-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cleanup-summary { justify-content: flex-start; white-space: normal; }
  .cleanup-warning { align-items: flex-start; flex-direction: column; gap: 2px; }
  .cleanup-group-row { grid-template-columns: 1fr; }
  .cleanup-group-open-button { padding: 13px 14px 7px; }
  .cleanup-group-actions { justify-content: flex-end; padding: 0 14px 11px; }
  .cleanup-chat-header { grid-template-columns: auto minmax(0, 1fr); }
  .cleanup-back-button { grid-column: 1 / -1; justify-content: flex-start; }
  .cleanup-back-button { width: max-content; }
  .cleanup-review-grid { padding: 8px; }
  .cleanup-review-card { grid-template-columns: 96px minmax(0, 1fr); }
  .cleanup-preview { min-height: 150px; }
  .cleanup-file-choice { grid-template-columns: auto minmax(0, 1fr); }
  .cleanup-delete-label { grid-column: 2; }
  .app-footer { width: calc(100% - 20px); }
}

@media (max-width: 420px) {
  .attachment-category-summary { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .package-modal-spinner { animation-duration: 1ms; animation-iteration-count: 1; }
  .package-modal-progress { transition: none; }
}
