:root {
  --bg: #f4f1ea;
  --panel: #fffaf2;
  --panel-border: #d9cdb9;
  --text: #1e1f1c;
  --muted: #6b675f;
  --accent: #1f5f5b;
  --accent-strong: #134541;
  --danger: #9f3131;
  --shadow: 0 14px 40px rgba(38, 34, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(31, 95, 91, 0.12), transparent 30%),
    linear-gradient(180deg, #f8f4ec 0%, var(--bg) 100%);
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  overflow-x: hidden;
}

a {
  color: inherit;
}

.page-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: end;
  margin-bottom: 20px;
}

.topbar h1,
.login-card h1 {
  margin: 4px 0 0;
  font-size: clamp(1.8rem, 4vw, 2.8rem);
}

.eyebrow {
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

.nav form {
  margin: 0;
}

.nav-link,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 10px 16px;
  background: rgba(255, 250, 242, 0.75);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
  transition: 0.18s ease;
  max-width: 100%;
  white-space: normal;
  text-align: center;
}

.nav-link:hover,
.btn:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.nav-link.is-active,
.btn-primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-strong);
}

.btn-danger {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.panel {
  background: color-mix(in srgb, var(--panel) 92%, white 8%);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 20px;
  margin-bottom: 16px;
}

.panel-header h2 {
  margin: 0;
}

.panel-header p,
.table-summary,
.notice,
dt {
  color: var(--muted);
}

.stack,
.toolbar {
  display: grid;
  gap: 14px;
}

.toolbar {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  align-items: end;
}

label {
  display: grid;
  gap: 8px;
  font-weight: 600;
}

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

input,
select {
  width: 100%;
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 11px 14px;
  background: #fffdf9;
}

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

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

.grid.two-up {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 18px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin: 0 0 18px;
}

.meta-grid div {
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(217, 205, 185, 0.9);
}

dt {
  font-size: 0.82rem;
  margin-bottom: 6px;
}

dd {
  margin: 0;
  font-weight: 700;
}

.log-box {
  margin: 0;
  min-height: 360px;
  max-height: 520px;
  overflow: auto;
  padding: 14px;
  border-radius: 18px;
  background: #171815;
  color: #f0f5ef;
  font-family: Consolas, "Cascadia Code", monospace;
  line-height: 1.45;
  white-space: pre-wrap;
}

.notice {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 14px;
  font-weight: 600;
}

.notice-info {
  background: rgba(31, 95, 91, 0.09);
  border: 1px solid rgba(31, 95, 91, 0.2);
}

.notice-error {
  background: rgba(159, 49, 49, 0.1);
  border: 1px solid rgba(159, 49, 49, 0.2);
}

.table-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.search-label {
  min-width: 280px;
}

.artifact-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.artifact-strip div {
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(217, 205, 185, 0.9);
  background: rgba(255, 255, 255, 0.65);
}

.artifact-strip span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 6px;
}

.artifact-strip strong {
  display: block;
  font-size: 0.98rem;
}

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

.compact-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr);
  gap: 12px;
  align-items: end;
}

.compact-toolbar label {
  gap: 6px;
}

.mini-actions,
.mini-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.mini-meta {
  margin: 0 0 14px;
}

