/* =============================================
   UTOPIA TRADE HISTORY — Page styles
   Gallery-style history log for /trade_history.html.
   Mobile-first. Fully theme-aware.
   ============================================= */

/* ---------- Page-scoped design tokens ---------- */
:root {
    --th-font-headline: 'Manrope', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --th-font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

    --th-canvas: var(--bg-primary);
    --th-tile: var(--bg-secondary);
    --th-tile-hover: var(--bg-tertiary);
    --th-avatar-bg: var(--bg-tertiary);

    --th-card-shadow: 0 4px 20px rgba(0, 0, 0, 0.28);
    --th-card-shadow-hover: 0 18px 40px rgba(0, 0, 0, 0.38), 0 0 0 1px rgba(59, 130, 246, 0.25);

    --th-status-completed: #22c55e;
    --th-status-declined: #ef4444;
    --th-status-cancelled: #94a3b8;
    --th-status-expired: #f59e0b;
    --th-status-pending: #38bdf8;
    --th-status-accepted: #22c55e;
    --th-status-countered: #a78bfa;
}

[data-theme="light"] {
    --th-canvas: #f8f9fa;
    --th-tile: #ffffff;
    --th-tile-hover: #f3f4f5;
    --th-avatar-bg: #e7eaee;
    --th-card-shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
    --th-card-shadow-hover: 0 18px 40px rgba(15, 23, 42, 0.10), 0 0 0 1px rgba(59, 130, 246, 0.15);
    --th-status-cancelled: #64748b;
}

/* ---------- Base ---------- */
html, body {
    background: var(--th-canvas);
    color: var(--text-primary);
    font-family: var(--th-font-body);
    min-height: 100vh;
    overflow-x: hidden;
}
body { -webkit-tap-highlight-color: transparent; margin: 0; }

a { color: inherit; text-decoration: none; }
button { font: inherit; border: 0; background: none; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }

/* ---------- Page container ---------- */
.th-page {
    max-width: 48rem;
    margin: 0 auto;
}
@media (min-width: 1024px) {
    .th-page { max-width: 56rem; }
}

/* ---------- Hero title ---------- */
.th-hero {
    padding: 6px 2px 18px;
}
.th-title {
    margin: 0 0 6px;
    font-family: var(--th-font-headline);
    font-weight: 800;
    font-size: 1.75rem;
    letter-spacing: -0.025em;
    line-height: 1.15;
    background: linear-gradient(90deg, var(--blue-700) 0%, var(--blue-500) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
}
:root:not([data-theme="light"]) .th-title {
    background: linear-gradient(90deg, var(--sky-400) 0%, var(--blue-400) 100%);
    -webkit-background-clip: text;
    background-clip: text;
}
.th-subtitle {
    margin: 0;
    font-family: var(--th-font-body);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}
@media (min-width: 768px) {
    .th-title { font-size: 2.125rem; }
    .th-subtitle { font-size: 0.9375rem; }
}

/* ---------- Stats grid ---------- */
.th-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}
@media (min-width: 768px) {
    .th-stats { grid-template-columns: repeat(4, 1fr); gap: 14px; }
}

.th-stat {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--th-tile);
    border-radius: 1rem;
    box-shadow: var(--th-card-shadow);
    transition: transform 0.2s var(--ease-in-out), box-shadow 0.25s var(--ease-in-out);
    min-width: 0;
}
.th-stat:hover {
    transform: translateY(-2px);
    box-shadow: var(--th-card-shadow-hover);
}

.th-stat-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    flex-shrink: 0;
    background: rgba(59, 130, 246, 0.12);
    color: var(--blue-500);
}
.th-stat-icon .material-symbols-outlined {
    font-size: 24px;
    font-variation-settings: 'FILL' 1, 'wght' 500, 'GRAD' 0, 'opsz' 24;
}
.th-stat[data-kind="total"] .th-stat-icon {
    background: rgba(14, 165, 233, 0.14);
    color: var(--sky-500);
}
.th-stat[data-kind="value"] .th-stat-icon {
    background: rgba(34, 197, 94, 0.14);
    color: #22c55e;
}
.th-stat[data-kind="rate"] .th-stat-icon {
    background: rgba(139, 92, 246, 0.14);
    color: #a78bfa;
}
.th-stat[data-kind="avg"] .th-stat-icon {
    background: rgba(245, 158, 11, 0.14);
    color: #f59e0b;
}

