:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --border: #e6e9f2;
  --text: #141a2e;
  --muted: #6b7390;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --low: #16a34a;
  --low-soft: #e8f7ee;
  --med: #d97706;
  --med-soft: #fdf3e2;
  --high: #dc2626;
  --high-soft: #fdecec;
  --shadow: 0 1px 2px rgba(20, 26, 46, .04), 0 12px 32px -12px rgba(20, 26, 46, .14);
  --radius: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1020;
    --surface: #161a2e;
    --surface-2: #1c2138;
    --border: #262c47;
    --text: #eef0fa;
    --muted: #949bb8;
    --accent: #818cf8;
    --accent-soft: #23284a;
    --low: #4ade80;
    --low-soft: #15301f;
    --med: #fbbf24;
    --med-soft: #33280f;
    --high: #f87171;
    --high-soft: #3a1717;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px -12px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  background-image: radial-gradient(1200px 500px at 50% -200px, var(--accent-soft), transparent);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.shell { max-width: 760px; margin: 0 auto; padding: 48px 16px 64px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Header */
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.brand h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.brand p { margin: 2px 0 0; color: var(--muted); }
.logo {
  width: 46px; height: 46px; border-radius: 14px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  box-shadow: 0 8px 20px -8px var(--accent);
}
.logo svg { width: 24px; fill: #fff; }

/* Search */
.search { position: relative; }
.search-field {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 6px 6px 6px 16px; box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
.search-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); }
.search-icon { width: 20px; fill: var(--muted); flex: none; }
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  color: var(--text); font: inherit; font-size: 18px; font-weight: 500; padding: 10px 4px;
  letter-spacing: .01em;
}
.search input::placeholder { color: var(--muted); opacity: .6; }
.search button[type=submit] {
  position: relative; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; font: inherit; font-weight: 600;
  padding: 12px 26px; border-radius: 12px; transition: filter .15s, transform .05s;
}
.search button[type=submit]:hover { filter: brightness(1.08); }
.search button[type=submit]:active { transform: translateY(1px); }
.search button[disabled] { cursor: progress; }
.spinner {
  display: none; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px;
  border: 2px solid rgba(255, 255, 255, .4); border-top-color: #fff; border-radius: 50%;
  animation: spin .7s linear infinite;
}
.loading .btn-label { visibility: hidden; }
.loading .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.key-toggle {
  margin-top: 10px; border: 0; background: none; color: var(--muted);
  font: inherit; font-size: 13px; cursor: pointer; padding: 4px 2px;
}
.key-toggle:hover { color: var(--accent); }
.key-row {
  margin-top: 6px; padding: 14px 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px;
  display: grid; gap: 6px;
}
.key-row[hidden] { display: none; }
.key-row label { font-size: 13px; font-weight: 600; }
.key-row input {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  background: var(--surface-2); color: var(--text); font: 14px ui-monospace, Menlo, monospace; outline: 0;
}
.key-row input:focus { border-color: var(--accent); }
.key-row small { color: var(--muted); }

/* Result area */
#result { margin-top: 20px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  animation: rise .35s cubic-bezier(.2, .8, .2, 1);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.card-head {
  display: flex; gap: 18px; align-items: center; padding: 18px 20px;
  background: linear-gradient(180deg, var(--tone-soft), transparent);
  border-bottom: 1px solid var(--border);
}
.tone-LOW { --tone: var(--low); --tone-soft: var(--low-soft); }
.tone-MEDIUM { --tone: var(--med); --tone-soft: var(--med-soft); }
.tone-HIGH { --tone: var(--high); --tone-soft: var(--high-soft); }

.gauge { position: relative; width: 92px; height: 92px; flex: none; }
.gauge svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge .track { stroke: var(--border); }
.gauge .value { stroke: var(--tone); stroke-linecap: round; transition: stroke-dashoffset 1s cubic-bezier(.2, .8, .2, 1); }
.gauge-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.gauge-label strong { font-size: 26px; font-weight: 800; line-height: 1; letter-spacing: -.03em; color: var(--tone); }
.gauge-label span { font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-top: 4px; }

