/* ════════════════════════════════════════════════════════════════
   AI ResearchPartner — Components
   Buttons, cards, KPIs, badges, tables, priority items, waterfalls.
   Mirrors patterns from templates/dashboard_base.html.
   ════════════════════════════════════════════════════════════════ */

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 22px;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  /* Long CTA labels may wrap on phones (see the max-width:520px override
     below) — nowrap min-content would otherwise force grid columns wider
     than the viewport. */
  cursor: pointer;
  transition: all var(--t-fast) var(--ease);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}

/* Phones: let long CTA labels wrap instead of forcing horizontal overflow
   (a nowrap button's min-content can exceed the viewport and widen the
   whole grid column it sits in). line-height loosens so wrapped labels
   stay readable. */
@media (max-width: 520px) {
  .btn {
    white-space: normal;
    line-height: 1.3;
    text-align: center;
  }
}

.btn-primary {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.18) inset, 0 6px 18px rgba(201, 100, 66, 0.28);
}
.btn-primary:hover {
  background: var(--brand-deep);
  transform: translateY(-1px);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.18) inset, 0 10px 24px rgba(201, 100, 66, 0.34);
}
.btn-primary:active { transform: translateY(0); }

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--ring);
}
.btn-outline:hover {
  background: var(--surface);
  border-color: var(--text);
}

.btn-ghost {
  background: transparent;
  color: var(--text2);
  padding: 10px 14px;
}
.btn-ghost:hover { color: var(--text); }

.btn-dark {
  background: var(--bg-dark);
  color: var(--text-inv);
}
.btn-dark:hover { background: #2a2a28; }

.btn-sm { padding: 9px 16px; font-size: 13px; }
.btn-lg { padding: 16px 28px; font-size: 16px; }

.btn-arrow::after {
  content: '→';
  margin-left: 4px;
  transition: transform var(--t-fast) var(--ease);
}
.btn-arrow:hover::after { transform: translateX(3px); }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 28px;
  transition: box-shadow var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.card:hover {
  box-shadow: var(--shadow-whisper);
  transform: translateY(-2px);
}

.card-bordered-top {
  border-top: 3px solid var(--brand);
}
.card-bordered-top.coral { border-top-color: var(--coral); }
.card-bordered-top.amber { border-top-color: var(--amber); }
.card-bordered-top.sky { border-top-color: var(--sky); }
.card-bordered-top.green { border-top-color: var(--green); }
.card-bordered-top.rose { border-top-color: var(--rose); }

.card-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text2);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── KPI tiles ── */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 22px;
  position: relative;
  overflow: hidden;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.kpi:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-whisper);
}
.kpi::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--brand);
}
.kpi.coral::after { background: var(--coral); }
.kpi.amber::after { background: var(--amber); }
.kpi.green::after { background: var(--green); }
.kpi.sky::after { background: var(--sky); }
.kpi.rose::after { background: var(--rose); }

.kpi-num {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.05;
  color: var(--text);
}
.kpi-lbl {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text3);
  margin-top: 6px;
}
.kpi-sub {
  font-size: 12px;
  color: var(--brand-deep);
  margin-top: 6px;
  font-weight: 500;
}

/* ── Tags / chips ── */
.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.t-green { background: var(--green-dim); color: var(--green); }
.t-amber { background: var(--amber-dim); color: var(--amber); }
.t-sky { background: var(--sky-dim); color: var(--sky); }
.t-rose { background: var(--rose-dim); color: var(--rose); }
.t-accent { background: var(--accent-dim); color: var(--brand-deep); }
.t-charcoal { background: rgba(77, 76, 72, 0.08); color: var(--charcoal); }

/* ── Priority items (gold/silver/bronze) ── */
.pri-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.pri-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 22px 26px;
  display: flex;
  gap: 20px;
  align-items: flex-start;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.pri-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-whisper);
}