.th-stat-body {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.th-stat-value {
    font-family: var(--th-font-headline);
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.th-stat-label {
    font-family: var(--th-font-body);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}
@media (min-width: 768px) {
    .th-stat-value { font-size: 1.5rem; }
}

/* ---------- Top-level tabs (Received / Sent / History) ---------- */
.th-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 6px;
    margin-bottom: 18px;
    background: var(--th-tile);
    border-radius: var(--radius-full);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .th-tabs { box-shadow: 0 2px 10px rgba(15, 23, 42, 0.05); }

.th-tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 10px;
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    font-family: var(--th-font-body);
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    transition: background 0.2s var(--ease-in-out),
                color 0.2s var(--ease-in-out),
                transform 0.15s var(--ease-in-out);
    min-width: 0;
    overflow: hidden;
}
.th-tab:hover { background: var(--th-tile-hover); color: var(--text-primary); }
.th-tab:active { transform: scale(0.97); }
.th-tab.active {
    background: var(--gradient-primary);
    color: #ffffff;
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.35);
}
.th-tab-icon { font-size: 20px; flex-shrink: 0; }
.th-tab.active .th-tab-icon {
    font-variation-settings: 'FILL' 1, 'wght' 600, 'GRAD' 0, 'opsz' 24;
}
.th-tab-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.th-tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 20px;
    padding: 0 7px;
    border-radius: var(--radius-full);
    background: rgba(15, 23, 42, 0.08);
    color: inherit;
    font-size: 0.6875rem;
    font-weight: 800;
    line-height: 1;
}
.th-tab.active .th-tab-count {
    background: rgba(255, 255, 255, 0.22);
    color: #ffffff;
}
[data-theme="light"] .th-tab-count { background: rgba(15, 23, 42, 0.06); }
/* Mobile: keep all three tabs on a single row (tightened on phones below). */
@media (max-width: 767.98px) {
    .th-tabs { grid-template-columns: repeat(3, 1fr); gap: 6px; }
}

/* Tighten typography on phones so all three labels stay on one row. */
@media (max-width: 430px) {
    .th-tab { padding: 10px 5px; gap: 4px; font-size: 0.8125rem; }
    .th-tab-icon { font-size: 18px; }
    .th-tab-count { min-width: 18px; padding: 0 5px; }
}

/* /trade_history.html (.th-page) ships only the "History" tab now. Make the
   lone tab span the full bar so it fits the page width on desktop and mobile
   (the base track is 3-up / 2-up for the multi-tab embed). Scoped to .th-page
   so trading.html's Active / Received / Sent bar is untouched; the extra
   class out-specifies the responsive grid rules above at every breakpoint. */
.th-page .th-tabs {
    grid-template-columns: 1fr;
}

/* Hide filter pills unless History tab is active */
.th-filter[hidden] { display: none; }

/* ---------- Filter pills ---------- */
.th-filter {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 2px 12px;
    margin-bottom: 4px;
    scrollbar-width: none;
}
.th-filter::-webkit-scrollbar { display: none; }

.th-pill {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border-radius: var(--radius-full);
    background: var(--th-tile);
    color: var(--text-secondary);
    font-family: var(--th-font-body);
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    transition: background 0.2s var(--ease-in-out),
                color 0.2s var(--ease-in-out),
                transform 0.15s var(--ease-in-out),
                box-shadow 0.25s var(--ease-in-out);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.th-pill:hover { background: var(--th-tile-hover); }
.th-pill:active { transform: scale(0.96); }
.th-pill.active {
    background: var(--gradient-primary);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.35);
}
.th-pill-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 20px;
    padding: 0 7px;
    border-radius: var(--radius-full);
    background: rgba(15, 23, 42, 0.08);
    color: inherit;
    font-size: 0.6875rem;
    font-weight: 800;
    line-height: 1;
}
.th-pill.active .th-pill-count {
    background: rgba(255, 255, 255, 0.22);
    color: #ffffff;
}
[data-theme="light"] .th-pill-count {
    background: rgba(15, 23, 42, 0.06);
}