.who { min-width: 0; flex: 1; }
.who h2 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.02em; overflow-wrap: anywhere; }
.who .meta { margin-top: 2px; font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; }
.badges { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px; letter-spacing: .03em;
  background: var(--tone-soft); color: var(--tone);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.star::before { content: "★"; width: auto; height: auto; background: none; font-size: 12px; line-height: 1; }
.badge.neutral { background: var(--surface-2); color: var(--muted); }
.badge.danger { background: var(--high); color: #fff; }
.badge.danger::before { background: #fff; }
.verdict { margin-top: 6px; font-size: 13px; font-weight: 600; color: var(--tone); }

.card-body { padding: 16px 20px 18px; display: grid; gap: 16px; }

.section-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 0 0 8px;
}

/* Delivery bar */
.ratio-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.ratio-row strong { font-size: 17px; font-weight: 800; }
.ratio-row span { color: var(--muted); font-size: 13px; }
.bar { display: flex; height: 8px; border-radius: 999px; overflow: hidden; background: var(--surface-2); gap: 2px; }
.bar i { display: block; height: 100%; transition: width .8s cubic-bezier(.2, .8, .2, 1); }
.bar .d { background: var(--low); }
.bar .r { background: var(--high); }
.bar .c { background: var(--muted); opacity: .5; }
.bar .t { background: var(--accent); opacity: .7; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 3px; }

/* Amount breakdown */
.money-total { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.money-total span { color: var(--muted); font-size: 13px; }
.money-total strong { font-size: 17px; font-weight: 800; letter-spacing: -.02em; }
.money-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.money-tile {
  background: var(--surface-2); border-radius: 10px; padding: 8px 10px;
  border-left: 3px solid var(--c);
}
.money-tile span { display: block; font-size: 11px; color: var(--muted); }
.money-tile b { display: block; font-size: 15px; font-weight: 700; letter-spacing: -.02em; margin: 1px 0; }
.money-tile small { color: var(--c); font-size: 11px; font-weight: 600; }

/* Stats grid */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 15px; font-weight: 700; letter-spacing: -.02em; }
.stat span { font-size: 11px; color: var(--muted); }

/* Sources */
.sources { display: grid; gap: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.src-item + .src-item { border-top: 1px solid var(--border); }
.source {
  display: grid; grid-template-columns: 62px 70px auto 1fr 14px; gap: 12px; align-items: center;
  padding: 7px 12px; width: 100%; border: 0; background: none; color: inherit; font: inherit;
  text-align: left; cursor: pointer; transition: background .15s;
}
.source:hover, .source[aria-expanded="true"] { background: var(--surface-2); }
.source:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.source .chev { width: 14px; fill: none; stroke: var(--muted); stroke-width: 2.2; stroke-linecap: round; transition: transform .2s; }
.source[aria-expanded="true"] .chev { transform: rotate(90deg); }

/* Orders inside a courier row */
.src-orders { border-top: 1px solid var(--border); padding: 4px 12px 10px; background: var(--surface-2); }
.order-list { list-style: none; margin: 0; padding: 0; }
.order {
  display: grid; grid-template-columns: minmax(72px, auto) auto 1fr auto; gap: 10px; align-items: center;
  padding: 7px 0; font-size: 12px; border-bottom: 1px dashed var(--border);
}
.order:last-child { border-bottom: 0; }
.oid { font-family: ui-monospace, Menlo, monospace; font-weight: 600; min-width: 0; }
.oship {
  display: block; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: Inter, system-ui, sans-serif; font-size: 11px; font-weight: 500; color: var(--muted); margin-top: 1px;
}
.pill { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; justify-self: start; }
.st-low { color: var(--low); background: var(--low-soft); }
.st-high { color: var(--high); background: var(--high-soft); }
.st-med { color: var(--med); background: var(--med-soft); }
.st-accent { color: var(--accent); background: var(--accent-soft); }
.st-muted { color: var(--muted); background: var(--surface); }
.odate { color: var(--muted); white-space: nowrap; }
.oamt { text-align: right; font-weight: 600; white-space: nowrap; }
.ostars { font-weight: 700; }
.ostars.t-low { color: var(--low); }
.ostars.t-med { color: var(--med); }
.ostars.t-high { color: var(--high); }
.oamt small { color: var(--muted); font-weight: 500; margin-left: 2px; }
.orders-foot { display: flex; align-items: center; gap: 10px; padding-top: 8px; font-size: 12px; color: var(--muted); }
.more-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 12px;
  font-weight: 600; padding: 5px 12px; border-radius: 8px; cursor: pointer;
}
.more-btn:hover { border-color: var(--accent); color: var(--accent); }
.mini-spin {
  width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
.source .name { font-weight: 700; font-size: 12px; }
.source .mini { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.source .mini i { display: block; height: 100%; background: var(--low); border-radius: 999px; }
.source .num { font-size: 12px; color: var(--muted); white-space: nowrap; }
.source .src-money { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Addresses */
.addresses { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.addresses li { display: flex; gap: 10px; padding: 8px 12px; background: var(--surface-2); border-radius: 10px; font-size: 13px; }
.addresses .pin { color: var(--accent); flex: none; margin-top: 2px; }
.addresses .pin svg { width: 16px; fill: currentColor; }
.addresses .addr { flex: 1; min-width: 0; }
.addresses .addr div { overflow-wrap: anywhere; }
.addresses small { color: var(--muted); font-size: 12px; }
.addresses .addr-check { flex: none; align-self: flex-start; }
.addr-result { margin-top: 8px; display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.addr-result[hidden] { display: none; }
.addr-verdict { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); font-weight: 600; }

/* AI insight */
.ai-box {
  position: relative; padding: 12px 14px; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-soft), var(--surface-2) 70%);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--border));
  animation: rise .35s cubic-bezier(.2, .8, .2, 1);
}
.ai-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ai-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.spark { width: 14px; height: 14px; fill: currentColor; }
.ai-status { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.ai-headline { margin: 8px 0 2px; font-weight: 700; font-size: 15px; }
.ai-summary { margin: 0; font-size: 13px; color: var(--text); opacity: .85; }
.ai-row { display: flex; gap: 12px; margin-top: 10px; align-items: stretch; }
.ai-limit {
  flex: none; display: grid; align-content: center; gap: 2px; padding: 8px 12px; min-width: 128px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.ai-limit span { font-size: 11px; color: var(--muted); font-weight: 600; }
.ai-limit b { font-size: 17px; font-weight: 800; }
.ai-signals { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; align-content: center; }
.sig { font-size: 12px; font-weight: 600; padding: 3px 9px 3px 8px; border-radius: 999px; display: inline-flex; align-items: center; gap: 6px; }
.sig::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.sig-good { color: var(--low); background: var(--low-soft); }
.sig-warn { color: var(--med); background: var(--med-soft); }
.sig-bad { color: var(--high); background: var(--high-soft); }
.ai-foot { margin-top: 8px; font-size: 11px; color: var(--muted); }

.foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; font-size: 11px; color: var(--muted); border-top: 1px dashed var(--border); padding-top: 10px; }

/* Empty / error states */
.notice {
  text-align: center; padding: 40px 24px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  animation: rise .35s cubic-bezier(.2, .8, .2, 1);
}
.notice .icon { width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 16px; display: grid; place-items: center; background: var(--surface-2); font-size: 24px; }
.notice h3 { margin: 0 0 4px; font-size: 18px; }
.notice p { margin: 0; color: var(--muted); }
.notice.error .icon { background: var(--high-soft); color: var(--high); }

/* Skeleton */
.skeleton { padding: 28px; }
.sk { background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 600px) {
  .shell { padding-top: 28px; }
  .card-head { padding: 16px; gap: 14px; }
  .gauge { width: 76px; height: 76px; }
  .gauge-label strong { font-size: 22px; }
  .card-body { padding: 14px 16px 16px; }
  .stats, .money-grid { grid-template-columns: repeat(2, 1fr); }
  .ai-row { flex-direction: column; }
  .source { grid-template-columns: 58px 1fr auto 14px; }
  .source .chev { grid-row: 1; grid-column: 4; }
  .source .src-money { grid-column: 1 / -1; text-align: left; margin-top: -4px; }
  .order { grid-template-columns: 1fr auto; row-gap: 3px; }
  .search button[type=submit] { padding: 12px 18px; }
}
