/* ============================================================
   CMT ENGINEERS: client portal components
   Layers on main.css tokens. Hard edges, mono labels, no radius.
   Mobile-first. Components:
     portal header bar · login card · stage / status chips ·
     assignment cards · admin shell (dark left rail ≥1080px,
     top bar below) · stat cards · data table · field-editor rows ·
     builder two-pane (editor + live preview) · modal/dialog ·
     copy button · portal form helpers.
   ============================================================ */

/* ---------- base ---------- */
/* portal pages set data-no-cta, undo the mobile quick-bar padding */
body[data-no-cta="true"] { padding-bottom: 0 !important; }

.portal-wrap { max-width: 720px; margin: 0 auto; }
.portal-main { padding-top: clamp(32px, 5vw, 64px); padding-bottom: clamp(56px, 8vw, 110px); }

/* ---------- portal header bar ---------- */
.portal-bar {
  position: sticky; top: 0; z-index: 90;
  background: var(--ink); color: var(--bone);
  border-bottom: 1px solid var(--line-d);
}
.portal-bar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding-top: 14px; padding-bottom: 14px;
}
.portal-bar .brand img { height: 30px; width: auto; }
.portal-bar-tag {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--concrete);
}
.portal-bar-tag::before { content: ""; width: 6px; height: 6px; background: var(--red); }
.portal-bar .btn { padding: 10px 16px; }
@media (max-width: 560px) {
  .portal-bar-tag { display: none; }
}

/* ---------- login (dark hero feel) ---------- */
.portal-login {
  position: relative; overflow: hidden;
  min-height: 100svh;
  display: flex; align-items: center; justify-content: center;
  background: var(--ink); color: var(--bone);
  padding: 120px var(--gutter) 64px;
}
.portal-login .webgl-wrap { position: absolute; inset: 0; z-index: 0; }
.login-card {
  position: relative; z-index: 2;
  width: 100%; max-width: 480px;
  background: var(--bone); color: var(--ink);
  border: 1.5px solid var(--ink);
  padding: clamp(26px, 4.5vw, 44px);
}
.login-card .h-mid { margin-top: 12px; }
.login-card form { margin-top: 22px; }
.login-error {
  margin-top: 12px;
  font-family: var(--font-mono); font-size: 11px;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--red);
}
.login-hint {
  margin-top: 24px; padding: 14px 16px;
  border: 1px solid var(--line); background: var(--stone);
  font-size: 13px; color: var(--mute);
}
.login-hint code {
  font-family: var(--font-mono); font-size: 12px; color: var(--ink);
  background: var(--bone); border: 1px solid var(--line); padding: 1px 6px;
}
.code-chip {
  display: inline-block; margin: 8px 8px 0 0; padding: 5px 9px;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .08em;
  color: var(--ink); background: var(--bone); border: 1px solid var(--line);
  cursor: pointer; transition: .25s var(--ease);
}
.code-chip:hover { background: var(--ink); border-color: var(--ink); color: var(--bone); }

