/* app/static/css/app.css */
:root {
  --bg:#f6f7fb;
  --card:#fff;
  --muted:#666;
  --line:#e6e8ef;

  --sidebar:#0b1020;
  --sidebar2:#0e1630;
  --sidebarText:#e8ecff;
  --sidebarMuted: rgba(232,236,255,0.7);

  --focus:#eef2ff;
  --focusLine:#dde3ff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  margin: 0;
  padding: 0;
  background: var(--bg);
  overflow-x: hidden;
}

h1 { margin: 0 0 12px 0; font-size: 20px; }
h2 { margin: 0 0 10px 0; font-size: 16px; }
h3 { margin: 0 0 10px 0; font-size: 14px; }

label { color: var(--muted); font-size: 12px; }
button {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  max-width: 100%;
}
button:hover { background: #fafafa; }

input, select, textarea {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  max-width: 100%;
  min-width: 0;
}
input[type="number"] { width: 90px; }
input[type="date"] { width: 160px; }
textarea { width: 100%; resize: none; }

.hint { color: var(--muted); font-size: 12px; }
.pill {
  display:inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--focus);
  border: 1px solid var(--focusLine);
  font-size: 12px;
  max-width: 100%;
}
.danger { background:#fff1f2; border-color:#ffd1d6; }

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid var(--line);
  border-top-color: #4f67ff;
  opacity: 0;
}
.spinner.spin {
  opacity: 1;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

pre {
  margin: 0;
  padding: 10px;
  background: #0b1020;
  color: #e8ecff;
  border-radius: 12px;
  overflow: auto;
  max-height: 35vh;
}

/* ---------- App Shell ---------- */
.appShell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar2));
  color: var(--sidebarText);
  padding: 16px;
  border-right: 1px solid rgba(255,255,255,0.08);
}

.brand { margin-bottom: 14px; }
.brandTitle { font-weight: 700; letter-spacing: 0.2px; }
.brandSub { font-size: 12px; color: var(--sidebarMuted); margin-top: 4px; }

.sideNav { display:flex; flex-direction: column; gap: 8px; margin: 12px 0 18px 0; }
.navItem {
  display:flex;
  align-items:center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 12px;
  text-decoration:none;
  color: var(--sidebarText);
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
}
.navItem:hover { background: rgba(255,255,255,0.06); }
.navItem.active { background: rgba(238,242,255,0.16); border-color: rgba(238,242,255,0.25); }
.navDot { width: 10px; height: 10px; border-radius: 999px; background: rgba(232,236,255,0.55); }
.navItem.active .navDot { background: rgba(232,236,255,0.95); }

.sideSection {
  border-top: 1px solid rgba(255,255,255,0.10);
  padding-top: 14px;
  margin-top: 14px;
}
.sideSectionTitle {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebarMuted);
  margin-bottom: 10px;
}

.sidebar .hint { color: rgba(232,236,255,0.72); }
.sidebar select, .sidebar button {
  border-color: rgba(255,255,255,0.14);
}
.sidebar select { background: rgba(255,255,255,0.06); color: var(--sidebarText); }
.sidebar option { color: #111; }

.main {
  padding: 18px;
  min-width: 0;
}

.pageHeader {
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.pageTitle {
  font-size: 18px;
  font-weight: 650;
  color: #111;
}

/* ---------- Core layout helpers ---------- */
.grid { display: grid; grid-template-columns: minmax(360px, 520px) minmax(0, 1fr); gap: 14px; width: 100%; max-width: 100%; }
.explorationGrid { grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr); }
@media (max-width: 1050px) {
  .appShell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 5; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .explorationGrid { grid-template-columns: minmax(0, 1fr); }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.02);
  min-width: 0;
}
.row { display:flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; min-width: 0; }
.row > * { min-width: 0; }
.stack { display:flex; flex-direction: column; gap: 10px; }

.adminOverviewRow { cursor: pointer; }
.adminOverviewRow.selected {
  background: #eef2ff;
}
.adminOverviewRow:hover {
  background: #f6f7ff;
}

