/* ===========================================================================
   Intelibs — Keycloak login theme  ·  "Portal" design system
   A refined, enterprise single-sign-on look: calm backdrop, one focused card,
   Intelibs wordmark, light + dark, app-neutral (fronts multiple apps).
   =========================================================================== */

/* ── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --bg:            #eaf0f9;
  --bg-grad-a:     #f6f9fe;
  --bg-grad-b:     #e4ecf8;
  --bg-orb-a:      rgba(37,99,235,.16);
  --bg-orb-b:      rgba(56,132,255,.14);
  --grid-line:     rgba(37,99,235,.05);

  --card:          #ffffff;
  --card-border:   #e8edf5;

  --text:          #0f1e34;
  --text-muted:    #5b6b82;
  --text-faint:    #8b99ad;

  --field-bg:      #f8fafd;
  --field-border:  #d9e1ec;
  --field-text:    #0f1e34;

  --accent:        #2563eb;
  --accent-hover:  #1d4ed8;
  --accent-soft:   #eaf1fd;
  --accent-ring:   rgba(37,99,235,.18);
  --on-accent:     #ffffff;

  --error:   #dc2626; --error-bg:   #fef2f3; --error-border:   #f6cccc;
  --success: #15924e; --success-bg: #ecfdf3; --success-border: #b6e8ca;
  --warn:    #b45309; --warn-bg:    #fff7ed; --warn-border:    #fbd7ae;
  --info:    #1d4ed8; --info-bg:    #eef4ff; --info-border:    #c9dbfb;

  --r-card: 20px;
  --r-field: 11px;
  --r-btn: 11px;
  --r-sm: 8px;

  --shadow-card: 0 1px 2px rgba(15,30,52,.05), 0 20px 48px -20px rgba(15,30,52,.28);
  --shadow-btn:  0 6px 18px -6px rgba(37,99,235,.5);
  --ring: 0 0 0 4px var(--accent-ring);
  --t: 200ms cubic-bezier(.4,0,.2,1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #070d18;
    --bg-grad-a:     #0d1728;
    --bg-grad-b:     #060a13;
    --bg-orb-a:      rgba(37,99,235,.24);
    --bg-orb-b:      rgba(56,132,255,.18);
    --grid-line:     rgba(120,160,255,.05);

    --card:          #101a2c;
    --card-border:   #223048;

    --text:          #eef3fa;
    --text-muted:    #9db0c8;
    --text-faint:    #64768e;

    --field-bg:      #0c1626;
    --field-border:  #27374f;
    --field-text:    #eef3fa;

    --accent:        #3b82f6;
    --accent-hover:  #60a5fa;
    --accent-soft:   #15243e;
    --accent-ring:   rgba(59,130,246,.32);
    --on-accent:     #ffffff;

    --error:   #f87171; --error-bg:   #2a1416; --error-border:   #542326;
    --success: #4ade80; --success-bg: #0e2419; --success-border: #1f4733;
    --warn:    #fbbf24; --warn-bg:    #291c0c; --warn-border:    #4a361a;
    --info:    #93b4fb; --info-bg:    #131f38; --info-border:    #263a63;

    --shadow-card: 0 1px 2px rgba(0,0,0,.4), 0 24px 60px -22px rgba(0,0,0,.7);
    --shadow-btn:  0 8px 22px -8px rgba(59,130,246,.6);
  }
}

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

html, body {
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ── Backdrop ──────────────────────────────────────────────────────────────── */
body.intelibs-login {
  position: relative;
  min-height: 100vh;
  display: flex;
  /* "safe center": center normally, but when the card is TALLER than the
     viewport fall back to top-alignment instead of clipping the top (the QR
     code) out of reach. Pairs with overflow-x:hidden below so the page scrolls
     vertically. */
  align-items: safe center;
  justify-content: center;
  padding: 2.5rem 1.25rem;
  background:
    radial-gradient(1200px 720px at 78% -10%, var(--bg-grad-a), transparent 60%),
    radial-gradient(1000px 700px at 8% 108%, var(--bg-grad-b), transparent 58%),
    var(--bg);
  /* Clip only the x-axis (keeps the drifting orbs from making a horizontal
     scrollbar) while allowing the page to scroll vertically when a tall page
     — e.g. the 2FA/TOTP setup with its QR code — exceeds the viewport. */
  overflow-x: hidden;
}
/* faint grid, faded to the middle */
body.intelibs-login::before {
  content: ''; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 58px 58px;
  -webkit-mask-image: radial-gradient(circle at 50% 42%, #000 0%, transparent 72%);
  mask-image: radial-gradient(circle at 50% 42%, #000 0%, transparent 72%);
}
.orb { position: fixed; z-index: 0; border-radius: 50%; filter: blur(70px); pointer-events: none; }
.orb.o1 { width: 460px; height: 460px; background: var(--bg-orb-a); top: -160px; right: -120px; animation: drift1 20s ease-in-out infinite; }
.orb.o2 { width: 380px; height: 380px; background: var(--bg-orb-b); bottom: -170px; left: -110px; animation: drift2 24s ease-in-out infinite; }

/* ── Shell ─────────────────────────────────────────────────────────────────── */
.shell {
  position: relative; z-index: 1;
  width: 100%; max-width: 428px;
  display: flex; flex-direction: column; align-items: stretch; gap: 1.4rem;
  animation: rise .5s cubic-bezier(.2,.7,.2,1) both;
}

/* Brand lockup above the card */
.brand {
  display: flex; align-items: center; justify-content: center; gap: .7rem;
}
.brand img { height: 34px; width: auto; object-fit: contain; }
.brand .wordmark {
  font-size: 1.18rem; font-weight: 700; letter-spacing: -.02em; color: var(--text);
}

/* ── Card ──────────────────────────────────────────────────────────────────── */
.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
  padding: 2.3rem 2.3rem 2rem;
  overflow: hidden;
}
/* subtle top sheen accent */
.card::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: .55;
}

