:root {
  color-scheme: light;
  --bg-top: #ffffff;
  --bg-bottom: #ffffff;
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --surface-border: rgba(30, 64, 112, 0.1);
  --text-main: #162333;
  --text-muted: #627488;
  --brand: #2d74da;
  --brand-strong: #164fa8;
  --brand-soft: #dce9ff;
  --accent: #0d7db6;
  --accent-soft: #d9eefb;
  --danger: #b9382e;
  --danger-soft: #f8d9d3;
  --shadow: 0 8px 20px rgba(22, 35, 51, 0.08);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
}

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  color: var(--text-main);
  font-family:
    "Avenir Next",
    "Hiragino Sans",
    "Yu Gothic",
    sans-serif;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(100%, 540px);
  margin: 0 auto;
  padding:
    calc(20px + var(--safe-top))
    16px
    calc(160px + var(--safe-bottom));
  display: grid;
  gap: 14px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-xl);
  padding: 18px 18px 20px;
  box-shadow: var(--shadow);
  backdrop-filter: none;
  animation: panel-enter 420ms ease both;
}

.panel-nav {
  padding: 8px;
}

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

.top-nav-link {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 42px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--text-main);
  background: rgba(29, 37, 43, 0.06);
  font-weight: 700;
}

.top-nav-link.is-active {
  background: #24476f;
  color: #fffdf8;
}

.panel:nth-child(2) {
  animation-delay: 60ms;
}

.panel:nth-child(3) {
  animation-delay: 120ms;
}

.panel:nth-child(4) {
  animation-delay: 180ms;
}

.panel:nth-child(5) {
  animation-delay: 240ms;
}

.eyebrow,
.section-label,
.count-caption {
  margin: 0;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
}

.hero-copy,
.section-copy {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.5;
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.last-sent-card {
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 14px;
  border-radius: var(--radius-lg);
  background: #ffffff;
  border: 1px solid var(--surface-border);
}

.last-sent-time {
  margin: 0;
  font-size: 1.28rem;
  font-weight: 800;
  line-height: 1.1;
}

.last-sent-summary {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.4;
}

.selection-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
  background: rgba(29, 37, 43, 0.08);
  color: var(--text-main);
}

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

.area-button {
  min-height: 66px;
  border: 1px solid rgba(29, 37, 43, 0.12);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.92);
  color: var(--text-main);
  display: grid;
  gap: 4px;
  justify-items: start;
  align-content: center;
  padding: 14px;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background-color 140ms ease,
    box-shadow 140ms ease;
}

.area-button:active {
  transform: scale(0.98);
}

.area-button.selected {
  border-color: rgba(45, 116, 218, 0.42);
  background: #e8f1ff;
  box-shadow: inset 0 0 0 1px rgba(45, 116, 218, 0.16);
}

.area-button-floor {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.area-button-zone {
  font-size: 0.92rem;
  color: var(--text-muted);
}

.ghost-button {
  border: none;
  background: transparent;
  color: var(--brand-strong);
  font: inherit;
  font-weight: 700;
  padding: 8px 0;
}

.count-panel {
  overflow: hidden;
}

.stepper {
  display: grid;
  grid-template-columns: 88px 1fr 88px;
  gap: 12px;
  align-items: center;
}

.stepper-button {
  min-height: 140px;
  border: none;
  border-radius: var(--radius-lg);
  background: #24476f;
  color: #fff9f2;
  font-size: 1.45rem;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(36, 71, 111, 0.16);
}

.stepper-button:active {
  transform: translateY(1px) scale(0.985);
}

.count-display {
  display: grid;
  gap: 10px;
  justify-items: center;
  padding: 16px 10px;
  border-radius: var(--radius-xl);
  background: var(--surface-strong);
  border: 1px solid rgba(29, 37, 43, 0.08);
}

.count-input {
  width: 100%;
  border: none;
  background: transparent;
  padding: 0;
  text-align: center;
  font-size: clamp(2.9rem, 14vw, 5rem);
  line-height: 1;
  font-weight: 800;
  color: var(--brand-strong);
  font-family: inherit;
  appearance: textfield;
}

.count-input::-webkit-outer-spin-button,
.count-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.count-input:focus {
  outline: none;
}

.count-unit {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-muted);
}

