/*
 * The look of every shared component. Tokens first (the same palette the
 * pages carry; see docs/design.md), then each component under a tg- prefix.
 * A page that loads this file gets the components looking right; a page may
 * still override a token in its own :root.
 */

:root {
  --ink: #0a0a0a; --ink-2: #404040; --muted: #525252; --subtle: #737373;
  --line: #eaeaea; --line-soft: #f0f0f0;
  --surface: #ffffff; --surface-2: #fafafa; --surface-3: #f4f4f4;
  --accent: #d4ff3a;
  --good: #15803d; --good-wash: #f0fdf4;
  --warn: #a16207; --warn-wash: #fffbeb;
  --bad: #b91c1c; --bad-wash: #fef2f2;
  --radius-card: 12px; --radius-control: 8px;
  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* The pages set this on everything; a component does not rely on it. */
.tg-field, .tg-field *, .tg-btn, .tg-icon-btn { box-sizing: border-box; }

/* Visible to assistive technology only. */
.tg-sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Focus is always visible, and never removed. */
.tg-field :focus-visible, .tg-btn:focus-visible, .tg-icon-btn:focus-visible {
  outline: 2px solid var(--ink); outline-offset: 2px;
}

.tg-icon { width: 16px; height: 16px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
tg-icon { display: inline-flex; vertical-align: middle; }

/* ---------- Field: label, control, hint, error ---------- */

.tg-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; font-family: var(--font-sans); }
.tg-field[hidden] { display: none; }
.tg-label { font-size: 13px; font-weight: 500; color: var(--ink); }
.tg-required { color: var(--bad); }
.tg-hint { font-size: 12px; color: var(--subtle); }
.tg-error { font-size: 12px; color: var(--bad); }
.tg-hint[hidden], .tg-error[hidden], .tg-label[hidden] { display: none; }

.tg-control { position: relative; display: flex; align-items: center; min-width: 0; }

.tg-field input, .tg-field select, .tg-field textarea {
  width: 100%; height: 36px; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius-control); padding: 0 12px; color: var(--ink);
  font-size: 14px; font-family: inherit; line-height: 1.5;
}
.tg-field textarea { height: auto; min-height: 72px; padding: 8px 12px; resize: vertical; }
.tg-field input:focus, .tg-field select:focus, .tg-field textarea:focus {
  outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(10, 10, 10, .06);
}
.tg-field input::placeholder, .tg-field textarea::placeholder { color: #a3a3a3; }

.tg-invalid input, .tg-invalid select, .tg-invalid textarea { border-color: var(--bad); }
.tg-invalid .tg-label { color: var(--bad); }
.tg-invalid input:focus, .tg-invalid select:focus, .tg-invalid textarea:focus { box-shadow: 0 0 0 3px rgba(185, 28, 28, .12); }

.tg-disabled .tg-label, .tg-disabled .tg-hint { opacity: .6; }
.tg-field input:disabled, .tg-field select:disabled, .tg-field textarea:disabled {
  background: var(--surface-2); color: var(--subtle); cursor: not-allowed;
}

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

.tg-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 16px; border-radius: var(--radius-control);
  font: 500 13px var(--font-sans); border: 1px solid transparent; cursor: pointer;
}
.tg-btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.tg-btn-primary:hover { background: var(--ink-2); border-color: var(--ink-2); }
.tg-btn-secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.tg-btn-secondary:hover { background: var(--surface-2); }
.tg-btn:disabled { opacity: .5; cursor: not-allowed; }
.tg-icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px;
  background: transparent; color: var(--subtle); cursor: pointer;
}
.tg-icon-btn:hover { background: var(--surface-3); color: var(--ink); }

/* ---------- Flag ---------- */

.tg-flag { display: inline-block; width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0; vertical-align: middle; box-shadow: 0 0 0 1px rgba(10, 10, 10, .08); object-fit: cover; }
.tg-flag-none { background: var(--surface-3); }
tg-flag { display: inline-flex; vertical-align: middle; }

/* ---------- Listbox (country and phone pickers) ---------- */

.tg-listbox {
  position: absolute; z-index: 1000; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 28px rgba(10, 10, 10, .14); font-family: var(--font-sans);
  display: flex; flex-direction: column; max-height: 320px; overflow: hidden;
}
.tg-listbox-search { border: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; font: 14px var(--font-sans); outline: none; border-radius: 10px 10px 0 0; }
.tg-listbox-list { list-style: none; margin: 0; padding: 4px; overflow-y: auto; }
.tg-listbox-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; font-size: 14px; cursor: pointer; }
.tg-listbox-list li.tg-active { background: var(--surface-3); }
.tg-listbox-list li[aria-selected="true"] { font-weight: 600; }
.tg-opt-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-opt-dial { color: var(--subtle); font-variant-numeric: tabular-nums; }
.tg-listbox-empty { padding: 14px; font-size: 13px; color: var(--subtle); text-align: center; }

