:root {
  --bg: #141F17;
  --bg-header: #0F1712;
  --bg-card: #1F2E22;
  --text: #FAF6EE;
  --text-secondary: #9C9586;
  --accent-sand: #C4A87A;
  --bad: #E2484D;
  --medium: #EF9F27;
  --good: #8FCB9B;
  --border: rgba(250, 246, 238, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", sans-serif;
  min-height: 100vh;
}

a { color: var(--accent-sand); }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.main-nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.main-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
}
.main-nav a:hover {
  color: var(--text);
  background: rgba(250, 246, 238, 0.06);
}
.main-nav a.active {
  color: var(--accent-sand);
  background: rgba(196, 168, 122, 0.12);
}

.scope-toggle {
  display: flex;
  gap: 6px;
}
.scope-toggle .btn {
  padding: 5px 10px;
  font-size: 12px;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--text-secondary);
  font-size: 14px;
}

.date-range {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.date-range input[type="date"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  color-scheme: dark;
}
.date-range .btn {
  padding: 5px 10px;
  font-size: 12px;
}
.range-presets {
  display: inline-flex;
  gap: 4px;
  padding-left: 4px;
  border-left: 1px solid var(--border);
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--good);
}
.live-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
}
.live-badge.stale {
  color: var(--text-secondary);
}
.live-badge.stale .dot {
  background: var(--text-secondary);
}

.updated-at {
  color: var(--text-secondary);
}

.btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}
.btn:hover { border-color: var(--accent-sand); }
.btn-primary {
  background: var(--accent-sand);
  color: var(--bg-header);
  border-color: var(--accent-sand);
  font-weight: 600;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 18px 20px;
  border: 1px solid var(--border);
}

.card .label {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 6px;
}

.card .value {
  font-size: 28px;
  font-weight: 700;
}

.card .value.good { color: var(--good); }
.card .value.medium { color: var(--medium); }
.card .value.bad { color: var(--bad); }

.rank-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  font-size: 12px;
  color: var(--text-secondary);
  margin: -8px 0 14px;
}
.rank-legend .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
}
.rank-legend .dot.bad { background: var(--bad); }
.rank-legend .dot.medium { background: var(--medium); }
.rank-legend .dot.good { background: var(--good); }

.panel {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 20px;
  border: 1px solid var(--border);
}

.panel h2 {
  font-size: 15px;
  margin: 0 0 16px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.panels-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 900px) {
  .panels-grid { grid-template-columns: 1fr; }
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
th:last-child, td:last-child { border-right: none; }
th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
}

tr.clickable-row {
  cursor: pointer;
}
tr.clickable-row:hover {
  background: rgba(196, 168, 122, 0.1);
}
tr.clickable-row.selected {
  background: rgba(196, 168, 122, 0.18);
}

.search-box-input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
}

.role-select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
}
.role-select:disabled {
  opacity: 0.6;
}

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.role-badge.admin { background: rgba(196, 168, 122, 0.2); color: var(--accent-sand); }
.role-badge.viewer { background: rgba(143, 203, 155, 0.15); color: var(--good); }

.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  text-align: center;
  padding: 24px;
}

.center-screen h1 {
  font-size: 22px;
  margin: 0;
}
.center-screen p {
  color: var(--text-secondary);
  max-width: 420px;
  margin: 0;
}

.google-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--accent-sand);
  color: var(--bg-header);
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
}

.admin-form {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.admin-form input, .admin-form select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
}

.error-text { color: var(--bad); font-size: 13px; }
.empty-state { color: var(--text-secondary); font-size: 14px; padding: 12px 0; }

.login-main {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-panel { width: 100%; max-width: 340px; }
.login-form { flex-direction: column; align-items: stretch; }
.login-form input { width: 100%; box-sizing: border-box; padding: 10px 12px; font-size: 14px; }
.login-panel code {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--accent-sand);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  word-break: break-all;
}

.export-dialog {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  width: 100%;
  max-width: 380px;
}
.export-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}
.export-dialog-form { display: flex; flex-direction: column; gap: 16px; }
.export-dialog-form h3 { margin: 0; font-size: 16px; }
.export-section { display: flex; flex-direction: column; gap: 8px; }
.export-section-label { font-size: 13px; color: var(--text-secondary); font-weight: 600; }
.export-section label { font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }
.export-section input[type="text"] {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  margin-top: 6px;
}
.export-presets { display: flex; gap: 4px; flex-wrap: wrap; }
.export-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.login-form .btn-primary { margin-top: 4px; }

tr.row-inactive {
  opacity: 0.5;
}
tr.row-inactive:hover {
  opacity: 0.75;
}

.inactive-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(226, 72, 77, 0.15);
  color: var(--bad);
  vertical-align: middle;
}
.inactive-badge.compact {
  padding: 1px 6px;
  font-size: 10px;
  margin-left: 4px;
}

tr.row-match {
  background: rgba(196, 168, 122, 0.16);
  box-shadow: inset 3px 0 0 var(--accent-sand);
}
tr.row-match:hover {
  background: rgba(196, 168, 122, 0.24);
}

td a.entity-link {
  color: var(--accent-sand);
  text-decoration: none;
}
td a.entity-link:hover {
  text-decoration: underline;
}

th.sortable-th {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.sortable-th:hover {
  color: var(--accent-sand);
}

tr.filter-row th {
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
}
.table-filter-input,
.table-filter-select {
  width: 100%;
  box-sizing: border-box;
  font-size: 12px;
  padding: 4px 6px;
}

.scroll-nav {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
}
.scroll-nav button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.scroll-nav button:hover {
  border-color: var(--accent-sand);
  color: var(--accent-sand);
}

.logo-link {
  text-decoration: none;
  color: inherit;
}

.names {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Hover/focus "?" tooltip — content comes from the data-tip attribute so no
   extra markup is needed per instance beyond the span itself. */
.info-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1px solid var(--text-secondary);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  position: relative;
  margin-left: 5px;
  vertical-align: middle;
}
.info-tip:hover,
.info-tip:focus {
  border-color: var(--accent-sand);
  color: var(--accent-sand);
  outline: none;
}
.info-tip::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  width: max-content;
  max-width: 260px;
  background: var(--bg-header);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  text-align: left;
  white-space: normal;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
  z-index: 60;
  pointer-events: none;
}
.info-tip:hover::after,
.info-tip:focus::after {
  opacity: 1;
  visibility: visible;
}

@media (max-width: 720px) {
  .app-header {
    padding: 12px 14px;
    gap: 10px;
  }
  .app-header h1 {
    font-size: 15px;
  }
  .main-nav a {
    font-size: 12px;
    padding: 5px 8px;
  }
  .header-right {
    font-size: 12px;
    gap: 10px;
    width: 100%;
    justify-content: flex-end;
  }

  main {
    padding: 12px;
    gap: 16px;
  }

  .cards-row {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
  }
  .card {
    padding: 12px 14px;
  }
  .card .value {
    font-size: 22px;
  }

  .panel {
    padding: 14px;
  }

  /* No horizontal page scroll for wide tables — the table itself scrolls
     instead, without needing a wrapper element on every page. */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  thead, tbody, tr {
    display: table;
    width: 100%;
    table-layout: auto;
  }

  .scope-toggle {
    flex-wrap: wrap;
  }
  .date-range {
    flex-wrap: wrap;
  }

  .scroll-nav {
    right: 12px;
    bottom: 12px;
    gap: 6px;
  }
  .scroll-nav button {
    width: 34px;
    height: 34px;
    font-size: 13px;
  }

  .export-dialog {
    max-width: 92vw;
  }
}
