/* Shared app controls, dialogs and motion. */

/* Every colour here is an alias of the canonical --tt-* tokens in tokens.css.
   The two dark blocks that used to live here duplicated the theme and could
   disagree with app.css; tokens.css is now the only place a theme is declared. */
:root {
    --tp-ink: var(--tt-inverse-bg);
    --tp-paper: var(--tt-bg);
    --tp-surface: var(--tt-surface);
    --tp-text: var(--tt-text);
    --tp-muted: var(--tt-text-muted);
    --tp-hairline: var(--tt-border);
    --tp-gold: var(--tt-accent);
    /* Decorative gold fails as text. Use this when gold must be read. */
    --tp-gold-ink: var(--tt-accent-ink);
    --tp-danger: var(--tt-danger);

    /* Chips: translucent tint + theme-aware dot, so one block serves both. */
    --tp-pill-pending-bg: var(--tt-warning-soft);
    --tp-pill-pending-fg: var(--tt-warning);
    --tp-pill-exported-bg: var(--tt-success-soft);
    --tp-pill-exported-fg: var(--tt-success);
    --tp-pill-deployed-bg: var(--tt-neutral-soft);
    --tp-pill-deployed-fg: var(--tt-text-muted);

    --tp-radius-card: var(--tt-radius-md);
    --tp-radius-input: var(--tt-radius-sm);
    --tp-shadow: var(--tt-shadow-2);
    --tp-font-display: var(--tt-font-serif);
    --tp-font-body: var(--tt-font-sans);
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--tp-paper);
    color: var(--tp-text);
    font-family: var(--tp-font-body);
    font-size: var(--tt-type-body);
    line-height: var(--tt-leading-body);
    -webkit-font-smoothing: antialiased;
}

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

.tp-icon { display: block; }

/* ------------------------------------------------------------- typography */
.tp-wordmark {
    font-family: var(--tp-font-display);
    font-size: 26px;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.tp-wordmark--big { font-size: clamp(44px, 12vw, 64px); }
.tp-title {
    font-family: var(--tp-font-display);
    font-size: clamp(32px, 7vw, 40px);
    font-weight: 600;
    letter-spacing: -0.02em;
    margin: 0 0 6px;
}
.tp-title--stage { margin-top: 4px; }
.tp-subtitle { color: var(--tp-muted); margin: 0 0 22px; max-width: 46ch; }
.tp-caption {
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--tp-muted);
    margin: 14px 0 0;
}
.tp-micro {
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--tp-muted);
}
.tp-micro-inline {
    font-size: 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--tp-muted);
}
.tp-hint { display: block; color: var(--tp-muted); font-size: 12.5px; margin-top: 6px; }
.tp-center { text-align: center; }
.tp-mt { margin-top: 26px; }

.tp-goldline {
    width: 84px;
    height: 1.5px;
    margin: 18px auto 0;
    background: linear-gradient(90deg, transparent, var(--tp-gold) 35%, var(--tp-gold) 65%, transparent);
}
.tp-goldline--left { margin-left: 0; }

/* ---------------------------------------------------------------- buttons */
.tp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 0 22px;
    border-radius: 999px;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    font-size: max(.875rem, var(--tt-type-caption));
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, letter-spacing 0.3s ease;
}
.tp-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.tp-btn--primary { background: var(--tp-ink); color: var(--tt-inverse-text); }
.tp-btn--primary:hover:not(:disabled) { box-shadow: var(--tt-shadow-1); }
.tp-btn--secondary { border-color: var(--tp-hairline); background: var(--tp-surface); }
.tp-btn--ghost { color: var(--tp-muted); }
.tp-btn--ghost:hover { color: var(--tp-text); }
.tp-btn--gold { border-color: var(--tp-gold); color: var(--tp-text); background: transparent; }
.tp-btn--gold:hover { background: rgba(184, 155, 94, 0.12); }
.tp-btn--danger { background: var(--tp-danger); color: #fff; }
.tp-btn--danger-text { color: var(--tp-danger); }
.tp-btn--sm { min-height: 40px; padding: 0 16px; font-size: var(--tt-type-caption); }
.tp-btn--full { width: 100%; }
.tp-btn--tall { min-height: 54px; }

.tp-iconbtn {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--tp-muted);
    cursor: pointer;
}
.tp-iconbtn:hover { color: var(--tp-text); background: rgba(138, 138, 133, 0.12); }
.tp-iconbtn--danger:hover { color: var(--tp-danger); }