.pri-rank {
  width: 42px;
  height: 42px;
  border-radius: var(--r);
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 800;
  flex-shrink: 0;
  color: #fff;
  background: var(--text3);
}
.pri-rank.g { background: var(--brand); }
.pri-rank.s { background: var(--charcoal); }
.pri-rank.b { background: #a0856a; }

.pri-body { flex: 1; }
.pri-body h4 { font-size: 16px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.pri-body p { font-size: 13.5px; color: var(--text3); line-height: 1.6; }

.next-step {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: var(--r-sm);
  font-size: 12.5px;
  color: var(--brand-deep);
  border-left: 3px solid var(--brand);
  line-height: 1.55;
  font-weight: 500;
}

/* ── Waterfall bars ── */
.wf {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.wf-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.wf-lbl {
  font-size: 12.5px;
  color: var(--text2);
  width: 200px;
  text-align: right;
  flex-shrink: 0;
  font-weight: 500;
}
.wf-track {
  flex: 1;
  height: 30px;
  background: var(--sand);
  border-radius: var(--r-sm);
  position: relative;
  overflow: hidden;
}
.wf-bar {
  position: absolute;
  height: 100%;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  padding-left: 12px;
  font-size: 11.5px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(90deg, var(--brand), var(--coral));
  transition: width 0.8s var(--ease);
}
.wf-bar.amber { background: linear-gradient(90deg, var(--amber), var(--coral)); }
.wf-bar.green { background: linear-gradient(90deg, var(--green), #5fb47b); }
.wf-bar.sky { background: linear-gradient(90deg, var(--sky), #6ea6ff); }
.wf-bar.rose { background: linear-gradient(90deg, var(--rose), var(--coral)); }
.wf-dur {
  font-size: 11.5px;
  color: var(--text3);
  width: 90px;
  flex-shrink: 0;
  text-align: right;
  font-weight: 500;
}

/* On narrow screens the 200px right-aligned label starved the track down to a
   0px width. Stack the label above a full-width track instead. */
@media (max-width: 640px) {
  .wf-row { flex-wrap: wrap; }
  .wf-lbl { width: 100%; text-align: left; }
  .wf-track { flex: 1 1 100%; min-width: 0; }
}

/* ── Tables ── */
.tbl-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 24px;
  overflow-x: auto;
}
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.tbl th {
  text-align: left;
  padding: 12px 16px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text3);
  background: var(--bg);
  border-bottom: 1px solid var(--border2);
}
.tbl td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  line-height: 1.55;
  color: var(--text2);
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: rgba(201, 100, 66, 0.03); }
.tbl strong { color: var(--text); font-weight: 600; }
.tbl td.brand { color: var(--brand-deep); font-weight: 600; }
.tbl td.dim { color: var(--text3); font-size: 12.5px; }

/* ── IP grid (compact assignee/source cards) ── */
.ip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
  gap: 14px;
}
.ip-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px;
  text-align: center;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.ip-cell:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-whisper);
}
.ip-cell .name { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.ip-cell .focus { font-size: 11.5px; color: var(--text3); margin-bottom: 12px; line-height: 1.5; }
.ip-cell .big { font-size: 22px; font-weight: 800; letter-spacing: -0.03em; color: var(--brand-deep); }
.ip-cell .small { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text3); margin-top: 3px; }

/* ── Source / integration logo tiles ── */
.logo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.logo-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.logo-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-whisper);
}
.logo-tile .lt-mark {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: var(--bg);
  display: grid;
  place-items: center;
  color: var(--brand-deep);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: -0.02em;
}
.logo-tile .lt-name { font-size: 14px; font-weight: 600; color: var(--text); }
.logo-tile .lt-desc { font-size: 12.5px; color: var(--text3); line-height: 1.55; }

/* ── Section title ── */
.sec-title {
  font-family: 'Source Serif 4', Georgia, serif;
  font-style: italic;
  font-weight: 500;
  font-size: clamp(28px, 3.4vw, 40px);
  letter-spacing: -0.025em;
  line-height: 1.15;
  color: var(--text);
  margin-bottom: 14px;
  max-width: 760px;
}

.sec-sub {
  font-size: 17px;
  color: var(--text2);
  max-width: 680px;
  line-height: 1.6;
  margin-bottom: 40px;
}

/* ── Pill / badge ── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-dim);
  color: var(--brand-deep);
  border: 1px solid rgba(201, 100, 66, 0.18);
}
.pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--brand);
  animation: pulse 2s infinite;
}

/* ── Form elements ── */
.input, .textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 14.5px;
  color: var(--text);
  transition: border var(--t-fast) var(--ease);
  outline: none;
}
.input:focus, .textarea:focus { border-color: var(--brand); }
.textarea { resize: vertical; min-height: 110px; line-height: 1.55; }

.label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 6px;
}

/* ── Inline brand link ── */
/* Replaces the scattered inline-styled anchors in body copy with a single
   branded, underlined-on-hover treatment. */
.link-brand {
  color: var(--brand-deep);
  border-bottom: 1px solid rgba(201, 100, 66, 0.35);
  transition: border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.link-brand:hover { border-bottom-color: var(--brand); }

/* ── Image lightbox (post figures) ──
   Progressive enhancement: the figure links to the raw asset; lightbox.js
   intercepts the click and opens this overlay instead. */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 4vw, 48px);
  background: rgba(20, 20, 19, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity var(--t-mid) var(--ease);
}
.lightbox.open { opacity: 1; }
/* The author display:flex above would override the hidden attribute's
   UA-level display:none — restore it, and make the overlay pointer-inert
   whenever it is not open (including the fade-out window) so a closed
   lightbox can never block clicks on the page beneath. */
.lightbox[hidden] { display: none; }
.lightbox:not(.open) { pointer-events: none; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 12px;
  box-shadow: var(--shadow-deep);
  cursor: zoom-out;
}
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(250, 249, 245, 0.3);
  background: rgba(250, 249, 245, 0.12);
  color: var(--text-inv);
  font-size: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast) var(--ease);
}
.lightbox-close:hover { background: rgba(250, 249, 245, 0.24); }
body.lightbox-open { overflow: hidden; }
