:root {
  --bg: #f1f1f1;
  --card: #ffffff;
  --panel: #f8f8f8;
  --line: #d9d9d9;
  --text: #1f1f1f;
  --muted: #595959;
  --red: #d92d2d;
  --red-alt: #f05a5a;
  --orange: #f39c26;
  --green: #2bb673;
  --blue: #2d9cdb;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100vh;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.topbar {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 18px 22px;
  margin-bottom: 20px;
}

.title-wrap h1 {
  margin: 0;
  font-size: clamp(1.4rem, 2vw, 2.1rem);
  font-weight: 800;
}

.actions, .image-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.file-upload {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  background: linear-gradient(135deg, var(--blue), #1a7ec7);
  color: #fff;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  overflow: hidden;
  box-shadow: 0 10px 22px rgba(34, 120, 189, 0.25);
}

.file-upload input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.secondary-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}

.card, .panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.filters-panel {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 18px;
  padding: 18px 20px;
  margin-bottom: 22px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-group label {
  font-weight: 600;
  font-size: 0.9rem;
}

.filter-group select,
.filter-group input[type="date"] {
  border: 1px solid var(--line);
  background: #fbfbfb;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.95rem;
  color: var(--text);
}

.filter-group input[type="date"]:disabled {
  color: #888;
  cursor: not-allowed;
  background: #f0f0f0;
}

.filter-hint {
  grid-column: 1 / -1;
  margin: -8px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 340px));
  gap: 18px;
  max-width: 1056px;
  margin-bottom: 22px;
}

.stat-card {
  position: relative;
  color: #fff;
  border-radius: 18px;
  padding: 22px 18px 20px;
  min-height: 150px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  box-shadow: var(--shadow);
}

.stat-card.impact {
  background: linear-gradient(135deg, #d62f2f, #b91f1f);
}

.stat-card.infrastructure {
  background: linear-gradient(135deg, #f39c26, #d47a00);
}

.stat-card.corrected {
  background: linear-gradient(135deg, #2ab46a, #1d8e57);
}

.stat-label {
  font-weight: 600;
  font-size: 1.02rem;
  line-height: 1.3;
  margin-bottom: 8px;
}

.stat-value {
  font-size: clamp(2rem, 3vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(300px, 1fr));
  gap: 20px;
}

.chart-panel, .table-panel, .image-panel {
  padding: 16px 16px 14px;
}

.chart-panel.wide, .table-panel.wide {
  grid-column: span 2;
}

.panel-header {
  margin-bottom: 12px;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.split-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.table-filter {
  min-width: 180px;
}

.table-filter label {
  font-size: 0.8rem;
}

.table-filter select {
  min-width: 180px;
  border: 1px solid var(--line);
  background: #fbfbfb;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.9rem;
  color: var(--text);
}

.chart-wrap {
  position: relative;
  height: 300px;
}

.pie-chart-wrap {
  height: 300px;
  max-width: 520px;
  margin: 0 auto;
}

.site-chart-wrap {
  height: 340px;
}

.summary-box {
  margin-top: 12px;
  padding: 12px 14px;
  background: #f5f5f5;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.table-wrap {
  max-height: 470px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

th {
  background: #f0f0f0;
  font-weight: 700;
}

td:first-child {
  text-align: left;
}

.tendency {
  font-weight: 800;
  font-size: 1.1rem;
}

.tendency.up { color: #df3939; }
.tendency.down { color: #1ea85c; }
.tendency.equal { color: #9a9a9a; }

.image-panel {
  margin-top: 22px;
}

.image-preview-area {
  min-height: 260px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: linear-gradient(180deg, #fafafa, #f0f0f0);
}

#uploadedImage {
  max-width: 100%;
  max-height: 420px;
  display: block;
}

.placeholder {
  color: var(--muted);
  font-weight: 600;
}

@media (max-width: 980px) {
  .filters-panel,
  .stats-grid,
  .charts-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    max-width: 100%;
  }

  .chart-panel.wide, .table-panel.wide {
    grid-column: span 1;
  }

  .topbar,
  .split-row {
    flex-direction: column;
    align-items: flex-start;
  }
}
