:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #19211f;
  --muted: #66736f;
  --line: #d9e5f5;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #eff6ff;
  --danger: #c2410c;
  --danger-soft: #fff3ec;
  --blue: #2563eb;
  --amber: #b45309;
  --shadow: 0 12px 30px rgba(25, 33, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--bg);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
textarea,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1560px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 22px;
  border: 1px solid #1d4ed8;
  color: #fff;
  background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 54%, #0f5fb8 100%);
  box-shadow: 0 16px 36px rgba(37, 99, 235, 0.22);
}

.eyebrow {
  margin: 0 0 6px;
  color: #dbeafe;
  font-size: 13px;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1.15;
}

h2 {
  font-size: 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-button,
.secondary-button,
.icon-button {
  border: 0;
  min-height: 42px;
}

.primary-button {
  color: var(--accent-strong);
  background: #fff;
  padding: 0 18px;
  border-radius: 6px;
  font-weight: 700;
}

.secondary-button {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid #bfdbfe;
  padding: 0 14px;
  border-radius: 6px;
  font-weight: 800;
}

.icon-button {
  color: var(--accent-strong);
  background: #fff;
  width: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 20px;
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

.control-panel,
.dashboard {
  display: grid;
  gap: 16px;
}

.control-panel {
  position: sticky;
  top: 16px;
}

.panel-section,
.chart-panel,
.table-panel,
.export-panel,
.metric-card {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-section,
.chart-panel,
.table-panel,
.export-panel {
  padding: 16px;
}

.panel-section.compact {
  display: grid;
  gap: 12px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  align-items: baseline;
}

.section-heading span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

textarea,
select,
input[type="date"],
input[type="time"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fbfdfc;
}

textarea {
  display: block;
  min-height: 160px;
  resize: vertical;
  padding: 12px;
  line-height: 1.55;
}

#keywordInput {
  min-height: 190px;
}

#chatInput {
  min-height: 420px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

select,
input[type="date"],
input[type="time"] {
  height: 40px;
  padding: 0 10px;
}

.file-drop {
  margin-bottom: 10px;
  padding: 14px;
  border: 1px dashed #93c5fd;
  border-radius: 6px;
  background: #f8fbff;
  color: var(--ink);
  transition:
    border-color 0.16s ease,
    background 0.16s ease,
    box-shadow 0.16s ease;
}

.file-drop.drag-over {
  border-color: var(--accent);
  background: #dbeafe;
  box-shadow: inset 0 0 0 1px var(--accent);
}

.file-drop input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.file-drop span {
  font-weight: 800;
}

.file-drop small {
  color: var(--muted);
  font-size: 12px;
}

.upload-status {
  margin-bottom: 10px;
  min-height: 34px;
  padding: 9px 10px;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  color: #1e3a8a;
  background: #eff6ff;
  font-size: 12px;
  line-height: 1.35;
}

.upload-progress {
  height: 10px;
  margin: 0 0 10px;
  border-radius: 999px;
  background: #dbeafe;
  overflow: hidden;
}

.upload-progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #60a5fa, #1d4ed8);
  transition: width 0.16s ease;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.plain-button {
  min-height: 38px;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  color: var(--accent-strong);
  background: #fff;
  font-weight: 800;
}

.metric-card {
  min-height: 108px;
  padding: 16px;
  display: grid;
  align-content: space-between;
  border-radius: 8px;
}

.metric-card.clickable {
  cursor: pointer;
  transition:
    border-color 0.16s ease,
    transform 0.16s ease,
    box-shadow 0.16s ease;
}

.metric-card.clickable:hover,
.metric-card.clickable:focus-visible {
  border-color: #93c5fd;
  box-shadow: 0 16px 34px rgba(37, 99, 235, 0.16);
  transform: translateY(-1px);
  outline: none;
}

.metric-card.disabled {
  cursor: default;
  opacity: 0.72;
}

.metric-card span {
  color: #38608f;
  font-size: 13px;
  font-weight: 700;
}

.metric-card strong {
  color: var(--accent-strong);
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1;
}

.chart-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr);
  gap: 16px;
}

.timeline-chart {
  height: 260px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 6px 0;
  overflow: auto hidden;
  border-top: 1px solid #bfdbfe;
  background: linear-gradient(180deg, #f8fbff 0%, #ffffff 100%);
}

.timeline-day {
  flex: 0 0 58px;
  display: grid;
  gap: 8px;
  align-content: end;
  text-align: center;
}

.timeline-bar {
  width: 100%;
  min-height: 8px;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, #60a5fa, #1d4ed8);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
}

.timeline-day strong {
  font-size: 13px;
}

.timeline-day span {
  color: var(--muted);
  font-size: 11px;
}

.keyword-bars {
  display: grid;
  gap: 12px;
  padding-top: 4px;
}

.keyword-bar-row {
  display: grid;
  grid-template-columns: 74px 1fr 34px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}

.keyword-label {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.keyword-track {
  height: 12px;
  border-radius: 999px;
  background: #dbeafe;
  overflow: hidden;
}

.keyword-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #3b82f6, #1d4ed8);
}

.table-wrap {
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  width: 100%;
  min-width: 880px;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #f8fbfa;
  font-size: 12px;
  white-space: nowrap;
}

tbody tr:hover {
  background: #f9fcfb;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.tag.keyword {
  color: var(--danger);
  background: var(--danger-soft);
}

.tag.internal {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.tag.external {
  color: var(--amber);
  background: #fff7ed;
}

.message-cell {
  max-width: 420px;
  color: #34413d;
}

.empty-state {
  padding: 38px 12px;
  color: var(--muted);
  text-align: center;
}

mark {
  padding: 0 2px;
  color: var(--danger);
  background: #ffedd5;
  border-radius: 3px;
}

@media (max-width: 1120px) {
  .layout-grid,
  .chart-row {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .filter-grid {
    grid-template-columns: 1fr;
  }

  .timeline-chart {
    overflow-x: auto;
  }

  .timeline-day {
    flex: 0 0 54px;
  }
}
