/*
 * Login, admin sign-in and admin console. Built on the tokens and components
 * in styles.css (top bar, fields, buttons, segmented control, pills).
 */

/* ---------- shell ---------- */
.gate-wrap {
  min-height: calc(100dvh - 62px - env(safe-area-inset-top));
  display: grid; grid-template-rows: 1fr auto; grid-template-columns: minmax(0, 1fr);
}
.gate-main {
  display: grid; align-items: center; gap: clamp(26px, 6vw, 80px);
  padding: clamp(14px, 6vh, 72px) 0 clamp(18px, 5vh, 56px);
}
.gate-main > * { min-width: 0; }
@media (min-width: 940px) { .gate-main { grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); } }

/* ---------- editorial side ---------- */
.gate-intro { animation: rise .6s var(--ease) both; }
.hero {
  margin: 0;
  font-family: var(--font-display); font-weight: 650;
  font-size: clamp(34px, 7.4vw, 64px); line-height: 1.04;
  letter-spacing: -.042em;
  text-wrap: balance;
}
.hero em {
  display: block;
  font-family: var(--font-serif); font-style: italic; font-weight: 400;
  font-size: 1.12em; letter-spacing: -.01em; line-height: 1;
  background: linear-gradient(100deg, var(--seal), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  padding-bottom: .08em;
}
html[lang="ar"] .hero { font-size: clamp(30px, 6.6vw, 54px); line-height: 1.3; letter-spacing: 0; font-weight: 700; }
html[lang="ar"] .hero em { font-family: var(--font-ui); font-style: normal; font-weight: 700; font-size: 1em; line-height: 1.35; }

.lede {
  margin: 20px 0 0; max-width: 46ch;
  font-size: clamp(15.5px, 1.8vw, 17.5px); line-height: 1.6; color: var(--ink-2);
}
.ledger {
  margin: 30px 0 0; padding: 0; list-style: none;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px;
  max-width: 560px;
}
.ledger li {
  display: flex; align-items: center; gap: 12px; min-width: 0;
  padding: 12px 14px; border-radius: 14px;
  background: color-mix(in srgb, var(--card) 70%, transparent); border: 1px solid var(--line);
  font-size: 14px; font-weight: 550; color: var(--ink);
}
.ledger b {
  flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px;
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  color: var(--seal); background: var(--seal-soft);
}
@media (max-width: 939px) { .ledger { display: none; } .lede { margin-top: 12px; font-size: 15px; } }

/* ---------- the card ---------- */
.gate-card {
  position: relative; overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: clamp(22px, 4vw, 38px);
  animation: rise .6s .08s var(--ease) both;
  isolation: isolate;
}
.gate-card::before {
  content: ""; position: absolute; inset: 0 0 auto; height: 3px;
  background: linear-gradient(90deg, var(--seal), var(--accent-2));
}
.gate-card::after {
  content: ""; position: absolute; z-index: -1; width: 320px; height: 320px; border-radius: 50%;
  inset-inline-end: -140px; top: -160px;
  background: radial-gradient(closest-side, var(--seal-soft), transparent);
}
.gate-stamp { position: absolute; top: 22px; inset-inline-end: 20px; }
.kicker {
  margin: 0 0 10px;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 500;
}
html[lang="ar"] .kicker { font-family: var(--font-ui); letter-spacing: 0; font-size: 12.5px; font-weight: 600; }
.card-title {
  margin: 0; padding-inline-end: 96px;
  font-family: var(--font-display); font-weight: 650;
  font-size: clamp(22px, 3.2vw, 28px); line-height: 1.15; letter-spacing: -.028em;
  text-wrap: balance;
}
html[lang="ar"] .card-title { letter-spacing: 0; font-weight: 700; line-height: 1.4; }
.card-body { margin: 10px 0 0; color: var(--ink-2); font-size: 14.5px; max-width: 42ch; }

.gate-form { margin-top: 24px; }
.gate-label { display: block; margin: 0 0 8px; font-size: 13px; font-weight: 550; color: var(--ink-2); }
.code-input {
  width: 100%;
  font-family: var(--font-mono); font-size: 17px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
}
.code-input::placeholder { letter-spacing: .02em; font-weight: 400; opacity: .5; font-size: 15px; }
html[dir="rtl"] .code-input { direction: ltr; text-align: right; }
.pass-input { font-size: 17px; letter-spacing: .06em; }
.go-arrow svg { width: 16px; height: 16px; transition: transform .2s; }
.go-arrow:hover svg { transform: translateX(3px); }
html[dir="rtl"] .go-arrow svg { transform: scaleX(-1); }
html[dir="rtl"] .go-arrow:hover svg { transform: scaleX(-1) translateX(3px); }
@media (max-width: 460px) {
  .code-field { flex-wrap: wrap; }
  .code-field .input { flex-basis: calc(100% - 44px); }
  .code-field .go { flex: 1 0 100%; }
}

.msg {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 12px 0 0; padding: 11px 13px;
  border-radius: 12px; font-size: 13.5px; line-height: 1.45;
  animation: rise .25s var(--ease) both;
}
.msg::before { content: ""; flex: none; width: 7px; height: 7px; margin-top: 6px; border-radius: 999px; background: currentColor; }
.msg.is-error { color: var(--bad); background: var(--bad-bg); }
.msg.is-note { color: var(--ink-2); background: var(--paper-2); }
.msg > span { color: var(--ink-2); text-wrap: pretty; }
.msg strong { display: block; margin-bottom: 2px; font-weight: 650; color: var(--bad); text-wrap: balance; }

.fine {
  margin: 26px 0 0; padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 13px; color: var(--ink-3); max-width: 46ch;
}
.fine a { color: var(--seal); font-weight: 550; text-decoration: none; }
.fine a:hover { text-decoration: underline; text-underline-offset: 3px; }

.shake { animation: shake .42s cubic-bezier(.36, .07, .19, .97) both; }
@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}
.is-granted .gate-card { transition: transform .35s, opacity .35s; transform: translateY(-6px); opacity: .6; }