/* ---------- Toolbar (search + sort) ---------- */
.th-toolbar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}
@media (min-width: 600px) {
    .th-toolbar { flex-direction: row; align-items: stretch; }
}

/* Search field with neutral ring */
.th-search { flex: 1 1 auto; min-width: 0; display: block; }
.th-search-ring {
    display: block;
    padding: 1px;
    border-radius: var(--radius-lg);
    background: var(--border-primary);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    transition: background 0.2s var(--ease-in-out), box-shadow 0.25s var(--ease-in-out);
}
.th-search:focus-within .th-search-ring {
    background: var(--text-tertiary);
}
.th-search-wrap {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--th-tile);
    border-radius: calc(var(--radius-lg) - 1px);
    overflow: hidden;
}
.th-search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 22px;
    pointer-events: none;
}
.th-search-input {
    flex: 1;
    width: 100%;
    padding: 13px 16px 13px 44px;
    background: transparent;
    border: 0;
    outline: none;
    font-size: 0.9375rem;
    color: var(--text-primary);
    font-family: var(--th-font-body);
}
.th-search-input::placeholder { color: var(--text-muted); }

/* Sort dropdown */
.th-sort {
    position: relative;
    flex: 0 0 auto;
    display: block;
}
.th-sort-select {
    appearance: none;
    -webkit-appearance: none;
    background: var(--th-tile);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: 12px 42px 12px 16px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    min-width: 180px;
    width: 100%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: border-color 0.2s var(--ease-in-out), box-shadow 0.25s var(--ease-in-out);
}
.th-sort-select:focus {
    outline: none;
    border-color: var(--blue-500);
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.18);
}
.th-sort-chevron {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    pointer-events: none;
    font-size: 22px;
}

/* ---------- Trade list (conversation-style rows) ---------- */
.th-list[hidden] { display: none; }
.th-list {
    display: flex;
    flex-direction: column;
    background: var(--th-tile);
    border-radius: 1rem;
    box-shadow: var(--th-card-shadow);
    padding: 6px 10px;
    min-height: 160px;
}

/* Inbox section header (Received / Sent tabs only) — separates "Awaiting
   finalization" (accepted) from "Awaiting response" (pending). */
.th-group-header {
    padding: 14px 6px 8px;
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.th-group-header + .th-group-header,
.th-trade + .th-group-header {
    margin-top: 6px;
}
.th-group-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--th-font-headline);
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
}
.th-group-title .material-symbols-outlined {
    font-size: 18px;
    color: var(--th-status-accepted);
}
.th-group-count {
    margin-left: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--th-tile-hover);
    color: var(--text-secondary);
}
.th-group-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-left: 26px;
}

.th-trade {
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--border-primary);
    transition: background 0.15s var(--ease-in-out);
}
.th-trade:last-child { border-bottom: none; }

.th-trade-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 14px;
    padding: 14px 6px;
    width: 100%;
    text-align: left;
    border-radius: 12px;
    transition: background 0.15s var(--ease-in-out);
}
.th-trade-row:hover { background: var(--th-tile-hover); }
.th-trade-row:focus-visible {
    outline: 2px solid var(--blue-500);
    outline-offset: 2px;
}

/* Avatar */
.th-avatar {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--th-avatar-bg);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--th-font-headline);
    font-weight: 800;
    font-size: 0.875rem;
    letter-spacing: 0.02em;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.04);
}
.th-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.th-avatar[data-status="completed"] { box-shadow: inset 0 0 0 2px var(--th-status-completed); }
.th-avatar[data-status="declined"]  { box-shadow: inset 0 0 0 2px var(--th-status-declined); }
.th-avatar[data-status="cancelled"] { box-shadow: inset 0 0 0 2px var(--th-status-cancelled); }
.th-avatar[data-status="expired"]   { box-shadow: inset 0 0 0 2px var(--th-status-expired); }
.th-avatar[data-status="pending"]   { box-shadow: inset 0 0 0 2px var(--th-status-pending); }
.th-avatar[data-status="accepted"]  { box-shadow: inset 0 0 0 2px var(--th-status-accepted); }
.th-avatar[data-status="countered"] { box-shadow: inset 0 0 0 2px var(--th-status-countered); }

