/*
 * Mythea admin viewer.
 *
 * Styled to match the game's own login and maintenance pages (same palette:
 * near-black ground, warm ink, gold accent) so it reads as part of Mythea
 * rather than a generic admin skin. The palette is the game's; see the :root
 * blocks in src/login.html and deploy/gcp/templates/mythea-caddy-mode.sh.
 *
 * Layout: a fixed viewport shell. The topbar, tabs, toolbar and pager never
 * scroll; the table has its own scroll region with a sticky header and a sticky
 * first column, so the record identity stays visible across the wide rows.
 */

:root {
  color-scheme: dark;

  --bg: #08090c;
  --bg-glow-1: rgba(214, 179, 106, 0.08);
  --bg-glow-2: rgba(119, 168, 200, 0.07);

  --panel: #12161c;
  --panel-strong: #15191f;
  --panel-raised: #1b2129;
  --row-alt: #12161c;
  --row-hover: #202836;

  --line: rgba(255, 255, 255, 0.14);
  --line-soft: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.28);

  --text: #f6f2ea;
  --muted: #a9b1bd;
  --faint: #7d8794;

  --gold: #d6b36a;
  --gold-ink: #1a1408;
  --blue: #77a8c8;
  --green: #6cc08b;
  --red: #e8927f;
  --red-bg: #401c19;
  --green-bg: #1c3f2a;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.45);

  --row-pad-y: 4px;
  --row-pad-y-head: 7px;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;

    --bg: #f4f2ee;
    --bg-glow-1: rgba(214, 179, 106, 0.18);
    --bg-glow-2: rgba(119, 168, 200, 0.16);

    --panel: #ffffff;
    --panel-strong: #ffffff;
    --panel-raised: #fbfaf8;
    --row-alt: #faf9f7;
    --row-hover: #f0ece2;

    --line: #dcd6ca;
    --line-soft: #eae5db;
    --line-strong: #c3bcae;

    --text: #1d1f24;
    --muted: #5d6470;
    --faint: #838a95;

    --gold: #8a6a1f;
    --gold-ink: #fffaf0;
    --blue: #2f6d92;
    --green: #1f7a45;
    --red: #a83b28;
    --red-bg: #fbe7e2;

    --shadow: 0 12px 30px rgba(40, 34, 22, 0.16);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 12% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, var(--bg-glow-2), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 14px/1.45 Arial, Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

/* Buttons are used bare in several places (sort headers, stat chips, menu
   actions), so reset the browser default font here rather than in each rule. */
button {
  font: inherit;
  color: inherit;
}

/* ------------------------------------------------------------- primitives */

.btn {
  font: inherit;
  color: var(--text);
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 11px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--row-hover);
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn.primary {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--gold-ink);
  font-weight: 700;
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(1.08);
  background: var(--gold);
}

.btn.ghost {
  background: transparent;
}

.btn.block {
  width: 100%;
  padding: 9px 12px;
  margin-top: 14px;
}

.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 17px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}

.icon:hover {
  color: var(--text);
  background: var(--row-hover);
  border-color: var(--line);
}

input,
select {
  font: inherit;
  color: var(--text);
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 9px;
}

input::placeholder {
  color: var(--faint);
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
.menu label:focus-within {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.pill {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.badge {
  margin-left: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--gold);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

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

.hint {
  font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--faint);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 5px;
}

.spacer {
  flex: 1 1 auto;
}

.notice {
  margin: 0;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 13px;
}

.notice.error {
  color: var(--red);
  background: var(--red-bg);
  border: 1px solid var(--red);
}

/* ---------------------------------------------------------------- sign in */

.signin {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 28px;
}

.card {
  width: 100%;
  max-width: 372px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 26px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--gold);
  border-radius: 6px;
  color: var(--gold);
  font: 700 17px/1 Georgia, 'Times New Roman', serif;
}

.wordmark-text {
  font: 700 13px/1 Georgia, 'Times New Roman', serif;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--gold);
}

.card h1 {
  margin: 16px 0 0;
  font: 700 25px/1.1 Georgia, 'Times New Roman', serif;
}

.lede {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.card label {
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ------------------------------------------------------------------- app */

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.22);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.identity {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.shell {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

.main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 0 18px 12px;
}

/* ------------------------------------------------------------------ tabs */

.tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 15px;
  margin-bottom: -1px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.tab:hover {
  color: var(--text);
}

.tab.is-active {
  background: var(--panel);
  border-color: var(--line);
  color: var(--text);
}

.tab.is-active::after {
  content: '';
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: var(--gold);
}

.tab.is-active .pill {
  background: var(--gold);
  color: var(--gold-ink);
}

/* --------------------------------------------------------------- toolbar */

.toolbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  padding: 12px 0 10px;
}

.search {
  position: relative;
  flex: 1 1 260px;
  min-width: 190px;
  max-width: 460px;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 9px;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: var(--faint);
  stroke-width: 1.6;
  pointer-events: none;
}

.search input {
  width: 100%;
  padding-left: 30px;
  padding-right: 58px;
}

.search .hint {
  position: absolute;
  right: 33px;
  pointer-events: none;
}

.search #filter-clear {
  position: absolute;
  right: 4px;
}

.field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.switch input {
  margin: 0;
  accent-color: var(--gold);
}

.menu-wrap {
  position: relative;
}

.pin-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 0 8px;
  padding: 5px 8px 5px 12px;
  border: 1px solid var(--blue);
  border-radius: 999px;
  background: rgba(119, 168, 200, 0.1);
  font-size: 12px;
  width: fit-content;
  max-width: 100%;
}

.menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  width: 272px;
  max-height: 62vh;
  overflow: auto;
  padding: 8px;
  background: var(--panel-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  padding: 2px 4px 8px;
  border-bottom: 1px solid var(--line-soft);
}

.menu-title {
  color: var(--faint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.menu-actions {
  display: flex;
  gap: 6px;
}

.menu-actions .btn {
  padding: 3px 8px;
  font-size: 11px;
}

.menu label {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 6px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

.menu label:hover {
  background: var(--row-hover);
}

.menu input {
  margin: 0;
  accent-color: var(--gold);
}

.menu-empty {
  padding: 8px 6px;
  color: var(--muted);
  font-size: 12px;
}

/* ----------------------------------------------------------------- table */

.table-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 140px;
  overflow: auto;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.loading,
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 190px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.empty strong {
  color: var(--text);
  font-size: 14px;
}

table.grid {
  border-collapse: separate;
  border-spacing: 0;
  /* Content-sized, deliberately not stretched to the container: min-width:100%
     hands all the slack to the last column, which leaves one column oddly wide
     with an empty gutter and the rest cramped. */
  width: max-content;
  font-variant-numeric: tabular-nums;
}

.grid th,
.grid td {
  padding: var(--row-pad-y) 11px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  white-space: nowrap;
}

.grid thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: var(--row-pad-y-head) 11px;
  background: var(--panel-raised);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.grid thead th .sort {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}

.grid thead th.col-number .sort,
.grid thead th.col-flag .sort,
.grid thead th.col-time .sort {
  justify-content: flex-end;
}

.grid thead th .sort:hover {
  color: var(--text);
}

.grid thead th.sorted-asc .sort,
.grid thead th.sorted-desc .sort {
  color: var(--gold);
}

.grid thead th.sorted-asc .sort::after {
  content: '\25B2';
  font-size: 8px;
}

.grid thead th.sorted-desc .sort::after {
  content: '\25BC';
  font-size: 8px;
}

/* Sticky first column: the record identity stays in view when scrolling right.
   Every background below has to be opaque or the cells slide underneath it. */
.grid th:first-child,
.grid td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--panel-strong);
  box-shadow: 1px 0 0 var(--line);
}

.grid thead th:first-child {
  z-index: 3;
  background: var(--panel-raised);
}

.grid tbody tr:nth-child(even) td,
.grid tbody tr:nth-child(even) td:first-child {
  background: var(--row-alt);
}

.grid tbody tr:hover td,
.grid tbody tr:hover td:first-child {
  background: var(--row-hover);
}

.grid tbody tr.is-open td,
.grid tbody tr.is-open td:first-child {
  background: var(--row-hover);
}

.grid tbody tr.is-open td:first-child {
  box-shadow: inset 2px 0 0 var(--gold), 1px 0 0 var(--line);
}

.grid tbody tr.clickable {
  cursor: pointer;
}

.grid td.col-number,
.grid td.col-time,
.grid td.col-flag {
  text-align: right;
}

.grid td.col-flag {
  color: var(--faint);
}

.grid td.col-flag.is-on {
  color: var(--green);
}

.grid td.identity-cell {
  font-weight: 700;
}

.grid td.col-text.linkable {
  color: var(--blue);
  text-decoration: underline;
  text-decoration-color: rgba(119, 168, 200, 0.35);
  text-underline-offset: 2px;
}

body.density-comfortable {
  --row-pad-y: 9px;
}

/* ----------------------------------------------------------------- pager */

.pager {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-top: 10px;
}

.page-label {
  min-width: 118px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.status {
  color: var(--faint);
  font-size: 12px;
}

/* -------------------------------------------------------------- inspector */

.detail {
  flex: 0 0 430px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
}

.detail-head {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
}

.detail-heading {
  min-width: 0;
}

.detail-head h2 {
  margin: 0;
  font: 700 19px/1.2 Georgia, 'Times New Roman', serif;
  overflow-wrap: anywhere;
}

.detail-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.stats {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
}

.stat {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  font-size: 12px;
}

.stat-label {
  color: var(--faint);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stat-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat.jump {
  color: var(--blue);
  cursor: pointer;
}

.stat.jump:hover {
  border-color: var(--blue);
}

.detail-tools {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line-soft);
}

.detail-tools input {
  flex: 1 1 auto;
  min-width: 0;
}

.detail-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 6px 16px 28px;
}

.field-group {
  margin-top: 14px;
}

.field-group h3 {
  margin: 0 0 5px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--gold);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(110px, 38%) 1fr auto;
  gap: 3px 12px;
  align-items: baseline;
  padding: 5px 0;
  border-bottom: 1px solid var(--line-soft);
}

.field-name {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.field-value {
  min-width: 0;
  overflow-wrap: anywhere;
}

.field-value.is-empty {
  color: var(--faint);
}

.field-index {
  color: var(--faint);
  font: 10px/1.7 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.detail-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12px;
}

/* Narrow screens: the inspector overlays instead of taking a column. */
@media (max-width: 1080px) {
  .detail {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(460px, 100%);
    z-index: 40;
    box-shadow: var(--shadow);
  }
}

@media (max-width: 640px) {
  .main {
    padding: 0 10px 10px;
  }

  .topbar {
    padding: 10px 12px;
  }

  .identity {
    display: none;
  }

  .search .hint {
    display: none;
  }
}
