:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d8dee7;
  --text: #17202a;
  --muted: #657386;
  --brand: #0f6b7a;
  --brand-strong: #084e59;
  --accent: #b94d26;
  --ok: #0f7a4f;
  --warn: #a05a00;
  --bad: #b42318;
  --shadow: 0 1px 2px rgba(20, 35, 50, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

a {
  color: var(--brand);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

pre,
textarea {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

textarea {
  width: 100%;
  min-height: 460px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  background: #fbfcfd;
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(8px);
}

.brand {
  margin-right: 10px;
  color: var(--text);
  font-weight: 800;
  letter-spacing: 0;
}

.topbar nav {
  display: flex;
  gap: 6px;
}

.topbar nav a {
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 700;
}

.topbar nav a.active,
.topbar nav a:hover {
  background: #e7f1f3;
  color: var(--brand-strong);
  text-decoration: none;
}

.page {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.page-head h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

.page-head p {
  margin: 6px 0 0;
  color: var(--muted);
}

.date-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

input[type="date"],
button,
.button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.button.ghost {
  background: #fff;
  color: var(--brand);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric-grid.compact {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  min-height: 86px;
  padding: 14px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
  line-height: 1.1;
}

.panel {
  margin: 14px 0;
  padding: 16px;
}

.alert {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-weight: 700;
}

.alert.warn {
  border-color: #f0c36d;
  background: #fff8e8;
  color: #7a4a00;
}

.alert.ok {
  border-color: #9bd8bd;
  background: #e9f8f1;
  color: var(--ok);
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

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

.panel-head h2 {
  margin: 0;
}

.muted,
.subtle {
  color: var(--muted);
}

.subtle {
  margin-top: 2px;
  font-size: 12px;
}

.table-wrap {
  overflow-x: auto;
}

.table-wrap.narrow {
  max-width: 820px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: #f8fafb;
}

.race-link {
  font-weight: 800;
}

.bet-accordion {
  max-width: 360px;
}

.bet-accordion summary {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  color: var(--brand-strong);
  font-weight: 800;
  cursor: pointer;
  list-style-position: inside;
  white-space: nowrap;
}

.bet-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  max-width: 360px;
}

.bet-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 8px;
  border: 1px solid #cbd6df;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-weight: 900;
  white-space: nowrap;
}

.combo {
  font-weight: 900;
  letter-spacing: .02em;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e8edf2;
  color: #425466;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.final,
.badge.sent,
.badge.dry_run,
.badge.hit,
.badge.completed,
.badge.main {
  background: #e2f4ec;
  color: var(--ok);
}

.badge.pre,
.badge.cover,
.badge.running,
.badge.pending {
  background: #fff1dc;
  color: var(--warn);
}

.badge.selected-pre {
  background: #e8f2ff;
  color: #155bb5;
  border: 1px solid #b8d4ff;
}

.badge.selected-final {
  background: #e2f4ec;
  color: var(--ok);
  border: 1px solid #a9dcc5;
}

.badge.selected-result {
  background: #f0e8ff;
  color: #6d3fb5;
  border: 1px solid #d3c0ff;
}

.badge.disabled {
  background: #eef1f4;
  color: #5c6670;
}

.badge.failed,
.badge.error,
.badge.miss,
.badge.unpublished {
  background: #fde8e5;
  color: var(--bad);
}

.empty {
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.tabs {
  margin-top: 12px;
}

.tab-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.tab {
  background: #fff;
  color: var(--muted);
  border-color: var(--line);
}

.tab.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.score-grid div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fbfcfd;
}

.score-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.score-grid strong {
  font-size: 20px;
}

.json-block,
.log-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fbfcfd;
}

.log-item {
  margin: 10px 0;
}

.info-line {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.boat-no {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-weight: 900;
  color: #111;
  background: #e5e7eb;
}

.boat-no.b1 { background: #fff; border: 1px solid #cfd6df; }
.boat-no.b2 { background: #222; color: #fff; }
.boat-no.b3 { background: #d82020; color: #fff; }
.boat-no.b4 { background: #2470d8; color: #fff; }
.boat-no.b5 { background: #f4d21f; }
.boat-no.b6 { background: #208a45; color: #fff; }

.public-home,
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #f2f5f7;
}

.public-shell,
.login-shell {
  width: min(720px, calc(100vw - 32px));
  padding: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.public-shell h1,
.login-shell h1 {
  margin: 0 0 12px;
  font-size: 34px;
}

.login-shell {
  width: min(480px, calc(100vw - 32px));
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.login-form label {
  display: grid;
  gap: 6px;
  font-weight: 800;
}

.login-form input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  font: inherit;
}

.link-form {
  margin-top: 12px;
}

.link-button {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--brand);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--brand);
  font-weight: 900;
}

@media (max-width: 980px) {
  .metric-grid,
  .metric-grid.compact,
  .score-grid,
  .two-col {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 680px) {
  .topbar,
  .page-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .page {
    padding: 12px;
  }

  .page-head h1 {
    font-size: 22px;
  }

  .page-head p {
    font-size: 13px;
  }

  .metric-grid,
  .metric-grid.compact,
  .score-grid,
  .two-col {
    grid-template-columns: 1fr;
  }

  .date-form {
    width: 100%;
  }

  input[type="date"] {
    flex: 1;
  }

  .panel {
    padding: 12px;
  }

  .metric {
    min-height: 72px;
    padding: 12px;
  }

  .metric strong {
    font-size: 22px;
  }

  .data-table {
    min-width: 760px;
    font-size: 12px;
  }

  .data-table th,
  .data-table td {
    padding: 8px 6px;
  }

  .page {
    overflow-x: hidden;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .tab-list {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .tab {
    flex: 0 0 auto;
    min-height: 34px;
    padding: 0 10px;
    font-size: 12px;
  }

  .bet-accordion,
  .bet-chip-list {
    max-width: calc(100vw - 80px);
  }

  .bet-accordion summary {
    min-height: 32px;
    padding: 4px 9px;
  }

  .bet-chip {
    min-height: 30px;
    padding: 3px 8px;
    font-size: 12px;
  }

  .badge {
    min-height: 22px;
    padding: 2px 7px;
    font-size: 11px;
  }

  .topbar {
    gap: 8px;
    padding: 10px 12px;
  }

  .topbar nav {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }
}

/* =========================================
   Mobile dashboard refinement
   Appended overrides for the current admin UI.
   ========================================= */

:root {
  --bg: #f6f8fa;
  --line: #e1e7ef;
  --line-soft: #edf1f5;
  --muted-soft: #8a96a8;
  --brand-soft: #e8f3f5;
  --ok-bg: #e8f6ef;
  --warn-bg: #fff4df;
  --bad-bg: #fdecea;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --shadow-card: 0 6px 18px rgba(20, 35, 50, .06);
}

body {
  background: linear-gradient(180deg, #f9fbfc 0%, var(--bg) 240px);
  line-height: 1.6;
}

.page {
  max-width: 1360px;
}

.topbar {
  min-height: 60px;
  border-bottom-color: var(--line-soft);
  background: rgba(255, 255, 255, .92);
}

.topbar nav a {
  border-radius: 999px;
}

.topbar nav a.active,
.topbar nav a:hover {
  background: var(--brand-soft);
}

.date-form {
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel);
  box-shadow: var(--shadow);
}

input[type="date"],
button,
.button {
  min-height: 42px;
  border-radius: 10px;
}

.metric-grid {
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.metric,
.panel {
  border-color: var(--line-soft);
  border-radius: var(--radius-lg);
}

.metric {
  min-height: 96px;
  padding: var(--space-4);
  transition: box-shadow .15s ease, transform .15s ease;
}

.metric:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-card);
}

.metric-primary {
  border-left: 4px solid var(--brand);
}

.metric-final {
  border-left: 4px solid var(--ok);
}

.metric-result {
  border-left: 4px solid #6d3fb5;
}

.metric-alert {
  border-left: 4px solid var(--bad);
}

.metric-alert strong {
  color: var(--bad);
}

.panel {
  margin: var(--space-4) 0;
  padding: var(--space-5);
}

.table-wrap {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-md);
  background: #fff;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
}

.data-table th,
.data-table td {
  border-bottom-color: var(--line-soft);
  padding: 11px 10px;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.badge.selected-final,
.badge.final,
.badge.sent,
.badge.dry_run,
.badge.hit,
.badge.completed,
.badge.main {
  background: var(--ok-bg);
  color: var(--ok);
}

.badge.pre,
.badge.cover,
.badge.running,
.badge.pending {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge.failed,
.badge.error,
.badge.miss,
.badge.unpublished {
  background: var(--bad-bg);
  color: var(--bad);
}

.info-line,
.json-block,
.log-item,
.score-grid div {
  border-color: var(--line-soft);
  border-radius: var(--radius-md);
  background: #f9fbfc;
}

.race-card-list {
  display: none;
}

.alert-list {
  display: grid;
  gap: 8px;
}

.alert-item {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-left: 4px solid var(--bad);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--text);
  font-weight: 700;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.alert-detail {
  margin-top: 12px;
}

.alert-detail summary {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--brand-strong);
  font-weight: 800;
  cursor: pointer;
}

.alert-detail .json-block {
  margin-top: 10px;
  max-height: 420px;
  overflow: auto;
  font-size: 12px;
}

@media (max-width: 680px) {
  body {
    font-size: 14px;
    background: #f6f8fa;
  }

  .page {
    padding: 14px 14px 88px;
  }

  .topbar {
    position: sticky;
    top: 0;
    padding: 10px 14px;
    gap: 10px;
    background: rgba(255, 255, 255, .96);
  }

  .brand {
    font-size: 14px;
  }

  .topbar nav {
    gap: 6px;
    padding-bottom: 3px;
  }

  .topbar nav a {
    flex: 0 0 auto;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 12px;
    white-space: nowrap;
  }

  .page-head {
    gap: 14px;
    margin-bottom: 16px;
  }

  .page-head h1 {
    font-size: 22px;
    line-height: 1.25;
  }

  .page-head p {
    font-size: 13px;
    line-height: 1.6;
  }

  .date-form {
    width: 100%;
    padding: 6px;
    border-radius: 14px;
  }

  input[type="date"] {
    min-height: 44px;
    font-size: 16px;
  }

  .date-form button {
    min-height: 44px;
    padding: 0 14px;
  }

  .metric-grid,
  .metric-grid.compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
  }

  .metric {
    min-height: 86px;
    padding: 13px;
    border-radius: 14px;
  }

  .metric span {
    font-size: 11px;
  }

  .metric strong {
    margin-top: 6px;
    font-size: 23px;
  }

  .metric-grid .metric:last-child:nth-child(odd),
  .metric-grid.compact .metric:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

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

  .panel h2 {
    font-size: 16px;
    margin-bottom: 12px;
  }

  .panel-head {
    gap: 6px;
    margin-bottom: 12px;
  }

  .tabs {
    margin-top: 10px;
  }

  .tab-list {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 8px;
    margin: 0 -14px 12px;
    padding: 0 14px 6px;
    scrollbar-width: none;
  }

  .tab-list::-webkit-scrollbar {
    display: none;
  }

  .tab {
    min-height: 38px;
    padding: 0 14px;
    font-size: 13px;
    border-radius: 999px;
    white-space: nowrap;
  }

  .tab.active {
    box-shadow: 0 4px 12px rgba(15, 107, 122, .18);
  }

  .tab-panel.active {
    animation: tabFade .14s ease;
  }

  @keyframes tabFade {
    from {
      opacity: .65;
      transform: translateY(3px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .table-wrap {
    margin: 0 -2px;
    border-radius: 14px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .data-table {
    min-width: 720px;
    font-size: 12px;
  }

  .data-table th,
  .data-table td {
    padding: 10px 8px;
  }

  .data-table th {
    font-size: 11px;
  }

  .table-wrap::after {
    content: "横にスクロールできます";
    display: block;
    padding: 8px 10px;
    color: var(--muted-soft);
    font-size: 11px;
    background: #f8fafc;
    border-top: 1px solid var(--line-soft);
  }

  .selected-race-table {
    display: none;
  }

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

  .race-card {
    display: block;
    padding: 14px;
    border: 1px solid var(--line-soft);
    border-radius: 16px;
    background: #fff;
    color: var(--text);
    box-shadow: var(--shadow);
  }

  .race-card:hover {
    text-decoration: none;
  }

  .race-card-top,
  .race-card-bottom,
  .race-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .race-card-top {
    margin-bottom: 12px;
  }

  .race-card-top strong {
    font-size: 15px;
  }

  .race-card-top span,
  .race-card-alert,
  .race-card-meta {
    color: var(--muted);
    font-size: 12px;
  }

  .race-card-main {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
  }

  .race-card-main div {
    min-width: 0;
    padding: 10px;
    border-radius: 12px;
    background: #f8fafc;
  }

  .race-card-main span {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
  }

  .race-card-main strong {
    font-size: 16px;
    word-break: keep-all;
  }

  .race-card-bottom {
    margin-bottom: 8px;
  }

  .race-card-meta {
    margin-bottom: 8px;
  }

  .race-card-theory {
    padding-top: 8px;
    border-top: 1px solid var(--line-soft);
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
    overflow-wrap: anywhere;
  }

  .alert-list {
    gap: 8px;
  }

  .alert-item {
    padding: 10px;
    font-size: 13px;
  }

  .alert-detail .json-block {
    max-height: 300px;
    font-size: 11px;
  }

  button,
  .button {
    min-height: 44px;
    border-radius: 12px;
    font-size: 14px;
  }

  .button.ghost {
    width: 100%;
  }

  .bet-chip-list {
    max-width: 100%;
    gap: 8px;
  }

  .bet-chip {
    min-height: 32px;
    padding: 4px 10px;
    border-radius: 999px;
  }

  textarea {
    min-height: 360px;
    border-radius: 14px;
    padding: 14px;
    font-size: 14px;
  }
}
