/* The Terms and Conditions gate (JS/components/terms-gate.js). A new sheet because the gate must draw before any
   shell mounts, on the phone (which loads none of components.css or the alt sheets) and on login.html (which loads
   no application stylesheet). The only styling every host shares is tokens.css, or login.css's mirror of it, so the
   --tg-* properties below resolve from the app token and fall back to login.css's name, then to the dark value.
   They are declared on .tg-scrim, a descendant of <body>, so a body.theme-light still re-themes them.
   Nothing under 11px. Light values are written for :root.theme-light AND body.theme-light. */

.tg-scrim{
  --tg-bg:var(--bg, #0a1628);
  --tg-panel:var(--panel, var(--surface, #101f36));
  --tg-panel-2:var(--panel-2, var(--surface-2, #16283f));
  --tg-border:var(--border, var(--border-mid, #395379));
  --tg-border-soft:var(--border-soft, var(--border, #294263));
  --tg-border-strong:var(--border-strong, #4e71a5);
  --tg-text:var(--text, #f4f6fb);
  --tg-dim:var(--text-dim, var(--text-2, #a9b6cc));
  --tg-faint:var(--text-faint, var(--text-3, #8390a5));
  --tg-accent:var(--accent, var(--blue, #3b82f6));
  --tg-accent-fill:var(--accent-fill, var(--blue-fill, #1e6ff5));
  --tg-accent-text:var(--accent-text, var(--blue-text, #70a4f8));
  --tg-accent-soft:var(--accent-soft, var(--blue-soft, rgba(59,130,246,.20)));
  --tg-ring:var(--focus-ring);
  --tg-red:var(--red, #d13438);
  --tg-red-text:var(--red-text, var(--red, #e07577));
  --tg-red-soft:var(--red-soft, rgba(209,52,56,.16));
  --tg-green-text:var(--green-text, #17b35e);
  --tg-r-sm:var(--a-r-sm);
  --tg-display:var(--display, 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif);
  --tg-body:var(--body, 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif);
  --tg-scrim:rgba(4,10,20,.66);
  --tg-shadow:0 18px 48px rgba(0,0,0,.45);
  /* The browser draws scrollbars and native checkboxes from `color-scheme`, and a host that loads no
     CSS/base.css (login.html) never declared one: the terms text got a white track and the agree box a white
     square on the dark dialog. Declared here so the gate follows the theme on every host. */
  color-scheme:dark;
}
:root.theme-light .tg-scrim, body.theme-light .tg-scrim{
  color-scheme:light;
  --tg-scrim:rgba(20,30,48,.46);
  --tg-shadow:0 18px 48px rgba(19,32,54,.22);
}

.tg-scrim{
  position:fixed; inset:0; display:grid; place-items:center; padding:16px; box-sizing:border-box;
  background:var(--tg-scrim); font:14px/1.45 var(--tg-body); color:var(--tg-text);
}
/* The required gate is a curtain; the read-only view is an ordinary dialog and the layer stack raises it. */
.tg-scrim.tg-required{ z-index:var(--z-boot, 9999); }
.tg-scrim.tg-read{ z-index:var(--z-dialog, 300); }
.tg-scrim *, .tg-scrim *::before, .tg-scrim *::after{ box-sizing:border-box; }
.tg-hidden{ display:none !important; }
/* The scrollbar of CSS/base.css (sys_design-system.md §2), restated on the gate's own tokens: --tg-border and
   --tg-border-strong resolve to the same --border and --border-strong. Covers the terms text, the table wrap
   and the dialog itself when a short viewport makes it scroll. */
.tg-scrim, .tg-scrim *{ scrollbar-width:thin; scrollbar-color:var(--tg-border) transparent; }
.tg-scrim ::-webkit-scrollbar{ width:9px; height:9px; }
.tg-scrim ::-webkit-scrollbar-thumb{ background:var(--tg-border); border-radius:var(--tg-r-sm); }
.tg-scrim ::-webkit-scrollbar-thumb:hover{ background:var(--tg-border-strong); }
.tg-scrim ::-webkit-scrollbar-track, .tg-scrim ::-webkit-scrollbar-corner{ background:transparent; }

.tg-dialog{
  width:min(640px, 100%); max-height:100%; display:flex; flex-direction:column;
  background:var(--tg-panel); border:1px solid var(--tg-border); border-radius:14px;
  box-shadow:var(--tg-shadow); overflow:hidden;
}
.tg-head{ padding:18px 20px 12px; border-bottom:1px solid var(--tg-border-soft); }
.tg-brand{
  display:flex; align-items:center; gap:8px; margin-bottom:10px;
  font:700 13px/1 var(--tg-display); color:var(--tg-dim);
}
.tg-mark{
  width:22px; height:22px; border-radius:6px; display:grid; place-items:center;
  background:var(--tg-accent-fill); color:#fff; font:800 12px/1 var(--tg-display);
}
.tg-title-row{ display:flex; align-items:baseline; gap:10px; flex-wrap:wrap; }
.tg-title{ margin:0; font:600 19px/1.25 var(--tg-display); color:var(--tg-text); }
.tg-ver{ font:600 12px/1 var(--tg-body); color:var(--tg-faint); white-space:nowrap; }
.tg-lede{ margin:6px 0 0; color:var(--tg-dim); font-size:13.5px; }
.tg-change{
  margin:10px 0 0; padding:8px 10px; border-radius:var(--tg-r-sm);
  background:var(--tg-accent-soft); color:var(--tg-text); font-size:13px;
}
.tg-read-status{ margin:8px 0 0; font-size:13px; color:var(--tg-dim); }
.tg-what{ margin:8px 0 0; font-size:13px; color:var(--tg-dim); }
.tg-what summary{ cursor:pointer; color:var(--tg-accent-text); font-weight:600; }
.tg-what summary:focus-visible{ outline:2px solid var(--tg-ring); outline-offset:2px; }

.tg-scroll{
  flex:1 1 auto; min-height:120px; overflow:auto; margin:12px 20px 0; padding:4px 16px 12px;
  border:1px solid var(--tg-border); border-radius:var(--tg-r-sm); background:var(--tg-bg);
  overscroll-behavior:contain;
}
.tg-scroll:focus-visible{ outline:2px solid var(--tg-ring); outline-offset:2px; }
.tg-body{ min-width:0; }
.tg-h{ color:var(--tg-text); }
h2.tg-h{ font:600 17px/1.3 var(--tg-display); margin:12px 0 4px; }
h3.tg-h{ font:600 15px/1.3 var(--tg-display); margin:16px 0 6px; }
h4.tg-h{ font:600 14px/1.3 var(--tg-display); margin:12px 0 4px; }
.tg-p, .tg-list li{ font-size:15px; line-height:1.55; color:var(--tg-text); margin:0 0 8px; }
.tg-list{ margin:0 0 8px; padding-left:20px; }
.tg-copy{ margin:8px 0 0; text-align:center; font-size:12px; line-height:1.5; color:var(--tg-faint); }
.tg-link{ color:var(--tg-accent-text); text-decoration:underline; overflow-wrap:anywhere; }
.tg-link:focus-visible{ outline:2px solid var(--tg-ring); outline-offset:2px; }
.tg-table-wrap{ overflow-x:auto; margin:0 0 10px; }
.tg-table{ border-collapse:collapse; width:100%; font-size:13px; line-height:1.45; }
.tg-table th, .tg-table td{ text-align:left; vertical-align:top; padding:6px 8px; border:1px solid var(--tg-border-soft); color:var(--tg-text); }
.tg-table th{ background:var(--tg-panel-2); color:var(--tg-dim); font-weight:700; }
.tg-end{
  margin:18px 0 4px; text-align:center; font:600 12px/1 var(--tg-body); color:var(--tg-faint);
  letter-spacing:.06em; text-transform:uppercase;
}
.tg-skel{ padding-top:8px; }
.tg-skel i{ display:block; height:12px; margin:10px 0; border-radius:6px; background:var(--tg-panel-2); }
.tg-skel i.short{ width:60%; }
.tg-err-box{ padding:28px 8px; text-align:center; color:var(--tg-dim); }

.tg-foot{ padding:12px 20px 16px; display:flex; flex-direction:column; gap:10px; }
.tg-status{ display:flex; align-items:center; gap:6px; font-size:13px; color:var(--tg-dim); min-height:18px; }
.tg-status.done{ color:var(--tg-green-text); }
.tg-check{ display:flex; align-items:flex-start; gap:9px; font-size:14px; color:var(--tg-text); cursor:pointer; }
/* The native checkbox at the application's size (DS-30: 16px, accent fill when checked); its edge follows the
   gate's color-scheme, so it is a themed box in both themes rather than the browser's white default. */
.tg-check input{ width:var(--a-check); height:var(--a-check); margin:2px 0 0; accent-color:var(--tg-accent-fill); flex:none; cursor:pointer; }
.tg-check[aria-disabled="true"]{ color:var(--tg-faint); cursor:not-allowed; }
.tg-check[aria-disabled="true"] input{ opacity:.45; cursor:not-allowed; }
.tg-check input:focus-visible{ outline:2px solid var(--tg-ring); outline-offset:2px; }
.tg-who{ font-size:12px; color:var(--tg-faint); overflow-wrap:anywhere; min-width:0; }
.tg-row{ display:flex; align-items:center; gap:10px; justify-content:flex-end; flex-wrap:wrap; }
.tg-row .tg-who{ margin-right:auto; flex:1 1 12rem; }
.tg-err{
  font-size:13px; color:var(--tg-red-text); background:var(--tg-red-soft); border:1px solid var(--tg-red);
  border-radius:var(--tg-r-sm); padding:6px 10px;
}
.tg-sr{ position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }

/* .tg-btn is the Suite's lg rung (`.alt-app .btn` + `.a-btn.lg`: 36px, 13px/600, 0 12px) with the colours of the dialog `.btn`
   (alt-shared-dialogs.css). Its tokens come from tokens.css (the phone, the suite) or from login.css's mirror of them; a test pins the copy. */
.tg-btn{
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
  background:var(--tg-panel); border:1px solid var(--tg-border-strong); color:var(--tg-text);
  border-radius:var(--a-r-sm); font-family:var(--app-font); font-size:var(--a-fs-ctl); font-weight:var(--a-fw-ctl); line-height:var(--a-lh-ctl);
  height:var(--a-ctl-lg); padding:0 12px; cursor:pointer;
}
.tg-btn:hover{ border-color:var(--tg-accent); color:var(--tg-accent-text); }
.tg-btn.primary{ background:var(--tg-accent-fill); border-color:transparent; color:#fff; min-width:96px; }
.tg-btn.primary:hover{ filter:brightness(1.06); color:#fff; }
.tg-btn[aria-disabled="true"]{ opacity:.45; cursor:not-allowed; }
.tg-btn[aria-disabled="true"]:hover{ border-color:var(--tg-border-strong); color:var(--tg-text); filter:none; }
.tg-btn.primary[aria-disabled="true"]:hover{ border-color:transparent; color:#fff; }
.tg-btn:focus-visible{ outline:2px solid var(--tg-ring); outline-offset:2px; }
.tg-x{
  width:32px; height:32px; margin-left:auto; border-radius:var(--tg-r-sm); border:1px solid transparent;
  background:transparent; color:var(--tg-dim); font-size:15px; cursor:pointer;
}
.tg-x:hover{ border-color:var(--tg-border); }
.tg-x:focus-visible{ outline:2px solid var(--tg-ring); outline-offset:2px; }
.tg-spin{
  width:12px; height:12px; border-radius:50%; border:2px solid currentColor; border-right-color:transparent;
  display:inline-block; animation:tg-spin .8s linear infinite;
}
@keyframes tg-spin{ to{ transform:rotate(360deg); } }
@media (prefers-reduced-motion:reduce){ .tg-spin{ animation-duration:2.4s; } }

/* Narrow: a full-height sheet, a 16px gutter, a sticky footer and buttons at least 44px tall. */
@media (max-width:639px){
  .tg-scrim{ padding:0; place-items:stretch; }
  .tg-dialog{ width:100%; max-height:none; height:100%; border-radius:0; border:0; }
  .tg-head{ padding:16px 16px 10px; }
  .tg-scroll{ margin:10px 16px 0; padding:2px 12px 10px; }
  .tg-p, .tg-list li{ font-size:16px; }
  .tg-foot{ padding:10px 16px 16px; border-top:1px solid var(--tg-border-soft); }
  .tg-row{ display:grid; grid-template-columns:1fr 1fr; }
  .tg-row .tg-who{ grid-column:1 / -1; margin-right:0; }
  .tg-read .tg-row{ display:flex; }
  .tg-btn{ height:44px; font-size:15px; }
  .tg-x{ width:44px; height:44px; }
}

/* Short viewports (200% browser zoom on a laptop, a phone on its side): the footer must stay reachable, so the
   header and footer tighten and the dialog scrolls as a whole when even that is not enough. */
@media (max-height:560px){
  .tg-dialog{ overflow-y:auto; }
  .tg-brand{ display:none; }
  .tg-head{ padding:10px 16px 8px; }
  .tg-lede{ margin-top:4px; font-size:12.5px; }
  .tg-scroll{ flex:none; height:max(120px, 38vh); margin:8px 16px 0; }
  .tg-foot{ gap:6px; padding:8px 16px 10px; }
  .tg-status{ min-height:0; }
}
