/* TGist design system: tokens, base, components. No build step, no inline styles (strict CSP). */

:root {
  color-scheme: light dark;

  /* light theme */
  --bg: #f5f7fb;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --border: #dde4ef;
  --border-strong: #c3cede;
  --control-border: #7c8da5; /* 3:1 against the surfaces controls sit on (WCAG 1.4.11) */
  --text: #0e1626;
  --text-muted: #55657d;
  --brand: #0a74a8;
  --brand-hover: #085f8b;
  --brand-soft: #e3f3fb;
  --accent: #5b4bd8;
  --success: #0d6b3c;
  --success-soft: #e0f6ea;
  --warning: #a35a00;
  --warning-soft: #fff1d6;
  --danger: #c02626;
  --danger-solid: #c02626;
  --danger-soft: #fde6e6;
  --ring: rgba(10, 116, 168, 0.55);
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2355657d' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  --shadow-sm: 0 1px 2px rgba(14, 22, 38, 0.06), 0 1px 3px rgba(14, 22, 38, 0.06);
  --shadow-md: 0 8px 24px rgba(14, 22, 38, 0.08);
  --shadow-lg: 0 24px 60px rgba(14, 22, 38, 0.14);
  --grad: linear-gradient(135deg, #0a74a8 0%, #5b4bd8 100%);
  --grad-text: linear-gradient(120deg, #0a74a8 10%, #5b4bd8 90%);
  --hero-glow: radial-gradient(60% 60% at 50% 0%, rgba(91, 75, 216, 0.16), transparent 70%);

  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 22px;
  --container: 1120px;
  --header-h: 64px;
  --font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #080d17;
    --bg-elevated: #0d1424;
    --surface: #101a2d;
    --surface-2: #16223a;
    --border: #22314d;
    --border-strong: #33466a;
    --control-border: #5d7295;
    --text: #eef3fb;
    --text-muted: #9aabc4;
    --brand: #4cb8ee;
    --brand-hover: #74c9f3;
    --brand-soft: rgba(76, 184, 238, 0.14);
    --accent: #9a8cff;
    --success: #4bd08a;
    --success-soft: rgba(75, 208, 138, 0.14);
    --warning: #f0b555;
    --warning-soft: rgba(240, 181, 85, 0.14);
    --danger: #ff7b7b;
    --danger-solid: #c53030;
    --danger-soft: rgba(255, 123, 123, 0.14);
    --ring: rgba(76, 184, 238, 0.6);
    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239aabc4' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.5);
    --grad-text: linear-gradient(120deg, #5cc4f5 10%, #a99cff 90%);
    --hero-glow: radial-gradient(60% 60% at 50% 0%, rgba(120, 100, 255, 0.28), transparent 70%);
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 12px);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

img,
svg {
  display: block;
  max-width: 100%;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.15;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

p {
  margin: 0;
  text-wrap: pretty;
}

a {
  color: var(--brand);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  color: var(--brand-hover);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  /* solid brand outline (4.8:1 light / 8.7:1 dark) plus a page-coloured halo so it reads on any background */
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--bg);
  border-radius: 6px;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  transition: top 0.15s;
}

.skip-link:focus {
  top: 12px;
  color: #fff;
}

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: max(20px, env(safe-area-inset-left)) max(20px, env(safe-area-inset-right));
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: var(--header-h);
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.site-header .container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding-block: 6px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  min-height: 44px;
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: -0.03em;
  text-decoration: none;
}

.brand:hover {
  color: var(--text);
}

.brand img {
  width: 32px;
  height: 32px;
}

.brand-tag {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--brand);
  background: var(--brand-soft);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 650;
  font-size: 0.95rem;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  max-width: 100%;
  transition: transform 0.12s ease, background-color 0.15s, border-color 0.15s, box-shadow 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.btn-primary {
  color: #fff;
  background: var(--grad);
  box-shadow: 0 6px 18px rgba(10, 116, 168, 0.28);
}

.btn-primary:hover:not(:disabled) {
  color: #fff;
  box-shadow: 0 8px 24px rgba(10, 116, 168, 0.4);
  filter: brightness(1.06);
}

.btn-secondary {
  color: var(--text);
  background: var(--surface);
  border-color: var(--control-border);
}

.btn-secondary:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-2);
}

.btn-ghost {
  color: var(--text-muted);
  background: transparent;
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-2);
}

