/* ------------------------------------------------------------ app shell */
.tp-shell {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}
.tp-sidebar {
    display: none;
    flex-direction: column;
    width: 250px;
    padding: 28px 24px;
    border-right: 1px solid var(--tp-hairline);
}
.tp-sidebar__foot { margin-top: auto; }
.tp-tagline {
    font-family: var(--tp-font-display);
    font-size: 17px;
    margin: 0;
}
.tp-nav { display: flex; flex-direction: column; gap: 6px; margin-top: 36px; }
.tp-nav__item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    padding: 0 16px;
    border: none;
    border-radius: 999px;
    background: transparent;
    cursor: pointer;
    color: var(--tp-muted);
    font-size: 14px;
}
.tp-nav__item.is-active { background: var(--tp-surface); color: var(--tp-text); }
.tp-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tp-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--tp-hairline);
    position: sticky;
    top: 0;
    background: var(--tp-paper);
    z-index: 20;
}
.tp-topbar__actions { display: flex; align-items: center; gap: 8px; }
.tp-wordmark--mobile { font-size: 22px; }
.tp-bell { position: relative; }
.tp-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--tp-gold);
    color: #0A0A0A;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tp-userchip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 4px 14px 4px 4px;
    border: 1px solid var(--tp-hairline);
    border-radius: 999px;
    background: var(--tp-surface);
    cursor: pointer;
}
.tp-userchip__avatar {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    background: var(--tp-ink);
    color: var(--tt-inverse-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}
.tp-userchip__name {
    display: none;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}
.tp-view { flex: 1; padding: 22px 16px 110px; }
.tp-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: space-around;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--tp-hairline);
    background: var(--tp-surface);
    z-index: 30;
}
.tp-tabbar__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 72px;
    min-height: 52px;
    border: none;
    background: transparent;
    color: var(--tp-muted);
    font-size: 10.5px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
}
.tp-tabbar__item.is-active { color: var(--tp-text); }

@media (min-width: 768px) {
    .tp-sidebar { display: flex; }
    .tp-tabbar { display: none; }
    .tp-wordmark--mobile { display: none; }
    .tp-userchip__name { display: block; }
    .tp-view { padding: 32px 32px 60px; }
}

/* --------------------------------------------------------------- sign-in */
.tp-signin {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 12vh 24px calc(32px + env(safe-area-inset-bottom));
}
.tp-signin__center { text-align: center; margin-top: 6vh; }
.tp-signin__foot { max-width: 420px; width: 100%; margin: 0 auto; display: grid; gap: 14px; }

/* --------------------------------------------------------------- menus */
.tp-menu {
    min-width: 220px;
    padding: 8px;
    border: 1px solid var(--tp-hairline);
    border-radius: 16px;
    background: var(--tp-surface);
    box-shadow: var(--tp-shadow);
}
.tp-menu--float { position: fixed; z-index: 60; }
.tp-menu--user {
    position: absolute;
    top: 62px;
    right: 16px;
    z-index: 60;
}
.tp-menu__label {
    font-size: 10px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--tp-muted);
    padding: 10px 12px 4px;
}
.tp-menu__item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
    border: none;
    border-radius: 12px;
    background: transparent;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
}
.tp-menu__item:hover { background: rgba(138, 138, 133, 0.12); }
.tp-menu__item--danger { color: var(--tp-danger); }
.tp-menu__sep { height: 1px; background: var(--tp-hairline); margin: 8px 4px; }

/* -------------------------------------------------------------- dashboard */
.tp-page__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.tp-tools {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
    margin: 18px 0;
}
.tp-table {
    border: 1px solid var(--tp-hairline);
    border-radius: var(--tp-radius-card);
    background: var(--tp-surface);
    overflow: hidden;
}
.tp-table__head {
    display: none;
    padding: 14px 20px;
    border-bottom: 1px solid var(--tp-hairline);
    font-size: 10.5px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--tp-muted);
}
.tp-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--tp-hairline);
}
.tp-row:last-child { border-bottom: none; }
.tp-row__client { display: flex; align-items: center; gap: 12px; min-width: 0; }
.tp-avatar {
    width: 42px;
    height: 42px;
    border-radius: 999px;
    object-fit: cover;
    flex: none;
    border: 1px solid var(--tp-hairline);
}
.tp-avatar--initial {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--tp-ink);
    color: var(--tt-inverse-text);
    font-family: var(--tp-font-display);
    font-size: 18px;
}
.tp-row__name { display: block; font-weight: 600; }
.tp-row__headline { display: block; color: var(--tp-muted); font-size: 12.5px; }
.tp-row__business, .tp-row__date { display: none; }
.tp-row__status { justify-self: end; }
.tp-row__actions { display: flex; gap: 2px; grid-column: 2; }
.tp-row__chevron { display: inline-flex; }

