:root {
  color-scheme: light;
  --tool-bg: #f3f6f8;
  --tool-text: #172c40;
  --tool-muted: #748493;
  --tool-line: #e5ebef;
  --tool-accent: #087f83;
  --tool-accent-dark: #066b6e;
  --tool-soft: #edf8f6;
}

[hidden] { display: none !important; }

html.tool-mode { height: auto; min-height: 100%; overflow: auto; }

body.tool-mode {
  width: 100%;
  height: auto;
  min-height: 100vh;
  overflow: auto;
  background: var(--tool-bg);
  color: var(--tool-text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.tool-page, .tool-page * { box-sizing: border-box; }
.tool-page { min-height: 100vh; }
.tool-page button, .tool-page select, .tool-page input { font: inherit; }
.tool-page button { cursor: pointer; }
.tool-page button:disabled { cursor: not-allowed; opacity: .42; }
.tool-page :focus-visible {
  outline: 3px solid #42ada8;
  outline-offset: 4px;
}
.tool-page svg { display: block; flex-shrink: 0; }
.tool-shell { width: min(1160px, calc(100% - 64px)); margin: 0 auto; }
.topbar {
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid #dfe7ec;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  place-items: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: #fff;
  background: var(--tool-text);
  font-size: 21px;
  font-weight: 700;
}
.brand-mark > span { color: #61cbc0; }
.brand-mark svg { width: 21px; height: 21px; }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: .05em; }
.brand-subtitle { margin-top: 1px; color: var(--tool-muted); font-size: 11px; letter-spacing: .12em; }
.local-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  flex-shrink: 0;
  border: 1px solid #d5e8e3;
  border-radius: 30px;
  background: #f6fcfa;
  color: #38766a;
  font-size: 12px;
}
.local-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #389b82; }
.local-badge svg { width: 15px; height: 15px; }
.page-heading { padding: 39px 0 30px; }
.eyebrow { margin: 0 0 8px; color: var(--tool-accent); font-size: 10px; font-weight: 700; letter-spacing: .17em; }
.page-heading h1 { margin: 0 0 10px; font-size: clamp(26px, 3vw, 32px); line-height: 1.35; letter-spacing: -.025em; font-weight: 700; }
.page-heading > p { margin: 0; color: #6a7c8d; font-size: 14px; }
.workspace { display: grid; grid-template-columns: 348px minmax(0, 1fr); align-items: start; gap: 22px; }
.settings-column, .preview-column { min-width: 0; }
.settings-column { display: grid; gap: 18px; }
.panel { min-width: 0; background: #fff; border: 1px solid var(--tool-line); border-radius: 14px; padding: 23px; box-shadow: 0 3px 14px #19364c03; }
.panel-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.step-number { display: inline-grid; place-items: center; width: 25px; height: 25px; flex-shrink: 0; border-radius: 7px; background: #eef3f6; color: #738496; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.panel h2 { margin: 0; font-size: 15px; line-height: 1.5; font-weight: 700; }
.panel-note { margin: -6px 0 16px; font-size: 12px; color: var(--tool-muted); }
.drop-zone { padding: 25px 15px 23px; border: 1.5px dashed #cbd8e0; border-radius: 10px; text-align: center; background: #fbfcfd; transition: background .15s, border-color .15s; cursor: pointer; }
.drop-zone:hover, .drop-zone.drag-over, .drop-zone.dragging { background: #f0faf8; border-color: #54a89d; }
.drop-zone:focus-visible { outline-offset: 3px; }
.upload-icon { display: grid; place-items: center; width: 44px; height: 44px; margin: 0 auto 13px; border: 1px solid #e1e9ec; border-radius: 12px; color: #5f7a8c; background: #fff; }
.upload-icon svg { width: 23px; height: 23px; }
.drop-zone h3 { margin: 0 0 5px; font-size: 14px; font-weight: 600; }
.drop-zone p { margin: 0 0 16px; color: #8a99a5; font-size: 12px; }
.file-button { border: 1px solid #d7e1e7; border-radius: 7px; padding: 7px 18px; background: #fff; color: #35536b; font-size: 12px !important; font-weight: 600 !important; }
.drop-zone .file-types { margin: 15px 0 0; font-size: 10px; }
.drop-zone.loading { cursor: progress; opacity: .6; }
.file-button:hover { background: #f4f8fa; }
.file-info { display: flex; align-items: center; gap: 11px; margin-top: 16px; padding: 12px; border: 1px solid #e2ece8; border-radius: 9px; background: #f8fcfa; }
.file-symbol { display: grid; place-items: center; width: 33px; height: 38px; border-radius: 6px; flex-shrink: 0; background: #e8f3ee; color: #3b846c; font-weight: 700; font-size: 11px; }
.file-symbol svg { width: 19px; height: 19px; }
.file-details { flex: 1; min-width: 0; }
.file-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #335047; font-size: 12px; font-weight: 600; }
.file-meta { display: block; margin-top: 1px; color: #83968d; font-size: 11px; }
.text-button { padding: 3px 0; border: 0; background: none; color: var(--tool-accent); white-space: nowrap; font-size: 12px !important; }
.text-button:hover { color: var(--tool-accent-dark); text-decoration: underline; }
.sheet-control { margin-top: 16px; }
.sheet-control label { display: block; color: #748493; font-size: 12px; margin-bottom: 7px; }
.sheet-control select { width: 100%; min-height: 38px; border: 1px solid #dce5eb; border-radius: 7px; padding: 7px 10px; background: #fff; color: #31495e; }
.field-actions { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.field-list { display: grid; gap: 7px; max-height: 330px; overflow: auto; padding: 2px; margin: -2px; }
.field-option { display: grid; gap: 9px; min-height: 41px; border: 1px solid #e8edf1; border-radius: 7px; padding: 10px 11px; color: #607488; transition: border-color .15s, background .15s; }
.field-option:hover { border-color: #b7d4ce; background: #fafdfc; }
.field-option.selected { background: #f1faf7; border-color: #c3e1d7; color: #285d51; }
.field-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.field-toggle input { width: 15px; height: 15px; margin: 0; accent-color: var(--tool-accent); flex-shrink: 0; }
.field-option input:disabled { cursor: not-allowed; }
.field-alias { display: flex; align-items: center; gap: 9px; padding-left: 25px; color: #7b8c99; font-size: 11px; }
.field-alias > span { flex-shrink: 0; }
.field-alias .alias-input { width: 100%; min-width: 0; min-height: 32px; padding: 5px 8px; border: 1px solid #dce5e9; border-radius: 5px; background: #fff; color: var(--tool-text); font-size: 12px; }
.alias-input::placeholder { color: #a0adb6; font-size: 11px; }
.field-alias .alias-input:focus { border-color: var(--tool-accent); }
.field-label { min-width: 0; flex: 1; overflow-wrap: anywhere; font-size: 12px; }
.field-tag { padding: 1px 5px; border-radius: 4px; color: #659181; background: #e3f1eb; font-size: 9px; white-space: nowrap; }
.rule-box { margin-top: 20px; padding-top: 17px; border-top: 1px solid #eef1f4; }
.rule-label { margin: 0 0 9px; color: #81909d; font-size: 11px; }
.rule-domains { display: grid; gap: 4px; font-size: 11px; font-family: Consolas, "SFMono-Regular", monospace; overflow-wrap: anywhere; }
.domain-old { color: #8d9aa5; }
.domain-new { color: var(--tool-accent); }
.rule-domains svg { width: 12px; height: 12px; color: #9aabb5; }
.preview-column > .panel { padding: 0; overflow: hidden; }
.preview-panel > .rule-box { margin: 0 23px 18px; padding: 15px 17px; border: 1px solid #dfeee9; border-radius: 8px; background: #f7fbfa; }
.preview-panel .rule-domains { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 5px; font-size: 12px; }
.preview-panel .rule-box p { margin: 7px 0 0; color: #81958e; font-size: 11px; }
.preview-panel .export-bar { margin: 0; border: 0; border-top: 1px solid var(--tool-line); border-radius: 0; }
.panel-heading .preview-badge { margin-left: auto; }
.field-list + .panel-note { margin: 14px 0 0; }
.preview-toolbar .panel-note { margin: 0; white-space: nowrap; }
.preview-empty > strong { margin-bottom: 7px; font-size: 14px; font-weight: 500; color: #708898; }
.preview-column .panel-heading { padding: 23px 23px 0; }
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 23px 19px; }
.preview-summary { color: #8595a2; font-size: 12px; }
.preview-summary strong { color: #3f5e73; font-weight: 600; }
.preview-badge { display: inline-block; flex-shrink: 0; padding: 3px 8px; border-radius: 5px; background: #f1f5f7; color: #7b8c99; font-size: 10px; }
.preview-empty { min-height: 394px; padding: 85px 24px; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; border-top: 1px solid #eef2f4; }
.empty-icon { display: grid; place-items: center; width: 70px; height: 70px; margin-bottom: 18px; border-radius: 18px; background: #f3f7f9; color: #b4c3cd; }
.empty-icon svg { width: 32px; height: 32px; }
.preview-empty h3 { margin: 0 0 6px; color: #6e8494; font-size: 14px; font-weight: 500; }
.preview-empty p { max-width: 280px; margin: 0; color: #9aa8b2; font-size: 12px; }
.table-scroll { max-width: 100%; overflow: auto; min-height: 325px; max-height: 500px; border-top: 1px solid #e7edf1; }
.table-scroll table { width: 100%; border-collapse: collapse; text-align: left; font-size: 12px; }
.table-scroll th { position: sticky; top: 0; z-index: 1; background: #f7f9fb; color: #6c8294; font-size: 11px; font-weight: 500; white-space: nowrap; }
.table-scroll th, .table-scroll td { height: 48px; padding: 12px 17px; border-bottom: 1px solid #edf1f4; max-width: 400px; }
.table-scroll td { color: #486174; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.table-scroll td.ticket-cell, .table-scroll td[data-ticket] { color: #278c83; font-size: 11px; font-family: Consolas, monospace; }
.table-scroll tbody tr:hover td { background: #fbfdfd; }
.table-scroll .row-number { width: 45px; text-align: center; padding-left: 12px; padding-right: 12px; color: #adbac4; font-size: 11px; }
.export-bar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 18px; padding: 21px 23px; background: #fff; border: 1px solid var(--tool-line); border-radius: 12px; }
.export-copy { min-width: 0; }
.export-copy strong { font-size: 13px; font-weight: 600; }
.export-copy p { margin: 4px 0 0; color: #91a0aa; font-size: 11px; }
.primary-button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; flex-shrink: 0; min-height: 42px; padding: 10px 20px; border: 1px solid var(--tool-accent); border-radius: 8px; background: var(--tool-accent); color: #fff; font-size: 12px !important; font-weight: 600 !important; }
.primary-button:hover:not(:disabled) { background: var(--tool-accent-dark); border-color: var(--tool-accent-dark); }
.primary-button svg { width: 15px; height: 15px; }
.status-message { margin: 13px 0 0; color: #7d8d98; font-size: 12px; overflow-wrap: anywhere; }
.status-message.error { color: #b44f4f; }
.status-message.success { color: #267f68; }
.tool-footer { display: flex; justify-content: space-between; gap: 18px; padding: 27px 0 31px; color: #9aa8b3; font-size: 11px; }
.tool-footer p { margin: 0; }

@media (min-width: 1050px) {
  .preview-column { position: sticky; top: 24px; }
}

@media (max-width: 900px) {
  .tool-shell { width: calc(100% - 40px); }
  .workspace { grid-template-columns: 300px minmax(0, 1fr); gap: 16px; }
  .panel { padding: 19px; }
  .preview-column .panel-heading { padding: 19px 19px 0; }
  .preview-toolbar { padding-left: 19px; padding-right: 19px; flex-wrap: wrap; }
  .export-bar { align-items: flex-start; flex-direction: column; gap: 13px; padding: 18px; }
  .export-bar .primary-button { width: 100%; }
}

@media (max-width: 700px) {
  .preview-panel > .rule-box { margin-left: 19px; margin-right: 19px; }
  .tool-shell { width: calc(100% - 32px); }
  .topbar { min-height: 82px; gap: 12px; }
  .brand-mark { width: 35px; height: 35px; border-radius: 10px; }
  .brand { gap: 9px; }
  .brand-name { font-size: 14px; }
  .brand-subtitle { font-size: 9px; letter-spacing: .08em; }
  .local-badge { gap: 5px; padding: 5px 8px; font-size: 10px; }
  .page-heading { padding: 29px 0 24px; }
  .page-heading h1 { font-size: 27px; }
  .page-heading > p { max-width: 330px; font-size: 12px; line-height: 1.8; }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 18px; }
  .settings-column { gap: 16px; }
  .panel { padding: 19px; border-radius: 12px; }
  .drop-zone { padding-top: 23px; padding-bottom: 22px; }
  .field-list { grid-template-columns: minmax(0, 1fr); max-height: 300px; }
  .field-option { padding: 8px; gap: 7px; }
  .field-tag { font-size: 8px; }
  .preview-empty { min-height: 270px; padding: 45px 20px; }
  .table-scroll { min-height: 240px; max-height: 410px; }
  .table-scroll th, .table-scroll td { padding: 11px 14px; }
  .export-bar { flex-direction: row; align-items: center; padding: 17px; gap: 10px; }
  .export-bar .primary-button { width: auto; padding: 10px 15px; }
  .export-copy strong { font-size: 12px; }
  .export-copy p { font-size: 10px; }
  .tool-footer { flex-direction: column; gap: 3px; padding-top: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .tool-page * { transition: none !important; }
}