.btn-danger {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

.btn-danger:hover:not(:disabled) {
  color: #fff;
  background: var(--danger-solid);
}

.btn-sm {
  min-height: 36px;
  padding: 0 14px;
  font-size: 0.85rem;
}

.btn-lg {
  min-height: 54px;
  padding: 12px 28px;
  font-size: 1.05rem;
  line-height: 1.25;
  text-align: center;
  white-space: normal;
  border-radius: var(--radius);
}

.btn-icon {
  width: 44px;
  padding: 0;
  flex: none;
}

.btn-icon.btn-sm {
  width: 36px;
}

.btn.is-loading {
  pointer-events: none;
  opacity: 0.75;
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Language switch ---------- */

.lang-switch {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

.lang-switch button {
  min-width: 44px;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.lang-switch button[aria-pressed='true'] {
  background: var(--brand-soft);
  color: var(--brand);
}

/* ---------- Cards, badges, forms ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-pad {
  padding: 20px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--text-muted);
  background: var(--surface-2);
  white-space: nowrap;
}

.badge-brand {
  color: var(--brand);
  background: var(--brand-soft);
}
.badge-success {
  color: var(--success);
  background: var(--success-soft);
}
.badge-warning {
  color: var(--warning);
  background: var(--warning-soft);
}
.badge-danger {
  color: var(--danger);
  background: var(--danger-soft);
}

.field {
  display: grid;
  gap: 6px;
}

.field > label,
.label {
  font-size: 0.85rem;
  font-weight: 650;
}

.hint {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  /* 16px stops iOS from zooming the page when a field is focused */
  font-size: 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.textarea {
  padding-block: 10px;
  min-height: 96px;
}

.input::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--brand);
}

.input[aria-invalid='true'] {
  border-color: var(--danger);
}

.select {
  appearance: none;
  padding-right: 38px;
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.select-sm {
  min-height: 36px;
  font-size: 14px;
}

.field-error {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--danger);
}

.search {
  position: relative;
}

.search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search .input {
  padding-left: 40px;
}

/* ---------- Chips ---------- */

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
}

.chips > * {
  scroll-snap-align: start;
}

@media (min-width: 760px) {
  .chips {
    -webkit-mask-image: none;
    mask-image: none;
  }
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: none;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--control-border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 650;
  white-space: nowrap;
}

.chip[aria-pressed='true'] {
  color: var(--brand);
  border-color: var(--brand);
  background: var(--brand-soft);
}

/* ---------- Avatar ---------- */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 50%;
  overflow: hidden;
  font-size: 0.85rem;
  font-weight: 800;
  color: #fff;
  background: var(--grad);
  object-fit: cover;
}

.avatar-lg {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  font-size: 1rem;
}

/* ---------- Dialog ---------- */

dialog.modal {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: auto;
}

dialog.modal::backdrop {
  background: rgba(4, 8, 16, 0.6);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

dialog.modal[open] {
  animation: pop 0.18s ease-out;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 22px 0;
}

.modal-head h2 {
  font-size: 1.25rem;
}

.modal-body {
  padding: 14px 22px 4px;
  display: grid;
  gap: 14px;
}

.modal-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  padding: 18px 22px 22px;
}

/* ---------- Toasts ---------- */

.toast-region {
  position: fixed;
  z-index: 200;
  inset: auto 16px max(16px, env(safe-area-inset-bottom)) 16px;
  width: auto;
  height: auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
  display: grid;
  justify-items: end;
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 420px;
  padding: 12px 16px;
  border: 1px solid var(--border-strong);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-md);
  font-size: 0.92rem;
  font-weight: 550;
  pointer-events: auto;
  animation: pop 0.2s ease-out;
}

.toast-success {
  border-left-color: var(--success);
}
.toast-error {
  border-left-color: var(--danger);
}
.toast-info {
  border-left-color: var(--brand);
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

table.data th {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-2);
  white-space: nowrap;
}

table.data th button {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
}

table.data td {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}

table.data tbody tr:hover {
  background: color-mix(in srgb, var(--surface-2) 55%, transparent);
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.86em;
}

.muted {
  color: var(--text-muted);
}

.truncate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- States ---------- */

.empty {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 44px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty h3 {
  color: var(--text);
  font-size: 1.1rem;
}

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, color-mix(in srgb, var(--surface-2) 60%, var(--surface)) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

.alert {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 550;
}

.alert-warning {
  color: var(--warning);
  background: var(--warning-soft);
}
.alert-danger {
  color: var(--danger);
  background: var(--danger-soft);
}
.alert-info {
  color: var(--brand);
  background: var(--brand-soft);
}

/* ---------- Layout helpers ---------- */

.stack {
  display: grid;
  gap: 16px;
}
.stack-lg {
  display: grid;
  gap: 28px;
}
.row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.row-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}
.spacer {
  flex: 1;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- App shell (signed-in pages) ---------- */

.app-nav {
  display: none;
  gap: 4px;
  margin-right: auto;
  margin-left: 16px;
}

.app-nav-link {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 650;
  font-size: 0.92rem;
  text-decoration: none;
}

.app-nav-link:hover {
  color: var(--text);
  background: var(--surface-2);
}

.app-nav-link.is-active {
  color: var(--brand);
  background: var(--brand-soft);
}

.menu {
  position: relative;
}

.menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  padding: 0 6px 0 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

.menu-chevron {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 60;
  width: min(280px, calc(100vw - 32px));
  display: grid;
  gap: 4px;
  padding: 10px;
  box-shadow: var(--shadow-lg);
}

.menu-user {
  display: grid;
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--border);
}

.menu-links {
  display: grid;
  padding: 6px 0;
}

.menu-links .app-nav-link {
  display: block;
}

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
}

.menu-signout {
  justify-content: flex-start;
  width: 100%;
}

.app-bot-link {
  display: none;
}

@media (min-width: 760px) {
  .app-nav {
    display: flex;
  }
  .app-bot-link {
    display: inline-flex;
  }
  .menu-links {
    display: none;
  }
}

/* ---------- Accessibility helpers ---------- */

h1,
h2,
h3 {
  overflow-wrap: anywhere;
}

/* text links that act like controls: give them a real touch target */
.tap {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

@media (forced-colors: active) {
  .grad {
    color: CanvasText;
    -webkit-text-fill-color: CanvasText;
    background: none;
  }
}

.toast-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.toast-close {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  margin: -4px -8px -4px 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
}

.toast-close:hover {
  color: var(--text);
  background: var(--surface-2);
}

.toast-close svg {
  width: 16px;
  height: 16px;
}