.tp-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    white-space: nowrap;
}
.tp-pill::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: currentColor;
}
.tp-pill--pending { background: var(--tp-pill-pending-bg); color: var(--tp-pill-pending-fg); }
.tp-pill--exported { background: var(--tp-pill-exported-bg); color: var(--tp-pill-exported-fg); }
.tp-pill--deployed { background: var(--tp-pill-deployed-bg); color: var(--tp-pill-deployed-fg); }

@media (min-width: 768px) {
    .tp-table__head {
        display: grid;
        grid-template-columns: minmax(200px, 2.2fr) 1.2fr 120px 130px 190px;
        gap: 16px;
        align-items: center;
    }
    .tp-table__actions-col { text-align: right; }
    .tp-row {
        grid-template-columns: minmax(200px, 2.2fr) 1.2fr 120px 130px 190px;
        padding: 14px 20px;
    }
    .tp-row__business, .tp-row__date { display: block; color: var(--tp-muted); font-size: 13.5px; }
    .tp-row__status { justify-self: start; }
    .tp-row__actions { justify-content: flex-end; grid-column: auto; }
    .tp-row__chevron { display: none; }
}

.tp-empty {
    text-align: center;
    padding: 60px 20px;
}
.tp-empty__title {
    font-family: var(--tp-font-display);
    font-size: 26px;
    margin: 0 0 8px;
}
.tp-empty__body { color: var(--tp-muted); margin: 0 0 22px; }
.tp-empty-line { color: var(--tp-muted); padding: 22px 4px; margin: 0; }

/* ----------------------------------------------- sections, lists, invites */
.tp-section-head { margin: 34px 0 14px; }
.tp-section-title {
    font-family: var(--tp-font-display);
    font-size: 24px;
    margin: 0;
}
.tp-section-sub { color: var(--tp-muted); margin: 4px 0 0; }
.tp-list { display: grid; gap: 12px; }
.tp-listrow {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border: 1px solid var(--tp-hairline);
    border-radius: var(--tp-radius-card);
    background: var(--tp-surface);
}
.tp-listrow__name { font-weight: 600; }
.tp-listrow__meta { color: var(--tp-muted); font-size: 12.5px; }
.tp-listrow__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tp-warnline { color: var(--tp-pill-pending-fg); font-size: 12.5px; margin-top: 4px; }

.tp-option {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 16px;
    margin-bottom: 12px;
    border: 1px solid var(--tp-hairline);
    border-radius: var(--tp-radius-card);
    background: transparent;
    cursor: pointer;
    text-align: left;
}
.tp-option:hover { border-color: var(--tp-gold); }
.tp-option__icon {
    width: 44px;
    height: 44px;
    border-radius: 999px;
    border: 1px solid var(--tp-hairline);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
}
.tp-option__go { margin-left: auto; color: var(--tp-muted); }
.tp-option strong { display: block; }

.tp-linkbox {
    padding: 14px 16px;
    border: 1px dashed var(--tp-gold);
    border-radius: 14px;
    margin-bottom: 12px;
}
.tp-linkbox__url {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 12.5px;
    word-break: break-all;
}

/* ------------------------------------------------------------- preview */
.tp-preview-frame {
    border: 1px solid var(--tp-hairline);
    border-radius: 16px;
    overflow: hidden;
    max-height: 62vh;
    overflow-y: auto;
}
.tp-preview-host { width: 100%; }

/* ---------------------------------------------------------- intro overlay */
.intro {
    position: fixed;
    inset: 0;
    z-index: 999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--tp-paper);
    opacity: 0;
    transition: opacity 0.4s ease;
}
.intro.intro-in { opacity: 1; }
.intro.intro-out { opacity: 0; pointer-events: none; }
.intro__wordmark {
    font-family: var(--tp-font-display);
    font-size: clamp(40px, 12vw, 72px);
    margin: 0;
    letter-spacing: -0.02em;
}
.intro__line {
    width: 90px;
    height: 2px;
    margin-top: 18px;
    background: linear-gradient(90deg, transparent, var(--tp-gold) 35%, var(--tp-gold) 65%, transparent);
    transform: scaleX(0);
    transition: transform 0.6s ease 0.3s;
}
.intro.intro-in .intro__line { transform: scaleX(1); }

@media (prefers-reduced-motion: reduce) {
    .intro { transition: none; }
    .intro__line { transition: none; transform: scaleX(1); }
}

