:root{
  --bg:#f8fafc;
  --surface:#ffffff;
  --surface-2:#f1f5f9;
  --surface-3:#e2e8f0;
  --border:#dbe4ee;
  --text:#0f172a;
  --muted:#64748b;
  --primary:#1d4ed8;
  --primary-2:#2563eb;
  --primary-3:#dbeafe;
  --sidebar:#0f172a;
  --sidebar-2:#111827;
  --sidebar-text:#e5e7eb;
  --sidebar-muted:#94a3b8;
  --success:#15803d;
  --danger:#dc2626;
  --warning:#d97706;
  --shadow:0 18px 45px rgba(15,23,42,.08);
  --shadow-soft:0 8px 24px rgba(15,23,42,.06);
  --radius:18px;
  --radius-sm:12px;
  --topbar-h:76px;
  --sidebar-w:280px;
}

*{ box-sizing:border-box; }

html,
body{
  margin:0;
  padding:0;
  width:100%;
  height:100%;
  font-family:Arial, Helvetica, sans-serif;
  background:var(--bg);
  color:var(--text);
}

body{
  overflow:hidden;
}

a{
  color:inherit;
  text-decoration:none;
}

button,
input,
select,
textarea{
  font:inherit;
}

button{
  cursor:pointer;
  border:none;
  background:none;
}