.card-head { margin-bottom: 1.5rem; }
.card-title {
  font-size: 1.45rem; font-weight: 700; letter-spacing: -.02em;
  line-height: 1.25; color: var(--text);
}
.card-sub {
  margin-top: .45rem; font-size: .9rem; color: var(--text-muted); line-height: 1.55;
}
.card-sub strong { color: var(--text); font-weight: 600; }

/* ── Alerts / Keycloak global messages ─────────────────────────────────────── */
.alert {
  display: flex; align-items: flex-start; gap: .6rem;
  padding: .8rem .95rem; border-radius: var(--r-sm);
  font-size: .86rem; font-weight: 500; line-height: 1.5;
  margin-bottom: 1.35rem; border: 1px solid transparent;
}
.alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; stroke-width: 2; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.alert-error   { background: var(--error-bg);   border-color: var(--error-border);   color: var(--error);   animation: shake .4s both; }
.alert-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success); }
.alert-warning { background: var(--warn-bg);    border-color: var(--warn-border);    color: var(--warn); }
.alert-info    { background: var(--info-bg);    border-color: var(--info-border);    color: var(--info); }

/* ── Fields ────────────────────────────────────────────────────────────────── */
.field { margin-bottom: 1.05rem; }
.field-label {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  margin-bottom: .42rem;
}
label, .field-label > label {
  font-size: .8rem; font-weight: 500; color: var(--text-muted); letter-spacing: .005em;
}
.input-wrap { position: relative; display: flex; align-items: center; }
.input-icon {
  position: absolute; left: 13px; display: flex; color: var(--text-faint);
  pointer-events: none; transition: color var(--t);
}
.input-icon svg { width: 17px; height: 17px; stroke-width: 1.75; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }

input[type="text"], input[type="email"], input[type="password"],
input[type="tel"], input[type="number"], input[type="url"], input[type="search"],
input:not([type]) {
  width: 100%; height: 46px; padding: 0 1rem;
  border: 1.5px solid var(--field-border); border-radius: var(--r-field);
  font-family: var(--font); font-size: .93rem; font-weight: 450;
  color: var(--field-text); background: var(--field-bg);
  outline: none; transition: border-color var(--t), box-shadow var(--t), background var(--t);
}
/* Reserve space for the leading icon / trailing eye button (kept higher-specificity
   than the base rule so the icon never overlaps the placeholder). */
.input-wrap .input-icon ~ input { padding-left: 2.7rem; }
.input-wrap:has(.btn-eye) input { padding-right: 2.8rem; }
input::placeholder { color: var(--text-faint); }
input:focus { border-color: var(--accent); background: var(--card); box-shadow: var(--ring); }
.input-wrap:focus-within .input-icon { color: var(--accent); }
.input-wrap.has-error input { border-color: var(--error); }
.input-wrap.has-error:focus-within input { box-shadow: 0 0 0 4px rgba(220,38,38,.14); }

