/* App-specific overrides on top of kit.css (admin panels, toasts, legacy helpers). */

:root {
  --ok: var(--free);
  --ok-bg: var(--free-bg);
  --warn: var(--error);
  --warn-bg: var(--error-bg);
  --bad: var(--taken);
  --bad-bg: var(--taken-bg);
}

html.app-shell-lock,
html.app-shell-lock body {
  height: 100%;
  overflow: hidden;
}

#appView .shell {
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

#appView .rail {
  width: 280px;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  position: static;
  min-height: 0;
  flex-shrink: 0;
  padding: 12px 12px 10px;
  display: flex !important;
  flex-direction: column;
  gap: 8px;
  box-sizing: border-box;
}

.rail-brand,
.rail-new,
.rail-mobile {
  flex-shrink: 0;
}
#appView .rail-brand h1 { font-size: 13px; }
#appView .rail-brand .sub { font-size: 10.5px; }
#appView .rail-brand .brand-logo { width: 28px; height: 28px; }
.rail-new { min-height: 36px; font-size: 13px; padding: 8px 12px; }
.rail-mobile { display: none; }

.history {
  flex: 1 1 0;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-left: -2px;
  margin-right: -2px;
}
.history-head {
  flex-shrink: 0;
  padding-left: 2px;
  padding-right: 2px;
}
#historyList {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
  scrollbar-width: thin;
}
.history-item,
.history-list-btn {
  width: 100%;
  box-sizing: border-box;
}
.history-item .name {
  word-break: break-word;
}
#appView .history-item {
  padding: 7px 10px;
}
#appView .history-item .name { font-size: 12px; }
#appView .history-item .meta { font-size: 11px; margin-top: 2px; }
.rail-nav {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: min(168px, 22vh);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  background: var(--rail);
  position: relative;
  z-index: 2;
}
.rail-footer {
  flex: 0 0 auto;
  margin-top: 0 !important;
  padding-top: 8px;
  padding-bottom: 0;
  gap: 8px;
  background: var(--rail);
  position: relative;
  z-index: 3;
  border-top: 1px solid var(--border);
  min-height: fit-content;
}
.rail-footer .theme-toggle-rail {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  display: flex;
  border-radius: 6px;
}
.rail-footer .theme-toggle-rail button {
  flex: 1 1 50%;
  min-width: 0;
  min-height: 26px;
  padding: 4px 6px;
  font-size: 10.5px;
}
.rail-footer .rail-user {
  flex-wrap: wrap;
  gap: 4px 8px;
  font-size: 11px;
}
.rail-footer .rail-user span {
  flex: 1 1 120px;
  min-width: 0;
}
.rail-footer .rail-user button {
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: 11px;
}

#appView .main {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#appView .main-inner {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0;
}

#appView .tab-panel:not(.hidden) {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}

/* Help / Users / Settings / Costs: scroll the main column, panels keep natural height. */
#appView .main-inner.is-config-scroll {
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

#appView .main-inner.is-config-scroll > .tab-panel:not(.hidden) {
  display: block;
  flex: none;
  height: auto;
  min-height: auto;
  overflow: visible;
  padding-bottom: 8px;
}

#appView .main-inner.is-config-scroll > .credit {
  flex-shrink: 0;
  margin-top: 12px;
  padding-bottom: 8px;
}

#appView .main-inner.is-config-scroll .panel {
  overflow: visible;
  margin-bottom: 16px;
}

#appView .main-inner.is-config-scroll .panel:last-child {
  margin-bottom: 0;
}

#tab-settings .panel-body,
#tab-users .panel-body,
#tab-costs .panel-body {
  padding: 18px 20px;
}

#tab-settings textarea,
#tab-users textarea {
  min-height: 88px;
  resize: vertical;
}

#tab-costs .panel-body {
  overflow-x: auto;
}

#tab-scan:not(.hidden) {
  overflow: hidden;
}
#tab-scan .page-head,
#tab-scan > .panel:first-of-type {
  flex-shrink: 0;
}
#tab-scan #reportPanel {
  flex: 1 1 auto;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-bottom: 0;
}

