:root {
  --bg: #0a0c10;
  --panel: #12161e;
  --panel-2: #1a2030;
  --border: #2a3344;
  --text: #eef1f6;
  --muted: #8b95a8;
  --accent: #1f6feb;
  --accent-2: #58a6ff;
  --good: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --fe: #58a6ff;
  --be: #3fb950;
  --radius: 12px;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  --font: "Plus Jakarta Sans", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background:
    radial-gradient(800px 420px at 10% -10%, rgba(31, 111, 235, 0.16), transparent 55%),
    radial-gradient(600px 360px at 90% 0%, rgba(63, 185, 80, 0.1), transparent 50%),
    var(--bg);
  color: var(--text);
}

h1, h2, h3, strong {
  font-family: var(--font);
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

/* ——— Gate ——— */
.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: min(100%, 400px);
  padding: 28px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(26, 32, 48, 0.98), rgba(18, 22, 30, 0.98));
  box-shadow: var(--shadow);
  display: grid;
  gap: 18px;
}
.gate-brand { display: flex; gap: 14px; align-items: center; }
.gate-brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
}
.gate-brand p { margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; font-weight: 400; }
.gate-field {
  display: grid;
  gap: 6px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.gate-field input {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}
.gate-field input:focus {
  outline: none;
  border-color: rgba(88, 166, 255, 0.7);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.22);
}
.gate-error {
  margin: 0;
  color: #ff7b72;
  font-size: 0.88rem;
}
.btn.wide { width: 100%; padding: 12px 16px; }

.mark {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #238636, #1f6feb);
  font-weight: 800;
  font-size: 0.95rem;
  box-shadow: 0 8px 22px rgba(31, 111, 235, 0.3);
  flex-shrink: 0;
}

/* ——— App shell ——— */
.app {
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px 16px;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 12, 16, 0.92);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
  z-index: 10;
}
.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}
.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
}

.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat-card {
  min-width: 88px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  display: grid;
  gap: 2px;
}
.stat-card.today {
  border-color: rgba(63, 185, 80, 0.4);
  background: rgba(35, 134, 54, 0.12);
}
.stat-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 600;
}
.stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}
.stat-card.today .stat-value { color: #7ee787; }

.top-actions { display: flex; gap: 8px; flex-shrink: 0; }

.filters {
  padding: 12px 20px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(18, 22, 30, 0.55);
  display: grid;
  gap: 10px;
  flex-shrink: 0;
}
.filter-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px 10px;
  align-items: center;
}
.filter-row #q {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 500;
}
.filter-row #q:focus {
  outline: none;
  border-color: rgba(88, 166, 255, 0.65);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.18);
}
.filter-actions {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
}
.filter-meta-row {
  display: flex;
  justify-content: flex-end;
}
.result-meta {
  white-space: nowrap;
}

/* ——— Date dropdown under All dates button ——— */
.range-picker { flex: 0 0 auto; position: relative; }
.range-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.86rem;
  font-family: inherit;
  white-space: nowrap;
  max-width: 240px;
  min-width: 148px;
}
.range-btn:hover,
.range-btn.open,
.range-btn[aria-expanded="true"],
.range-btn.active {
  border-color: rgba(88, 166, 255, 0.65);
  color: #9ecbff;
  background: rgba(31, 111, 235, 0.14);
}
.range-btn-icon {
  width: 16px;
  height: 16px;
  border: 1.5px solid currentColor;
  border-radius: 3px;
  position: relative;
  flex-shrink: 0;
}
.range-btn-icon::before {
  content: "";
  position: absolute;
  left: 2px;
  right: 2px;
  top: 4px;
  border-top: 1.5px solid currentColor;
}
.range-caret {
  width: 0;
  height: 0;
  margin-left: auto;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: 0.75;
  flex-shrink: 0;
}
.range-btn.open .range-caret {
  transform: rotate(180deg);
}
#rangeBtnLabel {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  text-align: left;
}

