/* aitap - a tool about a physical gesture, so it should feel like one.
   Dark by default, because it lives on a phone held up in a hallway. */

:root {
  color-scheme: dark;
  --bg: #0a0c10;
  --bg-glow: #121724;
  --surface: #151924;
  --surface-2: #1e2432;
  --line: #262d3d;
  --text: #eef1f6;
  --muted: #97a1b5;
  --accent: #f8d800;        /* the logo yellow, sampled from the mark */
  --accent-2: #ffab00;
  --accent-ink: #14100a;    /* dark ink on yellow - the readable direction */
  --accent-text: #f8d800;   /* safe as text on near-black */
  --danger: #ff6b6b;
  --ok: #4ade80;
  --warn: #ffb454;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow: 0 18px 40px rgba(0, 0, 0, .45);
  --ring: 0 0 0 3px rgba(248, 216, 0, .32);
  --glow: drop-shadow(0 0 14px rgba(248, 216, 0, .42));
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f5f7fb;
    --bg-glow: #f7f0d8;
    --surface: #ffffff;
    --surface-2: #eef1f7;
    --line: #dfe5ef;
    --text: #10141c;
    --muted: #5b6678;
    --accent: #f5cf00;
    --accent-2: #ff9f00;
    --accent-ink: #14100a;
    /* #f8d800 on white is ~1.4:1 - unreadable. Text needs its own value. */
    --accent-text: #7a5c00;
    --shadow: 0 14px 34px rgba(16, 20, 28, .10);
    --glow: none;
  }
}

* { box-sizing: border-box; }
/* Class rules below set `display`, which out-specifies the browser's own
   [hidden] rule. Without this, hiding an element by attribute does nothing. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 620px at 15% -10%, var(--bg-glow), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(248, 216, 0, .07), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

/* ---------- chrome ---------- */

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px calc(14px + env(safe-area-inset-top)) 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(140%) blur(14px);
}
.topbar h1 { font-size: 19px; margin: 0; letter-spacing: -.01em; font-weight: 700; }
/* #who takes the slack so the gear stays pinned to the trailing edge. */
.topbar #who { margin-left: auto; }
.topbar .icon {
  flex: none; margin: 0; padding: 0; width: 38px; height: 38px;
  font-size: 19px; line-height: 1; display: grid; place-items: center;
}
.logo { display: block; height: 30px; width: auto; filter: var(--glow); }
.sidebar .logo { height: 46px; margin-bottom: 4px; }
/* The mark is neon: yellow on white is ~1.4:1, so in a light theme it gets the
   dark plate it was drawn for instead of being left to fade out. */
@media (prefers-color-scheme: light) {
  .logo {
    background: #14100a; padding: 8px 12px; border-radius: 12px;
    box-sizing: content-box;
  }
}
main { padding: 20px 16px 48px; max-width: 680px; margin: 0 auto; }

h2 {
  font-size: clamp(22px, 5vw, 26px);
  line-height: 1.15; letter-spacing: -.02em; margin: 0 0 10px; font-weight: 700;
}
.lede { color: var(--muted); margin: 0 0 22px; font-size: 15.5px; }
.note { color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
code {
  background: var(--surface-2); padding: 2px 6px; border-radius: 6px;
  font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---------- controls ---------- */

button {
  font: inherit; font-weight: 600;
  border-radius: var(--radius); border: 1px solid transparent;
  padding: 12px 18px; cursor: pointer;
  background: var(--surface-2); color: var(--text);
  transition: transform .12s ease, background .16s ease, border-color .16s ease, box-shadow .16s ease;
}
button:hover { border-color: var(--line); }
button:active { transform: translateY(1px) scale(.995); }
button:focus-visible { outline: none; box-shadow: var(--ring); }
button.big { display: block; width: 100%; margin-bottom: 12px; padding: 17px 20px; font-size: 16px; }

button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  border-color: transparent;
  box-shadow: 0 10px 26px -12px var(--accent);
}
button.primary:hover { filter: brightness(1.06); }
button.secondary { background: var(--surface); border-color: var(--line); }
button.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
button.ghost:hover { color: var(--text); }
button.danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 55%, transparent); color: var(--danger); width: 100%; }
button.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
button[disabled] { opacity: .45; cursor: not-allowed; transform: none; }

