/* Crawl Monitor — dashboard styles (no external assets, works offline) */

:root {
  --navy: #0f2742;
  --navy-2: #16395f;
  --ink: #1f2d3d;
  --muted: #6b7c8f;
  --line: #e3e9f0;
  --bg: #f4f7fb;
  --card: #ffffff;
  --accent: #0ea5a4;
  --accent-2: #2dd4bf;
  --blue: #2f6fed;
  --green: #16a34a;
  --green-bg: #e8f8ee;
  --amber: #b7791f;
  --amber-bg: #fff6e5;
  --red: #b42318;
  --red-bg: #fdeceb;
  --slate-bg: #eef2f6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 39, 66, .05), 0 8px 24px rgba(15, 39, 66, .06);
  --mono: "Cascadia Mono", "Consolas", "SFMono-Regular", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(1200px 400px at 85% -180px, #dff3f2 0%, rgba(223, 243, 242, 0) 60%),
    var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 1500px; margin: 0 auto; padding: 22px 22px 40px; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  flex-wrap: wrap;
  background: linear-gradient(120deg, var(--navy) 0%, #123a5f 70%, #14506b 100%);
  color: #fff;
  padding: 18px 22px;
  border-radius: 18px;
  box-shadow: 0 12px 30px rgba(15, 39, 66, .18);
}

.brand { display: flex; align-items: center; gap: 13px; min-width: 260px; }
.logo {
  width: 46px; height: 46px; border-radius: 13px;
  background: rgba(255, 255, 255, .08);
  display: grid; place-items: center;
  border: 1px solid rgba(255, 255, 255, .12);
}
.brand-text h1 { margin: 0; font-size: 19px; letter-spacing: .2px; font-weight: 650; }
.brand-text p { margin: 2px 0 0; font-size: 12.5px; color: #b9cddd; }

.controls { display: flex; align-items: flex-end; gap: 9px; flex-wrap: wrap; }

.date-control { display: flex; flex-direction: column; gap: 4px; }
.date-control label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .7px;
  color: #a9c1d4; font-weight: 600;
}
.date-control input {
  background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .22);
  color: #fff;
  padding: 8px 10px;
  border-radius: 9px;
  font: inherit;
  font-size: 13px;
  color-scheme: dark;
}
.date-control input:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 14px;
  font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent-2); color: #06302c; }