/* Advanced report: give the table most of the viewport; hide form while viewing a scan. */
#tab-scan.is-advanced-view.is-report-active #scanFormPanel {
  display: none;
}
#tab-scan.is-advanced-view.is-report-active .page-head {
  margin-bottom: 0;
  padding-bottom: 4px;
}
#tab-scan.is-advanced-view #reportPanel {
  flex: 1 1 auto;
  min-height: min(520px, 62vh);
}
#tab-scan.is-advanced-view #reportPanel .table-wrap {
  flex: 1 1 auto;
  min-height: 360px;
}
#tab-scan.is-advanced-view #reportPanel.has-drilldown .table-wrap {
  flex: 1 1 58%;
  min-height: 220px;
}
#tab-scan.is-advanced-view #reportPanel .panel-head .actions {
  flex-wrap: wrap;
  gap: 6px;
}
#tab-scan.is-advanced-view #reportPanel .panel-head .actions button {
  min-height: 30px;
  padding: 4px 10px;
  font-size: 0.75rem;
}
.rail-nav-btn {
  width: 100%; text-align: left; background: transparent; border: 1px solid transparent;
  color: var(--muted); padding: 5px 9px; border-radius: 6px; min-height: 26px;
  font-family: var(--font-display); font-size: 11.5px; cursor: pointer;
}
.rail-nav-btn:hover { color: var(--text); background: var(--surface-2); }
.rail-nav-btn[aria-pressed="true"] {
  color: var(--text); background: var(--signal-dim); border-color: transparent;
}
.tab-panel.hidden { display: none !important; }
.main-inner { width: 100%; display: flex; flex-direction: column; gap: 20px; }
.staff-only.hidden { display: none !important; }
.superadmin-only.hidden { display: none !important; }

