/* 34_signin.css - KP Equipment sign-in screens (slice S3b2, PLAN-SIGNIN rev2 section 3). Wired by 35_signin_ui.js.
 * Everything hangs off the state hook 34_signin.js keeps on <html>:
 *   data-auth      = off | nodoor | error | idle | starting | signin | redirecting | signed-in | signed-out
 *   data-auth-role = none | some | unknown (only while signed-in)
 * off (opened from disk) and signed-in show the app. EVERY other value shows the gate, so a status this file does
 * not know reads as "checking" and never as an open app.
 * Uses tokens from 01_tokens.css only; defines no global token. No inline style anywhere (CSP style-src 'self'). */

/* ---- the gate: one calm full-page panel ---- */
.auth-gate { position: fixed; inset: 0; z-index: 1900; display: flex; overflow: auto;
  padding: var(--sp-5) var(--sp-4) calc(var(--sp-5) + env(safe-area-inset-bottom, 0px));
  background: var(--bg); color: var(--ink);
  visibility: hidden; opacity: 0; transition: opacity var(--dur-slow) var(--ease), visibility 0s linear var(--dur-slow); }
/* it comes up at once (it must cover the app) and leaves with a short fade */
html[data-auth]:not([data-auth="off"]):not([data-auth="signed-in"][data-app="open"]) .auth-gate { visibility: visible; opacity: 1; transition: none; }

/* G2: the card hangs from one line in every state (where the top of a centred 400px-tall card would be), so it does
 * not jump when the words change; the short states sit a little above the middle. On a short screen it starts at the top. */
.auth-card { width: min(400px, 100%); margin: max(0px, calc(50vh - 224px)) auto auto; padding: var(--sp-5); border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow); overflow-wrap: break-word; }
.auth-card:focus { outline: none; box-shadow: var(--shadow); } /* focus lands here only when the pressed button has gone */
.auth-brand { display: flex; align-items: center; gap: var(--sp-3); margin: 0 0 var(--sp-3); }
.auth-mark { display: block; flex: none; width: 40px; height: 40px; }
.auth-title { margin: 0; font-size: 22px; font-weight: 600; line-height: 1.2; letter-spacing: .01em; }
.auth-what { margin: 0 0 var(--sp-5); color: var(--ink-soft); }
.auth-msg { margin: 0 0 var(--sp-3); font-weight: 600; }
.auth-msg:empty { display: none; }
.auth-error { display: none; }
.auth-error-title { grid-column: 2; margin: 0; font-size: inherit; font-weight: 600; line-height: inherit; text-wrap: pretty; }
.auth-error-text { grid-column: 2; margin: 2px 0 0; color: var(--ink-soft); text-wrap: pretty; }

/* the action row keeps one height in every state, so the card does not jump between "checking" and the button */
.auth-act { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); min-height: 48px; }
.auth-btn { display: none; flex: 1 1 7.5em; align-items: center; justify-content: center; min-height: 48px; padding: 0 var(--sp-4);
  border: 1px solid var(--brand-solid); border-radius: var(--r-pill); background: var(--brand-solid); color: var(--acc-ink);
  font: inherit; font-weight: 600; cursor: pointer; }
.auth-btn:hover, .auth-btn:active { background: var(--brand-solid-hover); border-color: var(--brand-solid-hover); }
.auth-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; box-shadow: none; }
.auth-wait { display: flex; align-items: center; gap: var(--sp-3); margin: 0; color: var(--ink-soft); }
.auth-dots { display: inline-flex; flex: none; gap: 5px; }
.auth-dots i { display: block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .55; }
.auth-note { margin: var(--sp-3) 0 0; font-size: 14px; color: var(--ink-muted); }

/* which parts show in which state */
html[data-auth="signin"] .auth-wait, html[data-auth="signed-out"] .auth-wait, html[data-auth="error"] .auth-wait { display: none; }
html[data-auth="signin"] #auth-signin, html[data-auth="signed-out"] #auth-signin { display: inline-flex; }
html[data-auth="error"] #auth-retry { display: inline-flex; }
/* R39: "Sign-in could not start" is the same notice as the gate screens below - the amber band (something failed), a small
 * sign, the lead line and a plain line. Its words stay in the page markup: they show even when 35_signin_ui.js did not load. */
