/* ---------- Drawer & dialogs ---------- */
.scrim { position: fixed; inset: 0; z-index: 40; background: var(--scrim); }
.drawer {
  position: fixed; z-index: 41; top: 0; right: 0; bottom: 0; width: min(100%, clamp(340px, 40vw, 560px));
  background: var(--bg); box-shadow: var(--shadow-2); display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); padding-right: env(safe-area-inset-right, 0px);
}
.dr-head { display: flex; align-items: center; gap: 10px; padding: 14px var(--space-m); border-bottom: 1px solid var(--line); background: var(--surface); }
.dr-head h2 { margin: 0; flex: 1; font-size: var(--step-0); font-weight: 600; letter-spacing: -0.015em; }
.dr-body { overflow-y: auto; padding: var(--space-m); display: flex; flex-direction: column; gap: var(--space-m); flex: 1; }
.dr-tabs { display: flex; gap: 4px; padding: 10px var(--space-m) 0; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; }
.dr-tabs::-webkit-scrollbar { display: none; }
.dr-tabs button { border: 0; background: none; padding: 8px 10px 10px; font-size: var(--step--1); font-weight: 500; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.dr-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.fgroup { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-1); display: flex; flex-direction: column; }
.fgroup-h { font-size: var(--step--2); font-weight: 600; color: var(--ink-3); letter-spacing: 0.06em; text-transform: uppercase; padding: 0 4px; margin-bottom: -8px; }
.field { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 10px; align-items: center; padding: 9px 14px; min-height: 46px; }
.field + .field { border-top: 1px solid var(--line); }
.field.col { grid-template-columns: minmax(0, 1fr); gap: 4px; }
.field label { font-size: var(--step--1); color: var(--ink-2); }
.field label small { display: block; color: var(--ink-3); font-size: var(--step--2); }
.field input[type=text], .field input[type=url], .field input[type=number], .field select, .field textarea {
  width: 100%; border: 1px solid transparent; border-radius: 8px; background: var(--hover); padding: 7px 10px; font-size: var(--step--1); outline: none; transition: border-color 0.2s, background 0.2s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--focus); background: var(--surface); }