/* ---------- agent sign-in (/oauth/authorize) ---------- */
.az-agent {
  display: flex; align-items: center; gap: 12px; min-width: 0;
  margin: 18px 0 0; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 16px;
  background: linear-gradient(135deg, var(--seal-soft), color-mix(in srgb, var(--accent-2) 7%, transparent));
}
.az-agent-ico {
  flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  color: var(--on-accent); background: linear-gradient(135deg, var(--seal), var(--accent-2));
  box-shadow: 0 8px 18px -10px var(--seal);
}
.az-agent-ico svg { width: 22px; height: 22px; }
.az-agent-t { display: grid; gap: 2px; min-width: 0; }
.az-agent-name {
  font-family: var(--font-display); font-size: 17px; font-weight: 650; letter-spacing: -.015em; line-height: 1.25;
  overflow-wrap: anywhere;
}
html[lang="ar"] .az-agent-name { letter-spacing: 0; }
.az-agent-t small { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 6px; font-size: 13px; color: var(--ink-2); line-height: 1.45; }
.az-dot { color: var(--ink-3); }
.az-back { color: var(--ink-3); }
.az-back bdi { font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-2); overflow-wrap: anywhere; }
.az .card-body { margin-top: 14px; }
.az .card-title { margin-top: 0; }
.az-err { display: none; }
.az[data-oauth-error]:not([data-oauth-error=""]) .az-only { display: none; }
.az[data-oauth-error]:not([data-oauth-error=""]) .az-err { display: block; }
.az[data-oauth-error]:not([data-oauth-error=""]) .gate-stamp { color: var(--bad); }
.az-err .card-body { color: var(--ink-2); }
.az .msg.is-ok { color: var(--ok); background: var(--ok-bg); }
@media (max-width: 460px) { .az-agent { padding: 11px 12px; } .az-agent-ico { width: 36px; height: 36px; } }

/* ============ admin console ============ */
.admin .wrap, .admin .topbar-in { max-width: 1240px; }
.admin-head { margin-bottom: 22px; }
.icon-btn.link { text-decoration: none; }
.icon-btn.link svg { width: 14px; height: 14px; }
@media (max-width: 899px) { .admin .icon-btn span { display: none; } .admin .icon-btn { padding: 0; } }
@media (max-width: 420px) { .admin .brand-t small { display: none; } }

.admin-grid { display: grid; gap: 16px; align-items: start; }
.admin-grid > * { min-width: 0; }
@media (min-width: 980px) { .admin-grid { grid-template-columns: 340px minmax(0, 1fr); } }

.panel {
  position: relative; min-width: 0;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: clamp(16px, 3vw, 22px);
  animation: rise .45s var(--ease) both;
}
.panel + .panel { animation-delay: .06s; }
.panel-title { margin: 0; font-family: var(--font-display); font-weight: 650; font-size: 19px; line-height: 1.25; letter-spacing: -.02em; }
html[lang="ar"] .panel-title { letter-spacing: 0; font-weight: 700; }
.panel-sub { margin: 6px 0 0; font-size: 13.5px; color: var(--ink-3); }