/* ---- template picker (client form, "Choose your template") ------------- */
.tp-tpl-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--tt-space-3);
    margin-top: var(--tt-space-4);
}
.tp-tpl-skel {
    height: 236px;
    border-radius: 16px;
    background: var(--tt-neutral-soft);
    animation: tpTplPulse 1.2s ease-in-out infinite;
}
@keyframes tpTplPulse { 0%, 100% { opacity: .45; } 50% { opacity: .9; } }
.tp-tpl-card {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 0;
    border: 1px solid var(--tt-border);
    border-radius: 16px;
    background: var(--tt-surface);
    cursor: pointer;
    overflow: hidden;
    text-align: left;
    transition: border-color 180ms ease, box-shadow 180ms ease, transform 150ms ease;
}
.tp-tpl-card:active { transform: scale(.985); }
.tp-tpl-card.is-on {
    border-color: var(--tt-accent);
    box-shadow: 0 0 0 2px var(--tt-accent), var(--tt-shadow-1);
}
.tp-tpl-thumb {
    display: block;
    position: relative;
    height: 200px;
    overflow: hidden;
    background: var(--tt-surface-sunken);
    pointer-events: none;
}
.tp-tpl-thumb .tpl-page {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    pointer-events: none;
}
.tp-tpl-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--tt-border);
    background: var(--tt-surface);
}
.tp-tpl-name {
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--tt-text);
}
.tp-tpl-tick {
    display: none;
    width: 20px;
    height: 20px;
    border-radius: 999px;
    align-items: center;
    justify-content: center;
    background: var(--tt-accent);
    color: #111;
    flex: 0 0 auto;
}
.tp-tpl-card.is-on .tp-tpl-tick { display: inline-flex; }
.tp-tpl-card:focus-visible {
    outline: 2px solid var(--tt-focus-ring);
    outline-offset: 3px;
}
@media (prefers-reduced-motion: reduce) {
    .tp-tpl-skel { animation: none; }
    .tp-tpl-card { transition: none; }
}