/* ---------- stage + status chips ---------- */
.stage-chip, .status-chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-mono); text-transform: uppercase;
  letter-spacing: .14em; font-size: 10px; line-height: 1;
  padding: 6px 9px; border: 1px solid var(--line);
  color: var(--mute); background: transparent; white-space: nowrap;
}
.stage-chip::before { content: ""; width: 5px; height: 5px; background: var(--concrete2); }
.status-chip.is-action { background: var(--red); border-color: var(--red); color: #fff; }
.status-chip.is-submitted { background: var(--ink); border-color: var(--ink); color: var(--bone); }
.status-chip.is-published { border-color: var(--red); color: var(--red); }
.status-chip.is-draft { border-style: dashed; }
.bg-ink .stage-chip { border-color: var(--line-d); color: var(--concrete); }
.bg-ink .status-chip.is-submitted { background: var(--bone); border-color: var(--bone); color: var(--ink); }

/* ---------- client welcome row ---------- */
.portal-welcome {
  display: flex; flex-wrap: wrap; align-items: flex-end;
  justify-content: space-between; gap: 16px;
  border-bottom: 1px solid var(--line); padding-bottom: 20px;
}
.portal-kv { display: flex; flex-wrap: wrap; gap: 8px 22px; }
.portal-kv .label { color: var(--mute); }
.portal-kv b { font-family: var(--font-mono); font-size: 12px; font-weight: 500; letter-spacing: .06em; }

/* ---------- assignment cards ---------- */
.assign-group { margin-top: clamp(30px, 4.5vw, 48px); }
.assign-group-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.assign-group-head::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.assign-list { display: grid; gap: 14px; }
.assign-card {
  position: relative;
  border: 1px solid var(--line); background: var(--bone);
  padding: clamp(18px, 3vw, 28px);
  transition: border-color .3s var(--ease), background .3s var(--ease);
}
.assign-card:hover { border-color: var(--ink); }
.assign-card.is-done { background: var(--stone); }
.assign-card .ac-top {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: 8px;
}
.assign-card h3 {
  font-family: var(--font-display); font-weight: 800; text-transform: uppercase;
  letter-spacing: -.02em; line-height: 1; font-size: clamp(19px, 2.4vw, 26px);
  margin-top: 14px;
}
.assign-card p { color: var(--mute); font-size: 14px; margin-top: 8px; max-width: 60ch; }
.assign-card .ac-foot {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: 12px;
  margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line);
}
.assign-meta { font-family: var(--font-mono); font-size: 11px; letter-spacing: .08em; color: var(--mute); }

/* ---------- module form (client view + builder preview) ---------- */
.module-head { border-bottom: 1px solid var(--ink); padding-bottom: 16px; margin-bottom: 24px; }
.field-note {
  border-left: 3px solid var(--red); background: var(--stone);
  padding: 14px 16px; font-size: 14px; color: var(--mute);
}
.field-note b { display: block; color: var(--ink); font-size: 13px; margin-bottom: 4px; }
.field .help { font-size: 12.5px; color: var(--mute); margin-top: 6px; }
.field .req { color: var(--red); }
.file-meta { font-family: var(--font-mono); font-size: 11px; letter-spacing: .04em; color: var(--mute); margin-top: 6px; }
.filehint { font-family: var(--font-mono); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--concrete2); }

/* restore native radio/checkbox (main.css strips appearance in .field) */
.field input[type="radio"], .field input[type="checkbox"],
.opt input[type="radio"], .opt input[type="checkbox"],
.check-row input[type="checkbox"], .fe-required input[type="checkbox"] {
  appearance: auto; -webkit-appearance: auto;
  width: 16px; height: 16px; padding: 0; border: 0;
  accent-color: var(--red); flex: 0 0 auto;
}
.opt-list { display: grid; gap: 10px; }
.opt { display: flex; align-items: flex-start; gap: 11px; font-size: 15px; cursor: pointer; }
.opt input { margin-top: 3px; }

/* validation */
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--red); }
.field-err {
  display: none; margin-top: 6px;
  font-family: var(--font-mono); font-size: 10.5px;
  letter-spacing: .1em; text-transform: uppercase; color: var(--red);
}
.field.invalid .field-err { display: block; }

/* success + empty states */
.portal-success {
  border: 1.5px solid var(--ink); background: var(--bone);
  padding: clamp(26px, 5vw, 44px); text-align: center;
}
.portal-success .tick {
  display: inline-block; font-family: var(--font-display); font-weight: 800;
  font-size: 36px; line-height: 1; color: var(--red);
}
.portal-empty {
  border: 1px dashed var(--concrete2); padding: clamp(24px, 4vw, 40px);
  text-align: center; color: var(--mute); font-size: 14px;
}

/* ---------- admin shell ---------- */
/* mobile-first: dark top bar; ≥1080px: dark ink left rail */
.admin-shell { min-height: 100svh; display: flex; flex-direction: column; background: var(--bone); }
.admin-rail {
  position: sticky; top: 0; z-index: 80;
  display: flex; align-items: center; gap: 4px;
  background: var(--ink); color: var(--bone);
  border-bottom: 1px solid var(--line-d);
  padding: 10px var(--gutter); overflow-x: auto;
}
.rail-brand { display: flex; align-items: center; gap: 10px; margin-right: 12px; text-decoration: none; }
.rail-brand img { height: 26px; width: auto; }
.rail-brand .label { color: var(--concrete); white-space: nowrap; }
.rail-link {
  font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .12em;
  font-size: 11px; color: var(--concrete); text-decoration: none;
  background: none; border: 1px solid transparent;
  padding: 10px 12px; white-space: nowrap; text-align: left;
  transition: color .25s var(--ease), background .25s var(--ease), border-color .25s var(--ease);
}
.rail-link:hover { color: var(--bone); }
.rail-link.active { color: var(--bone); background: var(--ink2); border-color: var(--line-d); }
.rail-foot { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.admin-main {
  flex: 1; width: 100%; max-width: 1240px; min-width: 0;
  padding: clamp(22px, 3.5vw, 44px) var(--gutter) 90px;
}
@media (min-width: 1080px) {
  .admin-shell { flex-direction: row; }
  .admin-rail {
    flex-direction: column; align-items: stretch; gap: 2px;
    width: 250px; flex: 0 0 250px;
    height: 100svh; overflow-x: visible; overflow-y: auto;
    padding: 28px 20px;
    border-bottom: 0; border-right: 1px solid var(--line-d);
  }
  .rail-brand { margin: 0 0 32px; }
  .rail-link { padding: 12px 14px; border: 0; border-left: 2px solid transparent; }
  .rail-link.active { background: var(--ink2); border-left-color: var(--red); }
  .rail-foot { margin: auto 0 0; flex-direction: column; align-items: stretch; padding-top: 24px; border-top: 1px solid var(--line-d); }
}

/* admin page head */
.admin-head {
  display: flex; flex-wrap: wrap; align-items: flex-end;
  justify-content: space-between; gap: 16px;
  border-bottom: 1px solid var(--line); padding-bottom: 18px;
  margin-bottom: clamp(22px, 3vw, 36px);
}
.admin-head .actions { display: flex; flex-wrap: wrap; gap: 10px; }
.admin-view[hidden] { display: none; }

/* ---------- stat cards ---------- */
.stat-cards {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1px;
  background: var(--line); border: 1px solid var(--line);
}
.stat-card { background: var(--bone); padding: clamp(16px, 2vw, 26px); }
.stat-card b {
  display: block; font-family: var(--font-display); font-weight: 800;
  font-size: clamp(26px, 3vw, 42px); line-height: 1;
}
.stat-card b em { font-style: normal; color: var(--red); }
.stat-card .label { color: var(--mute); margin-top: 8px; font-size: 10px; }
@media (min-width: 640px) { .stat-cards { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 980px) { .stat-cards { grid-template-columns: repeat(5, 1fr); } }

/* ---------- data table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); background: var(--bone); }
.data-table { width: 100%; min-width: 640px; border-collapse: collapse; font-size: 14px; }
.data-table th {
  font-family: var(--font-mono); font-weight: 500; text-transform: uppercase;
  letter-spacing: .14em; font-size: 10px; color: var(--mute);
  text-align: left; white-space: nowrap;
  padding: 12px 14px; background: var(--stone); border-bottom: 1px solid var(--ink);
}
.data-table td { padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--stone); }
.data-table .mono, .data-table code { font-family: var(--font-mono); font-size: 12.5px; }
.row-actions { display: flex; gap: 8px; white-space: nowrap; }

/* ---------- icon + copy buttons ---------- */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; line-height: 1;
  font-family: var(--font-mono); font-size: 13px;
  border: 1px solid var(--line); background: var(--bone); color: var(--mute);
  transition: .2s var(--ease);
}
.icon-btn:hover { border-color: var(--ink); color: var(--ink); background: var(--stone); }
.icon-btn:disabled { opacity: .35; pointer-events: none; }
.icon-btn.danger:hover { background: var(--red); border-color: var(--red); color: #fff; }
.copy-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); text-transform: uppercase;
  letter-spacing: .1em; font-size: 10px; line-height: 1;
  padding: 7px 10px; border: 1px solid var(--line);
  background: transparent; color: var(--mute);
  transition: .2s var(--ease); white-space: nowrap;
}
.copy-btn::before { content: "⧉"; font-size: 12px; }
.copy-btn:hover { border-color: var(--ink); color: var(--ink); }
.copy-btn.copied { border-color: var(--red); color: var(--red); }
.copy-btn.copied::before { content: "✓"; }