.brand-logo[hidden] { display: none !important; }
.radar-ping { position: relative; width: 14px; height: 14px; flex-shrink: 0; }
.radar-ping::before, .radar-ping::after { content: ''; position: absolute; inset: 0; border-radius: 50%; background: var(--signal); }
.radar-ping::before { animation: ping 2.2s cubic-bezier(0,0,0.2,1) infinite; }
.radar-ping::after { transform: scale(0.45); }
@keyframes ping { 0% { transform: scale(0.45); opacity: 0.9; } 75%, 100% { transform: scale(2.4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .radar-ping::before { animation: none; opacity: 0; } }

.login-page { position: relative; overflow: hidden; }
.login-shell { position: relative; width: 100%; max-width: 420px; }
.login-shell .brand-logo { width: 56px; height: 56px; margin: 0 auto 14px; }
.login-shell h1 { text-align: center; }
.login-shell .sub { text-align: center; margin-bottom: 24px; }
.login-actions { display: flex; gap: 10px; }
.login-actions button { flex: 1; }
.google-signin-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 4px; }
.google-domains-hint { margin: 0; font-size: 0.82rem; text-align: center; opacity: 0.75; }
.auth-divider {
  margin: 14px 0 12px;
  text-align: center;
  font-size: 0.82rem;
  opacity: 0.65;
  position: relative;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 28%;
  height: 1px;
  background: currentColor;
  opacity: 0.25;
}
.auth-divider::before { left: 0; }
.auth-divider::after { right: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.status-chip {
  display: inline-flex; align-items: center; padding: 4px 9px; border-radius: 5px;
  font-size: 11px; font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.03em;
  background: var(--free-bg); color: var(--free);
}

button.is-busy, button:disabled:not(.secondary) { opacity: 0.72; cursor: wait; }
button.is-busy { pointer-events: none; box-shadow: inset 0 0 0 1px var(--signal-dim); }
button.is-busy::after {
  content: ""; display: inline-block; width: 0.85em; height: 0.85em; margin-left: 0.45em;
  border: 2px solid rgba(255,255,255,0.35); border-top-color: #fff; border-radius: 50%;
  vertical-align: -0.15em; animation: btn-spin 0.7s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }
button.is-ok-flash { background: var(--free) !important; border-color: var(--free) !important; color: #fff !important; }

.toast {
  position: fixed; right: 16px; bottom: 16px; z-index: 50;
  max-width: min(360px, calc(100vw - 32px)); padding: 12px 14px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  color: var(--text); font-size: 0.88rem; opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok { border-color: var(--free); }
.toast.err { border-color: var(--taken); color: var(--taken); }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.url-list { margin-top: 12px; max-height: 200px; overflow: auto; }
.url-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.url-item:last-child { border-bottom: none; }
.url-item button { width: auto; padding: 4px 10px; font-size: 0.8rem; min-height: 30px; }

.user-list-scroll {
  max-height: 320px; overflow-y: auto; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface-2);
}

.error { color: var(--taken); margin-top: 8px; font-size: 0.9rem; }
.ok-msg { color: var(--free); margin-top: 8px; font-size: 0.9rem; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }

.scan-progress-wrap { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 160px; justify-content: center; }
.scan-progress-bar { width: min(220px, 100%); height: 6px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.scan-progress-bar.hidden { display: none; }
.scan-progress-fill { height: 100%; width: 0%; background: var(--signal); border-radius: inherit; transition: width 0.35s ease; }

a.url-trunc { display: inline-block; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.link-list a { color: var(--signal); text-decoration: none; font-weight: 600; font-family: var(--font-display); }
.link-list .sep { color: var(--muted); margin: 0 2px; }

.history-list-btn {
  all: unset;
  cursor: pointer;
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  text-align: left;
}
.history-list-btn:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; border-radius: 8px; }

.panel-head .left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tiles-4 { grid-template-columns: repeat(4, 1fr); }
.tile-unavail .n { color: var(--error); }

.retry-link { color: var(--signal); text-decoration: underline; cursor: pointer; background: none; border: 0; padding: 0; font: inherit; }
.note-retry { margin-left: 6px; }

.secrets-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.secrets-table th, .secrets-table td { padding: 10px 8px; border-bottom: 1px solid var(--border-soft); text-align: left; vertical-align: top; }
.secrets-table th { font-family: var(--font-display); font-size: 10px; text-transform: uppercase; color: var(--muted); }
.secret-modal-backdrop { position: fixed; inset: 0; background: rgba(33,28,16,.35); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; }
.secret-modal { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 20px; width: min(420px, 100%); }
.secret-modal h4 { margin: 0 0 8px; font-family: var(--font-display); }
.secret-modal-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.prior-modal-progress.is-active {
  color: var(--signal-ink, #6b4c11);
  font-weight: 600;
}
.prior-modal-progress.is-active::before {
  content: "⏳ ";
}
.secret-modal-backdrop.is-busy { cursor: progress; }

.advanced-scan-only.hidden { display: none !important; }

#reportPanel .panel-head,
#reportPanel .progress,
#reportPanel #summaryTiles,
#reportPanel #bulkBar,
#reportPanel #summaryFoot {
  flex-shrink: 0;
}
#reportPanel .table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow: auto;
  overscroll-behavior: contain;
}
#reportPanel .table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  box-shadow: 0 1px 0 var(--border-soft);
}

.drilldown-bench {
  flex: 0 0 min(38vh, 320px);
  min-height: 200px;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  overflow: hidden;
}
.drilldown-bench.hidden { display: none !important; }
.drilldown-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
}
.drilldown-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 600;
}
.drilldown-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 16px 16px;
}
.drilldown-scroll .sub,
.drilldown-scroll p,
.drilldown-scroll li {
  font-size: 13px;
  line-height: 1.5;
}

.help-lang-toggle { display: flex; gap: 8px; margin-bottom: 16px; }
.help-lang-toggle button { width: auto; min-height: 34px; padding: 6px 14px; font-size: 12px; }
.help-lang-toggle button[aria-pressed="true"] { background: var(--signal-dim); color: var(--text); }
.help-section { margin-bottom: 22px; }
.help-section h4 { margin: 0 0 8px; font-family: var(--font-display); font-size: 13px; }
.help-section p, .help-section li { font-size: 13.5px; line-height: 1.55; color: var(--text-2); }
.help-section ul { margin: 8px 0 0; padding-left: 18px; }
.help-pill-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-top: 10px; }
.help-pill-card { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: var(--surface-2); font-size: 13px; }