.th-trade-body {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.th-trade-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}
.th-partner {
    font-family: var(--th-font-headline);
    font-weight: 800;
    font-size: 0.9375rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.005em;
    text-decoration: none;
}
/* Anchor variant — hover affordance for "go to profile" */
a.th-partner {
    cursor: pointer;
    transition: color 0.15s var(--ease-in-out), text-decoration-color 0.15s var(--ease-in-out);
    text-decoration-color: transparent;
}
a.th-partner:hover {
    color: var(--blue-500);
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}
a.th-partner:focus-visible {
    outline: 2px solid var(--blue-500);
    outline-offset: 3px;
    border-radius: 3px;
}
.th-time {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-tertiary);
    flex-shrink: 0;
    white-space: nowrap;
}
.th-trade-bottom {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 0;
}
.th-trade-bottom .material-symbols-outlined {
    font-size: 16px;
    flex-shrink: 0;
    font-variation-settings: 'FILL' 1, 'wght' 500, 'GRAD' 0, 'opsz' 24;
}
.th-preview-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1 1 auto;
}
.th-value {
    flex-shrink: 0;
    font-family: var(--th-font-headline);
    font-weight: 800;
    font-size: 0.8125rem;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    background: rgba(14, 165, 233, 0.12);
    color: var(--blue-500);
}
[data-theme="light"] .th-value { background: rgba(14, 165, 233, 0.10); }

/* Status-specific colour on status icon */
.th-trade[data-status="completed"] .th-trade-bottom .material-symbols-outlined { color: var(--th-status-completed); }
.th-trade[data-status="declined"]  .th-trade-bottom .material-symbols-outlined { color: var(--th-status-declined); }
.th-trade[data-status="cancelled"] .th-trade-bottom .material-symbols-outlined { color: var(--th-status-cancelled); }
.th-trade[data-status="expired"]   .th-trade-bottom .material-symbols-outlined { color: var(--th-status-expired); }
.th-trade[data-status="pending"]   .th-trade-bottom .material-symbols-outlined { color: var(--th-status-pending); }
.th-trade[data-status="accepted"]  .th-trade-bottom .material-symbols-outlined { color: var(--th-status-accepted); }
.th-trade[data-status="countered"] .th-trade-bottom .material-symbols-outlined { color: var(--th-status-countered); }

/* Expand chevron */
.th-chevron {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: var(--text-tertiary);
    transition: background 0.15s var(--ease-in-out), transform 0.25s var(--ease-in-out), color 0.15s var(--ease-in-out);
    flex-shrink: 0;
}
.th-trade-row:hover .th-chevron { background: rgba(59, 130, 246, 0.08); color: var(--blue-500); }
.th-trade.expanded .th-chevron { transform: rotate(180deg); color: var(--blue-500); }

/* ---------- Expand detail ---------- */
.th-detail {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s var(--ease-in-out);
}
.th-trade.expanded .th-detail { max-height: 2600px; }

.th-detail-inner {
    padding: 4px 6px 20px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.th-message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px 14px;
    background: var(--th-tile-hover);
    border-radius: 12px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}
.th-message .material-symbols-outlined {
    color: var(--text-tertiary);
    font-size: 20px;
    flex-shrink: 0;
    margin-top: 1px;
}

.th-detail-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
}
@media (min-width: 640px) {
    .th-detail-grid { grid-template-columns: 1fr 1fr; gap: 18px; }
}

.th-detail-col { min-width: 0; }
.th-detail-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 10px;
    gap: 8px;
}
.th-detail-title {
    font-family: var(--th-font-headline);
    font-weight: 700;
    font-size: 0.875rem;
    letter-spacing: -0.005em;
    color: var(--text-primary);
    margin: 0;
}
.th-detail-total {
    font-family: var(--th-font-headline);
    font-weight: 800;
    font-size: 0.9375rem;
    color: var(--blue-500);
}

