/* =====================================================================
   CQuestHub — Design system
   Premium SaaS aesthetic (Stripe / Linear / Vercel lineage).
   Light + dark themes via [data-theme]. All colour from tokens.
   ===================================================================== */

:root {
  /* Brand */
  --navy:        #001F54;
  --navy-600:    #0a2e6e;
  --cyan:        #00CFE8;
  --cyan-600:    #00b4cc;
  --white:       #FFFFFF;
  --gray-bg:     #F5F7FA;
  --text:        #333333;

  /* Semantic (light) */
  --bg:          var(--gray-bg);
  --surface:     var(--white);
  --surface-2:   #fbfcfe;
  --border:      #e4e9f2;
  --text-1:      #1c2434;
  --text-2:      #5b6678;
  --text-3:      #8a94a6;
  --primary:     var(--navy);
  --accent:      var(--cyan);
  --ring:        rgba(0, 207, 232, .35);
  --success:     #18a957;
  --danger:      #e23d3d;
  --warning:     #e0a106;

  /* Effects */
  --radius:      14px;
  --radius-sm:   10px;
  --shadow-sm:   0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow:      0 4px 16px rgba(16, 24, 40, .08);
  --shadow-lg:   0 12px 40px rgba(0, 31, 84, .14);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg:        #0a0f1c;
  --surface:   #111827;
  --surface-2: #0e1524;
  --border:    #1f2a3d;
  --text-1:    #eef2f8;
  --text-2:    #9aa6bd;
  --text-3:    #6b7689;
  --primary:   #14306e;
  --accent:    #22d8ef;
  --ring:      rgba(34, 216, 239, .28);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow:    0 6px 22px rgba(0,0,0,.45);
  --shadow-lg: 0 16px 50px rgba(0,0,0,.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-1);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

h1,h2,h3 { letter-spacing: -.02em; line-height: 1.15; }

/* ---- Buttons -------------------------------------------------------- */
.btn {
  --b: var(--primary);
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  font: inherit; font-weight: 600; font-size: .94rem;
  padding: .72rem 1.15rem; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer;
  transition: transform .12s ease, box-shadow .18s ease, background .18s ease, opacity .18s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--navy-600); box-shadow: var(--shadow); }
.btn-accent { background: var(--accent); color: var(--navy); }
.btn-accent:hover { background: var(--cyan-600); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-1); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---- Forms ---------------------------------------------------------- */
.field { margin-bottom: 1.05rem; }
.field label { display: block; font-size: .82rem; font-weight: 600; color: var(--text-2); margin-bottom: .4rem; }
.input {
  width: 100%; font: inherit; font-size: .96rem; color: var(--text-1);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .76rem .9rem;
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--text-3); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--ring); }
.field-error { color: var(--danger); font-size: .8rem; margin-top: .35rem; }

/* ---- Cards ---------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 1.4rem; }

/* ---- Auth split layout (the signature screen) ----------------------- */
.auth {
  min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr;
}
.auth__brand {
  position: relative; overflow: hidden; color: #fff;
  background:
    radial-gradient(120% 90% at 80% 10%, rgba(0,207,232,.30), transparent 55%),
    linear-gradient(160deg, var(--navy) 0%, #001233 100%);
  padding: 3.5rem; display: flex; flex-direction: column; justify-content: space-between;
}
.auth__logo { display: flex; align-items: center; gap: .65rem; font-weight: 800; font-size: 1.25rem; letter-spacing: -.02em; }
.auth__logo .dot { width: 12px; height: 12px; border-radius: 4px; background: var(--cyan); box-shadow: 0 0 18px var(--cyan); }
.auth__headline { max-width: 30ch; font-size: clamp(1.8rem, 3.4vw, 2.8rem); font-weight: 800; line-height: 1.08; }
.auth__sub { color: rgba(255,255,255,.72); max-width: 38ch; margin-top: 1rem; }
.auth__meta { font-size: .82rem; color: rgba(255,255,255,.5); }

/* Animated question-grid motif — the page's memorable element.
   Cells light up in sequence like answered questions in a palette. */
.qgrid { position: absolute; inset: auto -40px -60px auto; display: grid;
  grid-template-columns: repeat(6, 46px); gap: 12px; opacity: .9; transform: rotate(8deg); }
.qgrid span {
  width: 46px; height: 46px; border-radius: 10px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08);
  animation: qpulse 4.2s ease-in-out infinite;
}
.qgrid span:nth-child(3n)   { animation-delay: .4s; }
.qgrid span:nth-child(4n)   { animation-delay: .9s; }
.qgrid span:nth-child(5n)   { animation-delay: 1.5s; }
.qgrid span:nth-child(7n)   { animation-delay: 2.1s; }
@keyframes qpulse {
  0%, 100% { background: rgba(255,255,255,.05); }
  45%      { background: rgba(0,207,232,.55); box-shadow: 0 0 22px rgba(0,207,232,.5); }
}

.auth__panel { display: flex; align-items: center; justify-content: center; padding: 2.5rem; background: var(--bg); }
.auth__form { width: 100%; max-width: 380px; }
.auth__form h2 { font-size: 1.5rem; margin-bottom: .35rem; }
.auth__form p.lead { color: var(--text-2); margin-bottom: 1.8rem; font-size: .95rem; }

/* Glass card variant for the form on the panel side */
.glass {
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(10px) saturate(140%);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 2rem;
}