#tab-admin-history:not(.hidden) {
  overflow: hidden;
}
#tab-admin-history .admin-history-panel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-bottom: 0;
}
.admin-history-filters {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.admin-history-filters-top {
  flex-shrink: 0;
}
.admin-history-filters .row { align-items: end; }
.admin-history-filters label { font-size: 12px; }
.admin-history-filters input[type="date"] { min-width: 140px; width: auto; }

input[type="checkbox"].table-checkbox,
input[type="radio"].table-checkbox {
  width: 16px;
  height: 16px;
  min-height: 16px;
  padding: 0;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--signal);
}

.multi-select-wrap { min-width: 220px; max-width: 280px; }
.multi-select { position: relative; }
.multi-select-trigger {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.multi-select-trigger:hover { background: var(--surface); }
.multi-select-caret { color: var(--muted); font-size: 11px; }
.multi-select-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(33, 28, 16, 0.12);
  padding: 6px 0;
  scrollbar-width: thin;
}
.multi-select-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  padding: 7px 12px;
  cursor: pointer;
}
.multi-select-option:hover { background: var(--surface-2); }

.admin-history-table-bench {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  margin-top: 12px;
  scrollbar-width: thin;
}
.admin-history-table-bench thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  box-shadow: 0 1px 0 var(--border-soft);
}
.admin-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  table-layout: fixed;
}
.admin-history-table th,
.admin-history-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
  vertical-align: middle;
  line-height: 1.35;
  overflow: hidden;
}
.admin-history-table th {
  font-family: var(--font-display);
  font-size: 10px;
  text-transform: uppercase;
  color: var(--muted);
}
.admin-history-table col.col-check { width: 32px; }
.admin-history-table col.col-created { width: 92px; }
.admin-history-table col.col-alias { width: 30%; }
.admin-history-table col.col-user { width: 24%; }
.admin-history-table col.col-status { width: 68px; }
.admin-history-table col.col-links { width: 42px; }
.admin-history-table col.col-actions { width: 158px; }
.admin-history-table .col-check { padding-left: 6px; padding-right: 4px; }
.admin-history-table .col-created {
  font-size: 11.5px;
  font-family: var(--font-display);
  white-space: nowrap;
}
.admin-history-table .col-status { text-align: center; font-size: 11.5px; }
.admin-history-table .col-links { text-align: center; font-size: 11.5px; padding-left: 4px; padding-right: 4px; }
.admin-history-table .col-actions { padding-right: 6px; }
.admin-history-table .cell-clip {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.admin-history-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.admin-history-actions button { width: auto; min-height: 28px; padding: 3px 8px; font-size: 0.72rem; }

.source-badge {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
  white-space: nowrap;
}
.source-badge.is-history {
  color: var(--signal-ink, #6b4c11);
  background: color-mix(in srgb, var(--signal, #f5c542) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--signal, #f5c542) 45%, transparent);
}
.source-badge.is-cache {
  color: var(--placeholder, #5c6570);
  background: color-mix(in srgb, var(--border, #c8ced6) 35%, transparent);
  border: 1px solid color-mix(in srgb, var(--border, #c8ced6) 65%, transparent);
}
td.cache .source-badge.is-history,
td.cache .source-badge.is-cache { margin-right: 0; }

@media (max-width: 900px) {
  html.app-shell-lock,
  html.app-shell-lock body { height: auto; overflow: auto; }
  #appView .shell { height: auto; max-height: none; overflow: visible; }
  #appView .main,
  #appView .main-inner,
  #appView .tab-panel:not(.hidden) { overflow: visible; min-height: auto; }
  .rail { height: auto; max-height: none; position: static; overflow: visible; }
  .rail { display: flex; flex-direction: column; }
  .history { flex: none; min-height: auto; overflow: visible; }
  #historyList { min-height: 0; max-height: 420px; overflow-y: auto; flex: none; height: auto; }
  .rail-nav { display: none; }
  .rail-footer { flex-shrink: 0; }
  .tiles-4 { grid-template-columns: repeat(2, 1fr); }
  #tab-scan #reportPanel { min-height: auto; }
  #reportPanel .table-wrap { max-height: 420px; flex: none; }
  .admin-history-table-bench { max-height: 420px; flex: none; }
}