.range-panel {
  position: fixed;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  width: 300px;
  max-width: calc(100vw - 16px);
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #151a24;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  gap: 8px;
  overflow: hidden;
}
.range-panel[hidden] { display: none !important; }
.range-panel > .cal-months {
  flex: 0 0 auto;
  overflow: visible;
}
.date-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}
.chip {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.75rem;
  font-family: inherit;
  white-space: nowrap;
}
.chip:hover { border-color: var(--accent-2); color: var(--text); }
.chip.active {
  background: rgba(31, 111, 235, 0.22);
  border-color: rgba(88, 166, 255, 0.65);
  color: #9ecbff;
}
.cal-toolbar {
  display: grid;
  grid-template-columns: 32px 1fr 32px;
  gap: 6px;
  align-items: center;
}
.cal-nav {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}
.cal-nav:hover { border-color: var(--accent-2); }
.cal-month-title {
  text-align: center;
  font-weight: 700;
  font-size: 0.88rem;
}
.cal-months {
  min-width: 0;
  height: auto;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: 30px;
  align-content: start;
  gap: 2px;
  height: auto;
}
.cal-dow-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  text-align: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
}
.cal-day {
  box-sizing: border-box;
  width: 100%;
  height: 30px;
  min-height: 30px;
  max-height: 30px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  line-height: 30px;
  align-self: start;
}
.cal-day:hover:not(.empty) { background: rgba(88, 166, 255, 0.16); }
.cal-day.empty {
  pointer-events: none;
  visibility: hidden;
}
.cal-day.today { box-shadow: inset 0 0 0 1px rgba(88, 166, 255, 0.5); }
.cal-day.in-range { background: rgba(31, 111, 235, 0.2); border-radius: 0; }
.cal-day.selected,
.cal-day.start,
.cal-day.end {
  background: #6b8afd;
  color: #fff;
}
.cal-hint {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
}
.range-panel-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid rgba(42, 51, 68, 0.8);
  flex-shrink: 0;
}
.range-panel-actions .btn {
  padding: 8px 14px;
  font-size: 0.84rem;
}

