:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --ink: #1f2933;
  --muted: #65717f;
  --line: #d7d5ce;
  --panel: #ffffff;
  --accent: #176f64;
  --accent-dark: #0f4f48;
  --warn: #b65b2a;
  --blue: #365f91;
  --shadow: 0 18px 50px rgba(31, 41, 51, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  overflow-x: hidden;
}

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

.app-header {
  display: flex;
  align-items: stretch;
  flex-direction: column;
  gap: 14px;
  padding: 18px 14px 14px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 2rem;
  line-height: 1.05;
}

.target {
  min-width: 132px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
}

.target span,
.stat span,
.section-title span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.target strong {
  display: block;
  margin-top: 4px;
  font-size: 1.45rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 14px;
  padding: 0 14px 32px;
}

.status-message {
  grid-column: 1 / -1;
  border: 1px solid #e2c2b7;
  border-radius: 8px;
  background: #fff6f2;
  color: #7b2f1b;
  padding: 12px 14px;
  line-height: 1.6;
}

.dashboard {
  grid-column: auto;
  grid-row: auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(31, 41, 51, 0.08);
  padding: 16px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.section-title h2 {
  margin: 0;
  font-size: 1.3rem;
}

form {
  display: grid;
  gap: 16px;
}

.grid {
  display: grid;
  gap: 14px;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfbf9;
  color: var(--ink);
  padding: 10px 11px;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

output {
  justify-self: end;
  color: var(--ink);
  font-size: 1rem;
}

fieldset {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

legend {
  padding: 0 6px;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.86rem;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 600;
}

.check input {
  width: 18px;
  height: 18px;
}

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

button {
  min-height: 42px;
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
}

.actions button {
  flex: 1 1 140px;
}

button:hover {
  background: var(--accent-dark);
}

button.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

button.secondary:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

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

.stat {
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.stat strong {
  display: block;
  margin-top: 8px;
  color: var(--blue);
  font-size: 1.2rem;
  overflow-wrap: anywhere;
}

.insight {
  margin: 16px 0 20px;
  border-left: 4px solid var(--accent);
  background: #eef7f4;
  padding: 12px 14px;
  border-radius: 0 7px 7px 0;
  line-height: 1.6;
}

.chart-area h3 {
  margin-bottom: 10px;
  font-size: 1rem;
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(7, minmax(28px, 1fr));
  align-items: end;
  gap: 8px;
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfbf9;
}

.bar {
  display: grid;
  align-items: end;
  gap: 6px;
  height: 126px;
  color: var(--muted);
  font-size: 0.76rem;
  text-align: center;
}

.bar-fill {
  width: 100%;
  min-height: 4px;
  border-radius: 6px 6px 0 0;
  background: var(--accent);
}

.bar.low .bar-fill {
  background: var(--warn);
}

.history-section {
  margin-top: 18px;
}

.history-section h3 {
  margin-bottom: 10px;
  font-size: 1rem;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbf9;
  padding: 12px;
}

.history-card-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.history-card-title {
  display: grid;
  gap: 3px;
}

.history-card-title strong {
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.history-card-title span,
.kv span {
  color: var(--muted);
  font-size: 0.8rem;
}

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

.kv {
  min-width: 0;
  border-radius: 7px;
  background: #fff;
  padding: 9px;
}

.kv strong {
  display: block;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.history-note {
  color: var(--ink);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.delete-row {
  min-height: 44px;
  padding: 8px 12px;
  background: #fff;
  color: #9c3f26;
  border: 1px solid #e2c2b7;
}

.delete-row:hover {
  background: #fff6f2;
  color: #7b2f1b;
}

.utility {
  margin-top: 16px;
}

@media (min-width: 720px) {
  .app-header {
    align-items: end;
    flex-direction: row;
    justify-content: space-between;
    gap: 24px;
    padding: 32px clamp(20px, 4vw, 48px) 20px;
  }

  h1 {
    font-size: clamp(2.4rem, 5vw, 3.8rem);
  }

  .layout {
    gap: 20px;
    padding: 0 clamp(20px, 4vw, 48px) 42px;
  }

  .panel {
    padding: clamp(18px, 3vw, 28px);
  }

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

  .history-metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 1080px) {
  .layout {
    grid-template-columns: minmax(320px, 0.88fr) minmax(420px, 1.12fr);
  }

  .dashboard {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

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

@media (max-width: 420px) {
  .stats {
    grid-template-columns: 1fr;
  }

  .bar-chart {
    gap: 5px;
  }
}