.th-detail-items {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

.th-item {
    display: flex;
    gap: 10px;
    padding: 8px;
    background: var(--th-tile-hover);
    border-radius: 12px;
    min-width: 0;
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s var(--ease-in-out),
                box-shadow 0.2s var(--ease-in-out),
                background 0.15s var(--ease-in-out);
}
/* Anchor variant — clickable card item links to its detail page */
a.th-item--link { cursor: pointer; }
a.th-item--link:hover {
    transform: translateY(-1px);
    background: var(--th-tile);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(59, 130, 246, 0.18);
}
[data-theme="light"] a.th-item--link:hover {
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08), 0 0 0 1px rgba(59, 130, 246, 0.2);
}
a.th-item--link:active { transform: translateY(0); }
a.th-item--link:focus-visible {
    outline: 2px solid var(--blue-500);
    outline-offset: 2px;
}
.th-item-image {
    flex-shrink: 0;
    width: 44px;
    height: 62px;
    border-radius: 8px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    font-size: 1rem;
}
.th-item-image img { width: 100%; height: 100%; object-fit: cover; }
.th-item-body {
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
}
.th-item-name {
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.th-item-sub {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.th-item-price {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--blue-500);
    margin-top: 2px;
}

.th-detail-empty {
    padding: 14px;
    border-radius: 10px;
    background: var(--th-tile-hover);
    color: var(--text-tertiary);
    font-size: 0.8125rem;
    text-align: center;
}

/* Action buttons (expanded detail on Received/Sent rows) */
.th-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0;
}
.th-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: var(--radius-full);
    font-family: var(--th-font-body);
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: transform 0.15s var(--ease-in-out),
                box-shadow 0.2s var(--ease-in-out),
                background 0.2s var(--ease-in-out),
                color 0.2s var(--ease-in-out),
                border-color 0.2s var(--ease-in-out),
                filter 0.2s var(--ease-in-out);
    border: 1px solid transparent;
    white-space: nowrap;
}
.th-action .material-symbols-outlined { font-size: 18px; }
.th-action:hover { transform: translateY(-1px); }
.th-action:active { transform: translateY(0) scale(0.98); }
.th-action:focus-visible { outline: 2px solid var(--blue-500); outline-offset: 2px; }
.th-action:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Variants */
.th-action--accept {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(34, 197, 94, 0.35);
}
.th-action--accept:hover:not(:disabled) { filter: brightness(1.06); box-shadow: 0 6px 20px rgba(34, 197, 94, 0.45); }

.th-action--decline {
    background: transparent;
    color: var(--th-status-declined);
    border-color: rgba(239, 68, 68, 0.45);
}
.th-action--decline:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--th-status-declined);
}

.th-action--cancel {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-primary);
}
.th-action--cancel:hover:not(:disabled) {
    background: var(--th-tile-hover);
    color: var(--th-status-declined);
    border-color: rgba(239, 68, 68, 0.3);
}

.th-action--finalize {
    background: var(--gradient-primary);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
}
.th-action--finalize:hover:not(:disabled) { filter: brightness(1.06); }

.th-action--counter {
    background: transparent;
    color: var(--th-status-countered);
    border-color: rgba(167, 139, 250, 0.4);
}
.th-action--counter:hover:not(:disabled) {
    background: rgba(167, 139, 250, 0.12);
    border-color: var(--th-status-countered);
}

.th-action--message {
    background: var(--th-tile-hover);
    color: var(--text-primary);
    border-color: var(--border-primary);
}
.th-action--message:hover:not(:disabled) {
    background: var(--th-tile);
    border-color: rgba(59, 130, 246, 0.3);
    color: var(--blue-500);
}

.th-action--review {
    background: linear-gradient(135deg, #0058c3 0%, #3b82f6 50%, #38bdf8 100%);
    color: #ffffff;
    border-color: transparent;
    box-shadow: 0 6px 18px rgba(59, 130, 246, 0.32);
}
.th-action--review:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(59, 130, 246, 0.42);
}
.th-action--review:active:not(:disabled) { transform: translateY(0); }

.th-action--reviewed {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(16, 185, 129, 0.12);
    color: var(--accent-green);
    border: 1px solid rgba(16, 185, 129, 0.35);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: default;
    user-select: none;
}
.th-action--reviewed .material-symbols-outlined {
    font-size: 18px;
    font-variation-settings: 'FILL' 1;
}

/* Subtle "expires in X" hint on pending rows */
.th-expires {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-weight: 600;
    margin-left: 4px;
}
.th-expires--soon { color: var(--th-status-expired); font-weight: 700; }