.meta { color: var(--muted); font-size: 0.84rem; font-weight: 500; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent-2); }
.btn.primary {
  background: linear-gradient(145deg, #238636, #1f6feb);
  border-color: transparent;
}
.btn.ghost { background: transparent; }
.btn:disabled {
  opacity: 1;
  color: #6b7585;
  border-color: #2a3344;
  background: #12161e;
  cursor: not-allowed;
}

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.list-pane {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.list {
  padding: 12px;
  display: grid;
  gap: 8px;
  overflow: auto;
  flex: 1;
  min-height: 0;
  align-content: start;
}
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: #151a24;
  flex-shrink: 0;
  z-index: 5;
}
.pager .btn {
  min-width: 96px;
  color: var(--text);
  border-color: rgba(88, 166, 255, 0.35);
  background: var(--panel-2);
}
.pager .btn:disabled {
  color: #9aa3b2;
  border-color: var(--border);
  background: #1a2030;
}
.pager .meta {
  color: #c5ccd8;
  font-weight: 600;
}
.card-item {
  text-align: left;
  width: 100%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
}
.card-item:hover { border-color: rgba(88, 166, 255, 0.4); background: var(--panel-2); }
.card-item.active {
  border-color: rgba(88, 166, 255, 0.65);
  background: rgba(31, 111, 235, 0.14);
}
.card-item .title {
  font-weight: 700;
  margin-bottom: 3px;
  font-size: 0.95rem;
}
.card-item .sub { color: var(--muted); font-size: 0.82rem; font-weight: 500; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.badge {
  font-size: 0.68rem;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 600;
}
.badge.diff { color: #e3b341; border-color: rgba(210, 153, 34, 0.5); background: rgba(210, 153, 34, 0.08); }
.badge.be { color: #7ee787; border-color: rgba(63, 185, 80, 0.45); background: rgba(63, 185, 80, 0.08); }
.badge.warn { color: #ffb086; border-color: rgba(255, 176, 134, 0.45); background: rgba(255, 140, 80, 0.1); }
.badge.low { color: #ff7b72; border-color: rgba(248, 81, 73, 0.45); background: rgba(248, 81, 73, 0.08); }

.status-note {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 500;
  line-height: 1.35;
}
.status-note.ok {
  color: #9be3bc;
  background: rgba(63, 185, 80, 0.1);
  border: 1px solid rgba(63, 185, 80, 0.3);
}
.status-note.diff {
  color: #e3b341;
  background: rgba(210, 153, 34, 0.1);
  border: 1px solid rgba(210, 153, 34, 0.35);
}
.status-note.warn {
  color: #ffb086;
  background: rgba(255, 140, 80, 0.1);
  border: 1px solid rgba(255, 140, 80, 0.35);
}

.compare-tabs {
  display: none;
  gap: 6px;
  margin: 0 0 12px;
}
.compare-tab {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  padding: 10px 8px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.84rem;
  cursor: pointer;
}
.compare-tab.active {
  color: #9ecbff;
  border-color: rgba(88, 166, 255, 0.65);
  background: rgba(31, 111, 235, 0.18);
}
.raw-label {
  font-size: 0.8rem;
  margin: 8px 0 4px;
  font-weight: 600;
}
.raw-label.fe { color: var(--fe); }
.raw-label.be { color: var(--be); }
.detail-meta { color: var(--muted); font-size: 0.82rem; }

.detail-pane {
  padding: 18px 20px 40px;
  height: 100%;
  overflow: auto;
  min-width: 0;
  min-height: 0;
}
.back-btn {
  margin-bottom: 12px;
  display: none;
}
.detail-pane > .back-btn { margin-bottom: 12px; }
.empty {
  color: var(--muted);
  padding: 48px 12px;
  display: grid;
  gap: 8px;
}
.empty strong {
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 700;
}
.empty span { font-size: 0.92rem; font-weight: 500; }

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(42, 51, 68, 0.75);
}
.detail-head h2 {
  margin: 0 0 4px;
  font-size: 1.35rem;
  font-weight: 700;
}
.thumbs {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 10px 0 18px;
}
.thumbs .thumb-btn {
  display: block;
  width: min(100%, 400px);
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
  color: inherit;
  padding: 0;
  cursor: zoom-in;
  text-align: left;
  font-family: inherit;
}
.thumbs .thumb-btn:hover { border-color: rgba(88, 166, 255, 0.55); }
.thumbs img {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  display: block;
  background: #0a0a10;
}
.thumbs .sub { padding: 8px 10px; color: var(--muted); font-size: 0.8rem; }

/* In-page lightbox */
body.lightbox-open { overflow: hidden; }
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 48px 16px 24px;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(6px);
}
.lightbox[hidden] { display: none !important; }
.lightbox img {
  max-width: min(96vw, 1100px);
  max-height: min(78dvh, 860px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #0a0a10;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}
.lightbox-caption {
  margin: 0;
  color: #c5ccd8;
  font-size: 0.9rem;
  font-weight: 600;
}
.lightbox-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.col {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-width: 0;
}
.col h3 {
  margin: 0;
  padding: 11px 14px;
  font-size: 0.88rem;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
}
.col.fe h3 { background: rgba(31, 111, 235, 0.16); color: #9ecbff; }
.col.be h3 { background: rgba(63, 185, 80, 0.14); color: #9be3bc; }
.row {
  display: grid;
  grid-template-columns: minmax(88px, 110px) 1fr;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(42, 51, 68, 0.5);
  font-size: 0.88rem;
}
.row:last-child { border-bottom: 0; }
.row .k {
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.row .v { word-break: break-word; white-space: pre-wrap; font-weight: 500; }
.row.mismatch .v { color: #e3b341; }
.row.empty .v { color: #5c6574; font-style: italic; font-weight: 400; }

.raw {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.raw details {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-width: 0;
}
.raw summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.raw pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.76rem;
  color: #c9d1d9;
  max-height: 200px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Mobile: list ↔ detail swap */
.layout.show-detail .list-pane { display: flex; }
.layout.show-detail .detail-pane { display: block; }

@media (max-width: 1100px) {
  .top {
    grid-template-columns: 1fr auto;
  }
  .top-actions { grid-column: 2; grid-row: 1; }
  .stats { grid-column: 1 / -1; }
  .filter-row {
    grid-template-columns: 1fr auto;
  }
  .filter-actions { grid-column: 1 / -1; width: 100%; }
  .filter-actions .btn { flex: 1; }
  .filter-meta-row { justify-content: flex-start; }
  .range-btn { max-width: none; }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .list-pane,
  .detail-pane {
    height: 100%;
    min-height: 0;
  }
  .detail-pane .back-btn { display: inline-flex; }
  .layout:not(.show-detail) .detail-pane { display: none; }
  .layout.show-detail .list-pane { display: none; }
  .raw { grid-template-columns: 1fr; }

  .compare-tabs { display: flex; }
  .compare {
    grid-template-columns: 1fr;
  }
  .compare[data-mode="fe"] .col.be { display: none; }
  .compare[data-mode="be"] .col.fe { display: none; }
  .compare[data-mode="both"] {
    grid-template-columns: 1fr;
    gap: 10px;
  }
}

@media (max-width: 560px) {
  .top {
    padding: 10px 12px;
    gap: 8px;
  }
  .filters {
    padding: 8px 12px 10px;
    gap: 8px;
  }
  .brand h1 { font-size: 1rem; }
  .brand p { display: none; }
  .mark { width: 36px; height: 36px; border-radius: 10px; font-size: 0.82rem; }
  .stats { gap: 6px; }
  .stat-card { min-width: 0; flex: 1; padding: 6px 10px; }
  .stat-value { font-size: 1.05rem; }
  .top-actions .btn {
    padding: 8px 10px;
    font-size: 0.8rem;
  }
  .filter-row {
    grid-template-columns: 1fr;
  }
  .filter-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .filter-actions .btn {
    width: 100%;
    padding: 10px 8px;
  }
  .range-btn { width: 100%; max-width: none; }
  .pager .btn { flex: 1; min-width: 0; }
  .detail-pane { padding: 12px 12px 28px; }
  .detail-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .detail-head h2 { font-size: 1.15rem; }
  .thumbs .thumb-btn { width: 100%; }
  .thumbs img { max-height: 220px; }
  .lightbox { padding: 56px 10px 20px; }
  .lightbox img { max-height: 72dvh; }
  .row {
    grid-template-columns: 88px 1fr;
    gap: 6px;
    padding: 10px 12px;
  }
  .card-item { padding: 14px; }
  .card-item .title { font-size: 1rem; }
}
