/*
LAYOUT RULES (DO NOT BREAK):
- .row      = CSS GRID (page-level layout, filters, create panels)
- .flex-row = FLEX (inline editors / toolbars / tight control rows)
- In editors: controls must NOT stretch full-width unless explicitly desired.
*/

/* =========================================================
   TOKENS
========================================================= */
:root{
  --border:#e5e7eb;
  --text:#111827;
  --muted:rgba(17,24,39,.7);
  --bg:#ffffff;
  --chip:#f9fafb;
}

*{ box-sizing:border-box; }
html, body{ height:100%; }

body{
  margin:0;
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  color:var(--text);
  background:var(--bg);
  overflow-x:hidden; /* hard stop horizontal bleed */
}

a{ color:inherit; text-decoration:none; }

/* =========================================================
   APP SHELL
========================================================= */
.app{
  display:grid;
  grid-template-columns:240px minmax(0, 1fr);
  min-height:100vh;
  width:100%;
}

.sidebar-shell{
  border-right:1px solid var(--border);
  position:sticky;
  top:0;
  height:100vh;
  overflow:auto;
  background:#fff;
  min-width:0;
}

.main{
  padding:18px;
  min-width:0;
  overflow:hidden;
}

h1,h2{ margin:0 0 6px 0; }
.muted{ opacity:.7; }

/* =========================================================
   STANDARD LAYOUT PRIMITIVES (THE CONTRACT)
========================================================= */

/* GRID rows: page-level layouts, filter rows, create panels */
.row{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap:12px;
  margin-top:14px;
  min-width:0;
}

/* FLEX rows: toolbars, editors, tight controls */
.flex-row{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  align-items:center;
  min-width:0;
}

/* Utility helpers */
.w-auto{ width:auto !important; }
.flex-none{ flex:0 0 auto !important; }

/* =========================================================
   CARDS
========================================================= */
.card{
  border:1px solid var(--border);
  border-radius:12px;
  padding:12px;
  background:#fff;
  min-width:0;
}

.k{ font-size:12px; opacity:.7; }
.v{ font-size:20px; font-weight:700; margin-top:4px; }

.actions{
  margin-top:12px;
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
  min-width:0;
}

/* =========================================================
   INPUTS / BUTTONS (STANDARD CONTROL SYSTEM)
========================================================= */

/* Base controls */
button, select, input{
  padding:8px 10px;
  border-radius:10px;
  border:1px solid var(--border);
  background:#fff;
  color:var(--text);
}

button{ cursor:pointer; }

input{
  width:100%;
  min-width:0;
}

/* Buttons */
.btn{
  padding:8px 10px;
  border-radius:10px;
  border:1px solid var(--border);
  background:#fff;
  cursor:pointer;
}

.btn.primary{
  border:none;
  background:#111827;
  color:#fff;
}

/* Compact sizes (use these instead of inline styles) */
.btn-sm{
  height:34px;
  padding:6px 12px;
  font-size:13px;
  line-height:1;
}

.select-sm{
  height:34px;
  padding:6px 10px;
  font-size:13px;
  line-height:1.2;
  width:auto;
}

.input-sm{
  height:34px;
  padding:6px 10px;
  font-size:13px;
  line-height:1.2;
}

/* Pills */
.pill{
  display:inline-block;
  padding:2px 8px;
  border-radius:999px;
  background:var(--chip);
  border:1px solid var(--border);
  font-size:12px;
}

/* Default select used across app blocks */
.vxf-select{
  width:100%;
  padding:8px 10px;
  border-radius:10px;
  border:1px solid var(--border);
  background:#fff;
}

/* =========================================================
   TABLES
========================================================= */
table{
  width:100%;
  border-collapse:collapse;
  margin-top:10px;
  min-width:0;
}
th,td{
  text-align:left;
  padding:8px;
  border-bottom:1px solid #eee;
  font-size:14px;
  vertical-align:top;
}