input, select, textarea {
  font: inherit; width: 100%; padding: 13px 14px; margin-top: 6px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  transition: border-color .16s ease, box-shadow .16s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: var(--ring);
}
textarea {
  font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  resize: vertical;
}
label { font-size: 13.5px; color: var(--muted); font-weight: 500; }
.options { margin: 20px 0; display: grid; gap: 14px; }

/* ---------- surfaces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin: 14px 0;
}
.card.warn { border-color: color-mix(in srgb, var(--warn) 50%, transparent); background: color-mix(in srgb, var(--warn) 7%, var(--surface)); }
.card.warn p { margin-top: 0; }
.card.warn button { margin-right: 8px; }

.group-title {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--muted); margin: 22px 0 10px; font-weight: 700;
}

.item {
  display: flex; gap: 14px; align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px 16px; margin-bottom: 9px;
  position: relative; overflow: hidden;
  transition: border-color .16s ease, transform .12s ease, background .16s ease;
}
/* A hairline of accent on the leading edge: enough to read as a stack of
   distinct things without turning the list into a colour chart. */
.item::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: linear-gradient(var(--accent), var(--accent-2));
  opacity: 0; transition: opacity .16s ease;
}
.item:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.item.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.item.selected::before { opacity: 1; }
.item > span { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; }
.item input[type=checkbox] {
  width: 22px; height: 22px; margin: 1px 0 0; flex: none;
  accent-color: var(--accent); cursor: pointer;
}
.item .name { font-weight: 650; letter-spacing: -.01em; }
.item .desc { color: var(--muted); font-size: 14px; }

/* A passkey row is a fact plus one destructive verb, so the verb goes to the
   far edge rather than leaning on the name. */
#passkey-list .item { justify-content: space-between; align-items: center; }
#passkey-list .item button { flex: none; margin: 0; }

/* Project filter: a row of chips that scrolls sideways rather than wrapping
   into three lines on a phone. */
.chips {
  display: flex; gap: 8px; overflow-x: auto; margin: 0 0 14px;
  padding-bottom: 4px; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 14px; font-size: 13.5px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
}
.chip.current {
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  border-color: var(--accent); color: var(--text);
}
.badge.project { background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); color: var(--accent-text); }
.send-row { gap: 10px; margin-bottom: 12px; }
.send-row button { flex: 1; }

.filelist { margin-top: 8px; }
.fileline {
  display: flex; justify-content: space-between; gap: 12px;
  font: 12.5px/1.9 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted); border-bottom: 1px solid var(--line); padding: 2px 0;
}
.fileline:last-child { border-bottom: 0; }
.fileline .size { flex: none; }

/* Labels are inline by default, so one following a button lands beside it.
   In the connector card every field is its own line. */
#connector-card label { display: block; margin-top: 16px; }
#connector-card > label:first-of-type { margin-top: 0; }
#connector-card button { margin-top: 10px; margin-right: 8px; }

/* Sensitivity, project and file count are one line of facts, not a stack. */
.badges { display: flex; flex-wrap: wrap; gap: 6px; }