.alert { border-radius: var(--radius-sm); padding: .8rem 1rem; font-size: .9rem; margin-bottom: 1.1rem; }
.alert-danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }
.alert-info { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--text-1); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); }

/* ---- Toasts --------------------------------------------------------- */
#toasts { position: fixed; top: 1.1rem; right: 1.1rem; display: flex; flex-direction: column; gap: .6rem; z-index: 9999; }
.toast {
  min-width: 240px; max-width: 360px; background: var(--surface); color: var(--text-1);
  border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  padding: .8rem 1rem; font-size: .9rem;
  animation: toastIn .25s ease; 
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ---- Theme toggle --------------------------------------------------- */
.theme-toggle {
  position: fixed; bottom: 1.1rem; right: 1.1rem; z-index: 50;
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-1); cursor: pointer; box-shadow: var(--shadow);
  font-size: 1.05rem; display: grid; place-items: center;
}

/* ---- App shell (dashboards) ----------------------------------------- */
.shell { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 1.3rem 1rem; display: flex; flex-direction: column; gap: .25rem; }
.sidebar .brand { display: flex; align-items: center; gap: .55rem; font-weight: 800; padding: .4rem .6rem 1.2rem; }
.sidebar .brand .dot { width: 11px; height: 11px; border-radius: 3px; background: var(--accent); }
.nav-link { display: flex; align-items: center; gap: .65rem; padding: .62rem .7rem; border-radius: var(--radius-sm); color: var(--text-2); font-weight: 500; font-size: .92rem; }
.nav-link:hover { background: var(--surface-2); color: var(--text-1); text-decoration: none; }
.nav-link.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--text-1); }
.main { padding: 1.6rem 2rem; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.topbar h1 { font-size: 1.35rem; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.stat { padding: 1.2rem 1.3rem; }
.stat .label { color: var(--text-3); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.9rem; font-weight: 800; margin-top: .35rem; }

/* ---- Responsive ----------------------------------------------------- */
@media (max-width: 880px) {
  .auth { grid-template-columns: 1fr; }
  .auth__brand { display: none; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 252px; transform: translateX(-100%); transition: transform .2s; z-index: 60; }
  .sidebar.open { transform: none; }
  .main { padding: 1.1rem; }
}

/* ---- Accessibility -------------------------------------------------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* =====================================================================
   Phase 2 — admin tables, badges, pagination, modal, switches, forms
   ===================================================================== */

/* Toolbar above tables */
.toolbar { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.toolbar .grow { flex: 1; }
.search { position: relative; max-width: 320px; flex: 1; }
.search .input { padding-left: 2.2rem; }
.search::before { content: "⌕"; position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--text-3); font-size: 1.1rem; }
.select { font: inherit; font-size: .9rem; color: var(--text-1); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .6rem .8rem; }

/* Data table */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 700; padding: .85rem 1rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { padding: .85rem 1rem; border-bottom: 1px solid var(--border); color: var(--text-1); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background .12s; }
table.data tbody tr:hover { background: var(--surface-2); }
.cell-title { font-weight: 600; }
.cell-sub { color: var(--text-3); font-size: .82rem; }

.badge { display: inline-flex; align-items: center; gap: .35rem; font-size: .76rem; font-weight: 700; padding: .22rem .6rem; border-radius: 999px; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--c); }

/* Row actions */
.row-actions { display: flex; gap: .4rem; justify-content: flex-end; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text-2); border-radius: 8px; padding: .4rem .6rem; font-size: .82rem; cursor: pointer; font-weight: 600; }
.icon-btn:hover { background: var(--surface-2); color: var(--text-1); }
.icon-btn.danger:hover { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }

.empty { text-align: center; padding: 3rem 1rem; color: var(--text-3); }

/* Pagination */
.pagination { display: flex; gap: .35rem; justify-content: center; margin-top: 1.2rem; }
.page-link { display: inline-grid; place-items: center; min-width: 36px; height: 36px; padding: 0 .6rem; border: 1px solid var(--border); border-radius: 8px; color: var(--text-2); font-size: .88rem; font-weight: 600; }
.page-link:hover { background: var(--surface-2); text-decoration: none; }
.page-link.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-link.disabled { opacity: .45; pointer-events: none; }
.page-gap { display: inline-grid; place-items: center; min-width: 24px; color: var(--text-3); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(8,15,30,.55); backdrop-filter: blur(3px); display: none; align-items: center; justify-content: center; z-index: 1000; padding: 1rem; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 440px; padding: 1.6rem; animation: toastIn .2s ease; }
.modal h3 { margin-bottom: .5rem; }
.modal p { color: var(--text-2); font-size: .92rem; margin-bottom: 1.3rem; }
.modal-actions { display: flex; gap: .6rem; justify-content: flex-end; }

/* Form grid + switches */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.3rem; }
.form-grid .full { grid-column: 1 / -1; }
textarea.input { resize: vertical; min-height: 90px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.switch-row:last-child { border-bottom: none; }
.switch-row .label { font-size: .9rem; font-weight: 600; }
.switch-row .hint { font-size: .78rem; color: var(--text-3); }
.switch { position: relative; width: 44px; height: 25px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 19px; height: 19px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: var(--shadow-sm); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(19px); }

.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); font-weight: 700; margin: 1.4rem 0 .8rem; }

@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } }
