@import url("./shared/tokens.css");
@import url("./shared/chat.css");

/*
 * Account Kit cabinet layout. Tokens, base elements, buttons, fields, dialogs,
 * badges and toasts come from shared/tokens.css (shared with the admin).
 * A project re-colours the cabinet by overriding --kit-* in theme.css.
 */

/* ---- header ---- */
.bar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--kit-bg) 88%, transparent);
  border-bottom: 1px solid var(--kit-line);
  backdrop-filter: saturate(1.4) blur(10px);
}
.bar-inner {
  display: flex; align-items: center; gap: 28px;
  max-width: calc(var(--kit-width) + 48px); margin: 0 auto; padding: 0 24px; min-height: 60px;
}
/* Header items never break inside a word (the page wraps long words anywhere); the email in the account button gives way first. */
.brand { flex: none; font-weight: 700; font-size: 1.0625rem; letter-spacing: -0.01em; white-space: nowrap; overflow-wrap: normal; }
.tabs { display: flex; flex: none; gap: 4px; align-self: stretch; }
.tabs a {
  display: flex; align-items: center; padding: 0 12px;
  color: var(--kit-muted); text-decoration: none; font-weight: 560; font-size: 0.9375rem; white-space: nowrap; overflow-wrap: normal;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--kit-text); }
.tabs a[aria-current="page"] { color: var(--kit-text); border-bottom-color: var(--kit-accent); }
.tabs a:focus-visible { outline-offset: -4px; }
.tab-badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-left: 7px; padding: 0 6px;
  border-radius: 999px; background: var(--kit-accent); color: var(--kit-accent-text);
  font-size: 0.75rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums;
}
.bar-end { display: flex; align-items: center; gap: 10px; margin-left: auto; min-width: 0; }
.lang select {
  min-height: 36px; padding: 0 28px 0 10px;
  border: 1px solid var(--kit-line); border-radius: var(--kit-radius-s);
  background: var(--kit-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%23888' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 8px center / 12px;
  appearance: none; font-size: 0.875rem; cursor: pointer;
}
.account {
  display: inline-flex; align-items: center; gap: 8px; min-width: 0; max-width: 260px; min-height: 36px;
  padding: 3px 12px 3px 3px; border: 1px solid var(--kit-line); border-radius: 999px;
  background: var(--kit-surface); cursor: pointer;
}
.account:hover { background: var(--kit-surface-2); }
.account-initial {
  display: grid; place-items: center; width: 28px; height: 28px; flex: none; border-radius: 50%;
  background: var(--kit-accent-soft); color: var(--kit-accent); font-weight: 700; font-size: 0.875rem;
}
.account-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.875rem; overflow-wrap: normal; }

/* The account menu. Unsupported popover → hidden unless .is-open (app.js fallback). */
.menu {
  display: none; position: fixed; inset: auto; margin: 0; z-index: 20;
  min-width: 240px; max-width: calc(100vw - 32px); padding: 6px;
  border: 1px solid var(--kit-line); border-radius: 12px;
  background: var(--kit-surface); color: var(--kit-text); box-shadow: var(--kit-shadow);
}
/* Two rules: a browser without :popover-open drops only the first. */
.menu:popover-open { display: block; }
.menu.is-open { display: block; }
.menu-email { padding: 10px 12px; color: var(--kit-muted); font-size: 0.875rem; border-bottom: 1px solid var(--kit-line); margin-bottom: 6px; }
.menu-item {
  display: block; width: 100%; padding: 10px 12px; border: 0; border-radius: 6px;
  background: none; text-align: left; cursor: pointer; font-size: 0.9375rem;
}
.menu-item:hover { background: var(--kit-surface-2); }
.menu-item:focus-visible { outline-offset: -2px; }

/* ---- offline, toast ---- */
.offline {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px 16px;
  padding: 10px 16px; background: var(--kit-warning-soft); color: var(--kit-text);
  border-bottom: 1px solid var(--kit-line); font-size: 0.9375rem;
}

/* ---- page ---- */
main { display: block; max-width: calc(var(--kit-width) + 48px); margin: 0 auto; padding: 40px 24px 96px; }
main:focus { outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 16px 24px; margin-bottom: 28px; }
.page-title { font-size: 1.875rem; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; }
.page-lead { margin-top: 8px; color: var(--kit-muted); max-width: 60ch; }

/* ---- licence card ---- */
.licences { display: grid; gap: 24px; }
.licence {
  padding: 24px; border: 1px solid var(--kit-line); border-radius: var(--kit-radius);
  background: var(--kit-surface);
}
.licence-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 16px; }
.licence-head h2 { font-size: 1.0625rem; font-weight: 650; margin-right: auto; }
.licence-head h2 + .tag { margin-right: auto; margin-left: -4px; }
.licence-head h2:has(+ .tag) { margin-right: 0; }