.badge {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; margin-top: 4px;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--line);
}
.badge.confidential {
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

/* ---------- the tap, which is the whole point ---------- */

.tap-target {
  position: relative; display: grid; place-items: center;
  height: 240px; border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid var(--line);
  margin-bottom: 16px; overflow: hidden;
}
.tap-target p { position: relative; z-index: 1; text-align: center; padding: 0 22px; font-weight: 550; }
.pulse {
  position: absolute; width: 130px; height: 130px; border-radius: 50%;
  background: radial-gradient(circle, var(--accent), transparent 70%);
  opacity: .25; animation: pulse 2s cubic-bezier(.2, .7, .3, 1) infinite;
}
@keyframes pulse {
  0% { transform: scale(.55); opacity: .45; }
  100% { transform: scale(2.6); opacity: 0; }
}
.tap-target.done .pulse { animation: none; background: radial-gradient(circle, var(--ok), transparent 70%); opacity: .2; }

.qr-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 22px 20px 18px;
  display: grid; justify-items: center; gap: 6px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
/* The QR stays on white in both themes - inverted codes do not scan. */
.qr { width: min(290px, 74vw); height: auto; image-rendering: pixelated; }
.qr-card .code {
  color: #0a0c10; font-size: clamp(30px, 8vw, 38px); margin: 6px 0 0;
  font-weight: 800; letter-spacing: .16em; font-variant-numeric: tabular-nums;
}
.qr-card .note { color: #5b6678; text-align: center; margin: 0; }
.code { text-align: center; font-weight: 800; letter-spacing: .16em; }

.link-field { font-size: 13px; margin-bottom: 12px; font-family: ui-monospace, Menlo, monospace; }
.cmd {
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 14px; border-radius: 12px; overflow-x: auto;
  font-size: 13px; margin: 10px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.camera-wrap { display: grid; gap: 10px; margin-bottom: 12px; }
.camera-wrap video {
  width: 100%; border-radius: var(--radius-lg); background: #000;
  aspect-ratio: 1 / 1; object-fit: cover; border: 1px solid var(--line);
}

#save-list { display: grid; gap: 8px; }
#save-list a {
  color: var(--accent-text); text-decoration: none; padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; display: block; font-weight: 550;
}
#save-list a:hover { border-color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--line);
  padding: 13px 20px; border-radius: 999px;
  margin: 0; max-width: 90vw; box-shadow: var(--shadow);
  animation: rise .22s ease both; z-index: 50; font-weight: 550;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }

.row { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.row h2 { margin: 0; }
.status { font-size: 11.5px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-weight: 600; }
.status.live { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.status.revoked, .status.expired, .status.offline { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }

input[type=file] { padding: 11px; }
#library-list .item { cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
  .pulse { animation: none; opacity: .22; }
  .toast { animation: none; }
  button { transition: none; }
}

/* ---- Wide screens ----
   The phone layout above is untouched. From 900px the same views get a
   persistent sidebar, a wider column, and side-by-side forms, because
   curating a library means pasting whole files, not thumbing a text field. */
.sidebar { display: none; }

@media (min-width: 900px) {
  body { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }
  .topbar { display: none; }

  .sidebar {
    display: flex; flex-direction: column; gap: 4px;
    padding: 26px 16px; border-right: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 70%, transparent);
    backdrop-filter: blur(10px);
    position: sticky; top: 0; height: 100vh;
  }
  .sidebar-brand { padding: 0 10px 22px; display: grid; gap: 3px; }
  .brand-row { display: flex; align-items: center; gap: 9px; }
  .brand-mark { width: 26px; height: 26px; color: var(--accent-text); flex: none; }
  .sidebar-brand strong { font-size: 21px; letter-spacing: -.01em; }
  .sidebar-brand span { font-size: 13px; }
  .sidebar .nav {
    text-align: left; background: transparent; border-color: transparent;
    padding: 11px 13px; color: var(--muted); font-size: 15px;
  }
  .sidebar .nav:hover { background: var(--surface-2); color: var(--text); }
  .sidebar .nav.current {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: var(--accent-ink);
    box-shadow: 0 10px 24px -14px var(--accent);
  }
  .sidebar-foot { margin-top: auto; display: grid; gap: 10px; }

  main { max-width: 1080px; padding: 40px 44px 64px; margin: 0; }
  h2 { font-size: 30px; }

  /* Items read better as a grid once there is room for one. */
  #library-list, #catalog, #offer-items, #done-items, #history-list {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 10px; align-items: start;
  }
  #library-list .group-title, #catalog .group-title,
  #offer-items .group-title, #done-items .group-title { grid-column: 1 / -1; margin: 22px 0 2px; }
  .item { margin-bottom: 0; }

  /* The editor gets the space it always needed: fields beside the content. */
  #view-editor .card {
    display: grid; grid-template-columns: 320px minmax(0, 1fr);
    gap: 0 30px; align-items: start; padding: 24px;
  }
  #view-editor .card > label,
  #view-editor .card > input,
  #view-editor .card > select { grid-column: 1; }
  #content-field, #mcp-field { grid-column: 2; grid-row: 1 / 12; }
  #item-content, #item-mcp { min-height: 440px; }
  #save-item { grid-column: 1; margin-top: 20px; }
  #delete-item { grid-column: 1; }

  /* The tap screen is a handover: code and QR large, actions beside them. */
  #view-tap { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 30px; align-items: start; }
  .qr-card { grid-row: 1 / 9; margin-bottom: 0; }
  .qr { width: 340px; }

  button.big { width: auto; min-width: 260px; }
  /* Full-bleed buttons look unfinished beside a QR; cap the action column. */
  #view-tap button, #view-tap .card, #view-tap .note { max-width: 420px; }
  #view-home .lede { font-size: 17px; }
  .link-field { max-width: 640px; }
}

@media (min-width: 1280px) { main { max-width: 1240px; } }
