/* ===== RBN Portal — Apple-style design system (light, #007AFF) ===== */
:root {
  /* Palette */
  --bg: #f5f5f7;
  --bg-tint: #ffffff;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --ink-2: #424245;
  --muted: #6e6e73;
  --accent: #007aff;
  --accent-press: #0066d6;
  --accent-soft: rgba(0, 122, 255, 0.10);
  --accent-ink: #ffffff;
  --line: #d2d2d7;
  --hairline: rgba(0, 0, 0, 0.08);
  --fill: #f0f0f3;
  --ok: #1a8f43;
  --ok-soft: #e3f7ea;
  --err: #d70015;
  --err-soft: #ffe5e3;
  --warn: #9a6400;
  --warn-soft: #fff2d6;
  /* Shape & depth */
  --r-sm: 9px;
  --r: 14px;
  --r-lg: 20px;
  --r-pill: 980px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
  --shadow-pop: 0 14px 40px rgba(0, 0, 0, 0.16);
  --ring: 0 0 0 4px rgba(0, 122, 255, 0.18);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  background-image: linear-gradient(180deg, #ffffff 0%, var(--bg) 240px);
  background-repeat: no-repeat;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 15px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Headings ---------- */
h1 { margin: 0 0 18px; font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; margin: 0 0 14px; }
h3 { font-size: 16px; font-weight: 600; margin: 0 0 10px; }
.muted { color: var(--muted); }

/* ---------- Top navigation (frosted, sticky) ---------- */
.nav {
  position: sticky; top: 0; z-index: 100;
  background: rgba(255, 255, 255, 0.72);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--hairline);
}
.nav-inner {
  position: relative;
  max-width: 1280px; margin: 0 auto; padding: 10px 22px;
  display: flex; align-items: center; gap: 18px;
}
.brand {
  display: inline-flex; align-items: center; gap: 9px;
  font-weight: 700; font-size: 18px; letter-spacing: -0.02em;
  color: var(--ink) !important; text-decoration: none;
}
.brand .ico { color: var(--accent); width: 24px; height: 24px; }
.nav-links { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.nav-links a, .nav-links .who, .nav-links .link-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 13px; border-radius: var(--r-pill);
  font-size: 14px; font-weight: 500; color: var(--ink-2);
  text-decoration: none; white-space: nowrap;
}
.nav-links a:hover { background: rgba(0, 0, 0, 0.05); text-decoration: none; }
.nav-links a.active { color: var(--accent); background: var(--accent-soft); }
.nav-links .ico { width: 18px; height: 18px; }
.who { color: var(--muted); font-weight: 500; }
.link-btn { background: none; border: none; cursor: pointer; font: inherit; color: var(--ink-2); }
.link-btn:hover { background: rgba(0, 0, 0, 0.05); }
.inline { display: inline; }
.nav-toggle {
  display: none; margin-left: auto;
  background: none; border: none; color: var(--ink); cursor: pointer;
  padding: 8px; border-radius: 10px; box-shadow: none;
}
.nav-toggle:hover { background: rgba(0, 0, 0, 0.05); }
.ico { flex: none; vertical-align: -3px; }

/* ---------- Layout ---------- */
.container { max-width: 1080px; margin: 32px auto 64px; padding: 0 22px; }
.container.wide { max-width: 1320px; }

/* ---------- Cards ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: 28px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}
.card.narrow { max-width: 460px; margin: 56px auto; }
details.card.client-config { padding: 0; overflow: hidden; }
details.card.client-config > summary {
  list-style: none; cursor: pointer; padding: 18px 24px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
details.card.client-config > summary::-webkit-details-marker { display: none; }
details.card.client-config > summary::before {
  content: "›"; font-size: 20px; color: var(--muted);
  transition: transform 0.2s ease; line-height: 1;
}
details.card.client-config[open] > summary::before { transform: rotate(90deg); }
details.card.client-config > summary:hover { background: rgba(0, 0, 0, 0.02); }
details.card.client-config .cfg-grid { padding: 0 24px 22px; }

/* ---------- Forms ---------- */
label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 14px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 7px;
  padding: 11px 13px; font-size: 15px; font-weight: 400; font-family: inherit;
  color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--r);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder, textarea::placeholder { color: #aeaeb2; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
textarea { resize: vertical; }
select {
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%236e6e73' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px;
}
.row { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--accent); color: var(--accent-ink);
  border: none; border-radius: var(--r-pill);
  padding: 10px 20px; font-size: 15px; font-weight: 600; font-family: inherit;
  cursor: pointer; text-decoration: none; box-shadow: var(--shadow-sm);
  transition: background 0.15s ease, transform 0.08s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
button:hover, .btn:hover { background: var(--accent-press); text-decoration: none; transform: translateY(-1px); }
button:active, .btn:active { transform: translateY(0); }
button:focus-visible, .btn:focus-visible { outline: none; box-shadow: var(--ring); }
button:disabled, .btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }
button.secondary, .btn.secondary { background: rgba(0, 0, 0, 0.06); color: var(--ink); box-shadow: none; }
button.secondary:hover, .btn.secondary:hover { background: rgba(0, 0, 0, 0.10); }
.btn.block { width: 100%; }

