:root {
  color-scheme: light;
  --ink: #071735;
  --muted: #5d6676;
  --line: #d8dde6;
  --panel: #ffffff;
  --soft: #f5f6f8;
  --navy: #001b49;
  --navy-2: #001333;
  --accent: #001b49;
  --yellow: #d97706;
  --red: #c62828;
  --green: #087443;
  --safeBottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  background: #f4f5f7;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(180deg, rgba(0, 27, 73, 0.05), transparent 180px),
    #f4f2ee;
}

.appShell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 12px 82px;
  background: #f4f2ee;
}

.topBar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 82px;
  margin: 0 -12px;
  padding: 16px 14px;
  background: linear-gradient(135deg, var(--navy-2), var(--navy));
  color: #fff;
  box-shadow: 0 8px 22px rgba(0, 27, 73, 0.22);
}

.brandBlock { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brandMark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.88);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-weight: 950;
  line-height: 1;
}

.brandMark span { font-size: 16px; }
.brandMark small { font-size: 8px; letter-spacing: 0.2px; }

h1 {
  margin: 0;
  font-size: clamp(17px, 4.4vw, 24px);
  line-height: 1.18;
  letter-spacing: 0;
}

.topMeta {
  margin: 2px 0 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 11px;
  font-weight: 700;
}

.badge {
  min-width: 58px;
  padding: 5px 8px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

.badge.running { background: rgba(255,255,255,.16); }
.badge.done { background: rgba(8,116,67,.32); }
.badge.error { background: rgba(198,40,40,.34); }

.commandPanel,
.progressPanel,
.summaryItem,
.panel,
tr {
  border: 1px solid var(--line);
  background: var(--panel);
}

.appPage { display: none; }
.appPage.active {
  display: block;
  animation: pageIn 150ms ease-out;
}
.homePreview { margin-top: 10px; }
.textButton {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--navy);
  font-size: 12px;
  font-weight: 850;
  box-shadow: none;
}

.commandPanel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  margin-top: 10px;
  padding: 10px;
  border-radius: 8px;
}

.areaField,
.actions { grid-column: auto; }

.field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

select,
input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

select { padding: 0 10px; }
input { padding: 0 10px; }
.actions { display: grid; }

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

#startButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border-color: var(--navy);
  background: var(--navy);
  color: #fff;
  box-shadow: 0 8px 18px rgba(0, 27, 73, 0.16);
}
#startButton:hover { background: #000f2b; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
.buttonIcon { font-size: 18px; line-height: 1; }

.progressPanel {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
}

.meter { overflow: hidden; height: 6px; border-radius: 999px; background: #eceff3; }
#progressBar { width: 0%; height: 100%; background: var(--navy); transition: width 160ms ease; }

.status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}
#statusText { min-width: 0; overflow-wrap: anywhere; }
#countText { flex: none; font-weight: 800; }

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

.summaryItem {
  position: relative;
  overflow: hidden;
  min-height: 78px;
  padding: 10px 11px;
  border-radius: 8px;
}
.summaryItem::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--navy); }
.summaryItem.good::before { background: var(--green); }
.summaryItem.alert::before { background: var(--red); }
.summaryItem.watch::before { background: var(--yellow); }
.summaryItem span { color: var(--muted); font-size: 11px; font-weight: 800; }
.summaryItem strong { display: block; margin-top: 4px; font-size: clamp(21px, 5.8vw, 29px); line-height: 1.08; color: var(--ink); }
.summaryItem.good strong { color: var(--navy); }
.summaryItem.watch strong { color: var(--yellow); }
.summaryItem.alert strong { color: var(--red); }

.insightGrid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 10px;
}

#pageInsights .insightGrid,
#pageStores .tableSection {
  margin-top: 12px;
}