/* ---------- Collect page ---------- */
.collectClientList {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.collectClientButton {
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  border: 1px solid var(--line);
  background: #fff;
}
.collectClientButton.active {
  background: #eef2ff;
  border-color: #c9d3ff;
}

.collectMatchCard {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}
.collectMatchHeader {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}
.collectMatchMeta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 12px;
}
.collectMatchTable {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 12px;
}
.collectMatchTable th,
.collectMatchTable td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid #eee;
  vertical-align: top;
}
.collectMatchTable th {
  background: #fafbff;
  position: sticky;
  top: 0;
}
.collectMatchTable tr.matchedRow {
  background: #f1f5ff;
}

/* ---------- Step accordion ---------- */
.step {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  overflow: hidden;
}
.step + .step { margin-top: 12px; }

.step > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 10px;
  background: #fafbff;
  border-bottom: 1px solid var(--line);
}
.step > summary::-webkit-details-marker { display:none; }

.stepTitle {
  display:flex;
  flex-direction: column;
  gap: 2px;
}
.stepTitle .kicker {
  font-size: 12px;
  color: var(--muted);
}
.stepTitle .name {
  font-weight: 650;
  font-size: 14px;
  color: #111;
}

.stepMeta {
  display:flex;
  align-items:center;
  gap: 8px;
  white-space: nowrap;
}
.stepBody { padding: 12px 14px; }

/* ---------- Data Inspector ---------- */
.inspectorHeader {
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 12px;
}
.tabs { display:flex; gap: 8px; flex-wrap: wrap; }
.tabBtn {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 12px;
  cursor: pointer;
}
.tabBtn.active {
  background: var(--focus);
  border-color: var(--focusLine);
}

.tableScroller {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  max-height: 65vh;
  border: 1px solid #eee;
  border-radius: 12px;
  background: #fff;
}
@media (prefers-color-scheme: dark) {
  .tableScroller {
    border-color: var(--line);
    background: #121523;
  }
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
th {
  position: sticky;
  top: 0;
  background: #f5f5f5;
  z-index: 2;
  white-space: nowrap;
}
td { white-space: nowrap; }

.exploreCols {
  width: 100%;
  min-height: 180px;
}

/* Collect page helpers (moved from inline styling) */
.adminCard {
  border: 1px solid #eee;
  border-radius: 14px;
  background: #fff;
  margin: 12px 0;
  overflow: hidden;
}
.adminHeader {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
  background: #fafafa;
  border-bottom: 1px solid #eee;
}
.adminHeader .title { font-weight: 650; }
.adminHeader .meta { font-size: 12px; opacity: 0.75; white-space: nowrap; }

.adminBody {
  position: relative;
  padding: 14px;
  max-height: 220px;
  overflow: hidden;
}
.adminBody.expanded { max-height: none; }

.emailBox {
  border: 1px solid #f0f0f0;
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}

.clientCard {
  border: 1px solid #eee;
  border-radius: 14px;
  background: #fff;
  margin: 12px 0;
  overflow: hidden;
}
.clientHeader {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
  background: #fafafa;
  border-bottom: 1px solid #eee;
}
.clientHeader .title { font-weight: 650; }
.clientPills { display:flex; gap: 6px; flex-wrap: wrap; }
.pill.ok { background:#e9f7ef; border-color:#bfead1; }
.pill.off { background:#f4f5f8; border-color:#e2e4ea; }

.clientBody {
  position: relative;
  padding: 14px;
  max-height: 220px;
  overflow: hidden;
}
.clientBody.expanded { max-height: none; }

.clientsTableScroller {
  max-height: 70vh;
}
.clientsTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.clientsTable th,
.clientsTable td {
  padding: 10px 12px;
  border-bottom: 1px solid #eee;
  vertical-align: top;
}
.clientsRow {
  cursor: pointer;
  background: #fff;
}
.clientsRow:hover {
  background: #fafbff;
}
.clientsRow.expanded {
  background: #f3f6ff;
}
.clientNameCell {
  min-width: 240px;
}
.clientToggle {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font-weight: 650;
  cursor: pointer;
}
.clientDetailsRow td {
  padding: 0;
  background: #fbfcff;
}
.clientDetails {
  padding: 14px;
}

.tableScroller table {
  background: #fff;
}

@media (prefers-color-scheme: dark) {
  .tableScroller table {
    background: #121523;
  }
  .tableScroller th {
    background: #1b2234!important;
    border-bottom-color: var(--line);
    color: #eff2ff;
  }
  .tableScroller td {
    border-bottom-color: var(--line);
    color: #e7e9f0;
  }
  .adminOverviewRow {
    border-bottom: 1px solid var(--line);
  }
  .adminOverviewRow.selected {
    background: #1f2435;
  }
  .adminOverviewRow:hover {
    background: #1c2132;
  }
  .tableScroller td button {
    border-color: #2c3350;
    background: #151a2b;
    color: #e7e9f0;
  }
}

.modalBackdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 50;
}

.modal {
  position: fixed;
  top: 8vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 24px));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 60px rgba(0,0,0,0.18);
  padding: 14px;
  z-index: 51;
}