/* The key plate: the one loud thing on the page. */
.plate {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 14px 16px;
  padding: 16px; border-radius: 12px;
  background: var(--kit-plate-bg); color: var(--kit-plate-text);
  box-shadow: inset 0 0 0 1px var(--kit-plate-line), inset 0 1px 0 rgb(255 255 255 / 6%);
}
.plate :focus-visible { outline-color: var(--kit-plate-focus); }
.plate-code { min-width: 0; }
.plate-key {
  display: flex; flex-wrap: wrap; align-items: center; row-gap: 6px;
  font: 600 clamp(0.8125rem, 3.3vw, 1.3125rem)/1 var(--kit-font-key);
  letter-spacing: 0.06em; font-variant-numeric: tabular-nums slashed-zero;
}
.plate-group {
  padding: 0.42em 0.42em 0.38em 0.48em; border-radius: 6px;
  background: var(--kit-plate-cell); box-shadow: inset 0 0 0 1px var(--kit-plate-line);
  transition: color 0.2s ease;
}
.plate-group.is-hidden { color: var(--kit-plate-muted); }
.plate-dash { width: 0.7em; text-align: center; color: var(--kit-plate-muted); }
.plate-code.is-shown .plate-group { color: var(--kit-plate-text); user-select: all; }
.plate-actions { display: flex; gap: 8px; }
.btn-plate {
  min-height: 36px; padding: 0 12px; background: transparent; color: var(--kit-plate-text);
  border-color: var(--kit-plate-line); font-size: 0.875rem;
}
.btn-plate:hover { background: var(--kit-plate-cell); }
.btn-plate[aria-busy="true"]::after { border-color: var(--kit-plate-muted); border-right-color: transparent; }
.plate-missing { display: block; color: var(--kit-plate-text); }
.plate-missing .inline-link { color: var(--kit-plate-focus); }

.term { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 16px; margin-top: 16px; }
.term-text { max-width: 52ch; }
.term-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.block { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--kit-line); }
.block-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 12px; }
.block-head h3 { font-size: 0.9375rem; font-weight: 650; }
.block-count { display: inline-flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.block-note { margin-left: auto; color: var(--kit-muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.meter { display: inline-flex; gap: 3px; }
.pip { width: 10px; height: 10px; border-radius: 3px; box-shadow: inset 0 0 0 1.5px var(--kit-muted); opacity: 0.7; }
.pip.is-on { background: var(--kit-accent); box-shadow: none; opacity: 1; }

.devices li {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: 12px 0; border-top: 1px dashed var(--kit-line);
}
.devices li:first-child { border-top: 0; padding-top: 4px; }
.device-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; background: var(--kit-surface-2); color: var(--kit-muted); }
.device-name { font-weight: 560; }
.facts { display: flex; flex-wrap: wrap; gap: 2px 18px; margin-top: 2px; font-size: 0.875rem; }
.fact { display: flex; gap: 6px; }
.fact dt { color: var(--kit-muted); }
.note {
  margin-top: 12px; padding: 12px 14px; border-radius: 10px;
  background: var(--kit-warning-soft); font-size: 0.9375rem;
}

.payments li {
  display: grid; grid-template-columns: 1fr auto auto; gap: 4px 20px; align-items: baseline;
  padding: 8px 0; border-top: 1px dashed var(--kit-line); font-size: 0.9375rem;
}
.payments li:first-child { border-top: 0; padding-top: 0; }
.pay-amount { font-variant-numeric: tabular-nums; font-weight: 560; text-align: right; }
.pay-date { color: var(--kit-muted); font-variant-numeric: tabular-nums; text-align: right; min-width: 7.5em; }
.pay-status { margin-left: 8px; }
.pay-amount.is-void { color: var(--kit-muted); text-decoration: line-through; }

.licence-foot {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px;
  margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--kit-line); font-size: 0.9375rem;
}

/* ---- empty ---- */
.empty {
  padding: 40px 28px; border: 1px dashed var(--kit-line); border-radius: var(--kit-radius);
  background: var(--kit-surface);
}
.empty h2 { font-size: 1.25rem; font-weight: 650; margin-top: 24px; }
.empty p { margin-top: 8px; color: var(--kit-muted); max-width: 52ch; }
.empty .actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.empty-plate { display: flex; gap: 8px; max-width: 340px; }
.empty-plate span { flex: 1; height: 34px; border-radius: 6px; border: 1.5px dashed var(--kit-line); }

/* ---- sessions ---- */
.sessions { border: 1px solid var(--kit-line); border-radius: var(--kit-radius); background: var(--kit-surface); overflow: hidden; }
.session { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; padding: 16px 20px; }
.session + .session { border-top: 1px solid var(--kit-line); }
.session.is-current { box-shadow: inset 3px 0 0 var(--kit-accent); }
.session-main { min-width: 0; }
.session-name { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; font-weight: 600; }

/* ---- support: one conversation, the feed scrolls inside its panel (shared/chat.css) ---- */
.chat-log { height: clamp(300px, calc(100dvh - 470px), 640px); }

.chat-empty { margin: auto; max-width: 46ch; padding: 8px 0; color: var(--kit-muted); }
.chat-empty-mark {
  display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: 16px;
  border-radius: 12px; background: var(--kit-accent-soft); color: var(--kit-accent); font-size: 1.375rem;
}
.chat-empty h2 { color: var(--kit-text); font-size: 1.25rem; font-weight: 650; }
.chat-empty p { margin-top: 6px; }
.chat-empty ul { display: grid; gap: 6px; margin-top: 12px; }
.chat-empty li { position: relative; padding-left: 18px; color: var(--kit-text); }
.chat-empty li::before {
  content: ""; position: absolute; left: 2px; top: 0.6em; width: 7px; height: 7px;
  border-radius: 2px; background: var(--kit-accent);
}

.chat-legal { margin-top: 14px; color: var(--kit-muted); font-size: 0.875rem; max-width: 64ch; }

/* ---- loading, error ---- */
.skeleton-art, .ghost { display: grid; gap: 14px; }
.sk { display: block; border-radius: 8px; background: var(--kit-surface-2); }
.sk-title { width: 160px; height: 34px; }
.sk-line { width: min(380px, 80%); height: 16px; margin-bottom: 14px; }
.sk-card { height: 220px; border-radius: var(--kit-radius); border: 1px solid var(--kit-line); background: var(--kit-surface); }
.sk-short { height: 120px; }
.skeleton .sk {
  background-image: linear-gradient(90deg, transparent 0, color-mix(in srgb, var(--kit-line) 55%, transparent) 50%, transparent 100%);
  background-size: 200% 100%; background-repeat: no-repeat;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }
.ghost { opacity: 0.6; }
.state { padding: 32px 0; }
.state p { margin: 10px 0 20px; color: var(--kit-muted); max-width: 52ch; }

.signin { padding-top: 32px; }
.signin-product { font-weight: 700; color: var(--kit-muted); margin-bottom: 4px; }
.signin .sheet-title { font-size: 1.625rem; margin-bottom: 20px; }
.signin form .btn-wide { margin-top: 16px; min-height: 46px; }
.notice {
  margin-bottom: 16px; padding: 12px 14px; border-radius: 10px; border-left: 3px solid var(--kit-accent);
  background: var(--kit-surface-2); font-size: 0.9375rem;
}
.or { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--kit-muted); font-size: 0.875rem; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--kit-line); }
.btn-google { min-height: 46px; gap: 10px; }
.g-mark { width: 18px; height: 18px; }
.sent { margin-bottom: 16px; color: var(--kit-muted); }
.sent strong { color: var(--kit-text); font-weight: 600; }
.input-code {
  font: 600 1.625rem/1 var(--kit-font-key); letter-spacing: 0.45em; text-align: center; padding-left: 0.45em;
  font-variant-numeric: tabular-nums;
}
.check-slot { margin-top: 14px; min-height: 65px; }
.signin-links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; margin-top: 14px; }
.fine { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--kit-line); color: var(--kit-muted); font-size: 0.875rem; }
.noscript { margin: 40px auto; max-width: 480px; padding: 0 16px; }