/* ---------- Alerts ---------- */
.alert { padding: 13px 16px; border-radius: var(--r); margin-bottom: 18px; font-size: 14px; font-weight: 500; }
.alert-error { background: var(--err-soft); color: var(--err); }
.alert-success { background: var(--ok-soft); color: var(--ok); }

/* ---------- Filters toolbar ---------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--hairline);
  border-radius: var(--r-lg); padding: 14px; margin-bottom: 18px; box-shadow: var(--shadow-sm);
}
.filters input, .filters select { width: auto; margin-top: 0; min-width: 150px; }
.filters input[type="number"] { width: 120px; min-width: 0; }
.filters .check { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; margin: 0; }
.filters .check input { width: auto; margin-top: 0; }

/* ---------- Multi-select dropdown ---------- */
.multiselect { position: relative; }
.multiselect > summary {
  list-style: none; cursor: pointer; user-select: none;
  border: 1px solid var(--line); border-radius: var(--r);
  padding: 10px 13px; background: var(--panel); font-size: 14px; min-width: 150px;
  display: inline-flex; align-items: center; gap: 6px;
}
.multiselect > summary::-webkit-details-marker { display: none; }
.multiselect > summary::after { content: "⌄"; color: var(--muted); margin-left: auto; }
.multiselect[open] > summary { border-color: var(--accent); box-shadow: var(--ring); }
.ms-count { color: var(--accent); font-weight: 600; }
.ms-panel {
  position: absolute; z-index: 30; margin-top: 8px; width: 270px;
  background: var(--panel); border: 1px solid var(--hairline); border-radius: var(--r);
  box-shadow: var(--shadow-pop); padding: 10px;
}
.ms-filter { margin: 0 0 8px; }
.ms-list { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.ms-opt {
  display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 0;
  font-size: 14px; padding: 6px 8px; border-radius: 8px; cursor: pointer;
}
.ms-opt:hover { background: var(--fill); }
.ms-opt input { width: auto; margin: 0; }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; border-radius: var(--r-lg); }
table.grid {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--panel); border: 1px solid var(--hairline);
  border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-sm);
}
table.grid th, table.grid td {
  text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--hairline); font-size: 14px;
}
table.grid th {
  background: #fafafa; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
}
table.grid tbody tr { transition: background 0.12s ease; }
table.grid tbody tr:hover { background: rgba(0, 0, 0, 0.025); }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid input[type="number"], .qty { width: 72px; }

/* Reports table: self-contained scroll viewport with frozen header + 1st column */
.report-scroll {
  overflow: auto; max-height: 75vh;
  border: 1px solid var(--hairline); border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
}
/* Fit-to-screen: when body.fill, the page is exactly viewport-tall and only the
   table box scrolls — so its header/first column freeze and both scrollbars stay
   on screen. (Fixed height, not min-height, so many rows can't grow the page.) */
