:root {
  --analytics-bg: #f4f8fb;
  --analytics-card: #ffffff;
  --analytics-border: #dbe5ef;
  --analytics-text: #1f2937;
  --analytics-muted: #5f6f82;
  --analytics-main: #0f6ab5;
  --analytics-main-strong: #0a4f89;
  --analytics-sub: #f08c32;
}

body {
  margin: 0;
  background: var(--background-color);
  color: var(--analytics-text);
}

.analytics-page {
  width: 100%;
  margin: var(--page-margin-desktop);
  display: grid;
  gap: 16px;
}

.analytics-hero,
.filter-card,
.summary-card,
.panel-card {
  border: 1px solid var(--analytics-border);
  border-radius: 18px;
  background: var(--analytics-card);
  box-shadow: 0 10px 24px rgba(22, 42, 67, 0.08);
}

.analytics-hero {
  padding: 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.analytics-eyebrow {
  margin: 0 0 6px;
  color: var(--analytics-main-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.analytics-hero h1 {
  margin: 0;
  font-size: clamp(24px, 3.2vw, 36px);
  line-height: 1.2;
}

.analytics-description {
  margin: 10px 0 0;
  color: var(--analytics-muted);
  font-size: 14px;
}

.dashboard-back-link {
  color: var(--analytics-main-strong);
  text-decoration: none;
  font-weight: 700;
  font-size: 14px;
}

.dashboard-back-link:hover {
  text-decoration: underline;
}

.filter-card {
  padding: 16px;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-field span {
  color: var(--analytics-muted);
  font-size: 12px;
  font-weight: 700;
}

.filter-field input {
  height: 40px;
  border: 1px solid #c8d8e8;
  border-radius: 10px;
  padding: 0 10px;
  font-size: 14px;
  box-sizing: border-box;
}

.filter-field-wide {
  grid-column: span 1;
}

.filter-actions {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.action-button {
  min-width: 0;
  width: 100%;
  height: 40px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.action-button.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--analytics-main), var(--analytics-main-strong));
}

.action-button.secondary {
  color: #1f2937;
  background: #e6edf5;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.summary-card {
  padding: 14px;
}

.summary-card p {
  margin: 0 0 8px;
  color: var(--analytics-muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-card strong {
  font-size: 28px;
  font-weight: 800;
}

.panel-card {
  padding: 16px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 12px;
}

.panel-header h2 {
  margin: 0;
  font-size: 18px;
}

.period-label {
  color: var(--analytics-muted);
  font-size: 12px;
  font-weight: 700;
}

.chart-area {
  border: 1px solid #d8e5f2;
  border-radius: 14px;
  min-height: 250px;
  padding: 10px;
  box-sizing: border-box;
  overflow-x: auto;
}

.chart-legend {
  display: flex;
  gap: 16px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--analytics-muted);
  font-weight: 700;
}

.legend-line {
  display: inline-block;
  width: 16px;
  height: 3px;
  border-radius: 999px;
  margin-right: 6px;
  vertical-align: middle;
}

.legend-view {
  background: var(--analytics-main);
}

.legend-map {
  background: var(--analytics-sub);
}

.analytics-chart {
  width: 100%;
  height: auto;
}

.chart-plot-bg {
  fill: #f8fbff;
}

.chart-grid-line {
  stroke: #deebf8;
  stroke-width: 1;
}

.chart-axis-text {
  fill: #67809a;
  font-size: 11px;
}

.chart-line {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-line-view {
  stroke: var(--analytics-main);
}

.chart-line-map {
  stroke: var(--analytics-sub);
}

.table-wrap {
  overflow-x: auto;
}

.analytics-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.analytics-table th,
.analytics-table td {
  border-bottom: 1px solid #e5edf6;
  padding: 10px 8px;
  font-size: 13px;
  text-align: left;
  vertical-align: top;
}

.analytics-table th {
  color: var(--analytics-muted);
  font-weight: 700;
  background: #f8fbff;
}

.analytics-table td.num,
.analytics-table th.num {
  text-align: right;
}

.analytics-table .empty {
  color: var(--analytics-muted);
  text-align: center;
}

.scroll-top-button {
  position: fixed;
  right: 16px;
  bottom: calc(72px + env(safe-area-inset-bottom));
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: #1d4ed8;
  color: #ffffff;
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 20px rgba(29, 78, 216, 0.35);
  cursor: pointer;
  z-index: 1200;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.scroll-top-button.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.scroll-top-button:hover {
  opacity: 0.95;
}

.scroll-top-icon {
  display: block;
  width: 18px;
  height: 18px;
  background: currentColor;
  -webkit-clip-path: polygon(50% 0, 100% 45%, 70% 45%, 70% 100%, 30% 100%, 30% 45%, 0 45%);
  clip-path: polygon(50% 0, 100% 45%, 70% 45%, 70% 100%, 30% 100%, 30% 45%, 0 45%);
}

@media (max-width: 980px) {
  .filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .analytics-page {
    width: 100%;
    margin: var(--page-margin-mobile);
    padding: 0;
    box-sizing: border-box;
    gap: 12px;
  }

  .analytics-hero {
    flex-direction: column;
    padding: 16px;
    border-radius: 14px;
  }

  .analytics-hero h1 {
    font-size: 24px;
    line-height: 1.28;
  }

  .analytics-description {
    margin-top: 8px;
    font-size: 13px;
    line-height: 1.6;
  }

  .filter-card {
    padding: 12px;
    border-radius: 14px;
    box-shadow: 0 10px 18px rgba(22, 42, 67, 0.12);
  }

  .filter-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .filter-field input {
    height: 38px;
    font-size: 16px;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .summary-card {
    padding: 12px;
    border-radius: 14px;
  }

  .summary-card p {
    font-size: 11px;
    margin-bottom: 6px;
  }

  .summary-card strong {
    font-size: 22px;
    line-height: 1;
  }

  .action-button {
    height: 38px;
    min-width: 0;
    width: 100%;
  }

  .filter-actions {
    margin-top: 10px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .panel-card {
    border-radius: 14px;
    padding: 12px;
  }

  .panel-header {
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 8px;
    gap: 4px;
  }

  .panel-header h2 {
    font-size: 16px;
  }

  .period-label {
    font-size: 11px;
  }

  .chart-area {
    min-height: 210px;
    padding: 8px;
    border-radius: 12px;
  }

  .chart-legend {
    gap: 10px;
    font-size: 11px;
    margin-bottom: 6px;
  }

  .legend-line {
    width: 12px;
    margin-right: 4px;
  }

  .table-wrap {
    overflow: visible;
  }

  .analytics-table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 8px;
  }

  .analytics-table thead {
    display: none;
  }

  .analytics-table tbody,
  .analytics-table tr,
  .analytics-table td {
    display: block;
    width: 100%;
    box-sizing: border-box;
  }

  .analytics-table tr {
    border: 1px solid #dbe5ef;
    border-radius: 12px;
    background: #fbfdff;
    padding: 8px 10px;
    box-shadow: 0 6px 14px rgba(22, 42, 67, 0.06);
  }

  .analytics-table td {
    border-bottom: 1px dashed #e7eef6;
    padding: 7px 0;
    font-size: 13px;
  }

  .analytics-table td:last-child {
    border-bottom: none;
  }

  .analytics-table td::before {
    content: attr(data-label);
    display: block;
    color: #607286;
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 2px;
  }

  .analytics-table td.num {
    text-align: left;
    font-weight: 700;
  }

  .analytics-table .empty {
    text-align: center;
    border: none;
    background: transparent;
    box-shadow: none;
    padding: 12px 0;
  }

  .analytics-table .empty::before {
    content: "";
  }

  .scroll-top-button {
    right: 14px;
    bottom: calc(82px + env(safe-area-inset-bottom));
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
}