.btn-primary:hover { background: #5eead4; }
.btn-ghost {
  background: rgba(255, 255, 255, .08); color: #eaf3f8;
  border-color: rgba(255, 255, 255, .2);
}
.btn-ghost:hover { background: rgba(255, 255, 255, .16); }
.export-group { display: flex; gap: 6px; }
.btn-ai {
  background: #eef2ff; color: #3730a3; border-color: #dfe5ff;
  padding: 8px 13px;
}
.btn-ai:hover { background: #e4e9ff; }

/* ---------------------------------------------------------------- banner */
.banner {
  margin-top: 14px; padding: 12px 15px; border-radius: 12px;
  border: 1px solid #f4c7c3; background: var(--red-bg); color: #7a1d15;
  font-size: 13px;
}
.banner.warn { border-color: #f0d9a8; background: var(--amber-bg); color: #6b4a0f; }
.banner ul { margin: 6px 0 0; padding-left: 18px; }
.banner li { margin: 2px 0; }

/* ------------------------------------------------------------------ KPIs */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.kpi::after {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 4px;
  background: var(--line);
}
.kpi.k-blue::after { background: #9db9d6; }
.kpi.k-teal::after { background: #9ccac7; }
.kpi.k-green::after { background: #a6cdb3; }
.kpi.k-amber::after { background: #dfc38c; }
.kpi.k-red::after { background: #d9a8a3; }
.kpi.k-slate::after { background: #b6c2cf; }

.kpi-label {
  font-size: 10.8px; text-transform: uppercase; letter-spacing: .65px;
  color: var(--muted); font-weight: 700;
}
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.4px; margin-top: 5px; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.kpi-sub .up { color: var(--green); font-weight: 700; }
.kpi-sub .down { color: var(--red); font-weight: 700; }
.kpi-sub .flat { color: var(--muted); font-weight: 700; }

/* ---------------------------------------------------------------- panels */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-top: 14px;
}
.panel-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 10px;
}
.panel h2 { margin: 0; font-size: 15.5px; font-weight: 700; letter-spacing: .1px; }
.panel p.muted, .muted { color: var(--muted); }
.panel-head p.muted { margin: 3px 0 0; font-size: 12px; }

.summary-text { margin: 4px 0 0; font-size: 14.5px; line-height: 1.65; color: #2b3a4a; }
.summary-actions { display: flex; gap: 8px; }

.ai-box {
  margin-top: 14px; padding: 13px 15px;
  border: 1px solid #dfe5ff; background: #f8f9ff; border-radius: 12px;
}
.ai-head { display: flex; align-items: center; gap: 9px; margin-bottom: 7px; }
.ai-title { font-size: 12.5px; font-weight: 700; color: #3730a3; }
.ai-badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  background: #e5e9ff; color: #4338ca; border-radius: 20px; padding: 2px 8px;
}
.ai-list { margin: 0; padding-left: 18px; color: #2b3a4a; }
.ai-list li { margin: 5px 0; font-size: 13.5px; }
.ai-disclaimer { margin: 9px 0 0; font-size: 11.5px; color: var(--muted); }

/* ----------------------------------------------------------- attention */
.count-badge {
  display: inline-block; min-width: 22px; text-align: center;
  background: #f6efee; color: #8a4a43;
  border: 1px solid #ecdedb;
  border-radius: 20px; padding: 1px 8px; font-size: 12px; font-weight: 700;
  vertical-align: 1px; margin-left: 5px;
}
.attention-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px; margin-top: 4px;
}
.attention-card {
  border: 1px solid var(--line); border-left: 3px solid #d9c6a8;
  border-radius: 11px; padding: 11px 13px; background: #fff;
  cursor: pointer; transition: box-shadow .15s ease, transform .1s ease;
}
.attention-card:hover { box-shadow: 0 6px 18px rgba(15, 39, 66, .09); transform: translateY(-1px); }
.attention-card.sev-bad { border-left-color: #d8b0aa; background: #fff; }
.attention-card .ac-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.attention-card .ac-name { font-weight: 700; font-size: 13.2px; }
.attention-card .ac-reason { font-size: 12px; color: var(--muted); margin-top: 4px; }
.attention-card .ac-nums { font-size: 11.5px; color: #4a5a6a; margin-top: 6px; }
.btn-more {
  grid-column: 1 / -1;
  justify-self: start;
  background: #fff; border: 1px solid var(--line); color: #40546a;
  padding: 7px 14px; font-size: 12.5px;
}
.btn-more:hover { border-color: #c9d4e0; background: #f8fbfd; }

/* ---------------------------------------------------------------- table */
.table-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 10px;
}
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--line); background: #fff; color: #40546a;
  border-radius: 9px; padding: 7px 13px; font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.tab span { color: var(--muted); font-weight: 500; font-size: 11.5px; margin-left: 3px; }
.tab:hover { border-color: #c9d4e0; }
.tab.active { background: var(--navy); border-color: var(--navy); color: #fff; }
.tab.active span { color: #a9c1d4; }

.search-wrap { position: relative; }
.search-wrap svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: #8b9aab;
}
.search-wrap input {
  border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 12px 8px 34px; font: inherit; font-size: 13px;
  width: 320px; max-width: 70vw; background: #fff;
}
.search-wrap input:focus { outline: 2px solid #c7e9e8; border-color: var(--accent); }

.status-filter { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--line); background: #fff; color: #4a5a6a;
  border-radius: 20px; padding: 5px 12px; font: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer;
}
.chip:hover { border-color: #c9d4e0; }
.chip.active { background: #eaf1f8; border-color: #bfd3e6; color: var(--navy); }
.chip .chip-count { opacity: .75; font-weight: 600; margin-left: 2px; }
.chip-ok.active { background: var(--green-bg); border-color: #b7e4c7; color: #146c37; }
.chip-warn.active { background: var(--amber-bg); border-color: #f0d9a8; color: #7a5200; }
.chip-bad.active { background: var(--red-bg); border-color: #f4c7c3; color: #8f1d14; }

.table-wrap { overflow-x: auto; border-radius: 11px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 1240px; }
thead th {
  background: #f7f9fc; color: #55687b; text-align: left;
  font-size: 10.8px; text-transform: uppercase; letter-spacing: .55px;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--navy); }
thead th.sorted-asc::after { content: " ▲"; font-size: 9px; }
thead th.sorted-desc::after { content: " ▼"; font-size: 9px; }

tbody tr { border-bottom: 1px solid #eef2f7; cursor: pointer; }
tbody tr:last-child { border-bottom: 0; }
tbody tr:hover { background: #f8fbfd; }
tbody tr.sev-bad td:first-child { box-shadow: inset 2px 0 0 #d9b1ab; }
tbody tr.sev-warn td:first-child { box-shadow: inset 2px 0 0 #e0d0ae; }
tbody tr.sev-muted { opacity: .72; }
td { padding: 10px 12px; vertical-align: top; }
.c-date { white-space: nowrap; color: #5b6b7c; font-size: 12px; }
.c-source strong { font-weight: 700; color: #1c2c3c; }
.c-source .sub { display: block; font-size: 11.2px; color: var(--muted); margin-top: 2px; }
.c-file code {
  font-family: var(--mono); font-size: 11px; font-weight: 700; color: #24384c;
  background: #f4f7fa; border: 1px solid #e6ecf2; border-radius: 6px;
  padding: 2px 6px; display: inline-block; max-width: 290px;
  overflow-wrap: anywhere;
}
.c-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.c-num .num-main { font-weight: 700; font-size: 13.5px; }
.c-num .delta { display: block; font-size: 11px; margin-top: 1px; }
.delta.up { color: var(--green); } .delta.down { color: var(--red); } .delta.flat { color: var(--muted); }
.c-status { white-space: nowrap; min-width: 200px; }
.c-status .pill { margin-right: 4px; }
.status-reason {
  display: block; white-space: normal; max-width: 250px;
  font-size: 10.8px; line-height: 1.35; color: var(--muted); margin-top: 4px;
}
.diag-dot {
  display: inline-block; margin-left: 6px; font-size: 10.5px; font-weight: 700;
  color: #8a6524; background: #fdf8ee; border: 1px solid #f0e4cd;
  border-radius: 10px; padding: 1px 6px; vertical-align: 1px;
}
.dev { font-weight: 700; font-variant-numeric: tabular-nums; }
.dev.up { color: var(--green); } .dev.down { color: var(--red); } .dev.flat { color: var(--muted); }

.weekly-info {
  display: flex; align-items: center; flex-wrap: wrap; gap: 7px;
  background: #f3f7fb; border: 1px solid #dde8f2; color: #2f4a63;
  border-radius: 10px; padding: 10px 13px; margin-bottom: 12px; font-size: 12.8px;
}
.weekly-info strong { color: var(--navy); }
.weekly-info .sep { color: #a8b8c6; }

.diag-list { display: flex; flex-direction: column; gap: 7px; }
.diag-item {
  border: 1px solid var(--line); border-left: 3px solid #d9c6a8;
  border-radius: 8px; padding: 8px 10px; background: #fff;
}
.diag-item.sev-bad { border-left-color: #d8b0aa; }
.diag-label { display: block; font-size: 12px; font-weight: 700; color: #2f4053; }
.diag-msg { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.pill {
  display: inline-block; border-radius: 20px; padding: 3px 10px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  border: 1px solid transparent;
}
.pill-ok { background: #f1f7f3; color: #3a6b4f; border-color: #dde9e1; }
.pill-warn { background: #fdf8ee; color: #856329; border-color: #f0e4cd; }
.pill-bad { background: #fdf3f2; color: #92463d; border-color: #f1dcda; }
.pill-muted { background: #f4f6f8; color: #6d7b88; border-color: #e6ebf0; }

.spark { display: flex; align-items: flex-end; gap: 3px; height: 30px; min-width: 108px; }
.spark-bar { width: 11px; border-radius: 3px 3px 0 0; background: #cfe0ee; min-height: 2px; }
.spark-bar.hot { background: #7fb3d5; }
.spark-bar.today { background: var(--accent); }
.spark-bar.zero { background: #e8edf3; }

.table-foot { margin: 9px 2px 0; font-size: 12px; }
.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty p { margin: 0 0 10px; }

/* --------------------------------------------------------------- drawer */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(15, 32, 51, .38);
  backdrop-filter: blur(1px); z-index: 40;
}
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 500px; max-width: 94vw;
  background: #fff; z-index: 41;
  box-shadow: -18px 0 50px rgba(15, 39, 66, .22);
  transform: translateX(102%);
  transition: transform .22s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line);
  background: linear-gradient(120deg, #0f2742, #14506b); color: #fff;
}
.drawer-head h2 { margin: 0; font-size: 16px; }
.drawer-head .muted { color: #b9cddd; font-size: 12px; margin: 3px 0 0; }
.icon-btn {
  background: rgba(255, 255, 255, .12); border: 0; color: #fff;
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.drawer-body { padding: 18px 20px 30px; overflow-y: auto; }
.detail-status { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.detail-reason {
  margin: 10px 0 0; padding: 10px 12px; border-radius: 9px;
  background: #f6f8fb; border: 1px solid #e7edf4; font-size: 12.8px; color: #41536a;
}
.detail-section { margin-top: 18px; }
.detail-section h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .7px;
  color: var(--muted); margin: 0 0 8px;
}
.kv { display: grid; grid-template-columns: 132px 1fr; gap: 6px 10px; font-size: 12.8px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.kv dd code { font-family: var(--mono); font-size: 11px; }
.bar-chart { display: flex; align-items: flex-end; gap: 7px; height: 96px; padding: 4px 2px 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bar-col .bar { width: 100%; max-width: 34px; border-radius: 4px 4px 0 0; background: #cfe0ee; min-height: 2px; }
.bar-col .bar.today { background: var(--accent); }
.bar-col .bar.zero { background: #e8edf3; }
.bar-col .lbl { font-size: 9.5px; color: var(--muted); white-space: nowrap; }
.bar-col .val { font-size: 10px; font-weight: 700; color: #40546a; }
.tag {
  display: inline-block; font-size: 11px; font-weight: 600; border-radius: 7px;
  padding: 2px 8px; background: #eef2f6; color: #4a5a6a; margin-right: 4px;
}

/* -------------------------------------------------------------- loading */
.loading {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(244, 247, 251, .82); backdrop-filter: blur(2px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  color: #33475c; font-weight: 600;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid #d7e4ef; border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.footer {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-top: 22px; color: #8a99a8; font-size: 11.5px;
}

.hidden { display: none !important; }

/* ------------------------------------------------------------- responsive */
@media (max-width: 1200px) {
  .c-file, th.c-file { display: none; }
  table { min-width: 980px; }
}

@media (max-width: 900px) {
  .c-hist, th.c-hist { display: none; }
  table { min-width: 780px; }
}

@media (max-width: 980px) {
  .app { padding: 14px 12px 30px; }
  .topbar { padding: 15px 16px; border-radius: 14px; }
  .brand-text h1 { font-size: 17px; }
  .controls { width: 100%; }
  .date-control { flex: 1; }
  .date-control input { width: 100%; }
  .kpi-value { font-size: 22px; }
  .search-wrap input { width: 100%; }
  .search-wrap { flex: 1; }
}

@media (max-width: 620px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi-value { font-size: 20px; }
  .panel { padding: 14px; }
  .summary-text { font-size: 13.5px; }
  .c-date, th.c-date { display: none; }
  table { min-width: 600px; font-size: 12.5px; }
  .spark { min-width: 88px; }
  .status-reason { max-width: 170px; }
  .footer { font-size: 10.5px; }
  .drawer { width: 100vw; }
}