/* ---------- builder two-pane (editor + live preview) ---------- */
.builder { display: grid; gap: clamp(22px, 3vw, 34px); align-items: start; }
.builder-pane { min-width: 0; }
.pane-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border-bottom: 1px solid var(--ink); padding-bottom: 10px; margin-bottom: 18px;
}
.preview-pane { border: 1px solid var(--line); background: var(--stone); padding: clamp(16px, 2.4vw, 26px); }
.preview-frame { background: var(--bone); border: 1px solid var(--line); padding: clamp(16px, 2.4vw, 28px); }
@media (min-width: 1080px) {
  .builder { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); }
  .builder .preview-pane { position: sticky; top: 24px; max-height: calc(100svh - 48px); overflow-y: auto; }
}

/* add-field palette */
.field-palette { display: flex; flex-wrap: wrap; gap: 8px; }
.palette-btn {
  font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .12em;
  font-size: 10.5px; padding: 9px 13px;
  border: 1.5px solid var(--line); background: transparent; color: var(--mute);
  transition: .25s var(--ease);
}
.palette-btn:hover { background: var(--ink); border-color: var(--ink); color: var(--bone); }

/* ---------- field-editor rows ---------- */
.fe-list { display: grid; gap: 12px; }
.fe-row { border: 1px solid var(--line); background: var(--bone); }
.fe-row.is-note { border-left: 3px solid var(--red); }
.fe-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--stone); border-bottom: 1px solid var(--line);
}
.fe-type {
  font-family: var(--font-mono); text-transform: uppercase;
  letter-spacing: .14em; font-size: 10px; line-height: 1;
  color: var(--bone); background: var(--ink); padding: 5px 8px; white-space: nowrap;
}
.fe-controls { margin-left: auto; display: flex; gap: 6px; }
.fe-body { padding: 14px; display: grid; gap: 12px; }
.fe-grid { display: grid; gap: 12px; }
@media (min-width: 700px) { .fe-grid { grid-template-columns: 1fr 1fr; } }
.fe-required {
  display: inline-flex; align-items: center; gap: 9px;
  font-family: var(--font-mono); text-transform: uppercase;
  letter-spacing: .12em; font-size: 10.5px; color: var(--mute); cursor: pointer;
}
.fe-options { display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.fe-opt { display: flex; align-items: center; gap: 8px; }
.fe-opt input { flex: 1; min-width: 0; }

/* ---------- modal / dialog ---------- */
.modal {
  position: fixed; inset: 0; z-index: 120;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(21, 18, 13, .62);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.modal[hidden] { display: none; }
.modal-box {
  width: 100%; max-width: 560px; max-height: 86svh; overflow-y: auto;
  background: var(--bone); border: 1.5px solid var(--ink);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 16px 20px; background: var(--stone); border-bottom: 1px solid var(--line);
  position: sticky; top: 0;
}
.modal-body { padding: 20px; }
.modal-foot {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px;
  padding: 16px 20px; border-top: 1px solid var(--line);
}

/* publish dialog client checklist */
.check-list { display: grid; gap: 8px; }
.check-row {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--line); padding: 12px 14px;
  font-size: 14px; cursor: pointer; transition: background .2s var(--ease);
}
.check-row:hover { background: var(--stone); }
.check-row .label { margin-left: auto; color: var(--mute); white-space: nowrap; }

/* ---------- focus visibility (a11y) ---------- */
.rail-link:focus-visible, .icon-btn:focus-visible, .copy-btn:focus-visible,
.code-chip:focus-visible, .palette-btn:focus-visible, .check-row:focus-within {
  outline: 2px solid var(--red); outline-offset: 2px;
}
