/* ============================================================
   KWSM — Client Portal auth (login / register / onboard).
   Framework-free, scoped under .kwsm-cauth so it never collides
   with app.css. Split-screen brand panel + form, matching the
   redesigned admin login. Inherits the app's system font.
   Files: client-auth.css (this) · client-auth.js (behaviour)
   ============================================================ */

.kwsm-cauth {
  position: fixed; inset: 0; z-index: 1;
  display: grid; grid-template-columns: 1fr 1fr;
  background: linear-gradient(180deg, #070a0f, #0b0f14);
  color: #e7eef7; overflow: auto;
}
.kwsm-cauth.is-wide { grid-template-columns: .82fr 1.18fr; } /* register: wider form */
.kwsm-cauth *, .kwsm-cauth *::before, .kwsm-cauth *::after { box-sizing: border-box; }
.kwsm-cauth ::selection { background: rgba(39,170,225,.28); }

/* ---------------- Brand panel ------------------------------------- */
.kwsm-cauth-brand {
  position: relative; overflow: hidden;
  background: linear-gradient(150deg, #2a1140 0%, #4a1d63 38%, #123a5a 100%);
  padding: 56px 52px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 30px;
}
.kwsm-cauth-brand::before {
  content: ""; position: absolute; width: 460px; height: 460px; border-radius: 50%;
  background: radial-gradient(circle, rgba(39,170,225,.45), transparent 65%);
  top: -120px; inset-inline-start: -80px; filter: blur(14px);
  animation: kwsm-cdrift1 13s ease-in-out infinite alternate;
}
.kwsm-cauth-brand::after {
  content: ""; position: absolute; width: 380px; height: 380px; border-radius: 50%;
  background: radial-gradient(circle, rgba(106,44,134,.55), transparent 65%);
  bottom: -120px; inset-inline-end: -60px; filter: blur(14px);
  animation: kwsm-cdrift2 16s ease-in-out infinite alternate;
}
.kwsm-cauth-brandtop { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.kwsm-cauth-logo {
  width: 50px; height: 50px; flex: 0 0 50px; border-radius: 13px;
  background: #fff; padding: 7px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 22px rgba(0,0,0,.35);
}
.kwsm-cauth-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.kwsm-cauth-wordmark { display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.kwsm-cauth-wordmark strong { font-size: 22px; font-weight: 900; letter-spacing: .03em; }
.kwsm-cauth-wordmark span { font-size: 12px; color: rgba(231,238,247,.72); font-weight: 500; }

.kwsm-cauth-brandmid { position: relative; z-index: 2; max-width: 380px; }
.kwsm-cauth-brandmid h2 {
  font-size: 32px; font-weight: 900; line-height: 1.28;
  letter-spacing: -.01em; margin: 0 0 16px; text-wrap: balance;
}
.kwsm-cauth-brandmid p { font-size: 15px; color: rgba(231,238,247,.78); line-height: 1.7; margin: 0; }

.kwsm-cauth-features { position: relative; z-index: 2; list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; text-align: start; }
.kwsm-cauth-features li { display: flex; align-items: center; gap: 12px; font-size: 14px; color: rgba(231,238,247,.9); }
.kwsm-cauth-features .ic {
  width: 34px; height: 34px; flex: 0 0 34px; border-radius: 10px;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.16);
  display: flex; align-items: center; justify-content: center; color: #cfe9fb; backdrop-filter: blur(4px);
}

/* ---------------- Form panel -------------------------------------- */
.kwsm-cauth-formwrap { display: flex; align-items: center; justify-content: center; padding: 48px; overflow: auto; }
.kwsm-cauth-form { width: 100%; max-width: 380px; text-align: center; }
.kwsm-cauth.is-wide .kwsm-cauth-form { max-width: 560px; }
/* headings centered; field labels/help stay right-aligned for readability */
.kwsm-cauth-form form { text-align: start; }

.kwsm-cauth-eyebrow { font-size: 12px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; color: var(--b, #27AAE1); margin: 0; }
.kwsm-cauth-h1 { font-size: 28px; font-weight: 900; letter-spacing: -.02em; line-height: 1.1; margin: 10px 0 8px; }
.kwsm-cauth-sub { font-size: 15px; color: #9fb0c3; line-height: 1.6; margin: 0; }
.kwsm-cauth-meta { font-size: 13px; color: #7e8ea0; margin: 6px 0 0; }

.kwsm-cauth form { margin-top: 24px; }

/* grid for register (2-col on wide) */
.kwsm-cauth-grid { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
.kwsm-cauth.is-wide .kwsm-cauth-grid { grid-template-columns: 1fr 1fr; }
.kwsm-cauth-grid .kwsm-cauth-col-full { grid-column: 1 / -1; }

.kwsm-cauth-field { display: block; margin-bottom: 16px; }
.kwsm-cauth-field > label { display: block; font-size: 13px; font-weight: 700; color: #e7eef7; margin-bottom: 8px; text-align: start; }
.kwsm-cauth-input-wrap { position: relative; display: flex; align-items: center; }
.kwsm-cauth-input-wrap input {
  width: 100%; padding: 13px 44px 13px 14px;
  border-radius: var(--radius-lg, 12px); border: 1px solid var(--border-base, rgba(255,255,255,.10));
  background: #0b1220; color: #e7eef7; font: inherit; font-size: 15px; outline: none;
  transition: border-color .14s ease, box-shadow .14s ease, background .14s ease;
}
.kwsm-cauth-input-wrap input::placeholder { color: rgba(159,176,195,.6); }
.kwsm-cauth-input-wrap input:hover { border-color: rgba(255,255,255,.16); }
.kwsm-cauth-input-wrap input:focus { border-color: rgba(39,170,225,.55); box-shadow: var(--shadow-focus, 0 0 0 3px rgba(39,170,225,.20)); }
.kwsm-cauth-field.has-toggle .kwsm-cauth-input-wrap input { padding-inline-start: 46px; }
.kwsm-cauth-field.no-icon .kwsm-cauth-input-wrap input { padding-inline-end: 14px; }

.kwsm-cauth-iicon { position: absolute; inset-inline-end: 14px; display: flex; color: #9fb0c3; opacity: .8; pointer-events: none; }
.kwsm-cauth-input-wrap input:focus ~ .kwsm-cauth-iicon { color: var(--b, #27AAE1); opacity: 1; }

.kwsm-cauth-toggle {
  position: absolute; inset-inline-start: 8px; width: 32px; height: 32px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent; border-radius: 10px;
  color: #9fb0c3; cursor: pointer; transition: color .14s ease, background .14s ease;
}
.kwsm-cauth-toggle:hover { color: #e7eef7; background: rgba(255,255,255,.05); }
.kwsm-cauth-toggle .icon-off { display: none; }
.kwsm-cauth-toggle.is-shown .icon-on { display: none; }
.kwsm-cauth-toggle.is-shown .icon-off { display: flex; }

.kwsm-cauth-help { font-size: 12px; color: #7e8ea0; margin-top: 7px; line-height: 1.5; }
.kwsm-cauth-field.invalid .kwsm-cauth-input-wrap input { border-color: rgba(255,107,107,.6); background: rgba(255,107,107,.05); }
.kwsm-cauth-field.invalid .kwsm-cauth-input-wrap { animation: kwsm-cshake .35s ease; }
.kwsm-cauth-err { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #ffd1d1; margin-top: 7px; }

/* actions */
.kwsm-cauth-actions { display: grid; gap: 10px; margin-top: 6px; }
.kwsm-cauth-btn {
  position: relative; width: 100%; min-height: 50px; border: none; border-radius: var(--radius-lg, 12px);
  background: linear-gradient(90deg, var(--p, #6A2C86), var(--b, #27AAE1));
  color: #fff; font: inherit; font-size: 15px; font-weight: 700; cursor: pointer; overflow: hidden;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  box-shadow: 0 8px 22px rgba(39,170,225,.22);
  transition: transform .14s ease, box-shadow .14s ease, filter .14s ease;
}
.kwsm-cauth-btn::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,.22), transparent); transform: translateX(-120%); }
.kwsm-cauth-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(39,170,225,.34); }
.kwsm-cauth-btn:hover::after { animation: kwsm-csheen .7s ease; }
.kwsm-cauth-btn:active { transform: translateY(0); }
.kwsm-cauth-btn .arrow { display: inline-flex; transition: transform .14s ease; }
.kwsm-cauth-btn:hover .arrow { transform: translateX(-4px); }

.kwsm-cauth-btn-ghost {
  width: 100%; min-height: 48px; border-radius: var(--radius-lg, 12px);
  border: 1px solid var(--border-strong, rgba(255,255,255,.16)); background: rgba(255,255,255,.03);
  color: #e7eef7; font: inherit; font-size: 14.5px; font-weight: 700; cursor: pointer; text-decoration: none;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: border-color .14s ease, background .14s ease, color .14s ease;
}
.kwsm-cauth-btn-ghost:hover { border-color: rgba(39,170,225,.4); background: rgba(39,170,225,.08); color: #fff; }

/* server alert */
.kwsm-cauth-alert {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; margin-bottom: 18px;
  border-radius: 10px; background: rgba(255,107,107,.14); border: 1px solid rgba(255,107,107,.35);
  color: #ffd1d1; font-size: 13px;
}
.kwsm-cauth-alert.is-warning { background: rgba(241,196,15,.12); border-color: rgba(241,196,15,.32); color: #ffe9a8; }
.kwsm-cauth-alert svg { flex: 0 0 auto; margin-top: 1px; }

/* security badge */
.kwsm-cauth-secwrap { display: flex; justify-content: center; margin-top: 22px; }
.kwsm-cauth-secbadge {
  display: inline-flex; align-items: center; gap: 9px; white-space: nowrap;
  padding: 9px 14px; border-radius: 999px; background: rgba(39,170,225,.08); border: 1px solid rgba(39,170,225,.30);
  color: #bfe9fb; font-size: 13px; font-weight: 500;
}
.kwsm-cauth-secbadge svg { color: var(--b, #27AAE1); }
.kwsm-cauth-secbadge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success, #2ecc71); animation: kwsm-cpulse 2.4s infinite; }

/* notes grid (kept from production, restyled) */
.kwsm-cauth-notes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 22px; }
.kwsm-cauth-note {
  padding: 14px; border-radius: 12px; border: 1px solid var(--border-soft, rgba(255,255,255,.08));
  background: rgba(255,255,255,.025);
}
.kwsm-cauth-note strong { display: block; color: #e7eef7; font-size: 13.5px; font-weight: 700; margin-bottom: 5px; }
.kwsm-cauth-note span { color: #9fb0c3; font-size: 12.5px; line-height: 1.6; }

/* entrance: resting state visible; animate transform only */
.kwsm-cauth-form > *, .kwsm-cauth form > * { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  .kwsm-cauth-form > * { animation: kwsm-crise .5s ease backwards; }
  .kwsm-cauth-form > *:nth-child(1) { animation-delay: .04s; }
  .kwsm-cauth-form > *:nth-child(2) { animation-delay: .10s; }
  .kwsm-cauth-form > *:nth-child(3) { animation-delay: .16s; }
  .kwsm-cauth-form > *:nth-child(4) { animation-delay: .22s; }
  .kwsm-cauth-form > *:nth-child(5) { animation-delay: .28s; }
}

@keyframes kwsm-csheen { to { transform: translateX(120%); } }
@keyframes kwsm-cshake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-6px)} 40%{transform:translateX(6px)} 60%{transform:translateX(-4px)} 80%{transform:translateX(4px)} }
@keyframes kwsm-cpulse { 0%{box-shadow:0 0 0 0 rgba(46,204,113,.5)} 70%{box-shadow:0 0 0 6px rgba(46,204,113,0)} 100%{box-shadow:0 0 0 0 rgba(46,204,113,0)} }
@keyframes kwsm-cdrift1 { from { transform: translate(0,0); } to { transform: translate(40px,30px); } }
@keyframes kwsm-cdrift2 { from { transform: translate(0,0); } to { transform: translate(-36px,-28px); } }
@keyframes kwsm-crise { from { transform: translateY(7px); } to { transform: translateY(0); } }

/* ---------------- Responsive -------------------------------------- */
@media (max-width: 960px) {
  .kwsm-cauth, .kwsm-cauth.is-wide { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .kwsm-cauth-brand { padding: 30px 24px; gap: 16px; }
  .kwsm-cauth-brandmid h2 { font-size: 22px; margin-bottom: 10px; }
  .kwsm-cauth-features { display: none; }
  .kwsm-cauth-formwrap { padding: 30px 24px 44px; align-items: flex-start; }
}
@media (max-width: 560px) {
  .kwsm-cauth-brand { padding: 24px 20px; gap: 12px; }
  .kwsm-cauth-logo { width: 44px; height: 44px; flex: 0 0 44px; }
  .kwsm-cauth-brandmid h2 { font-size: 19px; line-height: 1.35; margin-bottom: 0; }
  .kwsm-cauth-brandmid p { display: none; }
  .kwsm-cauth.is-wide .kwsm-cauth-grid { grid-template-columns: 1fr; }
  .kwsm-cauth-formwrap { padding: 24px 18px 36px; }
  .kwsm-cauth-h1 { font-size: 24px; }
  .kwsm-cauth-form form { margin-top: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .kwsm-cauth *, .kwsm-cauth *::before, .kwsm-cauth *::after { animation: none !important; }
}

/* ---------------- UI-CLIENT-01 refinement ------------------------
   Hide the entire old pre-auth client header on guest pages only.
   The new .kwsm-cauth design already carries its own brand panel
   (logo + KWSM wordmark + title + features), so the legacy
   .client-header-shell strip ("بوابة العملاء" + subtitle + action
   buttons) above it is purely redundant for visitors.

   Scoping: client_layout.php sets `body.client-portal-guest`
   exactly when no client session is active (the audience of
   login / register / onboard). The logged-in branch keeps
   `body.client-portal-auth` and its full header (with
   `إضافة جهاز` + `تسجيل خروج`) untouched. Admin pages use a
   different layout entirely and are unaffected. */
body.client-portal-guest .client-header-shell { display: none; }
