/*
 * 应用基础样式。
 *
 * 设计说明：
 * - 提供轻量统一布局，保证模板分离后页面结构可读。
 * - 不引入第三方 CSS 框架，减少依赖与部署复杂度。
 */

:root {
  --bg: #f7f8fa;
  --bg2: #ffffff;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2563eb;
  --accent: #2563eb;
  --ok: #059669;
  --warn: #d97706;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --chart-h: 280px;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.app-shell {
  display: grid;
  grid-template-columns: 230px 1fr;
  min-height: calc(100vh - 56px);
  position: relative;
}

.app-shell.no-sidebar {
  grid-template-columns: 1fr;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.app-topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  gap: 10px;
}

.app-topbar-brand {
  font-weight: 700;
  color: #111827;
}

.app-topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.app-user {
  color: var(--muted);
  font-size: 13px;
}

.topbar-link {
  text-decoration: none;
  color: var(--brand);
  font-size: 14px;
}

.topbar-link:hover {
  text-decoration: underline;
}

.topbar-logout-form {
  margin: 0;
}

.topbar-link-btn {
  border: none;
  background: transparent;
  color: var(--brand);
  padding: 0;
  font-size: 14px;
  cursor: pointer;
}

.topbar-link-btn:hover {
  text-decoration: underline;
}

.app-sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 12px;
}

.app-shell.sidebar-hidden {
  grid-template-columns: 1fr;
}

.app-shell.sidebar-hidden .app-sidebar {
  display: none;
}

.sidebar-edge-toggle {
  position: fixed;
  left: 6px;
  top: 88px;
  z-index: 30;
  min-width: 20px;
  min-height: 42px;
  padding: 0 4px;
  font-size: 12px;
  opacity: .32;
  background: #f8fafc;
  color: #94a3b8;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  box-shadow: none;
}

.sidebar-edge-toggle:hover {
  opacity: .6;
}

.app-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.app-title {
  margin: 0;
  font-size: 18px;
}

.sidebar-collapsed {
  grid-template-columns: 64px 1fr;
}

.sidebar-collapsed .app-title,
.sidebar-collapsed .app-nav a {
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-collapsed .app-nav a {
  text-indent: -9999px;
  position: relative;
}

.sidebar-collapsed .app-nav a::before {
  content: attr(data-short);
  font-size: 13px;
  font-weight: 700;
  text-indent: 0;
  position: absolute;
  left: 12px;
  color: var(--accent);
}

.app-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.app-nav a {
  text-decoration: none;
  color: var(--brand);
  padding: 4px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  transition: all .2s ease;
}

.app-nav {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.app-nav a:hover {
  color: var(--brand);
  border-color: #bfdbfe;
  background: #eff6ff;
}

.app-nav a.active {
  color: #1d4ed8;
  border-color: #93c5fd;
  background: #dbeafe;
  box-shadow: none;
}

.nav-group-toggle {
  text-align: left;
  background: #fff;
  color: var(--brand);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 4px 10px;
}

.nav-group-toggle:hover {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.nav-group-toggle.active {
  color: #1d4ed8;
  border-color: #93c5fd;
  background: #dbeafe;
}

.nav-submenu {
  display: none;
  margin: -4px 0 4px 8px;
  padding-left: 8px;
  border-left: 2px solid #dbeafe;
}

.nav-submenu.open {
  display: grid;
  gap: 6px;
}

.nav-submenu a {
  font-size: 13px;
}

.app-main {
  margin: 20px;
  padding: 0 6px 24px;
}

.panel,
pre,
table,
textarea {
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 10px;
}

.panel {
  padding: 14px;
  margin-bottom: 14px;
}

h1, h2, h3 {
  margin-top: 0;
  margin-bottom: 10px;
}

p {
  line-height: 1.55;
}

.app-footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  padding: 16px 20px;
  background: #fff;
}

.auth-main {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(460px, calc(100vw - 32px));
}

.stack-form {
  display: grid;
  gap: 10px;
}

.stack-form label {
  display: grid;
  gap: 6px;
}

.muted {
  color: var(--muted);
}

.action-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.danger {
  background: #dc2626;
}

.warn {
  background: #d97706;
}

.inline-form {
  display: inline;
}

.notice-banner {
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1e3a8a;
  border-radius: 10px;
  padding: 10px 12px;
}

table {
  border-collapse: collapse;
  width: 100%;
  table-layout: auto;
}

td, th {
  overflow-wrap: anywhere;
}

th, td {
  border: 1px solid var(--line);
  padding: 8px;
}

th {
  background: #f9fafb;
}

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

input, select, button, textarea {
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.2);
}

button {
  cursor: pointer;
  background: #2563eb;
  color: #fff;
}

a { color: #2563eb; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}

.kpi {
  margin: 0;
  white-space: pre-wrap;
  padding: 10px;
}

.stats-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 12px;
  margin-top: 8px;
}

.stats-detail-stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 8px;
}

.table-panel h3 {
  margin-bottom: 12px;
}

.table-panel table {
  margin-top: 6px;
}

.stats-overview-inline-actions {
  margin-top: 8px;
}

.stats-full-filter {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  align-items: end;
}

.stats-full-filter label {
  display: grid;
  gap: 6px;
}

.stats-full-meta {
  color: var(--muted);
  font-size: 13px;
}

.stats-full-filter button,
.stats-overview-inline-actions button {
  padding: 6px 10px;
  min-height: auto;
  font-size: 14px;
  border-radius: 8px;
  width: auto;
  justify-self: start;
}

.status-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
}

.status-chip.pending { color: #92400e; background: #fffbeb; border-color: #fcd34d; }
.status-chip.running { color: #1d4ed8; background: #eff6ff; border-color: #93c5fd; }
.status-chip.done { color: #065f46; background: #ecfdf5; border-color: #86efac; }
.status-chip.failed { color: #991b1b; background: #fef2f2; border-color: #fca5a5; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}

/* 今日/昨日概览对比布局：固定两列，左今日右昨日，行内同指标可直接横向比对。 */
.metric-compare-grid {
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px 12px;
}

.metric-compare-head {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: -2px;
}

.metric-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.metric-value {
  font-size: 22px;
  font-weight: 700;
  color: #111827;
}

.trend-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.trend-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
}

.chart-error {
  min-height: 20px;
  color: #dc2626;
  font-size: 13px;
  margin-bottom: 6px;
}

.trend-card h4 {
  margin: 0 0 6px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .app-main {
    margin: 12px;
  }
}

.trend-up { color: var(--ok); }
.trend-down { color: #fb7185; }
.trend-flat { color: var(--warn); }

/* 预览卡片弱化辅助信息（如“昨日同期”），减少视觉竞争。 */
.preview-subtle {
  color: #b8c4d3;
  margin-top: 2px;
}

#trendChart,
#referrerChart,
#provinceChart,
#subdomainChart,
#keywordChart,
#aiChart,
#aiSparklineChart {
  min-height: var(--chart-h);
  max-height: var(--chart-h);
}

details summary {
  cursor: pointer;
  color: #2563eb;
  margin-bottom: 8px;
}