input,
select,
textarea{
  width:100%;
  border:1px solid var(--border);
  background:#fff;
  color:var(--text);
  border-radius:14px;
  padding:12px 14px;
  outline:none;
  transition:border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

input:focus,
select:focus,
textarea:focus{
  border-color:var(--primary);
  box-shadow:0 0 0 4px rgba(37,99,235,.10);
}

textarea{
  resize:vertical;
}

pre{
  margin:0;
  white-space:pre-wrap;
  word-break:break-word;
}

.hidden{
  display:none !important;
}

/* Layout */
.app-shell{
  display:flex;
  width:100%;
  height:100vh;
  min-height:0;
  background:var(--bg);
  overflow:hidden;
}

.sidebar{
  width:var(--sidebar-w);
  min-width:var(--sidebar-w);
  height:100vh;
  background:linear-gradient(180deg,var(--sidebar),var(--sidebar-2));
  color:var(--sidebar-text);
  display:flex;
  flex-direction:column;
  border-right:1px solid rgba(255,255,255,.05);
  position:relative;
  z-index:40;
  overflow:hidden;
}

.sidebar-top{
  padding:22px 18px 14px;
  border-bottom:1px solid rgba(255,255,255,.06);
  flex:0 0 auto;
}

.logo-wrap{
  display:flex;
  align-items:center;
  gap:12px;
}

.logo-box{
  width:42px;
  height:42px;
  border-radius:14px;
  display:grid;
  place-items:center;
  font-weight:700;
  background:linear-gradient(135deg,#2563eb,#1d4ed8);
  color:#fff;
  box-shadow:0 10px 24px rgba(37,99,235,.25);
}

.logo-text{
  display:flex;
  flex-direction:column;
  gap:2px;
}

.logo-title{
  font-size:15px;
  font-weight:700;
  letter-spacing:.4px;
}

.logo-sub{
  font-size:12px;
  color:var(--sidebar-muted);
}

.menu{
  padding:16px 12px;
  display:flex;
  flex-direction:column;
  gap:6px;
  overflow:auto;
  flex:1 1 auto;
  min-height:0;
}

.menu-section-title{
  font-size:12px;
  text-transform:uppercase;
  letter-spacing:.08em;
  color:var(--sidebar-muted);
  padding:8px 10px 10px;
}

.menu-item{
  width:100%;
  display:flex;
  align-items:center;
  gap:10px;
  min-height:44px;
  padding:10px 12px;
  border-radius:14px;
  color:var(--sidebar-text);
  transition:background .18s ease, transform .18s ease;
}

.menu-item:hover{
  background:rgba(255,255,255,.06);
}

.menu-item.is-active{
  background:rgba(37,99,235,.18);
  color:#fff;
}

.menu-btn{
  text-align:left;
}

.menu-label{
  font-size:14px;
  font-weight:600;
}

.sidebar-bottom{
  margin-top:auto;
  padding:16px;
  border-top:1px solid rgba(255,255,255,.06);
  flex:0 0 auto;
}

.logout-btn{
  width:100%;
  min-height:44px;
  border-radius:14px;
  background:rgba(255,255,255,.08);
  color:#fff;
  font-weight:600;
}

.logout-btn:hover{
  background:rgba(255,255,255,.12);
}

.main-area{
  flex:1;
  min-width:0;
  min-height:0;
  height:100vh;
  display:flex;
  flex-direction:column;
  overflow:hidden;
}

.topbar{
  height:var(--topbar-h);
  min-height:var(--topbar-h);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:14px 22px;
  background:rgba(255,255,255,.88);
  backdrop-filter:blur(10px);
  border-bottom:1px solid var(--border);
  position:sticky;
  top:0;
  z-index:20;
  flex:0 0 auto;
}

.topbar-left,
.topbar-right{
  display:flex;
  align-items:center;
  gap:16px;
  min-width:0;
}

.brand{
  display:flex;
  align-items:center;
  gap:14px;
  min-width:0;
}

.brand .logo{
  min-width:86px;
  height:38px;
  padding:0 14px;
  border-radius:12px;
  display:grid;
  place-items:center;
  font-size:13px;
  font-weight:700;
  color:var(--primary);
  background:var(--primary-3);
}

.title{
  min-width:0;
}

.h1{
  font-size:20px;
  font-weight:700;
  line-height:1.2;
}

.sub{
  font-size:13px;
  color:var(--muted);
  line-height:1.35;
  margin-top:2px;
}

.user-chip{
  display:flex;
  align-items:flex-start;
  gap:8px;
  padding:10px 12px;
  border:1px solid var(--border);
  border-radius:14px;
  background:#fff;
  color:var(--text);
  min-width:0;
}

.user-chip-label{
  font-size:12px;
  color:var(--muted);
}

#userEmail{
  font-size:13px;
  word-break:break-all;
}

.actions{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}

.content{
  flex:1 1 auto;
  min-height:0;
  overflow-y:auto;
  overflow-x:hidden;
  padding:22px;
}

.builder-wrap{
  display:grid;
  gap:18px;
  min-width:0;
}

/* Panels */
.panel{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  box-shadow:var(--shadow-soft);
  overflow:hidden;
  min-width:0;
}

.panel-h{
  padding:16px 18px;
  border-bottom:1px solid var(--border);
  font-size:15px;
  font-weight:700;
  background:linear-gradient(180deg,#ffffff,#fbfdff);
}

.panel-body{
  padding:18px;
}

.page-intro p{
  margin:0 0 10px;
  color:#334155;
  line-height:1.6;
}

.page-intro p:last-child{
  margin-bottom:0;
}

/* Form */
.grid2{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:16px 18px;
  padding:18px;
}

.field{
  min-width:0;
}

.field.colspan2{
  grid-column:1 / -1;
}

.field label{
  display:block;
  margin-bottom:8px;
  font-size:13px;
  font-weight:700;
  color:#334155;
}

.hint{
  margin-top:7px;
  font-size:12px;
  line-height:1.45;
  color:var(--muted);
}

.muted{
  color:var(--muted);
}

/* Generic rows / buttons */
.row{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}

.row-right{
  margin-left:auto;
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}

.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  min-height:40px;
  padding:0 14px;
  border:1px solid var(--border);
  border-radius:12px;
  background:#fff;
  color:var(--text);
  font-weight:600;
  transition:all .18s ease;
}

.btn:hover{
  border-color:#cbd5e1;
  background:#f8fafc;
}

.btn:disabled{
  opacity:.55;
  cursor:not-allowed;
}

.btn-primary{
  background:linear-gradient(180deg,var(--primary-2),var(--primary));
  border-color:var(--primary);
  color:#fff;
}

.btn-primary:hover{
  filter:brightness(1.03);
  background:linear-gradient(180deg,var(--primary-2),var(--primary));
}

.btn-small{
  min-height:34px;
  padding:0 10px;
  font-size:12px;
  border-radius:10px;
}

.btn-danger{
  border-color:#fecaca;
  color:#b91c1c;
  background:#fff5f5;
}

.btn-danger:hover{
  background:#fee2e2;
}

.icon-btn{
  width:40px;
  height:40px;
  border-radius:12px;
  border:1px solid var(--border);
  background:#fff;
  display:grid;
  place-items:center;
}

.mobile-only{
  display:none;
}

.chip,
.pill{
  display:inline-flex;
  align-items:center;
  gap:6px;
  min-height:30px;
  padding:0 10px;
  border-radius:999px;
  font-size:12px;
  font-weight:600;
  background:var(--surface-2);
  color:#334155;
  border:1px solid var(--border);
}

.pill{
  background:var(--primary-3);
  color:var(--primary);
  border-color:#bfdbfe;
}

/* Score Preview */
.score-preview{
  padding:18px;
  overflow-x:auto;
}

.score-preview table{
  min-width:580px;
}

.score-preview th{
  color:#334155;
  background:#f8fafc;
  font-weight:700;
}

.score-preview td,
.score-preview th{
  vertical-align:top;
}

/* Questions */
.q-list{
  padding:18px;
  display:grid;
  gap:18px;
}

.q-card{
  border:1px solid var(--border);
  border-radius:18px;
  background:linear-gradient(180deg,#ffffff,#fcfdff);
  box-shadow:var(--shadow-soft);
  padding:16px;
  display:grid;
  gap:16px;
  min-width:0;
}

.q-top{
  display:flex;
  align-items:flex-start;
  gap:10px;
  flex-wrap:wrap;
}

.q-actions{
  margin-left:auto;
  display:flex;
  align-items:center;
  gap:8px;
  flex-wrap:wrap;
}

.q-grid{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:14px 16px;
}

.opts,
.branches{
  display:grid;
  gap:12px;
  padding:14px;
  border:1px dashed var(--border);
  border-radius:16px;
  background:#fbfdff;
  min-width:0;
}

.opt-row{
  display:grid;
  grid-template-columns:minmax(180px,1.2fr) minmax(120px,.9fr) minmax(110px,.7fr) auto;
  gap:10px;
  align-items:center;
  padding:10px;
  border:1px solid var(--border);
  border-radius:14px;
  background:#fff;
}

.opt-row .muted{
  grid-column:1 / -1;
  font-size:12px;
  margin-top:-2px;
}

.branch-row{
  display:grid;
  grid-template-columns:
    minmax(180px,1fr)
    minmax(130px,.75fr)
    minmax(130px,.8fr)
    minmax(130px,.8fr)
    minmax(150px,.9fr)
    minmax(140px,.8fr)
    minmax(220px,1.2fr)
    auto;
  gap:10px;
  align-items:center;
  padding:12px;
  border:1px solid var(--border);
  border-radius:14px;
  background:#fff;
  overflow-x:auto;
}

.branch-row label{
  margin:0;
  font-size:13px;
  font-weight:600;
  color:#334155;
}

.branch-row input[type="checkbox"]{
  width:16px;
  height:16px;
  padding:0;
  margin:0;
  box-shadow:none;
}

/* Asset list modal items */
.asset-item{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  padding:12px 14px;
  border:1px solid var(--border);
  border-radius:14px;
  background:#fff;
  margin-bottom:10px;
}

.asset-item .meta{
  min-width:0;
}

.asset-item .t{
  font-weight:700;
  color:var(--text);
  margin-bottom:4px;
}

.asset-item .d{
  font-size:13px;
  color:var(--muted);
  line-height:1.5;
}

/* Log */
.log{
  min-height:220px;
  max-height:420px;
  overflow:auto;
  padding:18px;
  background:#0b1220;
  color:#dbeafe;
  font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;
  font-size:12px;
  line-height:1.55;
}

/* Modal */
.modal{
  position:fixed;
  inset:0;
  background:rgba(15,23,42,.45);
  display:grid;
  place-items:center;
  padding:24px;
  z-index:100;
}

.modal-card{
  width:min(1100px,100%);
  max-height:min(88vh,100%);
  overflow:hidden;
  display:flex;
  flex-direction:column;
  border-radius:20px;
  background:#fff;
  border:1px solid var(--border);
  box-shadow:0 30px 80px rgba(15,23,42,.22);
}

.modal-h{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  padding:16px 18px;
  border-bottom:1px solid var(--border);
  background:#fff;
  font-weight:700;
}

.modal-b{
  padding:18px;
  overflow:auto;
}

.modal-b textarea{
  font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;
  font-size:12px;
  line-height:1.5;
}

/* Helpers */
table{
  border-collapse:collapse;
}

th, td{
  text-align:left;
}

b,strong{
  font-weight:700;
}

/* Responsive */
@media (max-width: 1400px){
  .branch-row{
    grid-template-columns:
      minmax(170px,1fr)
      minmax(120px,.8fr)
      minmax(120px,.8fr)
      minmax(120px,.8fr)
      minmax(145px,.9fr)
      minmax(130px,.8fr)
      minmax(210px,1.1fr)
      auto;
  }
}

@media (max-width: 1180px){
  body{
    overflow:auto;
  }

  .app-shell{
    min-height:100vh;
    height:auto;
    overflow:visible;
  }

  .sidebar{
    position:fixed;
    inset:0 auto 0 0;
    transform:translateX(-100%);
    transition:transform .22s ease;
    box-shadow:0 20px 50px rgba(2,6,23,.35);
  }

  .sidebar.open{
    transform:translateX(0);
  }

  .mobile-only{
    display:grid;
  }

  .main-area{
    height:auto;
    min-height:100vh;
    overflow:visible;
  }

  .topbar{
    padding:14px 16px;
    height:auto;
    min-height:var(--topbar-h);
    align-items:flex-start;
    flex-wrap:wrap;
  }

  .content{
    padding:16px;
    overflow:visible;
  }

  .grid2,
  .q-grid{
    grid-template-columns:1fr;
  }

  .field.colspan2{
    grid-column:auto;
  }

  .topbar-right{
    width:100%;
    justify-content:space-between;
  }

  .actions{
    justify-content:flex-end;
  }

  .opt-row{
    grid-template-columns:1fr;
  }

  .branch-row{
    grid-template-columns:1fr 1fr;
  }

  .branch-row > *:last-child{
    justify-self:start;
  }
}

@media (max-width: 760px){
  body{
    overflow:auto;
  }

  .app-shell{
    min-height:auto;
    height:auto;
  }

  .main-area{
    min-height:auto;
    height:auto;
  }

  .topbar-left,
  .topbar-right,
  .brand{
    width:100%;
  }

  .topbar-right{
    flex-direction:column;
    align-items:stretch;
  }

  .user-chip{
    width:100%;
  }

  .actions{
    width:100%;
    justify-content:stretch;
  }

  .actions .btn{
    flex:1 1 calc(50% - 8px);
  }

  .panel-h{
    padding:14px 15px;
  }

  .panel-body,
  .grid2,
  .q-list,
  .score-preview,
  .modal-b{
    padding:14px;
  }

  .q-card{
    padding:14px;
  }

  .q-top{
    flex-direction:column;
    align-items:flex-start;
  }

  .q-actions{
    margin-left:0;
    width:100%;
  }

  .q-actions .btn{
    flex:1 1 calc(50% - 8px);
  }

  .row-right{
    margin-left:0;
    width:100%;
  }

  .row-right .btn{
    flex:1 1 calc(50% - 8px);
  }

  .branch-row{
    grid-template-columns:1fr;
  }

  .asset-item{
    flex-direction:column;
    align-items:flex-start;
  }

  .modal{
    padding:14px;
  }

  .modal-card{
    width:100%;
    max-height:92vh;
  }

  .modal-h{
    padding:14px;
  }
}