/* =========================================================
   DEBUG / PRE BLOCKS
========================================================= */
pre{
  background:#0b1020;
  color:#d1d5db;
  padding:12px;
  border-radius:12px;
  margin-top:8px;

  max-width:100%;
  overflow:auto;
  white-space:pre-wrap;
  overflow-wrap:anywhere;
  word-break:break-word;
}

/* =========================================================
   SIDEBAR
========================================================= */
.vxf-sidebar{
  padding:16px;
  display:flex;
  flex-direction:column;
  gap:12px;
}
.vxf-logo{ font-weight:800; font-size:18px; }
.vxf-nav{ display:flex; flex-direction:column; gap:6px; }
.vxf-nav a{
  display:block;
  padding:10px 12px;
  border-radius:10px;
  border:1px solid transparent;
}
.vxf-nav a:hover{ background:var(--chip); border-color:var(--border); }
.vxf-nav a.active{ background:#111827; color:#fff; border-color:#111827; }

.vxf-block{
  border:1px solid var(--border);
  border-radius:12px;
  padding:10px 12px;
  background:var(--chip);
  display:flex;
  flex-direction:column;
  gap:8px;
}
.vxf-k{ font-size:12px; opacity:.7; }
.vxf-help{ font-size:12px; opacity:.65; }

.vxf-who{
  margin-top:auto;
  border:1px solid var(--border);
  border-radius:12px;
  padding:10px 12px;
  background:var(--chip);
  font-size:12px;
  opacity:.75;
  word-break:break-all;
}

/* =========================================================
   MOBILE
========================================================= */
@media (max-width: 900px){
  .app{ grid-template-columns:1fr; }
  .sidebar-shell{
    position:relative;
    height:auto;
    border-right:none;
    border-bottom:1px solid var(--border);
  }
  .main{ overflow:visible; }
}

/* =========================================================
   BRIDGE PAGES (/bridge/*)
========================================================= */
.vxf-page{
  min-height:100vh;
  display:grid;
  place-items:center;
  padding:18px;
}
.vxf-center{
  width:100%;
  display:grid;
  place-items:center;
}
.vxf-bridge{
  width:min(520px, 92vw);
  text-align:center;
  padding:18px;
}
.vxf-bridge-actions{
  justify-content:center;
}
.vxf-spinner{
  width:28px;
  height:28px;
  margin:14px auto 0;
  border:3px solid var(--border);
  border-top-color: var(--text);
  border-radius:999px;
  animation:vxf-spin 900ms linear infinite;
}
@keyframes vxf-spin{
  to{ transform:rotate(360deg); }
}
.vxf-status{
  margin-top:10px;
  font-size:13px;
  opacity:.85;
}
.vxf-status.err{ color:#b91c1c; }
.vxf-status.ok{ color:#065f46; }

/* =========================================================
   ADMIN MODAL (KISS)
========================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.25);
  z-index: 999;
}

.modal {
  position: fixed;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
  width: min(720px, calc(100% - 24px));
  background: #fff;
  border: 1px solid #e6e6e6;
  border-radius: 14px;
  padding: 14px;
  z-index: 1000;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}

/* =========================================================
   ADMIN QUIZZES
   RULE: editor rows are FLEX, never .row
========================================================= */
.quiz-admin .qform{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  align-items:center;
}

/* In editors, selects should not be full-width */
.quiz-admin .qform .vxf-select{
  width:auto;
}

/* =========================================================
   ANALYTICS CARDS GRID (3 columns desktop)
   Reuses your grid contract but pins columns to 3.
========================================================= */
.cards-grid{
  display:grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap:12px;           /* matches .row */
  margin-top:14px;    /* matches .row behavior */
  min-width:0;
}

/* Tablet */
@media (max-width: 1024px){
  .cards-grid{
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }
}

/* Mobile */
@media (max-width: 640px){
  .cards-grid{
    grid-template-columns: 1fr;
  }
}

