:root {
  --ink: #1b1d1c;
  --muted: #686d69;
  --line: #dfe2df;
  --line-strong: #c9ceca;
  --paper: #f7f8f6;
  --surface: #ffffff;
  --charcoal: #202421;
  --green: #277554;
  --green-hover: #1d6245;
  --green-soft: #e9f2ed;
  --amber: #97620b;
  --amber-soft: #fff5dd;
  --danger: #a43d38;
  --danger-soft: #fbeceb;
  --radius: 6px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color: var(--ink); background: var(--paper); font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 15px; letter-spacing: 0; }
body { margin: 0; min-height: 100vh; background: var(--paper); }
.search-body { height: 100vh; height: 100dvh; overflow: hidden; }
button, input, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .55; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
a { color: inherit; text-decoration: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.topbar { height: 58px; display: flex; align-items: center; justify-content: space-between; padding: 0 max(20px, calc((100vw - 920px) / 2)); border-bottom: 1px solid var(--line); background: rgba(247,248,246,.96); }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 5px; background: var(--charcoal); color: white; font-size: 13px; }
.quiet-link { color: var(--muted); font-size: 13px; padding: 8px 0; }
.quiet-link:hover { color: var(--ink); }
.search-shell { width: min(900px, calc(100% - 32px)); height: calc(100vh - 58px); height: calc(100dvh - 58px); display: flex; flex-direction: column; margin: 0 auto; padding: 22px 0 0; overflow: hidden; }
.search-form { width: min(680px, 100%); flex: 0 0 auto; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; margin: 0 auto; }
.search-input-wrap { position: relative; min-width: 0; }
.search-input-wrap input { width: 100%; }
.search-suggestions { position: absolute; z-index: 8; top: calc(100% + 6px); left: 0; right: 0; max-height: min(280px, 42vh); overflow-y: auto; padding: 4px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); box-shadow: 0 10px 28px rgba(22,35,27,.14); }
.search-suggestion { width: 100%; min-height: 34px; display: block; overflow: hidden; border: 0; border-radius: 4px; padding: 7px 10px; background: transparent; color: var(--ink); text-align: left; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.search-suggestion:hover, .search-suggestion.is-active { background: var(--green-soft); color: var(--green-hover); }
input, select { min-width: 0; height: 42px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--ink); padding: 0 12px; outline: none; }
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(39,117,84,.11); }
input:disabled, select:disabled { cursor: not-allowed; background: #eef0ee; color: var(--muted); }
.search-form input { height: 44px; font-size: 16px; padding: 0 15px; }
.primary-button, .secondary-button { height: 40px; border-radius: var(--radius); padding: 0 16px; border: 1px solid transparent; font-weight: 650; white-space: nowrap; }
.primary-button { background: var(--green); color: white; }
.primary-button:hover { background: var(--green-hover); }
.search-form .primary-button { height: 44px; min-width: 92px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.button-spinner { width: 15px; height: 15px; flex: 0 0 auto; border: 2px solid rgba(255,255,255,.42); border-top-color: currentColor; border-radius: 50%; animation: spin .7s linear infinite; }
.button-spinner.dark { border-color: #d9ddda; border-top-color: var(--green); }
.secondary-button { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.secondary-button:hover { border-color: #9ea49f; background: #fafbfa; }
.search-meta { flex: 0 0 auto; display: flex; justify-content: space-between; align-items: center; min-height: 36px; color: var(--muted); font-size: 12px; margin-top: 12px; }
.state-dot { display: inline-flex; align-items: center; gap: 7px; }
.state-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.state-dot.done::before { background: #a9afaa; }
.result-viewport { flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding: 0 2px 20px; }
.search-footer { flex: 0 0 auto; min-height: 34px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; white-space: nowrap; }
.backup-links { display: flex; align-items: center; flex-wrap: nowrap; gap: 12px; }
.backup-links span, .backup-links a { white-space: nowrap; }
.backup-label-short { display: none; }
.backup-links a { color: var(--green); text-decoration: underline; text-decoration-color: #aec7bb; text-underline-offset: 3px; }
.backup-links a:hover { color: var(--green-hover); text-decoration-color: currentColor; }
.search-progress { position: sticky; z-index: 2; top: 0; min-height: 36px; display: flex; align-items: center; gap: 9px; padding: 0 12px; border-top: 1px solid var(--line); color: var(--muted); background: #f1f4f1; font-size: 12px; }
.progress-spinner { width: 13px; height: 13px; flex: 0 0 auto; border: 2px solid #d4dbd6; border-top-color: var(--green); border-radius: 50%; animation: spin .75s linear infinite; }
.notice { border-left: 3px solid; padding: 10px 12px; margin: 14px 0 0; font-size: 13px; }
.warning { color: #744d0b; background: var(--amber-soft); border-color: var(--amber); }
.result-list { background: var(--surface); }
.result-list.has-results { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.result-row { width: 100%; min-height: 76px; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 18px; align-items: center; padding: 14px 16px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; color: var(--ink); animation: result-in .24s ease-out both; animation-delay: var(--enter-delay, 0ms); content-visibility: auto; contain-intrinsic-size: auto 76px; }
.result-row:last-child { border-bottom: 0; }
.result-row:hover, .result-row:focus-visible { background: #f1f5f2; }
.result-row:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
.result-row:disabled { cursor: wait; opacity: 1; }
.result-row.is-transferring { background: var(--green-soft); }
.result-body { min-width: 0; }
.result-title { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; line-height: 1.45; }
.result-meta { display: flex; align-items: center; gap: 9px; min-width: 0; margin-top: 7px; color: var(--muted); font-size: 12px; }
.source-label { color: var(--green); font-weight: 650; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-action { min-width: 54px; color: var(--green); font-size: 12px; font-weight: 650; text-align: right; }
.empty-state { height: 100%; min-height: 260px; display: grid; place-content: center; justify-items: center; color: var(--muted); }
.empty-state p { margin: 12px 0 0; }
.empty-symbol { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 6px; font-weight: 700; color: var(--green); }
.skeleton { height: 78px; border-bottom: 1px solid var(--line); padding: 20px 14px; }
.skeleton::before, .skeleton::after { content: ""; display: block; height: 10px; border-radius: 3px; background: #e8ebe8; animation: pulse 1.1s ease-in-out infinite alternate; }
.skeleton::before { width: 67%; }.skeleton::after { width: 30%; margin-top: 11px; }
@keyframes pulse { to { opacity: .45; } }
@keyframes result-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
.sentinel { height: 1px; }
.load-more { margin: 22px auto 0; align-items: center; justify-content: center; gap: 8px; }
.load-more:not([hidden]) { display: flex; }
.transfer-dialog { width: min(430px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow: auto; border: 1px solid var(--line-strong); border-radius: 8px; padding: 36px 30px 32px; color: var(--ink); text-align: center; box-shadow: 0 18px 60px rgba(18,25,20,.18); }
.transfer-dialog:not([open]) { display: none; }
.transfer-dialog::backdrop { background: rgba(22,25,23,.46); }
.transfer-dialog h2 { margin: 18px 0 8px; font-size: 24px; line-height: 1.25; }
.transfer-dialog p { min-height: 24px; margin: 0; color: var(--muted); font-size: 15px; line-height: 1.6; }
.dialog-close { position: absolute; top: 9px; right: 9px; width: 32px; height: 32px; border: 0; background: transparent; color: var(--muted); font-size: 22px; }
.spinner { width: 40px; height: 40px; margin: 0 auto; border: 4px solid #dfe7e2; border-top-color: var(--green); border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.dialog-actions { margin-top: 20px; }
.dialog-actions .primary-button { min-width: 108px; }
.transfer-wait-body { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 24px; background: var(--paper); }
.transfer-wait { width: min(560px, 100%); text-align: center; }
.transfer-wait-indicator { position: relative; display: grid; place-items: center; width: 104px; height: 104px; margin: 0 auto 30px; }
.transfer-wait-indicator::before, .transfer-wait-indicator::after { content: ""; position: absolute; inset: 0; border: 3px solid #dce5df; border-top-color: var(--green); border-radius: 50%; animation: spin 1s linear infinite; }
.transfer-wait-indicator::after { inset: 11px; border-color: #e7ebe8; border-bottom-color: #8bad9d; animation-direction: reverse; animation-duration: 1.4s; }
.transfer-wait-indicator span { position: relative; z-index: 1; display: grid; place-items: center; width: 52px; height: 52px; border-radius: 7px; background: var(--charcoal); color: white; font-size: 21px; font-weight: 750; }
.transfer-wait h1 { margin: 0; font-size: 34px; line-height: 1.25; }
.transfer-wait p { min-height: 28px; margin: 14px 0 0; color: var(--muted); font-size: 17px; line-height: 1.6; }
.transfer-wait-error { color: var(--danger) !important; white-space: pre-wrap; }
.transfer-wait .primary-button { margin-top: 20px; min-width: 108px; }
.loading-dots::after { content: ""; display: inline-block; width: 1.5em; text-align: left; animation: loading-dots 1.2s steps(4,end) infinite; }
.transfer-wait-progress { width: min(360px, 78vw); height: 5px; margin: 30px auto 0; overflow: hidden; border-radius: 3px; background: #dfe5e1; }
.transfer-wait-progress span { display: block; width: 42%; height: 100%; background: var(--green); animation: loading-progress 1.5s ease-in-out infinite; }
@keyframes loading-dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75%, 100% { content: "..."; } }
@keyframes loading-progress { from { transform: translateX(-110%); } to { transform: translateX(350%); } }
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 20; transform: translateX(-50%); max-width: min(520px, calc(100% - 32px)); padding: 11px 14px; border-radius: 5px; background: var(--charcoal); color: white; box-shadow: 0 8px 24px rgba(0,0,0,.18); }

.admin-body { background: var(--surface); }
.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--paper); }
.login-panel { width: min(360px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.login-panel h1 { margin: 32px 0 22px; font-size: 21px; }
.login-panel label { display: grid; gap: 7px; margin: 14px 0; color: var(--muted); font-size: 13px; }
.full-button { width: 100%; margin-top: 10px; }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 9px 10px; font-size: 13px; border-radius: 4px; }
.admin-layout { min-height: 100vh; grid-template-columns: 220px minmax(0,1fr); }
.admin-sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 20px 14px; border-right: 1px solid var(--line); background: var(--paper); }
.admin-sidebar .brand { padding: 0 8px 22px; }
.admin-nav { display: grid; gap: 3px; }
.nav-item { height: 38px; border: 0; border-radius: 5px; padding: 0 10px; background: transparent; color: var(--muted); text-align: left; font-weight: 550; }
.nav-item:hover { background: #ecefec; color: var(--ink); }
.nav-item.active { color: var(--green); background: var(--green-soft); }
.logout-button { margin-top: auto; }
.admin-main { min-width: 0; padding: 28px 34px 60px; }
.admin-header { min-height: 68px; display: flex; align-items: flex-start; justify-content: space-between; border-bottom: 1px solid var(--line); margin-bottom: 26px; }
.eyebrow { margin: 0 0 5px; color: var(--muted); font-size: 12px; }
.admin-header h1 { margin: 0; font-size: 22px; }
.save-status { color: var(--green); font-size: 13px; padding-top: 12px; }
.admin-view { max-width: 1040px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.stat { min-height: 108px; padding: 20px; border-right: 1px solid var(--line); background: var(--surface); }
.stat:last-child { border-right: 0; }.stat span { color: var(--muted); font-size: 13px; }.stat strong { display: block; margin-top: 10px; font-size: 25px; font-variant-numeric: tabular-nums; }
.settings-section { margin-top: 26px; border-top: 1px solid var(--line); }
.section-heading { min-height: 74px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.section-heading h2 { margin: 0; font-size: 16px; }.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.maintenance-actions { display: flex; gap: 8px; }
.field-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 18px; padding-bottom: 22px; }
.field-grid label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }.wide-field { grid-column: 1 / -1; }
.compact-fields { margin-top: 16px; max-width: 520px; }
.mail-advanced-fields { max-width: none; grid-template-columns: repeat(4,minmax(0,1fr)); }
.setting-row { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-top: 1px solid var(--line); }
.setting-row strong { display: block; font-size: 14px; }.setting-row div span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.switch { position: relative; flex: 0 0 auto; width: 38px; height: 22px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { display: block; width: 38px; height: 22px; border-radius: 11px; background: #c9ceca; transition: .16s; }
.switch span::after { content: ""; position: absolute; width: 18px; height: 18px; top: 2px; left: 2px; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: .16s; }
.switch input:checked + span { background: var(--green); }.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 3px solid rgba(39,117,84,.16); }
.form-footer { position: sticky; z-index: 4; bottom: 0; display: flex; justify-content: flex-end; padding: 14px 0 12px; border-top: 1px solid var(--line); background: var(--surface); }
.sources-view { max-width: none; }
.tg-source-form { width: min(620px,100%); display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; margin-bottom: 14px; }
.tg-source-form .primary-button { height: 42px; }
.source-toolbar { display: grid; grid-template-columns: minmax(180px,1fr) 150px 150px auto auto; gap: 8px; }
.source-summary { height: 44px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; }
.source-table-head { height: 34px; display: grid; grid-template-columns: minmax(0,1fr) 92px 64px 70px 52px 38px; gap: 8px; align-items: center; padding: 0 12px; border: 1px solid var(--line); border-bottom: 0; border-radius: 6px 6px 0 0; background: var(--paper); color: var(--muted); font-size: 11px; font-weight: 650; }
.source-table-head span:nth-last-child(-n+2) { text-align: right; }
.source-viewport { height: min(586px, calc(100vh - 310px)); min-height: 326px; overflow: auto; border: 1px solid var(--line); border-radius: 0 0 6px 6px; background: var(--surface); }
.source-viewport:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.source-spacer { position: relative; width: 100%; }.source-rows { position: absolute; top: 0; left: 0; right: 0; }
.source-row { height: 46px; display: grid; grid-template-columns: minmax(0,1fr) 92px 64px 70px 52px 38px; gap: 8px; align-items: center; padding: 0 12px; border-bottom: 1px solid var(--line); }
.source-row:hover { background: #f6f8f6; }
.source-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.source-kind { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.source-health { font-size: 12px; color: var(--muted); }
.source-health.ok { color: var(--green); }.source-health.error { color: var(--danger); }.source-health.checking { color: #8b6418; }
.source-failures { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.source-row .switch { transform: scale(.9); transform-origin: right center; }
.source-action { display: flex; justify-content: flex-end; }
.source-delete { width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 20px; line-height: 1; }
.source-delete:hover { background: var(--danger-soft); color: var(--danger); }
.save-status.error { color: var(--danger); }

@media (max-width: 760px) {
  .topbar { padding-right: max(16px, env(safe-area-inset-right)); padding-left: max(16px, env(safe-area-inset-left)); }
  .search-shell { width: calc(100% - 24px); padding-top: 16px; }
  .search-form { grid-template-columns: minmax(0, 1fr) 74px; }
  .search-form .primary-button { min-width: 0; }
  .search-meta { margin-top: 10px; }
  .result-viewport { padding-bottom: 14px; scrollbar-gutter: auto; }
  .search-footer { min-height: 36px; flex-direction: row; gap: 6px; padding: 0 2px; font-size: 10px; }
  .backup-links { gap: 6px; }
  .backup-label-full { display: none; }
  .backup-label-short { display: inline; }
  .result-row { min-height: 74px; padding-left: 12px; padding-right: 12px; gap: 8px; }
  .result-title { white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  .source-label { max-width: 135px; }
  .admin-layout { grid-template-columns: 1fr; }
  .admin-sidebar { position: sticky; z-index: 5; height: auto; display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .admin-sidebar .brand { display: none; }
  .admin-nav { display: grid; grid-template-columns: repeat(3,1fr); gap: 4px; }
  .nav-item { text-align: center; padding: 0 5px; font-size: 13px; }
  .logout-button { position: static; width: auto; height: 38px; margin: 0 0 0 6px; padding: 0 8px; }
  .admin-main { padding: 20px 16px 50px; }
  .admin-header { min-height: 58px; margin-bottom: 20px; }
  .stats-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .stat:nth-child(2) { border-right: 0; }.stat:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .field-grid { grid-template-columns: 1fr; }.wide-field { grid-column: auto; }
  .mail-advanced-fields { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .source-toolbar { grid-template-columns: 1fr 1fr; }
  .source-toolbar input { grid-column: 1 / -1; }
  .source-toolbar button { padding: 0 8px; }
  .source-table-head { grid-template-columns: minmax(0,1fr) 82px 52px 38px 32px; }
  .source-table-head span:nth-child(4) { display: none; }
  .source-viewport { height: calc(100dvh - 390px); min-height: 260px; }
	.source-row { grid-template-columns: minmax(0,1fr) 82px 52px 38px 32px; }
	.source-row .source-kind { display: none; }
	.maintenance-actions { flex-wrap: wrap; justify-content: flex-end; }
  .transfer-wait-indicator { width: 88px; height: 88px; margin-bottom: 24px; }
  .transfer-wait-indicator span { width: 44px; height: 44px; font-size: 18px; }
  .transfer-wait h1 { font-size: 28px; }
  .transfer-wait p { font-size: 16px; }
}

@media (max-height: 680px) {
  .search-shell { padding-top: 12px; }
  .search-meta { min-height: 32px; margin-top: 8px; }
  .result-row { min-height: 68px; padding-top: 11px; padding-bottom: 11px; }
}

@media (max-width: 360px) {
  .search-footer { gap: 4px; font-size: 9px; }
  .backup-links { gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  .result-row { animation: none; }
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
  .button-spinner, .progress-spinner, .spinner, .transfer-wait-indicator::before, .transfer-wait-indicator::after, .transfer-wait-progress span, .loading-dots::after { animation: none; }
}