/* ---------- Select button (country) ---------- */

.tg-select-btn {
  width: 100%; height: 36px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 10px 0 12px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-control);
  font: 14px var(--font-sans); color: var(--ink); cursor: pointer; text-align: left;
}
.tg-select-btn:focus-visible { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(10, 10, 10, .06); }
.tg-select-btn:disabled { background: var(--surface-2); color: var(--subtle); cursor: not-allowed; }
.tg-sel-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tg-sel-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-placeholder { color: #a3a3a3; }
.tg-select-btn .tg-icon { color: var(--subtle); }
.tg-invalid .tg-select-btn { border-color: var(--bad); }

/* ---------- Phone ---------- */

.tg-phone { display: flex; width: 100%; min-width: 0; }
.tg-phone-cc {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 8px 0 10px; flex-shrink: 0;
  background: var(--surface-2); border: 1px solid var(--line); border-right: 0;
  border-radius: var(--radius-control) 0 0 var(--radius-control); font: 14px var(--font-sans); color: var(--ink); cursor: pointer;
}
.tg-phone-cc:hover:not(:disabled) { background: var(--surface-3); }
.tg-phone-cc:disabled { cursor: not-allowed; opacity: .6; }
.tg-phone-cc:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.tg-cc-dial { font-variant-numeric: tabular-nums; }
.tg-phone-cc .tg-icon { width: 14px; height: 14px; color: var(--subtle); }
.tg-phone input { border-radius: 0 var(--radius-control) var(--radius-control) 0; min-width: 0; font-variant-numeric: tabular-nums; }
.tg-invalid .tg-phone-cc { border-color: var(--bad); }

/* ---------- Password ---------- */

.tg-password { width: 100%; }
.tg-pw-row { position: relative; display: flex; align-items: center; }
.tg-pw-row input { padding-right: 44px; }
.tg-pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.tg-pw-meta { display: flex; justify-content: space-between; gap: 12px; min-height: 0; font-size: 12px; margin-top: 4px; }
.tg-pw-meta:empty, .tg-pw-meta > :empty { display: none; }
.tg-pw-caps { color: var(--warn); }
.tg-pw-strength[data-score="1"] { color: var(--bad); }
.tg-pw-strength[data-score="2"] { color: var(--warn); }
.tg-pw-strength[data-score="3"], .tg-pw-strength[data-score="4"] { color: var(--good); }
.tg-pw-confirm { margin-top: 12px; }

/* ---------- Secret ---------- */

.tg-secret { display: flex; align-items: center; gap: 4px; width: 100%; }
.tg-secret input { flex: 1; font-family: var(--font-mono); font-size: 13px; background: var(--surface-2); }

/* ---------- Money ---------- */

.tg-money { position: relative; display: flex; align-items: center; width: 100%; }
.tg-money-sym { position: absolute; left: 12px; color: var(--subtle); font-size: 14px; pointer-events: none; }
.tg-money input { padding-left: 32px; font-variant-numeric: tabular-nums; }

/* ---------- One-time code ---------- */

.tg-otp { display: flex; gap: 8px; width: 100%; min-width: 0; }
.tg-field .tg-otp-box { flex: 1 1 0; min-width: 0; max-width: 48px; width: auto; height: 48px; padding: 0; text-align: center; font: 600 20px var(--font-mono); }
.tg-field .tg-otp-recovery { text-transform: uppercase; letter-spacing: .08em; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Danger button ---------- */
.tg-btn-danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.tg-btn-danger:hover { background: #991b1b; border-color: #991b1b; }

/* ---------- Dialog ---------- */
.tg-dialog { margin: auto; border: 1px solid var(--line); border-radius: var(--radius-card); padding: 0; width: calc(100% - 32px); color: var(--ink); background: #fff; box-shadow: 0 20px 50px rgba(10, 10, 10, .18); font-family: var(--font-sans); }
.tg-dialog::backdrop { background: rgba(10, 10, 10, .4); }
.tg-dialog, .tg-dialog * { box-sizing: border-box; }
.tg-dialog-sm { max-width: 400px; } .tg-dialog-md { max-width: 520px; } .tg-dialog-lg { max-width: 760px; }
.tg-dialog-form { margin: 0; display: flex; flex-direction: column; max-height: calc(100vh - 64px); }
.tg-dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 20px 0; }
.tg-dialog-title { margin: 0; font: 600 16px/1.3 var(--font-sans); }
.tg-dialog-x { margin-left: auto; }
.tg-dialog-body { padding: 12px 20px 4px; overflow: auto; font-size: 14px; color: var(--ink-2); }
.tg-dialog-body p { margin: 0 0 12px; }
.tg-dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px 20px; flex-wrap: wrap; }
.tg-dialog :focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.tg-confirm-input { width: 100%; height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius-control); font: 14px var(--font-sans); margin-top: 6px; }

/* ---------- Toast ---------- */
.tg-toasts { position: fixed; right: 16px; bottom: 16px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100vw - 32px)); }
.tg-toast { display: flex; align-items: flex-start; gap: 10px; padding: 12px; background: #fff; border: 1px solid var(--line); border-left-width: 3px; border-radius: var(--radius-control); box-shadow: 0 8px 24px rgba(10, 10, 10, .12); font: 13px/1.4 var(--font-sans); color: var(--ink); box-sizing: border-box; }
.tg-toast-success { border-left-color: var(--good); } .tg-toast-success .tg-toast-icon { color: var(--good); }
.tg-toast-error { border-left-color: var(--bad); } .tg-toast-error .tg-toast-icon { color: var(--bad); }
.tg-toast-warning { border-left-color: var(--warn); } .tg-toast-warning .tg-toast-icon { color: var(--warn); }
.tg-toast-info { border-left-color: var(--ink); }
.tg-toast-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.tg-toast-ref { display: block; margin-top: 2px; font: 11px var(--font-mono); color: var(--subtle); }
.tg-toast-action { background: none; border: 0; padding: 0 4px; font: 600 13px var(--font-sans); color: var(--ink); text-decoration: underline; cursor: pointer; }
.tg-toast .tg-icon-btn { width: 22px; height: 22px; }

/* ---------- Alert ---------- */
.tg-alert { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-control); font: 13px/1.5 var(--font-sans); background: var(--surface-2); color: var(--ink); box-sizing: border-box; }
.tg-alert-main { flex: 1; min-width: 0; }
.tg-alert-title { font-weight: 600; }
.tg-alert-end a, .tg-alert-end button { font-weight: 600; color: inherit; }
.tg-alert-success { background: var(--good-wash); border-color: #bbf7d0; } .tg-alert-success .tg-alert-icon { color: var(--good); }
.tg-alert-warning { background: var(--warn-wash); border-color: #fde68a; } .tg-alert-warning .tg-alert-icon { color: var(--warn); }
.tg-alert-danger { background: var(--bad-wash); border-color: #fecaca; } .tg-alert-danger .tg-alert-icon { color: var(--bad); }
tg-alert, tg-empty, tg-error-state, tg-loading, tg-skeleton { display: block; }

/* ---------- Empty, error state, loading ---------- */
.tg-empty, .tg-error-state { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 32px 16px; text-align: center; font-family: var(--font-sans); box-sizing: border-box; }
.tg-empty-icon { display: inline-flex; width: 44px; height: 44px; align-items: center; justify-content: center; border-radius: 50%; background: var(--surface-3); color: var(--muted); }
.tg-error-icon { background: var(--bad-wash); color: var(--bad); }
.tg-empty-title { font-weight: 600; font-size: 14px; color: var(--ink); }
.tg-empty-body { font-size: 13px; color: var(--muted); max-width: 42ch; }
.tg-empty > [data-action], .tg-error-state .tg-btn { margin-top: 8px; }
.tg-error-ref { font: 11px var(--font-mono); color: var(--subtle); }
.tg-loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 24px; font: 13px var(--font-sans); color: var(--muted); }
.tg-spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: tg-spin .7s linear infinite; }
@keyframes tg-spin { to { transform: rotate(360deg); } }
.tg-skeleton { display: flex; flex-direction: column; gap: 10px; padding: 12px 0; }
.tg-skel-row { display: grid; grid-template-columns: repeat(var(--cols, 3), 1fr); gap: 16px; }
.tg-skel-row i { display: block; height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-3), var(--line-soft), var(--surface-3)); background-size: 200% 100%; animation: tg-shimmer 1.2s ease-in-out infinite; }
@keyframes tg-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .tg-spinner, .tg-skel-row i { animation: none; } }

.tg-dialog-body p { white-space: pre-line; }

/* ---------- Badge ---------- */
.tg-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font: 500 12px/1.5 var(--font-sans); white-space: nowrap; background: var(--surface-3); color: var(--ink-2); box-sizing: border-box; }
.tg-badge::first-letter { text-transform: uppercase; }
.tg-badge-success { background: var(--good-wash); color: var(--good); }
.tg-badge-warning { background: var(--warn-wash); color: var(--warn); }
.tg-badge-danger { background: var(--bad-wash); color: var(--bad); }
.tg-badge-solid { background: var(--ink); color: #fff; }
.tg-badge-accent { background: var(--accent); color: var(--ink); }
.tg-badge-outline { background: #fff; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
tg-badge { display: inline-block; }