body.fill { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
body.fill main.container { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
body.fill .report-scroll { flex: 1 1 auto; min-height: 0; max-height: none; }
/* High specificity so these beat the base table.grid rules. */
table.grid.report-grid { border: 0; box-shadow: none; border-radius: 0; overflow: visible; }
.report-grid th { white-space: nowrap; }
.report-grid thead th { position: sticky; top: 0; z-index: 2; background: #fafafa; box-shadow: inset 0 -1px 0 var(--hairline); }
.report-grid th:first-child, .report-grid td:first-child {
  position: sticky; left: 0; z-index: 1; background: var(--panel);
}
.report-grid thead th:first-child { z-index: 3; background: #fafafa; }
.report-filters {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--hairline);
  border-radius: var(--r-lg); padding: 12px 14px; margin-bottom: 14px; box-shadow: var(--shadow-sm);
}
.report-filters input, .report-filters select { width: auto; margin-top: 0; min-width: 150px; }
.report-filters #report-count { margin-left: auto; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 8px; align-items: center; margin-top: 18px; }

/* ---------- Tags, badges, chips ---------- */
.tag {
  display: inline-block; font-size: 12px; font-weight: 500;
  background: var(--fill); color: var(--ink-2);
  border-radius: 7px; padding: 2px 8px; margin: 0 4px 2px 0;
}
.badge {
  display: inline-flex; align-items: center;
  background: var(--fill); color: var(--ink-2);
  border-radius: var(--r-pill); padding: 3px 12px; font-size: 12px; font-weight: 600;
  margin: 1px 2px 1px 0;
}
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--err { background: var(--err-soft); color: var(--err); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--fill); border-radius: var(--r-pill); padding: 5px 8px 5px 13px; font-size: 13px;
}
.chip-x { background: none; border: none; box-shadow: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 0 4px; }
.chip-x:hover { background: none; color: var(--err); transform: none; }
/* Clickable field-name suggestions (admin Reports config) */
.report-field-chips { margin-top: 10px; }
.report-field-chips .chip { color: var(--ink); cursor: pointer; box-shadow: none; font-weight: 500; }
.report-field-chips .chip:hover { background: var(--accent-soft); color: var(--accent); transform: none; }

/* ---------- Cart & orders ---------- */
.cart-summary { margin: 18px 0; font-size: 20px; font-weight: 700; text-align: right; letter-spacing: -0.01em; }
.cart-item { padding: 20px; }
.cart-item-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.cart-item-head .line-total { font-weight: 600; }
.cart-item-head .remove { margin-left: auto; }
.remove { background: var(--err-soft); color: var(--err); box-shadow: none; }
.remove:hover { background: #ffd2cf; }
.cart-item-fields { display: grid; grid-template-columns: 96px 1fr 1fr 1fr; gap: 14px; }
.cart-item-fields label { margin-bottom: 0; font-size: 13px; }
.cart-item-fields .wide-field { grid-column: 1 / -1; }
.order-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.order-total { margin-top: 12px; text-align: right; font-weight: 600; }

/* ---------- Cart: bulk paste + grid ---------- */
.bulk-paste strong { display: block; margin-bottom: 4px; }
.bulk-paste textarea { margin-top: 8px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.cart-grid td { vertical-align: middle; }
.cart-grid input, .cart-grid textarea { margin-top: 0; padding: 8px 10px; border-radius: var(--r-sm); }
.cart-grid input.f-qty { width: 64px; }
.cart-grid input.f-anchor { min-width: 150px; }
.cart-grid input.f-targetUrl, .cart-grid input.f-articleUrl { min-width: 180px; }
.cart-grid textarea.f-comments { min-width: 150px; resize: vertical; }
.cart-grid .remove { padding: 6px 12px; }

/* ---------- Linking-domains profiles ---------- */
.link-profiles-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin-bottom: 14px; }
.link-profile {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--bg); border: 1px solid var(--hairline); border-radius: var(--r); padding: 14px;
}
.link-profile .lp-name { font-weight: 600; margin-top: 0; background: var(--panel); }
.link-profile .lp-text { width: 100%; resize: vertical; margin-top: 0; background: var(--panel); }

/* ---------- Admin client-config form ---------- */
.cfg-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; align-items: start; }
.cfg-field { margin-bottom: 0; }
.cfg-wide { grid-column: 1 / -1; border: 1px solid var(--hairline); border-radius: var(--r); padding: 14px 16px; margin: 0; }
.cfg-wide legend { font-weight: 600; font-size: 14px; padding: 0 6px; }
.cfg-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form select { width: auto; margin-top: 0; }

/* ---------- Reports embed ---------- */
.report-embed { background: var(--panel); border: 1px solid var(--hairline); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow); }
.airtable-embed { width: 100%; height: 80vh; min-height: 600px; border: 0; background: var(--panel); }

/* ---------- Bulk checker results ---------- */
#check-results h3 { margin: 20px 0 10px; font-size: 15px; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .nav-toggle { display: inline-flex; }
  .nav-links {
    display: none; position: absolute; top: 100%; left: 0; right: 0; margin: 0;
    flex-direction: column; align-items: stretch; gap: 2px; padding: 12px 14px;
    background: rgba(255, 255, 255, 0.96);
    -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--hairline); box-shadow: var(--shadow);
  }
  .nav-links.open { display: flex; }
  .nav-links a, .nav-links .who, .nav-links .link-btn { width: 100%; justify-content: flex-start; }
  .nav-links .inline, .nav-links form { width: 100%; }
  .container { margin-top: 22px; }
  .card { padding: 20px; }
  h1 { font-size: 25px; }
  .cart-item-fields { grid-template-columns: 1fr; }
  .filters input, .filters select { min-width: 0; flex: 1 1 140px; }
}

/* ---------- Admin tabs + collapsible card ---------- */
.tabs { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--fill); padding: 4px; border-radius: var(--r-pill); margin-bottom: 22px; }
.tab { background: transparent; color: var(--ink-2); box-shadow: none; border-radius: var(--r-pill); padding: 8px 18px; font-weight: 600; }
.tab:hover { background: rgba(0, 0, 0, 0.05); transform: none; color: var(--ink); }
.tab.active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow-sm); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.collapse-card { padding: 0; }
.collapse-card > summary { list-style: none; cursor: pointer; padding: 18px 24px; display: flex; align-items: center; gap: 10px; }
.collapse-card > summary::-webkit-details-marker { display: none; }
.collapse-card > summary::before { content: "\\203A"; font-size: 22px; line-height: 1; color: var(--muted); transition: transform 0.2s ease; }
.collapse-card[open] > summary::before { transform: rotate(90deg); }
.collapse-card > summary h2 { margin: 0; font-size: 18px; }
.collapse-body { padding: 0 24px 22px; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