/* Password eye */
.btn-eye {
  position: absolute; right: 8px; height: 32px; width: 32px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer; border-radius: var(--r-sm);
  color: var(--text-faint); transition: color var(--t), background var(--t);
}
.btn-eye:hover { color: var(--accent); background: var(--accent-soft); }
.btn-eye svg { width: 17px; height: 17px; stroke-width: 1.75; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.input-wrap:has(.btn-eye) input { padding-right: 2.8rem; }

.field-error { display: block; margin-top: .4rem; font-size: .79rem; color: var(--error); font-weight: 500; }
.field-hint  { display: block; margin-top: .4rem; font-size: .79rem; color: var(--text-faint); }

/* ── Options row (remember / forgot) ───────────────────────────────────────── */
.options-row {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  flex-wrap: wrap; margin: .35rem 0 1.4rem;
}
.check {
  display: inline-flex; align-items: center; gap: .5rem; cursor: pointer;
  font-size: .855rem; color: var(--text-muted); user-select: none;
}
.check input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 17px; height: 17px; border: 1.5px solid var(--field-border);
  border-radius: 5px; background: var(--field-bg); cursor: pointer; flex-shrink: 0;
  position: relative; transition: background var(--t), border-color var(--t);
}
.check input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.check input[type="checkbox"]:checked::after {
  content: ''; position: absolute; left: 5px; top: 1.5px; width: 5px; height: 9px;
  border: 2px solid #fff; border-top: none; border-left: none; transform: rotate(42deg);
}
.check input[type="checkbox"]:focus-visible { box-shadow: var(--ring); }

.link { font-size: .855rem; color: var(--accent); text-decoration: none; font-weight: 500; transition: color var(--t); }
.link:hover { color: var(--accent-hover); text-decoration: underline; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  width: 100%; height: 47px; padding: 0 1.1rem;
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  font-family: var(--font); font-size: .93rem; font-weight: 600; letter-spacing: .005em;
  border: 1.5px solid transparent; border-radius: var(--r-btn); cursor: pointer;
  transition: background var(--t), box-shadow var(--t), transform 90ms ease, border-color var(--t), color var(--t);
  position: relative; overflow: hidden;
}
.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-btn); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); transform: translateY(-1px); }
.btn-primary:active:not(:disabled) { transform: translateY(0); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary::before {
  content: ''; position: absolute; top: 0; left: -120%; width: 55%; height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,.3), transparent);
  transform: skewX(-18deg); pointer-events: none;
}
.btn-primary:hover:not(:disabled)::before { animation: sheen .9s ease; }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--field-border); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.btn + .btn { margin-top: .65rem; }
.btn-row { display: flex; gap: .65rem; }
.btn-row .btn { margin-top: 0; }

/* Card-level submit fallback (Keycloak default markup on some pages) */
.card button[type="submit"]:not(.btn),
.card input[type="submit"]:not(.btn) {
  width: 100%; height: 47px;
  background: var(--accent); color: var(--on-accent);
  border: none; border-radius: var(--r-btn); font-family: var(--font);
  font-size: .93rem; font-weight: 600; cursor: pointer; box-shadow: var(--shadow-btn);
  transition: background var(--t);
}
.card button[type="submit"]:not(.btn):hover { background: var(--accent-hover); }

/* ── Identity providers / social ───────────────────────────────────────────── */
.divider {
  display: flex; align-items: center; gap: .9rem; margin: 1.5rem 0 1.15rem;
  color: var(--text-faint); font-size: .76rem; font-weight: 500; letter-spacing: .02em;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--card-border); }
.social-list { display: flex; flex-direction: column; gap: .55rem; }
.social-btn {
  display: flex; align-items: center; justify-content: center; gap: .55rem;
  height: 45px; border: 1.5px solid var(--field-border); border-radius: var(--r-btn);
  background: var(--card); color: var(--text); font-size: .89rem; font-weight: 500;
  text-decoration: none; cursor: pointer; transition: var(--t);
}
.social-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.social-btn i { font-size: 1rem; }

/* ── Info / instruction blocks (reset, verify-email, error, info…) ─────────── */
.prose { font-size: .92rem; color: var(--text-muted); line-height: 1.65; }
.prose + .prose { margin-top: .8rem; }
.instruction { font-size: .92rem; color: var(--text-muted); line-height: 1.65; margin-bottom: 1.4rem; }