.history-panel {
  background: var(--surface);
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.history-item {
  padding: 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.66);
  border: 1px solid rgba(29, 37, 43, 0.08);
}

.history-item-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.history-item-time {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-summary {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.35;
  white-space: nowrap;
}

.history-empty {
  margin: 0;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: rgba(29, 37, 43, 0.06);
  color: var(--text-muted);
  line-height: 1.55;
}

.status-message {
  margin: 10px auto 0;
  width: min(100%, 540px);
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(29, 37, 43, 0.08);
  line-height: 1.55;
  text-align: center;
}

.status-message.success {
  background: var(--accent-soft);
  color: var(--accent);
}

.status-message.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-message.loading {
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.record-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(29, 37, 43, 0.08);
}

.record-row:last-child {
  border-bottom: none;
}

.record-row dt {
  color: var(--text-muted);
}

.record-row dd {
  margin: 0;
  font-weight: 700;
}

.submit-bar {
  position: fixed;
  inset: auto 0 0;
  z-index: 2;
  padding:
    12px 16px
    calc(16px + var(--safe-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid rgba(30, 64, 112, 0.08);
  backdrop-filter: none;
}

.submit-button {
  width: min(100%, 540px);
  display: block;
  margin: 0 auto;
  min-height: 62px;
  border: none;
  border-radius: 999px;
  background: var(--brand);
  color: #fffdf8;
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 18px rgba(22, 79, 168, 0.18);
}

.submit-button:disabled {
  opacity: 0.58;
  box-shadow: none;
}

.submit-status {
  font-size: 0.92rem;
}

.dashboard-shell {
  width: min(100%, 880px);
}

.dashboard-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.hero-title {
  margin: 6px 0 0;
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  line-height: 1.1;
}

.hero-meta {
  margin: 8px 0 0;
  color: var(--text-muted);
  line-height: 1.5;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
  background: rgba(29, 37, 43, 0.08);
  color: var(--text-main);
}

.status-pill.healthy {
  background: #def3e3;
  color: #1f6b38;
}

.status-pill.unhealthy {
  background: #f9dfdb;
  color: #9c3329;
}

.status-pill.db-error {
  background: #fce9c9;
  color: #8a5216;
}

.status-pill.unknown {
  background: #e8edf4;
  color: #4c6178;
}

.operating-grid,
.crowdedness-grid,
.scanner-grid,
.trend-list {
  display: grid;
  gap: 12px;
}

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

.operating-card,
.crowdedness-card,
.scanner-card,
.trend-card {
  border: 1px solid rgba(29, 37, 43, 0.08);
  border-radius: var(--radius-lg);
  padding: 16px;
  background: rgba(255, 255, 255, 0.88);
}

.operating-card-title,
.crowdedness-card-title,
.scanner-card-title,
.trend-card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
}

.operating-card-copy,
.scanner-card-copy,
.trend-card-copy {
  margin: 8px 0 0;
  color: var(--text-muted);
  line-height: 1.5;
}

.crowdedness-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

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

.crowdedness-card-meta {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.crowdedness-card-value {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
  color: var(--brand-strong);
  white-space: nowrap;
}

.crowdedness-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
  margin-top: 14px;
}

.crowdedness-history-title {
  margin: 14px 0 0;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.crowdedness-history-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.crowdedness-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: rgba(29, 37, 43, 0.05);
}

.crowdedness-history-time {
  font-size: 0.86rem;
  color: var(--text-muted);
}

.crowdedness-history-count {
  font-size: 0.92rem;
  font-weight: 800;
}

.scanner-card-meta,
.trend-card-meta {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.scanner-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.scanner-card-header,
.trend-card-header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.scanner-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
  margin-top: 14px;
}

.metric-label {
  display: block;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.metric-value {
  display: block;
  margin-top: 4px;
  font-size: 1rem;
  font-weight: 800;
}

.trend-list {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.trend-bars {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
  min-height: 96px;
  margin-top: 16px;
}

.trend-bar {
  display: grid;
  align-items: end;
  min-height: 96px;
}

.trend-bar-fill {
  width: 100%;
  border-radius: 0;
  background: #b7cbeb;
  min-height: 10px;
}

.trend-bar-fill.healthy {
  background: #71c08c;
}

.trend-bar-fill.unhealthy {
  background: #dc7567;
}

.trend-bar-fill.db-error {
  background: #d39a4b;
}

.trend-bar-fill.unknown {
  background: #bcc7d2;
}

.raw-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.raw-select {
  min-width: 180px;
  min-height: 42px;
  border: 1px solid rgba(29, 37, 43, 0.14);
  border-radius: 14px;
  padding: 0 12px;
  font: inherit;
  color: var(--text-main);
  background: #ffffff;
}

.raw-json-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.raw-json-card {
  border: 1px solid rgba(29, 37, 43, 0.08);
  border-radius: var(--radius-lg);
  padding: 14px;
  background: rgba(255, 255, 255, 0.88);
}

.raw-json-card-title {
  margin: 0 0 10px;
  font-size: 0.86rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.raw-json-code {
  margin: 0;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(29, 37, 43, 0.05);
  color: var(--brand-strong);
  font-size: 0.84rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.confirm-dialog {
  width: min(calc(100% - 24px), 420px);
  padding: 0;
  border: none;
  border-radius: var(--radius-xl);
  background: transparent;
  box-shadow: none;
}

.confirm-dialog:focus {
  outline: none;
}

.confirm-dialog::backdrop {
  background: rgba(29, 37, 43, 0.34);
  backdrop-filter: blur(6px);
}

.confirm-dialog-card {
  background: var(--surface-strong);
  border: 1px solid rgba(29, 37, 43, 0.08);
  border-radius: var(--radius-xl);
  padding: 20px;
  box-shadow: 0 12px 28px rgba(22, 35, 51, 0.14);
}

.confirm-dialog-title {
  margin: 8px 0 0;
  font-size: 1.35rem;
  line-height: 1.35;
}

.confirm-summary {
  margin: 18px 0 0;
}

.confirm-note {
  margin: 16px 0 0;
  color: var(--text-muted);
  line-height: 1.5;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 10px;
  margin-top: 18px;
}

.confirm-cancel-button {
  min-height: 52px;
  border-radius: 999px;
  background: rgba(29, 37, 43, 0.06);
  color: var(--text-main);
  padding: 0 18px;
}

.confirm-submit-button {
  min-height: 52px;
  border: none;
  border-radius: 999px;
  background: var(--brand);
  color: #fffdf8;
  font: inherit;
  font-weight: 800;
  padding: 0 18px;
  box-shadow: 0 8px 18px rgba(22, 79, 168, 0.18);
}

@keyframes panel-enter {
  from {
    opacity: 0;
    transform: translateY(18px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .panel {
    padding: 16px 16px 18px;
  }

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

  .stepper {
    grid-template-columns: 72px 1fr 72px;
    gap: 10px;
  }

  .stepper-button {
    min-height: 120px;
  }

  .confirm-actions {
    grid-template-columns: 1fr;
  }

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

  .dashboard-hero {
    flex-direction: column;
  }

  .scanner-metrics {
    grid-template-columns: 1fr;
  }

  .raw-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .raw-select {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .panel,
  .area-button,
  .stepper-button {
    animation: none;
    transition: none;
  }
}