/* Metadata footer */
.th-metadata {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 18px;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--th-tile-hover);
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.th-metadata-item { display: inline-flex; gap: 6px; align-items: center; }
.th-metadata-label { color: var(--text-tertiary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.6875rem; }
.th-metadata-value { font-weight: 700; color: var(--text-primary); }

/* ---------- Pagination ---------- */
.th-pager {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding: 20px 0;
    flex-wrap: wrap;
}
.th-pager[hidden] { display: none; }

.th-page-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--th-tile);
    border: 1px solid var(--border-primary);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 0.8125rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s var(--ease-in-out);
}
.th-page-btn:hover:not(:disabled) {
    background: var(--th-tile-hover);
    border-color: rgba(59, 130, 246, 0.3);
}
.th-page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.th-page-btn.active {
    background: var(--gradient-primary);
    color: #ffffff;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}
.th-page-btn .material-symbols-outlined { font-size: 18px; }
.th-page-ellipsis {
    color: var(--text-tertiary);
    padding: 0 4px;
    font-weight: 700;
}

/* ---------- Loading state ---------- */
.th-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 20px;
    color: var(--text-tertiary);
    font-size: 0.875rem;
}
.th-loading p { margin: 0; }
.th-spinner {
    width: 28px;
    height: 28px;
    border: 2px solid rgba(59, 130, 246, 0.15);
    border-top-color: var(--blue-500);
    border-radius: 50%;
    animation: thSpin 0.8s linear infinite;
}
@keyframes thSpin { to { transform: rotate(360deg); } }

/* ---------- Empty state ---------- */
.th-empty[hidden] { display: none; }
.th-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 56px 24px;
    text-align: center;
    background: var(--th-tile);
    border-radius: 1rem;
    box-shadow: var(--th-card-shadow);
    margin-top: 24px;
}
.th-empty-icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(59, 130, 246, 0.12);
    color: var(--blue-500);
}
.th-empty-icon .material-symbols-outlined { font-size: 40px; }
.th-empty-title {
    margin: 0;
    font-family: var(--th-font-headline);
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: -0.015em;
    color: var(--text-primary);
}
.th-empty-subtitle {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
    max-width: 36ch;
    line-height: 1.5;
}
.th-empty-cta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 22px;
    background: var(--gradient-primary);
    color: #ffffff;
    font-family: var(--th-font-headline);
    font-weight: 800;
    font-size: 0.9375rem;
    border-radius: var(--radius-full);
    box-shadow: 0 6px 18px rgba(59, 130, 246, 0.32);
    transition: transform 0.15s var(--ease-in-out), box-shadow 0.25s var(--ease-in-out), filter 0.2s ease;
    margin-top: 4px;
}
.th-empty-cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(59, 130, 246, 0.4);
    filter: brightness(1.05);
}
.th-empty-cta:active { transform: scale(0.97); }

/* ---------- Error state ---------- */
.th-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 36px 20px;
    text-align: center;
}
.th-error .th-empty-icon { background: rgba(239, 68, 68, 0.12); color: #ef4444; }
.th-error h3 { margin: 0; font-family: var(--th-font-headline); font-weight: 800; font-size: 1rem; color: var(--text-primary); }
.th-error p { margin: 0; font-size: 0.875rem; color: var(--text-secondary); }
.th-error button {
    margin-top: 6px;
    padding: 9px 18px;
    border-radius: var(--radius-full);
    background: var(--gradient-primary);
    color: #ffffff;
    font-weight: 700;
    font-size: 0.875rem;
    cursor: pointer;
}

/* ---------- Toast ---------- */
.th-toast {
    position: fixed;
    bottom: calc(var(--home-pill-height, 64px) + var(--home-pill-offset, 1.5rem) + 16px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translate(-50%, 120%);
    padding: 12px 20px;
    background: var(--th-tile);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 600;
    box-shadow: var(--th-card-shadow);
    opacity: 0;
    transition: transform 0.3s var(--ease-in-out), opacity 0.3s var(--ease-in-out);
    z-index: 1000;
    pointer-events: none;
}
.th-toast.show {
    transform: translate(-50%, 0);
    opacity: 1;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .th-stat, .th-trade-row, .th-detail, .th-chevron, .th-pill, .th-page-btn, .th-empty-cta {
        transition: none;
    }
    .th-spinner { animation-duration: 2s; }
}