/* Emphasis icon used on status pages */
.status-mark {
  width: 56px; height: 56px; border-radius: 15px; margin-bottom: 1.2rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
}
.status-mark svg { width: 27px; height: 27px; stroke-width: 2; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.status-mark.is-error   { background: var(--error-bg);   color: var(--error); }
.status-mark.is-success { background: var(--success-bg); color: var(--success); }
.status-mark.is-warn    { background: var(--warn-bg);    color: var(--warn); }

/* TOTP setup helpers */
.totp-qr { display: flex; justify-content: center; margin: 1rem 0 1.2rem; }
.totp-qr img { border-radius: var(--r-sm); border: 1px solid var(--card-border); background:#fff; padding:.5rem; }
.totp-manual {
  font-size: .82rem; color: var(--text-muted); background: var(--field-bg);
  border: 1px solid var(--field-border); border-radius: var(--r-sm);
  padding: .7rem .85rem; word-break: break-all; margin-bottom: 1.2rem;
}
.totp-manual code { font-weight: 600; color: var(--text); }
ol.steps { margin: 0 0 1.3rem 1.1rem; color: var(--text-muted); font-size: .9rem; line-height: 1.7; }
ol.steps li { padding-left: .2rem; }

/* Lists (recovery codes, provider links, etc.) */
.plain-list { list-style: none; display: flex; flex-direction: column; gap: .5rem; }

/* ── Footer ────────────────────────────────────────────────────────────────── */
.card-foot {
  margin-top: 1.6rem; padding-top: 1.25rem; border-top: 1px solid var(--card-border);
  text-align: center; font-size: .85rem; color: var(--text-muted);
}
.card-foot a { color: var(--accent); font-weight: 500; text-decoration: none; }
.card-foot a:hover { text-decoration: underline; }

.shell-foot {
  text-align: center; font-size: .76rem; color: var(--text-faint);
}
.shell-foot a { color: var(--text-muted); text-decoration: none; }
.shell-foot a:hover { color: var(--accent); }

/* Try-another-way (2FA) */
.try-another { margin-top: 1.1rem; text-align: center; }

/* ── Locale ────────────────────────────────────────────────────────────────── */
.kc-locale { position: fixed; top: 1.1rem; right: 1.3rem; z-index: 3; }
.kc-locale select {
  font-family: var(--font); font-size: .8rem; color: var(--text-muted);
  border: 1.5px solid var(--card-border); border-radius: var(--r-sm);
  padding: .35rem 1.7rem .35rem .65rem; background: var(--card); cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b99ad' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .5rem center;
}

/* ── Motion ────────────────────────────────────────────────────────────────── */
@keyframes rise  { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes sheen { to { left: 150%; } }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-5px)} 40%{transform:translateX(5px)} 60%{transform:translateX(-3px)} 80%{transform:translateX(3px)} }
@keyframes drift1 { 0%,100%{transform:translate(0,0)} 50%{transform:translate(-40px,36px)} }
@keyframes drift2 { 0%,100%{transform:translate(0,0)} 50%{transform:translate(38px,-30px)} }

@media (max-width: 480px) {
  .card { padding: 1.8rem 1.4rem 1.6rem; }
  .shell { gap: 1.15rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── Fields rendered by userProfileFormFields ──────────────────────────────
   The User Profile macro emits its own markup, driven by the kc*Class values
   in theme.properties. Its inputs are NOT wrapped in .input-wrap, so the
   error state hangs off aria-invalid — which the macro always sets — rather
   than off a wrapper class. Everything else already works: inputs are styled
   by element selector, not by class. */

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--error);
}

input[aria-invalid="true"]:focus,
select[aria-invalid="true"]:focus,
textarea[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 4px rgba(220, 38, 38, .14);
}

/* The macro marks required attributes with a bare <span class="required">*.
   .field-label is a space-between flex row, so this sits at the right edge. */
.field-label .required {
  color: var(--error);
  font-weight: 600;
  line-height: 1;
}

/* Select and textarea attributes get the same treatment as text inputs. */
select,
textarea {
  width: 100%;
  padding: .7rem 1rem;
  border: 1.5px solid var(--field-border);
  border-radius: var(--r-field);
  font-family: var(--font);
  font-size: .93rem;
  color: var(--field-text);
  background: var(--field-bg);
  outline: none;
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
}
select { height: 46px; }
textarea { min-height: 92px; resize: vertical; }
select:focus,
textarea:focus {
  border-color: var(--accent);
  background: var(--card);
  box-shadow: var(--ring);
}

/* Checkbox and radio attributes (inputType select-radiobuttons / multiselect-
   checkboxes). One row per option. */
.check-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: .3rem 0;
  font-size: .855rem;
  color: var(--text-muted);
}
.check-row label { cursor: pointer; }
.check-row .is-disabled { opacity: .55; cursor: not-allowed; }
