@scope (#scan-tab) {

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--text); background: radial-gradient(circle at 50% -20%, #162b4a 0, var(--bg) 34%); }
button, input, select, summary { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }
.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; }

.app-header {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  min-height: 76px; padding: 12px max(24px, calc((100vw - 1480px) / 2));
  background: rgba(8, 17, 31, .88); border-bottom: 1px solid var(--line-soft); backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: linear-gradient(145deg, #7895ff, #4e6fe7); color: #fff; font-size: 18px; font-weight: 850; box-shadow: 0 9px 24px rgba(78,111,231,.3); }
.brand-copy { display: grid; gap: 3px; }
.brand-copy strong { font-size: 16px; }
.brand-copy span, .refresh-copy { color: var(--muted); font-size: 12px; }
.header-actions { display: flex; align-items: center; gap: 11px; }
.connection-pill { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 13px; border: 1px solid var(--line); border-radius: 999px; color: var(--text-2); background: var(--surface); font-size: 12px; }
.connection-pill.is-online { border-color: rgba(71,212,156,.3); color: #9aefd1; background: var(--good-soft); }
.connection-pill.is-offline { border-color: rgba(255,113,128,.3); color: #ffadb6; background: var(--bad-soft); }
.connection-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 4px color-mix(in srgb,currentColor 18%,transparent); }
.icon-button { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 1px solid var(--line); border-radius: 10px; color: var(--text-2); background: var(--surface-2); cursor: pointer; font-size: 20px; }
.icon-button:hover { border-color: var(--brand); color: #fff; }
.icon-button:disabled { cursor: wait; opacity: .55; }
.icon-button.is-spinning { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.scan-main { max-width: 1480px; margin: 0 auto; padding: 28px 24px 52px; }
.page-heading, .section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.page-heading { align-items: center; margin-bottom: 18px; }
.page-heading h1 { margin: 4px 0 0; font-size: 27px; letter-spacing: -.035em; }
.page-heading p:last-child { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.eyebrow { margin: 0; color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .1em; }
.surface { background: rgba(16, 27, 45, .95); border: 1px solid var(--line-soft); border-radius: 16px; box-shadow: 0 1px 0 rgba(255,255,255,.02); }
.section-heading { padding: 18px 18px 13px; }
.section-heading h2, .log-summary h2 { margin: 3px 0 0; font-size: 18px; letter-spacing: -.025em; }
.button { min-height: 40px; padding: 0 14px; border: 1px solid transparent; border-radius: 9px; cursor: pointer; font-weight: 650; font-size: 12px; }
.button-ghost { border-color: var(--line); color: var(--text-2); background: var(--surface-2); }
.button-ghost:hover { border-color: #405579; color: #fff; }
.text-button { padding: 5px 0; border: 0; color: #9cb1ff; background: transparent; cursor: pointer; font-size: 12px; }
.text-button:hover, .text-button.active { color: #dce3ff; }

.maintenance-menu { position: relative; }
.maintenance-menu summary { display: grid; place-items: center; list-style: none; }
.maintenance-menu summary::-webkit-details-marker { display: none; }
.maintenance-menu > button { position: absolute; right: 0; top: 46px; z-index: 10; width: 180px; min-height: 42px; padding: 0 13px; border: 1px solid rgba(255,113,128,.3); border-radius: 10px; color: #ffadb6; background: #162238; box-shadow: var(--shadow); cursor: pointer; }

.status-board { display: grid; grid-template-columns: minmax(270px,1.1fr) minmax(450px,1.7fr); overflow: hidden; }
.status-lead { display: flex; align-items: center; gap: 14px; min-height: 128px; padding: 22px; border-right: 1px solid var(--line-soft); }
.status-dot { flex: 0 0 auto; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 7px rgba(142,157,178,.1); }
.status-dot.is-good { background: var(--good); box-shadow: 0 0 0 7px var(--good-soft); }
.status-dot.is-warning { background: var(--warning); box-shadow: 0 0 0 7px var(--warning-soft); }
.status-dot.is-bad { background: var(--bad); box-shadow: 0 0 0 7px var(--bad-soft); }
.status-lead strong { display: block; font-size: 17px; }
.status-lead span:last-child { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.status-metrics { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); }
.status-metrics > div { display: grid; align-content: center; gap: 7px; min-height: 128px; padding: 18px; border-right: 1px solid var(--line-soft); }
.status-metrics > div:last-child { border-right: 0; }
.status-metrics span, .daily-strip span { color: var(--muted); font-size: 12px; }
.status-metrics strong { font-size: 30px; letter-spacing: -.04em; }
.status-metrics small { margin-left: 3px; color: var(--muted); font-size: 13px; font-weight: 550; }
.daily-strip { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); border-top: 1px solid var(--line-soft); background: rgba(21,34,56,.5); }
.daily-strip > div { display: flex; align-items: center; justify-content: space-between; min-height: 58px; padding: 0 20px; border-right: 1px solid var(--line-soft); }
.daily-strip > div:last-child { border-right: 0; }
.daily-strip strong { font-size: 18px; }

.failed-panel { margin-top: 14px; border-color: rgba(255,113,128,.22); }
.failed-list { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 8px; padding: 0 16px 16px; }
.failed-phone-item { display: flex; justify-content: space-between; gap: 10px; padding: 11px 12px; border: 1px solid var(--line-soft); border-radius: 10px; color: var(--text-2); background: var(--surface-2); font-size: 12px; }
.failed-phone-item .count { color: #ff9eaa; }

.work-grid { display: grid; grid-template-columns: minmax(0,1.12fr) minmax(340px,.88fr); gap: 14px; margin-top: 14px; align-items: start; }
.list-panel { min-width: 0; overflow: hidden; }
.list-body { max-height: 640px; padding: 0 12px 12px; overflow: auto; scrollbar-gutter: stable; }
.task-item, .phone-item { padding: 13px 12px; border-top: 1px solid var(--line-soft); font-size: 13px; }
.task-item:first-child, .phone-item:first-child { border-top: 0; }
.task-item:hover, .phone-item:hover { border-radius: 10px; background: rgba(255,255,255,.018); }
.scan-item-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.scan-item-head > div { display: flex; align-items: center; gap: 9px; min-width: 0; }
.scan-item-head strong { color: var(--text); font-size: 14px; }
.scan-item-head small { color: var(--muted); font-size: 11px; }
.phone-item.is-offline { opacity: .62; }
.status-badge { display: inline-flex; align-items: center; min-height: 23px; padding: 0 8px; border-radius: 999px; font-size: 10px; font-weight: 750; white-space: nowrap; }
.status-online, .status-completed { color: #8cebc5; background: var(--good-soft); }
.status-pending { color: #ffd278; background: var(--warning-soft); }
.status-assigned, .status-dispatching { color: #9cd4ff; background: rgba(100,185,255,.13); }
.status-failed, .status-offline { color: #ff9eaa; background: var(--bad-soft); }
.scan-executor-line { display: flex; justify-content: space-between; gap: 16px; margin-top: 10px; color: var(--muted); font-size: 12px; }
.scan-executor-line strong { color: var(--text-2); }
.scan-item-meta, .scan-task-context { margin-top: 7px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.scan-item-meta.is-active { color: #9cd4ff; }
.scan-task-id { margin-top: 7px; color: #65778f; font: 10px ui-monospace,SFMono-Regular,Consolas,monospace; overflow-wrap: anywhere; }
.scan-warning-text { color: #ffd278; }
.scan-task-actions { display: flex; gap: 7px; margin-top: 10px; }
.scan-inline-button { min-height: 31px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--text-2); background: var(--surface-2); cursor: pointer; font-size: 11px; }
.scan-inline-button:hover { border-color: var(--brand); color: #fff; }
.scan-inline-button.is-danger { border-color: rgba(255,113,128,.25); color: #ff9eaa; }
.scan-inline-button.is-success { border-color: rgba(71,212,156,.25); color: #8cebc5; }
.empty-state, .scan-empty { padding: 54px 20px; color: var(--muted); font-size: 14px; line-height: 1.65; text-align: center; }

.log-panel { margin-top: 14px; overflow: hidden; }
.log-summary { display: flex; align-items: center; justify-content: space-between; gap: 18px; min-height: 78px; padding: 16px 18px; cursor: pointer; list-style: none; }
.log-summary::-webkit-details-marker { display: none; }
.log-summary div > span, .log-summary > span { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; }
.log-summary > span { margin: 0; color: #9cb1ff; }
.log-content { padding: 0 16px 16px; border-top: 1px solid var(--line-soft); }
.log-stats { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 8px; padding: 14px 0 10px; }
.log-stats > div { display: flex; justify-content: space-between; align-items: center; min-height: 50px; padding: 0 13px; border: 1px solid var(--line-soft); border-radius: 9px; color: var(--muted); background: var(--surface-2); font-size: 11px; }
.log-stats strong { color: var(--text); font-size: 17px; }
.log-stats .tone-info strong { color: var(--info); }
.log-stats .tone-warning strong { color: var(--warning); }
.log-stats .tone-error strong { color: var(--bad); }
.log-toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.log-toolbar input, .log-toolbar select { min-height: 40px; padding: 0 11px; border: 1px solid var(--line); border-radius: 9px; color: var(--text); background: var(--surface-2); outline: none; }
.log-toolbar input:focus, .log-toolbar select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.search-field { flex: 1; }
.search-field input { width: 100%; min-width: 210px; }
.logs { height: 430px; padding: 10px; overflow: auto; border: 1px solid var(--line-soft); border-radius: 10px; color: var(--text-2); background: #091321; font: 12px/1.75 ui-monospace,SFMono-Regular,Consolas,monospace; scrollbar-gutter: stable; }
.log-entry { padding: 3px 5px; border-bottom: 1px solid rgba(36,54,80,.45); overflow-wrap: anywhere; }
.log-info { color: #a9c7e5; }
.log-warning { color: #f4c979; }
.log-error { color: #ff98a4; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 50; display: grid; gap: 8px; }
.toast { min-width: 240px; max-width: 390px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); box-shadow: var(--shadow); color: var(--text-2); font-size: 13px; }
.toast.error { border-color: rgba(255,113,128,.35); color: #ffadb6; }

@media (max-width: 900px) {
  .app-header { padding: 11px 14px; }
  .refresh-copy { display: none; }
  .connection-pill { max-width: 190px; }
  .scan-main { padding: 20px 14px 36px; }
  .status-board { grid-template-columns: 1fr; }
  .status-lead { min-height: 92px; border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .status-metrics > div { min-height: 88px; }
  .work-grid { grid-template-columns: 1fr; }
  .list-body { max-height: 520px; }
  .failed-list { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .log-toolbar { flex-wrap: wrap; }
  .log-toolbar .search-field { flex: 1 0 100%; }
}

@media (max-width: 560px) {
  .brand-copy span, .connection-pill span:last-child { display: none; }
  .connection-pill { width: 38px; padding: 0; justify-content: center; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .page-heading h1 { font-size: 23px; }
  .maintenance-menu summary { width: 100%; }
  .maintenance-menu > button { width: 100%; }
  .status-metrics { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .status-metrics > div:nth-child(2) { border-right: 0; }
  .status-metrics > div:nth-child(-n+2) { border-bottom: 1px solid var(--line-soft); }
  .daily-strip { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .daily-strip > div:nth-child(2) { border-right: 0; }
  .daily-strip > div:nth-child(-n+2) { border-bottom: 1px solid var(--line-soft); }
  .failed-list, .log-stats { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .log-toolbar select { flex: 1; min-width: 0; }
  .log-toolbar .button { flex: 1; }
  .logs { height: 340px; font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

img.brand-mark {background:transparent;border-radius:0;box-shadow:none;object-fit:contain;flex-shrink:0}

}