.panel {
  min-width: 0;
  padding: 12px;
  border-radius: 8px;
}
.panelHeader { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.panelHeader h2 { margin: 0; font-size: 15px; line-height: 1.3; }
.panelHeader span { color: var(--muted); font-size: 11px; font-weight: 750; white-space: nowrap; }

.barChart,
.watchList,
.rankList,
.distributionGrid,
.heatGrid,
.levelStack,
.openWaitStats { display: grid; gap: 7px; }

.barRow { display: grid; grid-template-columns: 78px 1fr 42px; align-items: center; gap: 8px; min-height: 28px; font-size: 12px; }
.barLabel { overflow: hidden; color: var(--ink); font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.barTrack { overflow: hidden; height: 7px; border-radius: 999px; background: #e9edf2; }
.barTrack span { display: block; height: 100%; border-radius: inherit; background: var(--navy); }
.barRow strong,
.barRow em { color: var(--muted); font-style: normal; text-align: right; }
.barRow em { display: none; }

.weatherGrid { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scroll-snap-type: x mandatory; }
.weatherTile {
  flex: 0 0 112px;
  display: grid;
  gap: 2px;
  min-height: 64px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  scroll-snap-align: start;
}
.weatherTile strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.weatherTile span,
.weatherTile em { color: var(--muted); font-size: 11px; font-style: normal; }

.rankItem {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 9px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #edf0f4;
}

.rankItem:last-child { border-bottom: 0; }
.rankNo {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--navy);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
}
.rankItem strong,
.rankItem small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rankItem small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.rankItem em { color: var(--ink); font-size: 14px; font-style: normal; font-weight: 900; }

.distributionGrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.distItem {
  min-width: 0;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}
.distItem span { color: var(--muted); font-size: 11px; font-weight: 800; }
.distItem strong { display: block; margin: 3px 0 6px; font-size: 20px; line-height: 1; }
.miniTrack { overflow: hidden; height: 5px; border-radius: 999px; background: #e9edf2; }
.miniTrack i { display: block; height: 100%; border-radius: inherit; background: var(--navy); }

.heatGrid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.heatCell {
  min-width: 0;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(0, 27, 73, var(--heatAlpha));
  color: var(--ink);
}
.heatCell strong,
.heatCell span,
.heatCell em { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.heatCell strong { font-size: 12px; }
.heatCell span { margin-top: 5px; font-size: 17px; font-weight: 900; }
.heatCell em { color: rgba(7,23,53,.68); font-size: 11px; font-style: normal; }

.stackBar {
  display: flex;
  overflow: hidden;
  height: 13px;
  border-radius: 999px;
  background: #e9edf2;
}
.stackBar i { display: block; height: 100%; }
.stackBar .zero, .stackLegend .zero { background: #b8c0cc; }
.stackBar .mid, .stackLegend .mid { background: #d97706; }
.stackBar .high, .stackLegend .high { background: #c62828; }
.stackLegend {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
}
.stackLegend span { display: flex; align-items: center; gap: 6px; }
.stackLegend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 999px;
}

.statLine {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid #edf0f4;
}
.statLine:last-child { border-bottom: 0; }
.statLine span { color: var(--muted); font-size: 12px; font-weight: 850; }
.statLine strong { color: var(--ink); font-size: 18px; }

.watchItem {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}
.watchItem strong,
.watchItem span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.watchItem span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.watchItem em {
  min-width: 44px;
  padding: 4px 7px;
  border-radius: 4px;
  background: #fff7e8;
  color: #8a4b00;
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
  text-align: center;
}

.tableSection { margin-top: 12px; }
.tableHeader,
.filterBar { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 8px; padding-bottom: 2px; }
.tableHeader input { flex: 0 0 248px; }
.tableHeader select,
.filterBar label { flex: 0 0 158px; }
.filterBar label { display: grid; gap: 5px; color: var(--muted); font-size: 11px; font-weight: 800; }

.tableWrap { max-height: none; overflow: visible; border: 0; border-radius: 0; background: transparent; }
table, thead, tbody, tr, td { display: block; }
thead { display: none; }
tbody { display: grid; gap: 8px; }
tr { padding: 11px; border-radius: 8px; }
td { width: auto !important; padding: 3px 0; border: 0; text-align: left !important; vertical-align: top; white-space: normal !important; }
td:first-child { padding-bottom: 7px; font-size: 15px; }
td:not(:first-child) { display: inline-flex; align-items: center; margin-right: 9px; color: var(--muted); font-size: 12px; }
td:nth-child(2)::before { content: "状態 "; font-weight: 800; color: var(--ink); }
td:nth-child(3)::before { content: "待ち "; font-weight: 800; color: var(--ink); }
td:nth-child(4)::before { content: "受付システム "; font-weight: 800; color: var(--ink); }
td:nth-child(5)::before { content: "席 "; font-weight: 800; color: var(--ink); }
td:nth-child(6)::before { content: "地域 "; font-weight: 800; color: var(--ink); }
td:nth-child(7)::before { content: "天気 "; font-weight: 800; color: var(--ink); }
td:nth-child(8)::before { content: "気温 "; font-weight: 800; color: var(--ink); }
td:nth-child(9) { display: block; width: 100% !important; margin-top: 6px; color: var(--muted); }

.storeLink { color: var(--ink); font-weight: 850; text-decoration: none; }
.storeLink:hover { color: var(--navy); text-decoration: underline; }
.pill { display: inline-block; min-width: 50px; padding: 3px 7px; border-radius: 999px; background: var(--soft); color: var(--muted); font-size: 11px; text-align: center; }
.pill.open { background: #e9f6ef; color: var(--green); }
.pill.close { background: #fff1f0; color: var(--red); }
.pill.other { background: #eef1f6; color: var(--navy); }
.queueBadge { display: inline-block; min-width: 40px; padding: 3px 7px; border-radius: 999px; background: var(--soft); color: var(--muted); font-size: 11px; font-weight: 850; text-align: center; }
.queueBadge.queue-on { background: #e9f6ef; color: var(--green); }
.queueBadge.queue-error { background: #fff1f0; color: var(--red); }
.queueBadge.queue-off { background: #f1f3f6; color: var(--muted); }
.queueBadge.queue-unknown { background: #eef1f6; color: var(--muted); }
.wait-blue { color: var(--navy); font-weight: 900; }
.wait-yellow { color: var(--yellow); font-weight: 900; }
.wait-red { color: var(--red); font-weight: 900; }
.empty { padding: 20px; color: var(--muted); text-align: center; }
.weatherCell { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.weatherIcon { display: inline-grid; place-items: center; min-width: 22px; height: 22px; border-radius: 999px; background: #eef1f6; color: var(--navy); font-size: 14px; }

.mobileNav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 8px 14px calc(8px + var(--safeBottom));
  border-top: 1px solid rgba(0, 27, 73, 0.22);
  background: rgba(0, 19, 51, 0.96);
  backdrop-filter: blur(16px);
  box-shadow: 0 -8px 22px rgba(7, 23, 53, 0.22);
}
.mobileNav button {
  display: grid;
  gap: 3px;
  justify-items: center;
  min-height: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.62);
  font-size: 11px;
  font-weight: 850;
  text-decoration: none;
  box-shadow: none;
}
.mobileNav span { font-size: 20px; line-height: 1; }
.mobileNav button.active { color: #fff; }
.mobileNav button.active span {
  transform: translateY(-1px);
}

@keyframes pageIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 721px) {
  .appShell { padding: 0 22px 28px; }
  .topBar { min-height: 82px; margin: 0 -22px; padding: 16px 22px; }
  .brandMark { width: 46px; height: 46px; border-radius: 8px; }
  .brandMark span { font-size: 18px; }
  .brandMark small { font-size: 9px; }
  .topMeta { font-size: 12px; }
  .commandPanel { grid-template-columns: minmax(220px, 1fr) 180px; align-items: end; }
  .summary { grid-template-columns: repeat(4, 1fr); }
  .insightGrid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .barRow { grid-template-columns: minmax(72px, 96px) 1fr 54px 60px; }
  .barRow em { display: block; }
  .weatherGrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; }
  .weatherTile { flex: initial; }
  .tableHeader { display: grid; grid-template-columns: 1fr 210px; }
  .filterBar { display: grid; grid-template-columns: repeat(3, minmax(160px, 1fr)); }
  .tableHeader input, .tableHeader select, .filterBar label { flex: initial; }
  .tableWrap { max-height: calc(100vh - 420px); overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
  table { display: table; width: 100%; border-collapse: collapse; font-size: 13px; }
  thead { display: table-header-group; }
  tbody { display: table-row-group; }
  tr { display: table-row; padding: 0; border: 0; border-radius: 0; }
  td, th { display: table-cell; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
  thead th { position: sticky; top: 0; z-index: 1; background: #f7f8fa; color: var(--muted); font-size: 12px; text-align: left; }
  td:not(:first-child) { display: table-cell; margin-right: 0; color: inherit; font-size: 13px; }
  td:nth-child(n)::before { content: none; }
  td:nth-child(3), td:nth-child(5), td:nth-child(8) { width: 58px !important; text-align: right !important; white-space: nowrap !important; }
  td:nth-child(4) { width: 82px !important; white-space: nowrap !important; }
  td:nth-child(6), td:nth-child(7) { width: 112px !important; white-space: nowrap !important; }
  .mobileNav { display: none; }
}

@media (min-width: 1121px) {
  .appShell {
    min-height: calc(100vh - 48px);
    margin: 24px auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 14px 38px rgba(7, 23, 53, 0.08);
  }
}