.issue form { display: grid; gap: 16px; margin-top: 18px; }
.issue .seg { display: grid; grid-template-columns: 1fr 1fr; grid-auto-flow: row; width: 100%; }
.issue .seg-opt span { white-space: normal; line-height: 1.25; padding: 6px 10px; min-height: 44px; }
.fld .help { font-size: 12.5px; color: var(--ink-3); }
.fld input[type="date"] { font-family: var(--font-mono); font-size: 15px; }
.custom-code { font-family: var(--font-mono) !important; letter-spacing: .06em; }
.issue .go { width: 100%; }
.issue .go svg { width: 16px; height: 16px; }
.form-err { margin: 0; color: var(--bad); font-size: 13px; }

/* the freshly issued code, shown once */
.reveal {
  margin-top: 18px; padding: 16px;
  border: 1px solid color-mix(in srgb, var(--seal) 35%, transparent); border-radius: 16px;
  background: var(--seal-soft);
  animation: rise .35s var(--ease) both;
}
.reveal-k { margin: 0; font-family: var(--font-mono); font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--seal); }
html[lang="ar"] .reveal-k { font-family: var(--font-ui); letter-spacing: 0; font-size: 12.5px; }
.reveal-who { margin: 4px 0 0; font-size: 17px; font-weight: 650; overflow-wrap: anywhere; }
.reveal-code {
  display: block; margin: 12px 0 0; padding: 14px 12px;
  border-radius: 12px; background: var(--card); border: 1px solid var(--line);
  font-family: var(--font-mono); font-size: clamp(15px, 4.2vw, 19px); font-weight: 600;
  letter-spacing: .06em; text-align: center; direction: ltr; white-space: nowrap;
  user-select: all; overflow-x: auto;
}
.reveal-note { margin: 10px 0 0; font-size: 12.5px; color: var(--ink-2); }
.reveal-act { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.reveal-act .ghost.done { margin-inline-start: auto; }

/* ---------- list ---------- */
.list-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.tally { display: flex; gap: 22px; margin: 14px 0 0; padding: 0; }
.tally div { display: grid; gap: 2px; }
.tally dt { font-size: 12px; color: var(--ink-3); order: 2; }
.tally dd { margin: 0; font-family: var(--font-display); font-size: 28px; font-weight: 650; letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.tally .t-active dd { color: var(--ok); }
.tally .t-revoked dd { color: var(--bad); }
.tally .t-expired dd { color: var(--mute); }
.list-head .seg-opt span { min-height: 36px; font-size: 13px; padding: 0 12px; }
@media (max-width: 559px) { .list-head > .seg { width: 100%; } }

.codes { width: 100%; margin-top: 16px; border-collapse: collapse; font-size: 14px; }
.codes th {
  padding: 0 8px 10px; text-align: start; white-space: nowrap;
  font-size: 12px; font-weight: 550; color: var(--ink-3);
  border-bottom: 1px solid var(--line);
}
.codes td { padding: 13px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.codes tbody tr { animation: rise .35s var(--ease) both; animation-delay: calc(var(--i, 0) * 25ms); }
.codes tbody tr:hover { background: var(--card-2); }
.codes tr.is-off .who b { color: var(--ink-3); }
.codes td.who { min-width: 10em; }
.who i { white-space: nowrap; }
.who b { display: block; font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.who i { font-style: normal; font-size: 12px; color: var(--ink-3); font-family: var(--font-mono); letter-spacing: .03em; }
.when { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.when small { display: block; font-size: 12px; color: var(--ink-3); }
.when.never { color: var(--ink-3); font-style: italic; }
html[lang="ar"] .when.never { font-style: normal; }
html[lang="ar"] .who i { font-family: var(--font-ui); letter-spacing: 0; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: color-mix(in srgb, currentColor 11%, transparent);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.acts { text-align: end; white-space: nowrap; }
.acts .ghost { white-space: nowrap; margin-block: 2px; }
.acts .ghost { display: flex; justify-content: center; width: 100%; }
.acts .ghost + .ghost { margin-top: 6px; }
.codes td.acts.confirming { white-space: normal; }
.codes td.acts.confirming .ghost { display: flex; width: 100%; margin: 6px 0 0; }
.ghost.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.ghost.danger:hover { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.ghost.solid-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.ghost.solid-danger:hover { filter: brightness(1.08); color: #fff; }
.ghost.solid { background: var(--seal); border-color: var(--seal); color: var(--on-accent); }
.ghost.solid:hover { filter: brightness(1.08); color: var(--on-accent); }
.dev-name { display: block; }
.codes td.dev { white-space: normal; min-width: 8.5em; }
.dev-reset {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 8px; min-height: 30px; padding: 0 12px; padding-inline-start: 9px;
  border: 1px solid color-mix(in srgb, var(--seal) 30%, var(--line)); border-radius: 999px;
  background: var(--card); color: var(--seal); cursor: pointer;
  font: inherit; font-size: 12.5px; font-weight: 600; font-style: normal; line-height: 1; white-space: nowrap;
  box-shadow: 0 1px 0 color-mix(in srgb, var(--ink) 4%, transparent);
  transition: background-color .15s, border-color .15s, color .15s;
}
.dev-reset svg { flex: none; width: 13px; height: 13px; transition: transform .35s var(--ease); }
.dev-reset:hover { background: var(--seal-soft); border-color: var(--seal); }
.dev-reset:hover svg { transform: rotate(-200deg); }
.dev-reset:active { transform: translateY(1px); }
.dev-reset:focus-visible { outline: 2px solid var(--seal); outline-offset: 2px; border-radius: 999px; }
.confirm-q { display: block; margin-bottom: 6px; font-size: 12.5px; color: var(--ink-2); white-space: normal; text-align: end; }

.empty { margin-top: 16px; padding: 36px 18px; border: 1px dashed var(--line-strong); border-radius: 16px; text-align: center; }
.empty h3 { margin: 0 0 4px; font-weight: 650; font-size: 17px; }
.empty p { margin: 0; color: var(--ink-3); font-size: 14px; }

.toast {
  position: fixed; z-index: 70; inset-inline: 0; bottom: calc(20px + env(safe-area-inset-bottom));
  width: max-content; max-width: calc(100% - 32px); margin: 0 auto;
  padding: 11px 18px; border-radius: 999px;
  background: var(--ink); color: var(--paper);
  font-size: 13.5px; font-weight: 550; box-shadow: var(--shadow-lg);
  animation: rise .25s var(--ease) both;
}

#list { container-type: inline-size; }
@container (max-width: 760px) {
  .codes thead { display: none; }
  .codes, .codes tbody, .codes tr, .codes td { display: block; width: 100%; }
  .codes tr {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) auto; gap: 12px;
    padding: 14px 0; border-bottom: 1px solid var(--line);
  }
  .codes td { padding: 0; border: 0; min-width: 0; }
  .codes td.who { grid-column: 1 / 3; grid-row: 1; min-width: 0; }
  .codes td.st { grid-column: 3; grid-row: 1; text-align: end; }
  .codes td.when { font-size: 13px; white-space: normal; }
  .codes td.c-used { grid-column: 1; grid-row: 2; }
  .codes td.c-exp { grid-column: 2 / -1; grid-row: 2; }
  .codes td.when::before { content: attr(data-k); display: block; font-size: 11.5px; color: var(--ink-3); font-style: normal; }
  .codes td.dev {
    grid-column: 1 / -1; grid-row: 3;
    display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; align-items: center;
    padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px;
    background: color-mix(in srgb, var(--paper-2) 60%, transparent);
  }
  .codes td.dev::before, .codes td.dev > * { grid-column: 1; min-width: 0; overflow-wrap: anywhere; }
  .codes td.dev .dev-reset {
    grid-column: 2; grid-row: 1 / span 3; align-self: center; margin: 0;
    min-height: 38px; padding: 0 14px; padding-inline-start: 11px;
  }
  .codes td.dev.agent { grid-row: 4; }
  .codes td.acts { grid-column: 1 / -1; grid-row: 5; text-align: start; white-space: normal; display: flex; flex-wrap: wrap; gap: 6px; }
  .acts .ghost, .codes td.acts.confirming .ghost { width: auto; margin: 0; }
  .acts .ghost + .ghost { margin-inline-start: 0; }
  .confirm-q { text-align: start; flex-basis: 100%; }
  .codes tbody tr:hover { background: none; }
}

@media (prefers-reduced-motion: reduce) {
  .gate-intro, .gate-card, .panel, .reveal, .msg, .codes tbody tr, .toast, .shake { animation: none !important; }
  .dev-reset svg { transition: none; }
}