/* ----------------------------------------------------------------- inputs */
.tp-field { display: block; margin-bottom: 18px; }
.tp-label {
    display: block;
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--tp-muted);
    margin-bottom: 8px;
}
.tp-input {
    width: 100%;
    min-height: 48px;
    padding: 12px 16px;
    border: 1px solid var(--tp-hairline);
    border-radius: var(--tp-radius-input);
    background: var(--tp-surface);
    outline: none;
    transition: border-color 0.2s ease;
}
.tp-input:focus { border-color: var(--tp-gold); }
.tp-input--sm { min-height: 40px; padding: 8px 12px; font-size: 13px; }
.tp-input--mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
.tp-textarea { resize: vertical; min-height: 90px; }

.tp-search {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-height: 48px;
    padding: 0 18px;
    border: 1px solid var(--tp-hairline);
    border-radius: 999px;
    background: var(--tp-surface);
    color: var(--tp-muted);
}
.tp-search__input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    min-height: 44px;
}

.tp-check {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-height: 44px;
    padding: 14px 16px;
    border: 1px solid var(--tp-hairline);
    border-radius: var(--tp-radius-input);
    background: var(--tp-surface);
    cursor: pointer;
}
.tp-check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--tp-gold); }

/* ------------------------------------------------------------------ chips */
.tp-chips { display: flex; gap: 10px; flex-wrap: wrap; }
.tp-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 18px;
    border-radius: 999px;
    border: 1px solid var(--tp-hairline);
    background: transparent;
    cursor: pointer;
    font-size: 13.5px;
}
.tp-chip--lg { min-height: 48px; padding: 0 22px; font-size: 14px; }
.tp-chip.is-active { background: var(--tp-ink); border-color: var(--tp-ink); color: var(--tt-inverse-text); }
.tp-chip__count {
    font-size: 11px;
    letter-spacing: 0.08em;
    opacity: 0.7;
}

.tp-segment {
    display: inline-flex;
    padding: 4px;
    border: 1px solid var(--tp-hairline);
    border-radius: 999px;
    gap: 4px;
}
.tp-segment__btn {
    min-height: 40px;
    padding: 0 20px;
    border: none;
    border-radius: 999px;
    background: transparent;
    cursor: pointer;
    font-size: 13.5px;
}
.tp-segment__btn.is-active { background: var(--tp-ink); color: var(--tt-inverse-text); }

/* -------------------------------------------------------- dialogs, toast */
.tp-dialog-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 10, 0.45);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    z-index: 100;
}
@media (min-width: 768px) {
    .tp-dialog-backdrop { align-items: center; }
}
.tp-dialog {
    width: 100%;
    max-width: 460px;
    max-height: 88vh;
    overflow: auto;
    padding: 26px 22px calc(22px + env(safe-area-inset-bottom));
    border-radius: 22px 22px 18px 18px;
    background: var(--tp-surface);
    box-shadow: var(--tp-shadow);
}
.tp-dialog--wide { max-width: 640px; }
.tp-dialog__title {
    font-family: var(--tp-font-display);
    font-size: 26px;
    margin: 0 0 8px;
}
.tp-dialog__body { color: var(--tp-muted); margin: 0 0 18px; overflow-wrap: anywhere; }
.tp-dialog__actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
    margin-top: 20px;
}
.tp-dialog__actions--wrap > .tp-btn { flex: 1; min-width: 130px; }
.tp-dialog__error { color: var(--tp-danger); font-size: 13px; margin: 8px 0 0; }
.tp-sheet-handle {
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: var(--tp-hairline);
    margin: 0 auto 18px;
}

.tp-toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translate(-50%, 16px);
    padding: 14px 22px;
    width: max-content;
    max-width: min(400px, calc(100vw - 32px));
    overflow-wrap: anywhere;
    border-radius: var(--tt-radius-md);
    background: var(--tp-ink);
    color: var(--tt-inverse-text);
    font-size: 13.5px;
    opacity: 0;
    transition: opacity 0.28s ease, transform 0.28s ease;
    z-index: 200;
}
.tp-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.tp-toast--error { background: var(--tp-danger); }
#toast-root > .tp-toast { position: static; transform: translateY(var(--tt-space-2)); }
#toast-root > .tp-toast.is-visible { transform: none; }

/* ---------------------------------------------------------------- motion */
@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;
    }
}

.tp-dialog { padding: var(--tt-space-5); padding-bottom: calc(var(--tt-space-5) + env(safe-area-inset-bottom)); border-radius: var(--tt-radius-lg); max-height: 88dvh; }

.tp-dialog__title { font-size: var(--tt-type-title); }

.tp-dialog__actions { gap: var(--tt-space-2); }

.tp-dialog__actions > .tp-btn { min-width: 0; white-space: normal; }

@media (max-width: 359px) {
    .tp-dialog-backdrop { padding: var(--tt-space-2); }
    .tp-dialog { padding: var(--tt-space-4); padding-bottom: calc(var(--tt-space-4) + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: no-preference) {
    .tp-dialog { animation: uiSheetIn var(--tt-duration-enter) var(--tt-ease-out) both; }
}

@keyframes uiSheetIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: none; }
}