html[data-auth="error"] .auth-error { display: grid; grid-template-columns: 20px minmax(0, 1fr); column-gap: var(--sp-3); margin: 0 0 var(--sp-4); padding: var(--sp-3) var(--sp-4); border-radius: var(--r); background: var(--warning-bg); }
html[data-auth="error"] .auth-ico-error { display: block; grid-row: 1 / span 2; color: var(--warning-fg); }
html[data-auth="error"] .auth-note { display: none; }
/* G1 (D287): screens that are not about signing in; 35_signin_ui.js sets data-gate and the words */
#auth-signout { display: none; }
html[data-gate] .auth-wait { display: none; }
html[data-gate="noaccess"] #auth-retry, html[data-gate="noaccess"] #auth-signout, html[data-gate="unchecked"] #auth-retry { display: inline-flex; }
html[data-gate="nodoor"] .auth-act, html[data-gate] .auth-note { display: none; }
/* G2 (design pass): a gate message is a notice inside the card - the soft band of the view-only strip, a small sign,
 * the lead line (what happened) and a plain line (what to do). 35_signin_ui.js builds the two lines (setSays).
 * Blue = nothing is broken (wrong address, no access yet). Amber = something failed (the access check). */
.auth-ico { display: none; flex: none; width: 20px; height: 20px; margin-top: 2px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.auth-lead, .auth-more { display: block; text-wrap: pretty; } /* pretty: no single word is left alone on the last line */
.auth-more { margin-top: 2px; font-weight: 400; color: var(--ink-soft); }
html[data-gate] .auth-says { display: flex; align-items: flex-start; gap: var(--sp-3); margin: 0 0 var(--sp-4); padding: var(--sp-3) var(--sp-4); border-radius: var(--r); background: var(--info-bg); }
html[data-gate] .auth-msg { flex: 1 1 auto; min-width: 0; margin: 0; }
html[data-gate="nodoor"] .auth-ico-nodoor, html[data-gate="noaccess"] .auth-ico-noaccess { display: block; color: var(--info); }
html[data-gate="unchecked"] .auth-ico-unchecked { display: block; color: var(--warning-fg); }
html[data-gate="unchecked"] .auth-says { background: var(--warning-bg); }
html[data-gate="nodoor"] .auth-says { margin-bottom: 0; }
.auth-btn-quiet { background: transparent; border-color: var(--ink-muted); color: var(--ink); }
.auth-btn-quiet:hover { background: var(--surface-alt); border-color: var(--ink-soft); }
.auth-btn-quiet:active { background: var(--brand-soft); border-color: var(--ink-soft); }
/* the late "did not load fully" card (02_base.css) waits for 90_start.js; while the gate decides and stage 2 has not started, the gate is the screen */
html[data-auth]:not([data-auth="off"]):not([data-app]) .boot-fail { display: none; }

/* quiet progress: nothing appears for the first third of a second, so a fast start shows no flash */
@media (prefers-reduced-motion: no-preference) {
  .auth-wait { animation: auth-in var(--dur-slow) var(--ease) .35s both; }
  .auth-dots i { animation: auth-dot 1.4s var(--ease) infinite both; }
  .auth-dots i:nth-child(2) { animation-delay: .2s; }
  .auth-dots i:nth-child(3) { animation-delay: .4s; }
}
@keyframes auth-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes auth-dot { 0%, 80%, 100% { opacity: .25; } 40% { opacity: .9; } }
@media (prefers-reduced-motion: reduce) { .auth-gate { transition: none; } }
@media (forced-colors: active) { .auth-card { border: 2px solid CanvasText; } .auth-btn { border: 2px solid ButtonText; } html[data-gate] .auth-says, html[data-auth="error"] .auth-error { border: 1px solid CanvasText; } }

/* ---- signed in: the account and "Sign out" in the house bar, last, after the tools ---- */
.acct { display: none; order: 50; min-width: 0; margin: 0; }
.acct-label, .acct-user { display: none; }
.acct-name { display: block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 500; color: var(--kp-bar-ink); }
/* margin-left: auto only does something when "Sign out" has wrapped to a row of its own (tablet): it then sits right */
#signout-btn { display: none; order: 51; margin-left: auto; }
html[data-auth="signed-in"] #signout-btn { display: inline-flex; }
/* wide screens have room for the name beside the button; the view-only band already carries it */
@media screen and (min-width: 1300px) {
  html[data-auth="signed-in"]:not([data-auth-role="none"]):not([data-auth-role="unknown"]) .acct { display: block; }
}
html[data-auth="signed-in"] body.is-editing .acct, html[data-auth="signed-in"] body.is-editing #signout-btn { display: none; }
/* A2b (rc3): the bar was laid out before "Sign out" joined it. From 901 px it is one row whose controls cannot shrink,
 * so the extra button ran past the right edge of the screen (6 px at 1024, more on a narrower screen). While signed in:
 * 901-1099 the name gives way to its mark (as it already does up to 960); 901-960 the gaps close to 4 px (as up to 900). */
@media screen and (min-width: 901px) and (max-width: 1099px) and (min-height: 501px) {
  html[data-auth="signed-in"] .kp-bar .kp-bar-title { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
@media screen and (min-width: 901px) and (max-width: 960px) and (min-height: 501px) {
  html[data-auth="signed-in"] .plan-root .kp-bar { gap: 4px; }
}
/* A2b: from 1300 px a long name beside the button pushed "Sign out" onto a second row. The bar stays one row;
 * the search field and the name (it already ends in an ellipsis) give way instead. */
@media screen and (min-width: 1300px) {
  html[data-auth="signed-in"] .plan-root .kp-bar { flex-wrap: nowrap; }
  html[data-auth="signed-in"] .plan-root .kp-bar .bar-btn { flex: 0 0 auto; } /* buttons keep their size, as on 901-1299 */
  html[data-auth="signed-in"] .plan-root .kp-bar .search { flex-shrink: 1000000; min-width: 96px; } /* the search field gives way before the name does */
}

/* ---- signed in, no KP Equipment role (D155: view only): one slim band straight under the house bar ----
 * The page bands are pinned to grid rows (65_editor.css, O5b). The band is a row of its own, so while it shows, the
 * bands below it each sit one row lower. When it does not show, nothing here touches the grid. */
.ro-strip { display: none; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-4); min-width: 0; margin: 0; padding: 6px var(--sp-4);
  border-bottom: 1px solid var(--line); background: var(--info-bg); color: var(--ink); font-size: 14px; line-height: 1.4; }
html:is([data-auth="signed-in"]:is([data-auth-role="none"], [data-auth-role="unknown"]), [data-auth="nodoor"]) .ro-strip { display: flex; }
html:is([data-auth="signed-in"]:is([data-auth-role="none"], [data-auth-role="unknown"]), [data-auth="nodoor"]) body.plan-root { grid-template-rows: auto auto auto auto 1fr auto; }
html:is([data-auth="signed-in"]:is([data-auth-role="none"], [data-auth-role="unknown"]), [data-auth="nodoor"]) body.plan-root > .ro-strip { grid-row: 2; }
html:is([data-auth="signed-in"]:is([data-auth-role="none"], [data-auth-role="unknown"]), [data-auth="nodoor"]) body.plan-root > .toolbar { grid-row: 3; }
html:is([data-auth="signed-in"]:is([data-auth-role="none"], [data-auth-role="unknown"]), [data-auth="nodoor"]) body.plan-root > .editbar { grid-row: 4; }
html:is([data-auth="signed-in"]:is([data-auth-role="none"], [data-auth-role="unknown"]), [data-auth="nodoor"]) body.plan-root > .plan-main { grid-row: 5; }
html:is([data-auth="signed-in"]:is([data-auth-role="none"], [data-auth-role="unknown"]), [data-auth="nodoor"]) body.plan-root > .foot { grid-row: 6; }
.ro-text { flex: 1 1 280px; min-width: 0; }
.ro-who { flex: 0 1 auto; min-width: 0; overflow-wrap: anywhere; color: var(--ink-soft); }
.ro-who:empty { display: none; }
.ro-who b { font-weight: 600; color: var(--ink); }
.ro-retry { flex: none; min-height: 36px; padding: 0 var(--sp-3); border: 1px solid currentColor; border-radius: var(--r-pill);
  background: transparent; color: inherit; font: inherit; font-weight: 600; cursor: pointer; }
.ro-retry[hidden] { display: none; }
.ro-retry:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; box-shadow: none; }

/* phone: the account sits in the More sheet, above "Sign out"; the band runs as one paragraph, name without the address */
@media screen and (max-width: 700px), screen and (max-height: 500px) and (max-width: 960px) {
  html[data-auth="signed-in"] .kp-bar .more-menu:popover-open .acct { display: block; order: 20; margin-top: var(--sp-1); padding-top: var(--sp-3); border-top: 1px solid var(--line); }
  .kp-bar .more-menu:popover-open .acct-label { display: block; font-size: 13px; color: var(--ink-muted); }
  .kp-bar .more-menu:popover-open .acct-name { max-width: none; overflow: visible; white-space: normal; overflow-wrap: anywhere; font-size: 16px; font-weight: 600; color: var(--ink); }
  .kp-bar .more-menu:popover-open .acct-user { display: block; font-size: 14px; color: var(--ink-soft); overflow-wrap: anywhere; }
  .kp-bar .more-menu:popover-open #signout-btn { order: 21; }
  .kp-bar .more-menu:popover-open .more-close { order: 22; }
  html:is([data-auth="signed-in"]:is([data-auth-role="none"], [data-auth-role="unknown"]), [data-auth="nodoor"]) .ro-strip { display: block; padding: 6px var(--sp-3); font-size: 13px; }
  .ro-user { display: none; }
  .ro-retry { min-height: 44px; margin: var(--sp-1) 0 2px var(--sp-2); vertical-align: middle; }
}
@media print { .ro-strip, .auth-gate { display: none !important; } }
