:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #52616d;
  --paper: #eef3f8;
  --surface: #fff;
  --line: #d7e0e8;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --amber: #a45107;
  --red: #b42318;
  --blue: #1d4ed8;
  --shadow: 0 12px 30px rgba(37, 57, 78, .08);
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  line-height: 1.55;
}
a { color: #0b5d78; text-underline-offset: .18em; }
button, input, textarea { font: inherit; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip { position: absolute; left: -999px; top: 8px; background: #fff; padding: .6rem 1rem; z-index: 20; }
.skip:focus { left: 8px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 64px;
  padding: .75rem max(1rem, calc((100vw - 1520px) / 2));
  background: rgba(255, 255, 255, .98);
  border-bottom: 1px solid #d9e1e8;
  box-shadow: 0 4px 14px rgba(37, 57, 78, .05);
}
.brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  color: #1d3442;
  text-decoration: none;
  font-weight: 780;
  letter-spacing: .01em;
  white-space: nowrap;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: .6rem;
  background: #155e75;
  color: #ecfeff;
  font-size: .78rem;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .28);
}
nav { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .15rem; }
nav a { color: #4b5f6c; text-decoration: none; padding: .42rem .62rem; border-radius: .45rem; }
nav a:hover { background: #e7eef3; color: #17202a; }
.header-actions { min-width: 0; display: flex; align-items: center; justify-content: flex-end; gap: .65rem; }
.session-actions { flex: 0 0 auto; display: flex; align-items: center; gap: .45rem; padding-left: .65rem; border-left: 1px solid var(--line); }
.session-role { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.session-logout { border: 1px solid #aebdc8; background: #fff; color: #304653; border-radius: .45rem; padding: .4rem .62rem; font-weight: 700; cursor: pointer; white-space: nowrap; }
.session-logout:hover { border-color: #647d8e; background: #f5f8fa; }
.session-logout:disabled { cursor: wait; opacity: .65; }

main {
  width: min(1520px, calc(100vw - 80px));
  min-height: 70vh;
  margin: 1.35rem auto 2.2rem;
}
.loading { min-height: calc(100vh - 64px - 3.55rem); }
footer { display: none; }

.dashboard-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(500px, .8fr);
  gap: 1.25rem;
  align-items: end;
  margin-bottom: 1rem;
}
.dashboard-heading h1 { margin: .15rem 0 .2rem; font-size: clamp(1.75rem, 3vw, 2.6rem); line-height: 1.15; }
.dashboard-heading > div > p:last-child { margin: .35rem 0 0; color: var(--muted); }
.eyebrow, .section-kicker {
  margin: 0;
  color: #0e7490;
  font-weight: 780;
  letter-spacing: .08em;
  font-size: .75rem;
}
.refresh-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0;
  background: rgba(255, 255, 255, .72);
  border: 1px solid var(--line);
  border-radius: .75rem;
  overflow: hidden;
}
.refresh-summary > div { min-width: 0; padding: .65rem .75rem; border-left: 1px solid var(--line); }
.refresh-summary > div:first-child { border-left: 0; }
.refresh-summary dt { color: var(--muted); font-size: .75rem; }
.refresh-summary dd { margin: .18rem 0 0; font-weight: 760; overflow-wrap: anywhere; }

.legacy-toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(230px, 390px);
  gap: .8rem;
  align-items: center;
  padding: .75rem;
  margin-bottom: 1rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: .75rem;
  box-shadow: 0 5px 18px rgba(37, 57, 78, .05);
}
.view-tabs { display: flex; flex-wrap: wrap; gap: .35rem; }
.view-tabs button,
.favorite-button,
.button {
  border: 1px solid #cbd6df;
  background: #fff;
  color: #2b3b47;
  border-radius: .48rem;
  padding: .5rem .78rem;
  font-weight: 700;
  cursor: pointer;
}
.view-tabs button:hover, .favorite-button:hover, .button:hover { border-color: #8299aa; }
.view-tabs button[aria-pressed="true"], .button.primary {
  background: #155e75;
  color: #fff;
  border-color: #155e75;
}
.search-box {
  min-width: 0;
  grid-column: 3;
  display: flex;
  align-items: center;
  background: #f8fafc;
  border: 1px solid #bdcbd5;
  border-radius: .5rem;
  overflow: hidden;
}
.search-box input { min-width: 0; width: 100%; border: 0; background: transparent; padding: .52rem .68rem; color: var(--ink); }
.search-box span[aria-hidden] { flex: 0 0 auto; color: var(--muted); border-left: 1px solid var(--line); padding: .25rem .65rem; font-size: .78rem; }
.results-status { margin: 0; color: var(--muted); text-align: right; font-size: .84rem; }

.legacy-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  align-items: start;
}
.legacy-card {
  min-width: 0;
  height: 560px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--card-bg);
  border: 1px solid rgba(67, 88, 105, .18);
  border-top: 5px solid var(--accent);
  border-radius: .65rem;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.legacy-card.palette-0 { --accent: #0891b2; --accent-text: #0e7490; --card-bg: #edf7fb; }
.legacy-card.palette-1 { --accent: #16a34a; --accent-text: #15803d; --card-bg: #eef9f0; }
.legacy-card.palette-2 { --accent: #7c3aed; --accent-text: #6d28d9; --card-bg: #f4efff; }
.legacy-card.palette-3 { --accent: #ea580c; --accent-text: #c2410c; --card-bg: #fff2ea; }
.legacy-card.palette-4 { --accent: #2563eb; --accent-text: #1d4ed8; --card-bg: #eef4ff; }
.legacy-card.palette-5 { --accent: #db2777; --accent-text: #be185d; --card-bg: #fff0f6; }
.legacy-card:hover { border-right-color: rgba(67, 88, 105, .34); border-bottom-color: rgba(67, 88, 105, .34); border-left-color: rgba(67, 88, 105, .34); }
.card-head { padding: .9rem 1rem .7rem; background: rgba(255, 255, 255, .24); border-bottom: 1px solid rgba(67, 88, 105, .14); }
.card-title-row { min-width: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: .7rem; }
.card-title-row > div { min-width: 0; }
.card-head h2 { margin: 0; font-size: 1.2rem; line-height: 1.3; overflow-wrap: anywhere; }
.card-head h2 a { color: #1b2c37; text-decoration: none; }
.card-head h2 a:hover { text-decoration: underline; }
.favorite-button { flex: 0 0 auto; padding: .35rem .55rem; background: rgba(255, 255, 255, .7); color: #435665; font-size: .78rem; }
.favorite-button[aria-pressed="true"] { border-color: var(--accent); color: #17202a; box-shadow: inset 0 0 0 1px var(--accent); }
.badges { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .6rem; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: .17rem .48rem; font-size: .7rem; font-weight: 760; background: #e4f4f0; color: #0f625c; }
.badge.warn { background: #fff0cf; color: var(--amber); }
.badge.error { background: #fee4e2; color: var(--red); }
.card-scroll { min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding: .8rem 1rem 1rem; }
.card-description { margin: 0 0 .75rem; color: #5b6872; font-size: .88rem; }
.card-fact-section, .card-ai { padding: .8rem; background: rgba(255, 255, 255, .58); border: 1px solid rgba(67, 88, 105, .13); border-radius: .55rem; }
.card-fact-section h3 { margin: .35rem 0; font-size: 1rem; line-height: 1.4; }
.card-fact-section > p:not(.section-kicker) { margin: .35rem 0 .75rem; color: #4d5d68; font-size: .88rem; }
.card-facts { list-style: none; padding: 0; margin: .65rem 0 0; }
.card-facts li { padding: .65rem 0; border-top: 1px solid rgba(67, 88, 105, .15); }
.card-facts h4 { margin: 0 0 .25rem; font-size: .92rem; line-height: 1.38; }
.card-facts p { margin: .25rem 0; color: #53626c; font-size: .82rem; }
.card-facts small { color: var(--muted); font-size: .74rem; }
.card-empty { color: var(--muted); }
.card-ai { margin-top: .75rem; border-left: 3px solid var(--accent); }
.card-ai-group h4 { margin: .55rem 0 .18rem; font-size: .83rem; }
.card-ai-group ul { margin: .15rem 0 .4rem; padding-left: 1.15rem; }
.card-ai-group li { margin: .18rem 0; font-size: .82rem; }
.empty-panel { grid-column: 1 / -1; padding: 3rem 1rem; text-align: center; background: #fff; border: 1px dashed #aebdc8; border-radius: .75rem; }
.empty-panel h2 { margin: 0 0 .4rem; }
.empty-panel p { max-width: 50ch; margin: auto; color: var(--muted); }

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: .9rem;
  padding: clamp(1rem, 2.5vw, 2rem);
  box-shadow: var(--shadow);
}
.panel h1, .panel h2 { margin-top: 0; }
.lede { color: var(--muted); max-width: 66ch; font-size: 1.05rem; }
.muted { color: var(--muted); }
.danger { color: var(--red); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; margin-top: 1rem; }
.facts { border-top: 4px solid var(--blue); }
.analysis { border-top: 4px solid var(--teal); }
.detail-heading .badges { margin: 0 0 .75rem; }
.detail-meta { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .6rem; margin: 1rem 0 0; }
.detail-meta > div { padding: .65rem; background: #f5f8fa; border-radius: .5rem; }
.detail-meta dt { color: var(--muted); font-size: .75rem; }
.detail-meta dd { margin: .2rem 0 0; font-weight: 700; overflow-wrap: anywhere; }
.evidence { list-style: none; padding: 0; }
.evidence li { padding: 1rem 0; border-top: 1px solid var(--line); }
.evidence time { display: block; color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }
.status-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.status-row { min-width: 0; margin: 0; background: #fff; border: 1px solid var(--line); border-radius: .75rem; padding: 1rem; }
.status-row dt { color: var(--muted); }
.status-row dd { font-size: 1.08rem; font-weight: 750; margin: .25rem 0 .55rem; overflow-wrap: anywhere; }

textarea { width: 100%; min-height: 460px; resize: vertical; border: 1px solid #aab9bc; border-radius: .6rem; padding: .8rem; font: 13px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; margin: 1rem 0; }
.rollback { min-width: 0; display: grid; grid-template-columns: minmax(240px, 1fr) auto; gap: .55rem; align-items: end; margin: 1rem 0; }
.rollback label { grid-column: 1 / -1; }
.rollback input { min-width: 0; width: 100%; border: 1px solid #aab9bc; border-radius: .55rem; padding: .62rem; font: 13px ui-monospace, SFMono-Regular, Consolas, monospace; }
.message { white-space: pre-wrap; background: #f8fafc; border-left: 4px solid var(--teal); padding: 1rem; max-height: 360px; overflow: auto; }
code { display: inline-block; max-width: 100%; overflow-wrap:anywhere; word-break: break-all; background: #e7edef; padding: .1rem .3rem; border-radius: .25rem; }
.auth-shell { min-height: 62vh; display: grid; place-items: center; }
.login-panel { width: min(470px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 1.1rem; padding: clamp(1.4rem, 4vw, 2.6rem); box-shadow: var(--shadow); }
.login-panel h1 { font-size: clamp(1.8rem, 5vw, 2.7rem); margin: .35rem 0; }
.login-mark { display: grid; place-items: center; width: 3.2rem; height: 3.2rem; border-radius: .85rem; background: #155e75; color: #ecfeff; font-weight: 800; letter-spacing: .08em; }
.login-form { display: grid; gap: .55rem; margin: 1.5rem 0; }
.login-form label { font-weight: 700; margin-top: .35rem; }
.login-form input { width: 100%; border: 1px solid #aab9bc; border-radius: .65rem; padding: .72rem .8rem; }
.login-form .button { margin-top: .75rem; padding: .72rem; }
.login-error { border-left: 4px solid var(--red); background: #fff1f0; color: var(--red); padding: .75rem; }
.security-note { color: var(--muted); font-size: .88rem; margin-bottom: 0; }
.admin-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }

.auth-page .topbar,
.auth-page footer,
.auth-page .skip { display: none !important; }
.auth-page main {
  width: min(760px, calc(100vw - 2rem));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  place-items: center;
}
.auth-page .auth-shell { width: 100%; min-height: auto; }

.config-panel { max-width: 1240px; margin: 0 auto; }
.config-notice {
  margin: 1rem 0;
  padding: .85rem 1rem;
  border: 1px solid #b9d9e3;
  border-left: 4px solid #0e7490;
  border-radius: .65rem;
  background: #f2fbfd;
  color: #294752;
}
.config-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin: 1rem 0; }
.config-toolbar #config-count { margin-left: auto; }
.config-cards { display: grid; gap: 1rem; }
.config-card {
  min-width: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: .8rem;
  padding: 1rem;
  background: #f9fbfc;
}
.config-card legend { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; padding: 0 .35rem; color: #243843; }
.config-card legend > span { display: grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 999px; background: #155e75; color: #fff; font-size: .78rem; font-weight: 800; }
.config-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.config-fields > label,
.company-config > label { min-width: 0; display: grid; gap: .35rem; color: #2d414d; font-size: .88rem; font-weight: 700; }
.config-fields input[type="text"],
.config-fields input:not([type]),
.config-fields select,
.config-fields textarea,
.company-config input,
.company-config select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #aebdc8;
  border-radius: .55rem;
  padding: .58rem .65rem;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
.config-fields textarea { min-height: 84px; resize: vertical; }
.config-fields .wide { grid-column: 1 / -1; }
.company-config { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .8rem; padding: .85rem; border-radius: .65rem; background: #eef4f7; }
.source-config { display: grid; gap: .45rem; }
.field-label { color: #2d414d; font-size: .88rem; font-weight: 700; }
.source-choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .55rem; }
.source-choice { min-width: 0; display: flex; align-items: flex-start; gap: .5rem; padding: .65rem; border: 1px solid var(--line); border-radius: .55rem; background: #fff; cursor: pointer; }
.source-choice input { margin-top: .18rem; }
.source-choice span { min-width: 0; display: grid; }
.source-choice strong { overflow-wrap: anywhere; }
.source-choice small { color: var(--muted); font-weight: 500; }
.inline-check { display: flex !important; align-items: center; align-self: center; grid-template-columns: auto 1fr; }
.inline-check input { width: auto !important; min-height: auto !important; }
.danger-button { justify-self: end; color: var(--red); border-color: #efb5ae; }
.danger-button:hover { border-color: var(--red); background: #fff1f0; }
.advanced-config { margin-top: 1rem; border: 1px solid var(--line); border-radius: .65rem; padding: .75rem 1rem; background: #f8fafc; }
.advanced-config summary { cursor: pointer; font-weight: 750; }
.advanced-config textarea { min-height: 280px; margin: .75rem 0; }
.card-ai-summary { margin: .35rem 0 .7rem; color: #43545f; font-size: .86rem; }

:focus-visible { outline: 3px solid #0e7490; outline-offset: 3px; }
.search-box:focus-within { border-color: #0e7490; box-shadow: 0 0 0 3px rgba(14, 116, 144, .2); }
.search-box input:focus { outline: 0; }

@media (max-width: 1180px) {
  main { width: min(100% - 2rem, 1180px); }
  .dashboard-heading { grid-template-columns: 1fr; }
  .legacy-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .topbar { align-items: flex-start; flex-direction: column; padding: .75rem 1rem; }
  .header-actions { width: 100%; justify-content: space-between; }
  nav { justify-content: flex-start; }
  .legacy-toolbar { grid-template-columns: 1fr; }
  .search-box { grid-column: 1; }
  .config-fields { grid-template-columns: 1fr; }
  .config-fields .wide, .company-config { grid-column: 1; }
  .company-config { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .source-choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .results-status { text-align: left; }
  .refresh-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .refresh-summary > div:nth-child(3) { border-left: 0; border-top: 1px solid var(--line); }
  .refresh-summary > div:nth-child(4) { border-top: 1px solid var(--line); }
  .split { grid-template-columns: 1fr; }
  .detail-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  main { width: min(100% - 1rem, 720px); margin: .8rem auto 1.5rem; }
  .legacy-grid, .status-list { grid-template-columns: 1fr; }
  .legacy-card { height: 550px; }
  .rollback { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
  .brand { white-space: normal; }
  .header-actions { align-items: flex-start; flex-wrap: wrap; }
  .session-actions { padding-left: 0; border-left: 0; }
  nav a { padding: .35rem .48rem; font-size: .88rem; }
  .dashboard-heading h1 { font-size: 1.65rem; }
  .refresh-summary { grid-template-columns: 1fr 1fr; }
  .view-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .view-tabs button { min-width: 0; padding: .5rem .28rem; font-size: .86rem; }
  .card-head, .card-scroll { padding-left: .8rem; padding-right: .8rem; }
  .detail-meta { grid-template-columns: 1fr; }
  .admin-heading { flex-direction: column; }
  .company-config, .source-choices { grid-template-columns: 1fr; }
  .config-toolbar #config-count { width: 100%; margin-left: 0; }
  .danger-button { justify-self: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