/* ---- template picker: mount point -------------------------------------- */
.tp-tpl-mount { display: block; container: template-picker / inline-size; }
@container template-picker (min-width: 340px) {
    .tp-tpl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---- template picker: category chips ----------------------------------- */
.tp-tpl-cats {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    gap: 8px;
    margin: 14px -4px 0;
    padding: 8px 4px;
    background: var(--tt-bg);
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-snap-type: x proximity;
}
.tp-tpl-cats::-webkit-scrollbar { display: none; }
.tp-tpl-cat {
    flex: 0 0 auto;
    min-height: var(--tt-target);
    padding: 0 14px;
    border: 1px solid var(--tt-border);
    border-radius: 999px;
    background: var(--tt-surface);
    color: var(--tt-text-muted);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    scroll-snap-align: start;
    transition: background 160ms ease, color 160ms ease, border-color 160ms ease;
}
.tp-tpl-cat.is-on {
    background: var(--tt-text);
    border-color: var(--tt-text);
    color: var(--tt-bg);
}
.tp-tpl-cat:focus-visible {
    outline: 2px solid var(--tt-focus-ring);
    outline-offset: 2px;
}

/* ---- template picker: card + always-reachable actions ------------------ */
.tp-tpl-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    /* Skips offscreen rendering and painting; the browser still lays the
       item out for scroll anchoring. */
    content-visibility: auto;
    contain-intrinsic-size: auto 268px;
}
.tp-tpl-item[hidden] { display: none; }
.tp-tpl-item .tp-tpl-card { flex: 1; }
.tp-tpl-actions {
    display: flex;
    gap: 6px;
}
.tp-tpl-act {
    flex: 1;
    min-height: 44px;
    padding: 0 8px;
    border-radius: 10px;
    border: 1px solid var(--tt-border);
    background: var(--tt-surface);
    color: var(--tt-text);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.tp-tpl-act--use {
    background: var(--tt-inverse-bg);
    border-color: var(--tt-inverse-bg);
    color: var(--tt-inverse-text);
}
.tp-tpl-item:has(.is-on) .tp-tpl-act--use { background: var(--tt-surface-sunken); color: var(--tt-text); border-color: var(--tt-border-strong); }
.tp-tpl-act:focus-visible {
    outline: 2px solid var(--tt-focus-ring);
    outline-offset: 2px;
}
/* Preview and Use stay visible on every input type: on a phone there is no
   hover, and a hidden control is a control that does not exist. */

/* ---- template preview sheet -------------------------------------------- */
:root:has(dialog.ttp-prev[open]) { overflow: hidden; }
.ttp-prev {
    position: fixed;
    inset: 0;
    /* Above the app's own sheet (.sheet-wrap is 150) — the picker can be opened
       from the dashboard's template sheet. */
    z-index: 200;
    display: flex;
    align-items: stretch;
    justify-content: center;
    background: rgba(0, 0, 0, .55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.ttp-prev[hidden] { display: none; }
dialog.ttp-prev {
    box-sizing: border-box; margin: 0; padding: 0; border: 0;
    width: 100%; max-width: none; height: 100dvh; max-height: none;
}
dialog.ttp-prev:not([open]) { display: none; }
dialog.ttp-prev::backdrop { background: transparent; }
.ttp-prev__sheet {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100dvh;
    background: var(--tt-bg);
    color: var(--tt-text);
}
.ttp-prev__bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    padding-top: calc(10px + env(safe-area-inset-top));
    border-bottom: 1px solid var(--tt-border);
    background: var(--tt-surface);
}
.ttp-prev__icon,
.ttp-prev__arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--tt-border);
    border-radius: 999px;
    background: var(--tt-surface);
    color: var(--tt-text);
    cursor: pointer;
}
.ttp-prev__count {
    flex: 1;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .04em;
    color: var(--tt-text-muted);
}
.ttp-prev__seg {
    display: inline-flex;
    padding: 3px;
    border-radius: 999px;
    background: var(--tt-surface-sunken);
    border: 1px solid var(--tt-border);
}
.ttp-prev__seg button {
    min-height: 34px;
    padding: 0 12px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--tt-text-muted);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.ttp-prev__seg button.is-on {
    background: var(--tt-surface);
    color: var(--tt-text);
    box-shadow: var(--tt-shadow-1);
}
.ttp-prev__stage {
    flex: 1;
    min-height: 0;
    display: flex;
    justify-content: center;
    overflow: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    padding: 12px 0 20px;
    background: var(--tt-surface-sunken);
}
.ttp-prev__stage .tpl-page {
    flex: 0 0 auto;
    width: 390px;
}
.ttp-prev__foot {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    align-items: center;
    gap: 10px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--tt-border);
    background: var(--tt-surface);
}
.ttp-prev__meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    text-align: center;
}
.ttp-prev__meta strong {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ttp-prev__meta span {
    font-size: 11px;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--tt-text-muted);
}
.ttp-prev__use {
    grid-column: 1 / -1;
    min-height: 48px;
    border: 0;
    border-radius: 14px;
    background: var(--tt-accent);
    color: var(--tt-on-accent);
    font: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
.ttp-prev__use:active { transform: scale(.99); }
.ttp-prev__icon:focus-visible,
.ttp-prev__arrow:focus-visible,
.ttp-prev__use:focus-visible,
.ttp-prev__seg button:focus-visible {
    outline: 2px solid var(--tt-focus-ring);
    outline-offset: 2px;
}
@media (min-width: 560px) {
    .ttp-prev { align-items: center; }
    .ttp-prev__sheet {
        width: min(430px, 92vw);
        height: min(880px, 92dvh);
        border-radius: 24px;
        overflow: hidden;
        box-shadow: var(--tt-shadow-3);
    }
    .ttp-prev__bar { padding-top: 10px; }
}

/* Shared editorial finish: the same rhythm across inbox, forms and sheets. */
.tp-page__head { gap: var(--tt-space-4); margin-bottom: var(--tt-space-4); }
.tp-title { font-size: var(--tt-type-display); line-height: var(--tt-leading-tight); }
.tp-subtitle { line-height: var(--tt-leading-body); margin-bottom: var(--tt-space-5); }
.tp-tools, .tp-list { gap: var(--tt-space-4); }
.tp-tools { margin-block: var(--tt-space-5); }
.tp-listrow { padding: var(--tt-space-5); gap: var(--tt-space-4); }
.tp-listrow__main { flex: 1 1 240px; min-width: 0; }
.tp-listrow__name, .tp-listrow__meta, .tp-row__name, .tp-row__headline { overflow-wrap: anywhere; }
.tp-listrow__meta { margin-top: var(--tt-space-1); line-height: var(--tt-leading-body); }
.tp-listrow__actions { gap: var(--tt-space-2); }
.tp-btn--sm, .tp-input--sm, .tp-chip, .tp-segment__btn,
.ttp-prev__seg button { min-height: var(--tt-target); }
.tp-input, .tp-search__input { min-width: 0; font-size: var(--tt-type-body); }
.tp-search { min-width: 0; max-width: 100%; }
.tp-field { min-width: 0; }

@media (max-width: 359px) {
    .tp-listrow { padding: var(--tt-space-4); }
    .tp-listrow__actions { width: 100%; }
    .tp-listrow__actions > .tp-btn { flex: 1 1 auto; }
}