.modalHeader {
  display:flex;
  align-items:flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.modalTitle {
  font-weight: 700;
  font-size: 16px;
  color: #111;
}

.modalClose {
  border-radius: 12px;
  padding: 6px 10px;
}

/* ---------- Sidebar-specific pill styling ---------- */
.sidebar .pill {
  background: rgba(232,236,255,0.18);   /* subtle light tint on dark bg */
  border-color: rgba(232,236,255,0.35);
  color: #ffffff;                      /* force readable text */
  font-weight: 600;
}

.sidebar .pill.danger {
  background: rgba(255, 99, 99, 0.25);
  border-color: rgba(255, 120, 120, 0.45);
  color: #ffffff;
}

/* ---------- Dark mode ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:#0f1116;
    --card:#151922;
    --muted:#9aa3b2;
    --line:#2a3140;
    --focus:#1a2234;
    --focusLine:#293552;
  }

  body { color: #e7e9f0; }
  button,
  input,
  select,
  textarea {
    background: #121723;
    color: #e7e9f0;
    border-color: var(--line);
  }
  button:hover { background: #151c2b; }

  .card,
  .collectMatchCard,
  .step,
  .adminCard,
  .clientCard,
  .modal,
  .emailBox,
  .tableScroller {
    background: var(--card);
    border-color: var(--line);
  }

  .pageTitle,
  .stepTitle .name,
  .modalTitle { color: #e7e9f0; }

  .collectMatchTable th,
  th,
  .step > summary,
  .adminHeader,
  .clientHeader {
    background: #171c28;
    border-bottom-color: var(--line);
  }

  .collectMatchTable tr.matchedRow {
    background: #1b2436;
  }

  .emailBox,
  .emailBox * {
    color: #e7e9f0;
  }
  .emailBox {
    background: #121523;
    border-color: #2f3649;
  }
  .emailBox table {
    border-color: #2a3040;
  }

  .collectClientButton {
    color: #e7e9f0;
  }

  .clientsTable th,
  .clientsTable td {
    color: #e7e9f0;
  }
  .clientsRow,
  .clientsRow.expanded {
    background: #151b28;
    color: #e7e9f0;
  }

  .clientHeader,
  .adminHeader,
  .clientCard,
  .adminCard,
  .clientDetails {
    background: #121725;
    color: #f5f5ff;
    border-color: #2a3140;
  }
  .clientHeader .title,
  .clientHeader .meta,
  .adminHeader .title,
  .adminHeader .meta {
    color: #f5f5ff;
  }
  .clientPills .pill {
    background: #1d2436;
    border-color: #2d3645;
  }

  .collectMatchTable td,
  .clientsTable td,
  .clientsTable th {
    border-bottom-color: var(--line);
  }

  .collectClientButton {
    background: #121723;
    border-color: var(--line);
    color: #e7e9f0;
  }

  .collectClientButton.active {
    background: #1c2436;
    border-color: #334060;
  }

  .pill.ok { background:#123224; border-color:#1f5b3e; }
  .pill.off { background:#1a1f2a; border-color:#2b3444; }

  pre { background: #0b0f18; color: #dbe3ff; }
}

.apiTextarea {
  width: 100%;
  min-height: 140px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
}

.apiHistory {
  margin-top: 8px;
}

.apiHistoryList {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.apiHistoryRow {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid #e6e7eb;
  border-radius: 8px;
  background: #fafbff;
  font-size: 12px;
}

.apiHistoryMain {
  font-weight: 600;
}

.apiHistoryMeta {
  color: #6b7280;
  white-space: nowrap;
}

.apiConsoleMeta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
}

.previewBox {
  border: 1px solid #e6e7eb;
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 160px;
  background: #fff;
  font-size: 12px;
  overflow: auto;
}