.mini-actions .btn,
.mini-meta span {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(217, 205, 185, 0.9);
  background: rgba(255, 255, 255, 0.72);
  font-weight: 600;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.empty-sheet-state {
  text-align: center;
  color: var(--muted);
}

.overview-hero,
.sheet-hero {
  background:
    linear-gradient(135deg, rgba(31, 95, 91, 0.13), rgba(255, 250, 242, 0.9)),
    #fffaf2;
}

.overview-subtitle {
  margin: 10px 0 0;
  color: var(--muted);
  font-weight: 600;
}

.overview-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.overview-stat {
  display: inline-flex;
  align-items: center;
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(217, 205, 185, 0.9);
  font-weight: 700;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.overview-section .panel-header h2,
.sheet-hero h2 {
  margin: 0;
}

.compact-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.compact-toggle input {
  width: auto;
}

.table-wrap {
  overflow: auto;
  border-radius: 18px;
  border: 1px solid var(--panel-border);
  background: #fff;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.data-table.is-matrix td {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #ece4d5;
  text-align: left;
  vertical-align: top;
}

.data-table thead th {
  position: sticky;
  top: 0;
  background: #f8efe2;
  cursor: pointer;
  z-index: 1;
}

.data-table tbody th {
  font-weight: 700;
}

.data-table td {
  min-width: 120px;
  max-width: 280px;
  white-space: pre-wrap;
  word-break: break-word;
}

.row-index-head,
.row-index-cell {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 58px;
  width: 58px;
  text-align: right;
}

.row-index-head {
  background: #efe4d3;
  z-index: 3;
}

.row-index-cell {
  background: #fbf5eb;
}

.col-index {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.col-label {
  display: block;
  min-width: 90px;
  overflow-wrap: anywhere;
}

.data-table.is-dense th,
.data-table.is-dense td {
  padding: 6px 8px;
  font-size: 0.92rem;
}

.data-table tbody tr:nth-child(2n) {
  background: #fffaf3;
}

.prediction-list {
  display: grid;
  gap: 16px;
}

.prediction-card {
  background: color-mix(in srgb, var(--panel) 94%, white 6%);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.prediction-card-top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}

.rank-badge {
  min-width: 70px;
  padding: 14px 12px;
  border-radius: 18px;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.prediction-main h3,
.prediction-detail h4 {
  margin: 0;
}

.prediction-main h3 {
  font-size: clamp(1.1rem, 2.4vw, 1.4rem);
}

.prediction-main h3 span {
  color: var(--muted);
  font-size: 0.9em;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.prediction-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.prediction-chip {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(217, 205, 185, 0.9);
  font-weight: 700;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

.prediction-chip.is-tier {
  color: var(--accent-strong);
}

.prediction-chip.is-confidence.high {
  background: rgba(31, 95, 91, 0.14);
  border-color: rgba(31, 95, 91, 0.3);
}

.prediction-chip.is-confidence.mid {
  background: rgba(196, 144, 20, 0.14);
  border-color: rgba(196, 144, 20, 0.3);
}

.prediction-chip.is-confidence.low {
  background: rgba(159, 49, 49, 0.12);
  border-color: rgba(159, 49, 49, 0.24);
}

.prediction-score-block {
  min-width: 116px;
  text-align: right;
  min-width: 0;
}

.prediction-score-block span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.prediction-score-block strong {
  display: block;
  font-size: clamp(1.4rem, 3vw, 1.9rem);
  line-height: 1;
}

.prediction-card-body {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.prediction-detail {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(217, 205, 185, 0.9);
}

.prediction-detail h4 {
  margin-bottom: 10px;
}

.prediction-detail ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
}

.prediction-detail p {
  margin: 0;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.prediction-detail.is-trace {
  background: rgba(31, 95, 91, 0.06);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.insight-card {
  background: color-mix(in srgb, var(--panel) 94%, white 6%);
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.insight-card h3 {
  margin: 0 0 10px;
}

.insight-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 8px;
}

.prediction-main,
.prediction-detail,
.insight-card {
  min-width: 0;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.login-card {
  width: min(460px, 100%);
  padding: 28px;
  border-radius: 28px;
  background: rgba(255, 250, 242, 0.95);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
}

@media (max-width: 920px) {
  .topbar,
  .panel-header,
  .grid.two-up {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topbar {
    align-items: start;
  }

  .summary-grid,
  .compact-toolbar {
    grid-template-columns: 1fr;
  }

  .prediction-card-top,
  .prediction-card-body {
    grid-template-columns: 1fr;
  }

  .prediction-score-block {
    text-align: left;
  }
}

@media (max-width: 640px) {
  .page-shell {
    padding: 12px 10px 24px;
  }

  .panel,
  .login-card {
    border-radius: 18px;
    padding: 14px;
  }

  .button-row,
  .nav {
    flex-direction: column;
  }

  .btn,
  .nav-link {
    width: 100%;
  }

  .topbar h1,
  .login-card h1 {
    font-size: 1.45rem;
  }

  .table-tools,
  .mini-actions,
  .mini-meta,
  .overview-stats {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .search-label {
    min-width: 0;
    width: 100%;
  }

  .table-wrap {
    border-radius: 14px;
  }

  .data-table {
    min-width: 560px;
  }

  .data-table thead th,
  .row-index-head,
  .row-index-cell {
    position: static;
  }

  .row-index-head,
  .row-index-cell {
    min-width: 42px;
    width: 42px;
  }

  .prediction-card,
  .insight-card {
    border-radius: 18px;
    padding: 14px;
  }

  .prediction-chip-row {
    gap: 6px;
  }

  .prediction-score-block strong {
    font-size: 1.5rem;
  }
}
