:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #dbe3f0;
  --accent: #2563eb;
  --accent-weak: #dbeafe;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", "Noto Sans JP", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #f8fbff 0%, #f1f5f9 100%);
}

.app-shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 20px 48px;
}

.topbar {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

header h1 { margin: 0 0 6px; font-size: 1.5rem; }
header p { margin: 0; color: var(--muted); }

.tabs {
  display: flex;
  gap: 8px;
  margin: 14px 0 0;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  position: sticky;
  top: 8px;
  z-index: 2;
}

.tab-btn {
  border: 1px solid transparent;
  background: #f8fafc;
  color: #334155;
  border-radius: 10px;
  padding: 8px 13px;
  cursor: pointer;
}
.tab-btn.active {
  background: var(--accent);
  color: #fff;
}

main { padding-top: 16px; }
.tab-content { display: none; }
.tab-content.active { display: block; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

h2 { margin: 0 0 10px; font-size: 1.15rem; }
h3 { margin-top: 0; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin: 10px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

label { display: flex; flex-direction: column; gap: 6px; font-size: 0.88rem; color: #334155; }

input, select, button {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
}

.btn { cursor: pointer; min-width: 112px; }
.btn-primary {
  color: #fff;
  border-color: var(--accent);
  background: linear-gradient(180deg, #3b82f6, #2563eb);
}
.btn-secondary {
  color: #1e293b;
  background: #f8fafc;
}
.btn:hover { filter: brightness(0.98); }

.chart {
  width: 100%;
  min-height: 460px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.muted { color: var(--muted); font-size: 0.9rem; }

.mapping-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 8px;
}
.mapping-item {
  background: #f8fbff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
}

table { border-collapse: collapse; width: 100%; background: #fff; }
th, td { border: 1px solid #e2e8f0; padding: 6px 8px; font-size: 0.85rem; }

.year-filter { min-width: 300px; }
.year-range-inputs { display: flex; gap: 8px; align-items: center; }

.source-options { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.source-option { flex-direction: row; align-items: center; gap: 6px; }

.color-option { display: flex; align-items: center; gap: 8px; }
.color-swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid #9ca3af; display: inline-block; }

.palette-preview { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.palette-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.78rem;
}
.palette-chip.active { border-color: var(--accent); background: var(--accent-weak); }
.chip-swatch { width: 12px; height: 12px; border-radius: 999px; border: 1px solid #9ca3af; }
.chip-label { color: #334155; }


.compact-panel { padding: 12px 16px; }

input, select, button {
  min-height: 42px;
}

button {
  touch-action: manipulation;
}

.actions {
  gap: 8px;
  flex-wrap: wrap;
}

#preview {
  overflow-x: auto;
}

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

  .topbar {
    padding: 16px;
  }

  header h1 {
    font-size: 1.2rem;
    line-height: 1.4;
  }

  .tabs {
    overflow-x: auto;
    padding: 8px;
    gap: 6px;
    scrollbar-width: thin;
  }

  .tab-btn {
    white-space: nowrap;
    flex: 0 0 auto;
  }

  .panel {
    padding: 14px;
    border-radius: 12px;
  }

  .controls {
    padding: 10px;
    gap: 8px;
  }

  .controls > label,
  .controls > button,
  .controls > div,
  .controls > span {
    width: 100%;
  }

  .year-filter {
    min-width: 0;
  }

  .year-range-inputs {
    gap: 6px;
  }

  .chart {
    min-height: 320px;
  }

  .actions {
    justify-content: stretch;
  }

  .actions .btn {
    flex: 1 1 140px;
    min-width: 0;
  }

  th, td {
    font-size: 0.78rem;
    white-space: nowrap;
  }
}
