:root {
  --bg: #0f1115; --panel: #171a21; --panel-2: #1f232c; --line: #2a2f3a;
  --text: #e7eaf0; --muted: #8a93a6;
  --accent: #6aa6ff; --green: #3fbf7f; --yellow: #e2b13a; --orange: #e88a3a; --red: #e25555;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --pad-x: max(16px, var(--safe-l));
  --pad-x-r: max(16px, var(--safe-r));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { overflow-x: hidden; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px; line-height: 1.5; min-height: 100vh;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

/* ----- Header ------------------------------------------------------ */
header {
  padding: 12px var(--pad-x-r) 12px var(--pad-x);
  padding-top: max(12px, var(--safe-t));
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #131620 0%, #0f1115 100%);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 36px; height: 36px; flex: 0 0 36px; border-radius: 8px;
  background: linear-gradient(135deg, #6aa6ff 0%, #8b5cf6 100%);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
header h1 { margin: 0; font-size: 16px; line-height: 1.2; }
.tag { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.header-right { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
#user-info { font-size: 12px; max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (min-width: 720px) {
  header { padding: 18px 32px; }
  header h1 { font-size: 18px; }
  .tag { font-size: 12px; }
  #user-info { max-width: none; }
}
@media (max-width: 480px) {
  .tag { display: none; }
}

/* ----- Tabs (horizontally scrollable on mobile) -------------------- */
.tabs {
  padding: 0 var(--pad-x-r) 0 var(--pad-x);
  border-bottom: 1px solid var(--line);
  display: flex; gap: 2px; align-items: center;
  overflow-x: auto; overflow-y: hidden;
  flex-wrap: nowrap; scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  position: sticky; top: 60px; z-index: 49;
  background: var(--bg);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent; border: none; color: var(--muted);
  padding: 14px 14px; cursor: pointer;
  border-bottom: 2px solid transparent;
  font: inherit; flex: 0 0 auto;
  min-height: 44px; min-width: 44px;
  scroll-snap-align: start;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.kbd-hint { display: none; }
@media (pointer: fine) and (min-width: 1024px) {
  .tabs { padding: 0 32px; position: static; }
  .kbd-hint { display: inline; margin-left: auto; font-size: 11px; padding-left: 12px; }
}
@media (min-width: 720px) {
  .tabs { top: 0; }
  header { position: static; }
}

kbd {
  background: var(--panel-2); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 1px 5px; font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ----- Layout ------------------------------------------------------ */
main {
  max-width: 1200px; margin: 0 auto;
  padding: 16px var(--pad-x-r) max(24px, var(--safe-b)) var(--pad-x);
  display: grid; gap: 16px; grid-template-columns: 1fr;
}
@media (min-width: 720px) { main { padding: 20px 24px 32px; gap: 20px; } }
@media (min-width: 1024px) { main { padding: 24px 32px 32px; } }

.lookup-card, .result-card, .history-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px;
}
@media (min-width: 720px) {
  .lookup-card, .result-card, .history-card { padding: 20px; }
}

h2 { margin: 0 0 10px; font-size: 16px; letter-spacing: .01em; }
h3 { margin: 16px 0 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

/* ----- Form controls (mobile-friendly) ---------------------------- */
label { display: block; margin-bottom: 12px; font-size: 12px; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="tel"],
input[type="number"], input[type="search"], input[type="file"],
textarea, select {
  width: 100%; margin-top: 4px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 12px;
  /* 16px font on mobile prevents iOS Safari from zooming on focus */
  font-size: 16px;
  font-family: inherit;
  min-height: 44px;
  -webkit-appearance: none;
  appearance: none;
}
@media (min-width: 720px) {
  input[type="text"], input[type="email"], input[type="password"], input[type="tel"],
  input[type="number"], input[type="search"], textarea, select { font-size: 14px; padding: 10px 12px; min-height: 40px; }
}
textarea {
  resize: vertical; min-height: 80px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
input[type="file"] { padding: 10px 12px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

button {
  background: var(--accent); color: #0a1020;
  border: none; border-radius: 8px;
  padding: 12px 18px; font-weight: 600; cursor: pointer;
  font-family: inherit; font-size: 15px;
  min-height: 44px;
  touch-action: manipulation;
}
button:disabled { opacity: .6; cursor: progress; }
button.full-width { width: 100%; }
.link-btn {
  background: transparent; border: 1px solid var(--line); color: var(--accent);
  padding: 8px 12px; font-size: 13px; border-radius: 6px;
  min-height: 36px;
}
.link-btn:hover { background: var(--panel-2); }

.error {
  margin-top: 10px; padding: 10px 12px; border-radius: 8px;
  background: rgba(226,85,85,.15); color: #ffb8b8;
  border: 1px solid rgba(226,85,85,.4);
}
.info {
  margin-top: 10px; padding: 10px 12px; border-radius: 8px;
  background: rgba(106,166,255,.1); color: #cfe1ff;
  border: 1px solid rgba(106,166,255,.4);
}
.exp { white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--muted); }

.row { display: flex; }
.gap-8 { gap: 8px; flex-wrap: wrap; align-items: stretch; }
.row.gap-8 > * { flex: 1 1 160px; min-width: 0; }
.row.gap-8 > button { flex: 0 0 auto; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

/* ----- Result panel ----------------------------------------------- */
.result-header {
  display: flex; flex-direction: column;
  align-items: flex-start; gap: 12px;
}
@media (min-width: 600px) {
  .result-header { flex-direction: row; justify-content: space-between; align-items: center; }
}

.muted { color: var(--muted); font-size: 12px; }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 12px; }
.field-hint { display: block; margin-top: 4px; font-size: 11px; color: var(--muted); line-height: 1.4; }

.pill {
  padding: 8px 14px; border-radius: 999px;
  font-weight: 700; font-size: 14px;
  background: var(--panel-2); border: 1px solid var(--line);
  white-space: nowrap;
}
.pill.minimal { color: var(--green); border-color: rgba(63,191,127,.4); background: rgba(63,191,127,.1); }
.pill.low     { color: #b9d56f; border-color: rgba(185,213,111,.4); background: rgba(185,213,111,.1); }
.pill.medium  { color: var(--yellow); border-color: rgba(226,177,58,.4); background: rgba(226,177,58,.1); }
.pill.high    { color: var(--red);    border-color: rgba(226,85,85,.4);  background: rgba(226,85,85,.1); }

.contrib-list, .history-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; max-height: none; overflow: visible; }
@media (min-width: 720px) { .contrib-list, .history-list { max-height: 380px; overflow-y: auto; } }
.contrib-list li, .history-list li {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 12px;
  display: grid; grid-template-columns: 1fr; gap: 6px; align-items: start;
}
@media (min-width: 480px) {
  .contrib-list li, .history-list li { grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
}
.contrib-list .name { font-weight: 600; }
.contrib-list .why { color: var(--muted); font-size: 12px; }
.contrib-list .meta { color: var(--muted); font-size: 11px; }
.history-list .target { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.history-list .label-pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); white-space: nowrap; }

/* ----- Signals: table on desktop, cards on mobile ----------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
table { width: 100%; border-collapse: collapse; margin-top: 4px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: top; }
th { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .06em; }
td.exp { color: var(--muted); }

@media (max-width: 720px) {
  .table-wrap { overflow: visible; margin: 0; padding: 0; }
  #signals-table, #signals-table tbody, #signals-table tr, #signals-table td { display: block; width: 100%; }
  #signals-table thead { display: none; }
  #signals-table tr {
    background: var(--panel-2); border: 1px solid var(--line);
    border-radius: 8px; padding: 8px 12px; margin-bottom: 8px;
  }
  #signals-table td {
    padding: 4px 0; border-bottom: 1px dashed var(--line);
  }
  #signals-table td:last-child { border-bottom: none; }
  #signals-table td::before {
    content: attr(data-label) " · ";
    font-weight: 600; color: var(--muted); font-size: 11px;
    text-transform: uppercase; letter-spacing: .06em;
  }
  #signals-table td[data-label="Explanation"] { padding-top: 6px; }
  #signals-table td[data-label="Explanation"]::before { display: block; margin-bottom: 4px; }
}

.help-panel {
  margin-top: 16px; padding: 14px 16px;
  border: 1px dashed var(--line); border-radius: 10px; background: var(--panel-2);
}

/* ----- Help tab ---------------------------------------------------- */
.help-layout { display: grid; grid-template-columns: 1fr; gap: 12px; align-items: start; }
@media (min-width: 880px) { .help-layout { grid-template-columns: 280px 1fr; gap: 20px; } }
.help-toc { position: static; max-height: none; overflow: visible; }
@media (min-width: 880px) {
  .help-toc { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
}
.help-toc nav {
  display: flex; gap: 4px; margin-top: 8px;
  flex-wrap: nowrap; overflow-x: auto;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.help-toc nav::-webkit-scrollbar { display: none; }
@media (min-width: 880px) {
  .help-toc nav { display: grid; gap: 2px; overflow: visible; padding-bottom: 0; }
}
.help-toc a {
  color: var(--muted); text-decoration: none; padding: 8px 12px;
  border-radius: 6px; font-size: 13px;
  white-space: nowrap;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}
@media (min-width: 880px) {
  .help-toc a { display: block; padding: 6px 10px; border: none; white-space: normal; }
}
.help-toc a:hover { background: var(--panel-2); color: var(--text); }
.help-toc a.section { color: var(--accent); font-weight: 600; }
@media (min-width: 880px) {
  .help-toc a.section { margin-top: 6px; }
  .help-toc a.signal { padding-left: 22px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
}
@media (max-width: 879px) {
  .help-toc a.signal { display: none; } /* keep mobile TOC scannable */
}
.help-toc a.hidden { display: none; }
.help-content h2 { margin-top: 0; }
.help-content section { padding: 14px 0; border-bottom: 1px solid var(--line); }
.help-content section:last-child { border-bottom: none; }
.help-content section h3 { margin: 0 0 8px; color: var(--accent); font-size: 14px; text-transform: none; letter-spacing: 0; }
.help-content section h4 { margin: 12px 0 6px; font-size: 13px; }
.help-content code {
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 4px; font-size: 12px;
  word-break: break-word;
}
.help-content pre {
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 10px 12px; border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.help-content ul { padding-left: 20px; }
.help-content .example { color: var(--muted); font-style: italic; }
.help-content .severity { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 600; margin-right: 4px; }
.help-content .sev-low { color: var(--green); background: rgba(63,191,127,.12); border: 1px solid rgba(63,191,127,.3); }
.help-content .sev-med { color: var(--yellow); background: rgba(226,177,58,.12); border: 1px solid rgba(226,177,58,.3); }
.help-content .sev-hi  { color: var(--orange); background: rgba(232,138,58,.12); border: 1px solid rgba(232,138,58,.3); }
.help-content .sev-crit { color: var(--red); background: rgba(226,85,85,.12); border: 1px solid rgba(226,85,85,.3); }
.help-content .action { margin-top: 8px; padding: 8px 10px; background: var(--panel-2); border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0; }
.help-content .action::before { content: "Action: "; font-weight: 700; color: var(--accent); }

.signal-link { color: var(--accent); text-decoration: none; cursor: pointer; }
.signal-link:hover { text-decoration: underline; }
.help-icon { color: var(--muted); cursor: pointer; margin-left: 4px; font-size: 11px; border: 1px solid var(--line); padding: 0 4px; border-radius: 4px; }
.help-icon:hover { color: var(--accent); border-color: var(--accent); }

/* ----- Card-head row (lookup card) -------------------------------- */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

footer {
  padding: 16px var(--pad-x-r) max(20px, var(--safe-b)) var(--pad-x);
  text-align: center;
}

/* ----- Toast (fixed) honors safe areas ---------------------------- */
.error[style*="position: fixed"], .info[style*="position: fixed"] {
  bottom: max(20px, var(--safe-b)) !important;
  right: max(20px, var(--safe-r)) !important;
  left: max(20px, var(--safe-l));
  max-width: calc(100% - max(20px, var(--safe-l)) - max(20px, var(--safe-r)));
}

/* Reduce motion for users who request it */
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

/* iOS Safari address-bar safe scroll */
@supports (-webkit-touch-callout: none) {
  .contrib-list, .history-list { -webkit-overflow-scrolling: touch; }
}