/* ---- tablets: the account button shows the initial only (the email is in its menu) ---- */
@media (max-width: 760px) {
  .account { padding-right: 3px; }
  .account-email { display: none; }
}

/* ---- narrow screens (to 320px) ---- */
@media (max-width: 640px) {
  .bar-inner {
    display: grid; grid-template-columns: 1fr auto; grid-template-areas: "brand end" "tabs tabs";
    gap: 0 12px; padding: 0 16px; min-height: 0;
  }
  .brand { grid-area: brand; padding: 12px 0; }
  .bar-end { grid-area: end; }
  .tabs { grid-area: tabs; margin: 0 -16px; padding: 0 4px; border-top: 1px solid var(--kit-line); }
  .tabs a { flex: 1; justify-content: center; min-height: 44px; }
  main { padding: 28px 16px 88px; }
  .page-title { font-size: 1.625rem; }
  .licence { padding: 18px 16px; }
  .plate { padding: 14px 12px; }
  .plate-key { font-size: clamp(0.6875rem, 3.35vw, 1rem); }
  .plate-group { padding: 0.42em 0.3em 0.38em 0.36em; }
  .plate-dash { width: 0.5em; }
  .plate-actions { width: 100%; }
  .plate-actions .btn { flex: 1; }
  /* The shared .btn rule (44px) loads first now; these two used to lose to it. */
  .btn-plate, .btn-google { min-height: 44px; }
  .term-actions { width: 100%; }
  .term-actions .btn { flex: 1 1 auto; }
  .block-note { margin-left: 0; width: 100%; }
  .devices li { grid-template-columns: 1fr auto; }
  .device-icon { display: none; }
  .payments li { grid-template-columns: 1fr auto; }
  .pay-date { grid-column: 1 / -1; text-align: left; }
  .session { flex-direction: column; align-items: stretch; padding: 16px; }
  .session .btn { align-self: flex-start; }
  .empty { padding: 28px 18px; }
  .tabs a { padding: 0 6px; }
  .chat-log { height: clamp(260px, calc(100dvh - 450px), 560px); }
}

@media (prefers-reduced-motion: reduce) {
  .btn-plate[aria-busy="true"]::after { border-right-color: currentColor; }
}

@media (forced-colors: active) {
  .tab-badge { forced-color-adjust: none; background: CanvasText; color: Canvas; }
  .pip.is-on { background: CanvasText; }
}