.field textarea { min-height: 76px; resize: vertical; line-height: 1.5; }
.field input.num { font-family: var(--font-num); }
.tagset { display: flex; flex-wrap: wrap; gap: 6px; }
.tagset button { border: 0; border-radius: 999px; padding: 5px 11px; font-size: var(--step--2); font-weight: 500; background: var(--hover); color: var(--ink-2); transition: background 0.2s, color 0.2s, transform 0.15s; }
.tagset button[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); }
.tagset button:active { transform: scale(0.95); }
.switch { position: relative; width: 40px; height: 24px; justify-self: end; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 12px; background: var(--line-2); transition: background 0.25s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.2); transition: transform 0.3s var(--ease); }
.switch input:checked + span { background: var(--ink); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.seg.tri { justify-self: end; }
.vrow { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 14px; }
.vrow + .vrow { border-top: 1px solid var(--line); }
.thumb { width: 64px; height: 48px; border-radius: 8px; background-color: var(--canvas); background-image: radial-gradient(circle, var(--canvas-dot) 1px, transparent 1.2px); background-size: 8px 8px; display: grid; place-items: center; overflow: hidden; border: 0; padding: 0; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb svg { width: 18px; height: 18px; color: var(--ink-3); }
.vrow .vf { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.vrow .vf input { width: 100%; border: 1px solid transparent; border-radius: 8px; background: var(--hover); padding: 6px 9px; font-size: var(--step--1); outline: none; }
.vrow .vf input:focus { border-color: var(--focus); background: var(--surface); }
.vrow .vact { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.icon-btn { width: 30px; height: 30px; border-radius: 50%; border: 0; background: none; color: var(--ink-2); display: grid; place-items: center; transition: background 0.2s; }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn[aria-pressed="true"] { color: var(--pos); }

.modal-wrap { position: fixed; inset: 0; z-index: 41; display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); pointer-events: none; }
.modal { pointer-events: auto; width: min(100%, 600px); max-height: 100%; overflow: auto; background: var(--bg); border-radius: var(--radius-card); box-shadow: var(--shadow-2); }
.status-line { display: flex; gap: 8px; align-items: center; font-size: var(--step--1); color: var(--ink-2); min-height: 22px; }
.spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--ink); animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.lightbox { position: fixed; inset: 0; z-index: 50; background: color-mix(in srgb, var(--bg) 92%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); display: grid; place-items: center; padding: max(24px, env(safe-area-inset-top, 0px)) max(24px, env(safe-area-inset-right, 0px)) max(24px, env(safe-area-inset-bottom, 0px)) max(24px, env(safe-area-inset-left, 0px)); cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 12px; box-shadow: var(--shadow-2); }
.toast { position: fixed; z-index: 60; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--on-ink); padding: 10px 18px; border-radius: 999px; font-size: var(--step--1); font-weight: 500; box-shadow: var(--shadow-2); white-space: nowrap; max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis; }
.confirm-row { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; font-size: var(--step--1); color: var(--ink-2); }

/* ---------- Deep Dive Drawer & Dossier ---------- */
.drawer.dd-drawer {
  width: min(100%, clamp(420px, 52vw, 760px));
}
@media (max-width: 700px) {
  .drawer.dd-drawer {
    top: auto; left: 0; right: 0; width: 100%; max-height: 90vh;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
    padding-right: 0;
  }
}
.modal.deep-dive-modal { width: min(100%, 780px); max-height: min(92vh, 880px); display: flex; flex-direction: column; overflow: hidden; }
.dd-head { padding: 14px 20px 12px; border-bottom: 1px solid var(--line); background: var(--surface); display: flex; align-items: flex-start; gap: 12px; }
.dd-tabs { display: flex; gap: 4px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; flex-shrink: 0; scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; }
.dd-tabs::-webkit-scrollbar { display: none; }
.dd-tabs button { border: 0; background: none; padding: 10px 12px 9px; font-size: var(--step--1); font-weight: 500; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; cursor: pointer; transition: color 0.15s; }
.dd-tabs button:hover { color: var(--ink); }
.dd-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }
.dd-body { padding: 16px 20px; overflow-y: auto; flex: 1; background: var(--bg); display: flex; flex-direction: column; gap: 14px; }
.dd-tab-pane { display: flex; flex-direction: column; gap: 12px; }
.dd-banner { background: var(--surface); border-radius: var(--radius); padding: 12px 16px; border: 1px solid var(--line); box-shadow: var(--shadow-1); }
.dd-stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.dd-stat-box { background: var(--hover); border-radius: 8px; padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; }
.dd-stat-label { font-size: 0.68rem; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.dd-stat-val { font-size: var(--step-1); font-weight: 700; color: var(--ink); line-height: 1.2; }
.dd-stat-sub { font-size: var(--step--2); color: var(--ink-2); }
.dd-sec-h { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
.dd-sec-h h3 { font-size: var(--step--1); text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-2); margin: 0; font-weight: 600; }
.dd-cards-list { display: flex; flex-direction: column; gap: 8px; }
.dd-test-card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; box-shadow: var(--shadow-1); transition: border-color 0.15s; }
.dd-test-card:hover { border-color: var(--line-2); }
.dd-test-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.dd-link-btn { border: 0; background: none; padding: 0; text-align: left; font-size: var(--step-0); color: var(--ink); cursor: pointer; text-decoration: underline; text-decoration-color: transparent; transition: text-decoration-color 0.15s; }
.dd-link-btn:hover { text-decoration-color: currentColor; }
.dd-meta { font-size: var(--step--2); color: var(--ink-3); margin-top: 2px; }
.dd-test-hyp { font-size: var(--step--1); color: var(--ink-2); margin: 6px 0 0; line-height: 1.45; }
.dd-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.dd-chips .chip { padding: 2px 8px; font-size: 0.72rem; font-weight: 500; background: var(--hover); color: var(--ink-2); box-shadow: none; border-radius: 999px; }
.dd-card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; box-shadow: var(--shadow-1); }
.dd-card.highlighted { border-left: 3px solid var(--ink); }
.dd-card-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; gap: 8px; }
.dd-p { margin: 0; font-size: var(--step--1); color: var(--ink-2); line-height: 1.5; }
.dd-grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.dd-trace-steps { display: flex; align-items: center; gap: 6px; overflow-x: auto; padding: 6px 0; }
.dd-step { display: flex; flex-direction: column; background: var(--hover); padding: 8px 10px; border-radius: 6px; font-size: var(--step--2); min-width: 110px; flex: 1; }
.dd-step-k { color: var(--ink-3); font-weight: 600; text-transform: uppercase; font-size: 10px; letter-spacing: 0.04em; }
.dd-step-sep { color: var(--ink-3); font-weight: 700; flex: none; }
.dd-foot { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; gap: 10px; flex-shrink: 0; }
.dd-learnings-list { display: flex; flex-direction: column; gap: 8px; }
.dd-learn-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; transition: border-color 0.15s, background-color 0.15s; }
.dd-learn-row:hover { border-color: var(--focus); background: var(--hover); }
.dd-companion-impact { margin-top: 8px; padding: 6px 10px; background: var(--hover); border-radius: 6px; font-size: var(--step--2); color: var(--ink-2); }

/* ---------- Learnings Filter Drawer ---------- */
.drawer.ldrawer {
  width: min(100%, clamp(360px, 44vw, 540px));
}
@media (max-width: 700px) {
  .drawer.ldrawer {
    top: auto; left: 0; right: 0; width: 100%; max-height: 88vh;
    border-radius: var(--radius-card) var(--radius-card) 0 0;
    padding-right: 0;
  }
}
.ldr-body {
  gap: 24px;
  padding: 20px var(--space-m);
}
.dr-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dr-sec-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.dr-clear-btn {
  border: 0;
  background: none;
  font-size: var(--step--2);
  color: var(--ink-3);
  cursor: pointer;
  text-decoration: underline;
  padding: 0 4px;
}
.dr-clear-btn:hover {
  color: var(--ink);
}
.tag-cnt {
  font-size: 0.75rem;
  opacity: 0.65;
  margin-left: 2px;
}
.active-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px 0 12px;
  cursor: pointer;
}
.active-pill .pill-x {
  font-size: 14px;
  opacity: 0.7;
  font-weight: 700;
  line-height: 1;
}
.active-pill:hover .pill-x {
  opacity: 1;
}

