/* Share (/share) and Manage (/share/manage). Mobile first; builds on base.css tokens. */
:root {
  /* Images are shown on black in both themes; the QR code stays dark on white so it scans; dialogs
     dim the page with a dark scrim in both themes. */
  --image-bg: #000;
  --qr-bg: #fff;
  --scrim: rgba(0, 0, 0, 0.5);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 760px;
  margin: 0 auto;
  padding: calc(8px + var(--safe-t)) calc(var(--gutter) + var(--safe-r)) 0 calc(var(--gutter) + var(--safe-l));
}
.brand { font-weight: 650; color: var(--text); text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
.topbar .btn { min-height: 44px; }

.wiz, .mg {
  max-width: 760px;
  margin: 0 auto;
  padding: 8px calc(var(--gutter) + var(--safe-r)) calc(48px + var(--safe-b)) calc(var(--gutter) + var(--safe-l));
}
h1 { font-size: 1.6rem; margin-top: 8px; }
h1:focus { outline: none; }
h2 { font-size: 1.15rem; }
.lede { color: var(--text-2); font-size: 1.02rem; }
.hint { color: var(--text-3); font-size: 0.875rem; margin: 4px 0 0; display: block; }
.tech { color: var(--text-3); font-size: 0.8rem; font-variant-numeric: tabular-nums; margin: 6px 0 0; }
.right { text-align: right; }
.center { text-align: center; }
.error { color: var(--danger); background: var(--danger-soft); border-radius: var(--radius-sm); padding: 10px 12px; margin: 8px 0; }
.break { word-break: break-all; font-size: 0.8rem; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack > .btn { align-self: flex-start; }
label { font-weight: 550; }
.field { margin: 0 0 18px; border: 0; padding: 0; min-width: 0; }
.field > label, .field > legend { display: block; margin-bottom: 6px; padding: 0; font-weight: 600; }
input[type="number"] { font: inherit; min-height: 44px; padding: 8px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); width: 100%; }

/* Step indicator */
.steps { margin: 8px 0 16px; }
.steps ol { list-style: none; margin: 0; padding: 0; display: flex; gap: 6px; }
.steps li { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.steps li::before { content: ""; height: 4px; border-radius: 2px; background: var(--border); }
.steps li.done::before, .steps li.current::before { background: var(--accent); }
.steps .dot { display: none; }
.steps .lbl { display: none; font-size: 0.8rem; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.steps li.current .lbl { color: var(--text); font-weight: 600; }
.step-count { margin: 8px 0 0; font-size: 0.85rem; color: var(--text-3); }
@media (min-width: 640px) {
  .steps .lbl { display: block; }
  .step-count { display: none; }
}

/* Step 1: source choices */
.choices { display: grid; gap: 10px; margin: 16px 0 24px; }
@media (min-width: 640px) { .choices { grid-template-columns: 1fr 1fr; } }
.choice {
  display: flex; align-items: flex-start; gap: 14px; text-align: left;
  padding: 16px; min-height: 88px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); color: var(--text); font: inherit; cursor: pointer;
}
.choice:hover { border-color: var(--accent); }
.choice:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.c-icon { flex: none; width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.c-icon svg { width: 22px; height: 22px; }
.c-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.c-title { font-weight: 650; font-size: 1.05rem; }
.c-sub { color: var(--text-3); font-size: 0.9rem; }
.back { margin: 0 0 4px -8px; }
.panel { padding-top: 4px; }
.drop {
  margin-top: 16px; padding: 24px 16px; border: 2px dashed var(--border); border-radius: var(--radius);
  background: var(--surface); text-align: center;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.drop-hint { margin: 12px 0 0; }
@media (pointer: coarse) { .drop-hint { display: none; } }
.saved h2 { font-size: 1rem; color: var(--text-2); }
.saved ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.saved-link { width: 100%; justify-content: space-between; text-align: left; flex-wrap: wrap; min-height: 44px; }
.saved-link .tech { margin: 0; }

.found { font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; margin: 12px 0 0; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 16px 0 0; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width 0.15s linear; }
#add-loading .btn { margin-top: 16px; }

/* Step 2: review */
.studies { display: flex; flex-direction: column; gap: 12px; margin: 12px 0; }
.study { padding: 14px; transition: opacity 0.15s; min-width: 0; }
.study.excluded { opacity: 0.55; }
.study.excluded .thumbs { filter: grayscale(1); }
.study-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.study-name { min-width: 0; }
.study h2 { margin: 0; overflow-wrap: anywhere; }
.date { margin: 2px 0 0; color: var(--text-2); }
.thumbs { display: flex; gap: 8px; overflow-x: auto; margin: 12px -14px 0; padding: 0 14px 4px; scrollbar-width: thin; }
.thumb { margin: 0; flex: none; width: 76px; }
.thumb canvas { width: 76px; height: 76px; border-radius: 6px; background: var(--image-bg); }
.thumb canvas.failed { background: var(--surface-2); }
.thumb figcaption { font-size: 0.7rem; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.report-line { margin: 10px 0 0; font-size: 0.9rem; color: var(--text-2); }

/* Switch: the checkbox covers the whole label, so the touch target is the label's size. */
.switch-label, .toggle-row { position: relative; display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; flex: none; }
.switch { display: inline-block; flex: none; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.track { position: relative; display: block; width: 46px; height: 28px; border-radius: 14px; background: var(--border); transition: background 0.15s; }
.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow); transition: transform 0.15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.sw-text { font-size: 0.9rem; color: var(--text-2); font-weight: 500; min-width: 4.5em; }
.toggle-row { display: flex; align-items: flex-start; gap: 14px; margin: 0 0 18px; padding: 8px 0; }
.toggle-row > span:last-child { display: flex; flex-direction: column; }

.actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; }
.actions .btn { min-width: 120px; }

/* Step 3: expiry presets */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (min-width: 640px) { .seg { grid-template-columns: repeat(4, 1fr); } }
.seg-opt { position: relative; display: flex; min-height: 44px; }
.seg-opt input { position: absolute; inset: 0; opacity: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.seg-opt span {
  flex: 1; display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); font-weight: 550;
}
.seg-opt input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.seg-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Step 4: upload log */
.tech-log { list-style: none; margin: 12px 0 0; padding: 0; font-size: 0.78rem; color: var(--text-3); font-family: var(--mono); max-height: 220px; overflow: auto; }
.tech-log li { padding: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Step 5: hand over */
.qr-wrap { display: flex; justify-content: center; margin: 16px 0; }
.qr { width: min(320px, 80vw); aspect-ratio: 1; background: var(--qr-bg); padding: 8px; border-radius: var(--radius); box-shadow: var(--shadow); }
.qr svg { width: 100%; height: 100%; display: block; }
.share-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
@media (min-width: 640px) { .share-actions { display: flex; justify-content: center; flex-wrap: wrap; } }
.share-actions.left { justify-content: flex-start; }
.tech-details { margin: 8px 0 16px; font-size: 0.9rem; color: var(--text-3); }
.tech-details summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.manage-box { padding: 16px; margin: 24px 0 16px; border: 2px solid var(--accent); }
.manage-box h2 { margin-bottom: 6px; }
.manage-box input { font-family: var(--mono); font-size: 0.8rem; margin: 4px 0 8px; }

/* Manage */
.mg-summary { color: var(--text-2); }
.links { display: flex; flex-direction: column; gap: 12px; margin: 12px 0 24px; }
.link-card { padding: 14px; min-width: 0; }
.link-card.off { opacity: 0.8; }
.lc-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.lc-head h3 { margin: 0; font-size: 1.1rem; overflow-wrap: anywhere; }
.pill { display: inline-block; font-size: 0.8rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: var(--ok-soft); color: var(--ok); white-space: nowrap; }
.pill.off { background: var(--surface-2); color: var(--text-2); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.lc-studies { margin: 4px 0 0; color: var(--text-2); }
.lc-status { margin: 8px 0 0; }
.lc-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.lc-qr { display: grid; gap: 12px; margin-top: 12px; }
@media (min-width: 640px) { .lc-qr { grid-template-columns: 180px 1fr; align-items: start; } }
.lc-qr .qr { width: 180px; justify-self: center; }
.inline-form { margin-top: 12px; padding: 14px; border-radius: var(--radius-sm); background: var(--surface-2); }
.check-row { position: relative; display: flex; align-items: center; gap: 12px; min-height: 44px; font-weight: 500; cursor: pointer; }
.check-row input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.check-row .box { flex: none; width: 22px; height: 22px; border: 2px solid var(--text-3); border-radius: 5px; background: var(--surface); display: grid; place-items: center; }
.check-row input:checked + .box { background: var(--accent); border-color: var(--accent); }
.check-row input:checked + .box::after { content: ""; width: 6px; height: 11px; border: solid var(--accent-text); border-width: 0 2.5px 2.5px 0; transform: translateY(-1px) rotate(45deg); }
.compress { margin: 16px 0; }
.picks { display: grid; gap: 8px; }
.pick { position: relative; display: flex; min-height: 44px; }
.pick input { position: absolute; inset: 0; opacity: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.pick > span { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.pick .pick-title { font-weight: 600; }
.pick input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
.pick input:checked + span .pick-title { color: var(--accent); }
.pick input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.check-row input:focus-visible + .box { outline: 2px solid var(--accent); outline-offset: 2px; }
.timeline { list-style: none; padding: 0; margin: 8px 0; }
.timeline li { display: grid; grid-template-columns: 9.5em 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.timeline time { color: var(--text-3); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
@media (max-width: 480px) { .timeline li { grid-template-columns: 1fr; gap: 0; } }
.log-wrap { overflow-x: auto; max-width: 100%; }
.log-table { border-collapse: collapse; font-family: var(--mono); font-size: 0.75rem; color: var(--text-2); white-space: nowrap; }
.log-table th, .log-table td { text-align: left; padding: 3px 10px 3px 0; border-bottom: 1px solid var(--border); }
.mg-section { margin-top: 28px; }
.mg-section > h2 { margin-bottom: 8px; }
.danger-zone { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border); }
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: min(420px, calc(100vw - 32px)); padding: 20px; }
dialog::backdrop { background: var(--scrim); }
.toast { position: fixed; left: 50%; bottom: calc(16px + var(--safe-b)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius-sm); font-size: 0.9rem; z-index: 10; max-width: calc(100vw - 32px); }

.tech-details summary::before { content: "▸"; margin-right: 8px; transition: transform 0.15s; display: inline-block; }
.tech-details[open] summary::before { transform: rotate(90deg); }

.reports { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.report-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; border-top: 1px solid var(--border); }
.report-row.excluded .report-name { opacity: 0.55; }
.report-name { display: flex; flex-direction: column; min-width: 0; }
.report-name .report-line { margin: 0; overflow-wrap: anywhere; }
.reports .attach { align-self: flex-start; margin-left: -8px; }

.resume { padding: 16px; margin: 16px 0 0; border: 2px solid var(--warn); }
.resume h2 { margin-bottom: 4px; }

.found.warn { color: var(--warn); }

.switch-label.disabled { cursor: default; }
.switch-label.disabled .track { opacity: 0.5; }
.switch-label.disabled .sw-text { color: var(--text-3); }
.report-row.excluded .report-name, .report-row.follows-study .report-name { opacity: 0.55; }
.attach[disabled] { opacity: 0.45; }
