/* ==========================================================================
   THEME — 03 components
   --------------------------------------------------------------------------
   Buttons, cards, forms, tables, badges, alerts, pagination, modals, tabs and
   the dropdown/menu system. Every class is theme-prefixed (`t-`) so it can
   coexist with the legacy stylesheet during migration.
   ========================================================================== */

/* ------------------------------------------------------------------ Buttons */
.t-btn {
    --t-btn-bg: var(--brand);
    --t-btn-fg: var(--text-on-brand);
    --t-btn-border: transparent;

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: .7rem 1.4rem;
    border: 1px solid var(--t-btn-border);
    border-radius: var(--r-md);
    background: var(--t-btn-bg);
    color: var(--t-btn-fg);
    font-size: var(--fs-sm);
    font-weight: 700;
    line-height: 1.25;
    text-align: center;
    white-space: nowrap;
    transition: transform var(--dur-fast) var(--ease-out),
                box-shadow var(--dur-base) var(--ease-out),
                background-color var(--dur-fast) var(--ease-out),
                border-color var(--dur-fast) var(--ease-out),
                color var(--dur-fast) var(--ease-out);
}

.t-btn:hover {
    transform: translateY(-2px);
    color: var(--t-btn-fg);
    box-shadow: var(--sh-md);
}

.t-btn:active {
    transform: translateY(0);
}

.t-btn[disabled],
.t-btn[aria-disabled="true"] {
    opacity: .55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Variants --------------------------------------------------------------- */
.t-btn--primary {
    --t-btn-bg: var(--brand);
    box-shadow: var(--sh-brand);
}
.t-btn--primary:hover { --t-btn-bg: var(--brand-hover); }

.t-btn--gradient {
    --t-btn-bg: var(--grad-brand);
    background-image: var(--grad-brand);
    background-size: 160% 160%;
    box-shadow: var(--sh-brand);
}
.t-btn--gradient:hover {
    background-image: var(--grad-brand-h);
    background-position: 100% 50%;
}

.t-btn--ghost {
    --t-btn-bg: transparent;
    --t-btn-fg: var(--text-strong);
    --t-btn-border: var(--border-default);
}
.t-btn--ghost:hover {
    --t-btn-border: var(--brand);
    --t-btn-fg: var(--brand);
    box-shadow: none;
}

.t-btn--soft {
    --t-btn-bg: var(--brand-soft);
    --t-btn-fg: var(--brand-soft-text);
}
.t-btn--soft:hover { --t-btn-bg: var(--brand-soft); filter: brightness(.97); }

.t-btn--onbrand {
    --t-btn-bg: #fff;
    --t-btn-fg: var(--c-slate-900);
    box-shadow: var(--sh-md);
}
.t-btn--onbrand:hover { --t-btn-fg: var(--c-blue-700); }

.t-btn--outline-brand {
    --t-btn-bg: transparent;
    --t-btn-fg: var(--brand);
    --t-btn-border: var(--brand);
}
.t-btn--outline-brand:hover {
    --t-btn-bg: var(--brand);
    --t-btn-fg: var(--text-on-brand);
}

.t-btn--danger {
    --t-btn-bg: var(--danger);
}
.t-btn--danger:hover { --t-btn-bg: var(--danger-text); }

.t-btn--subtle-danger {
    --t-btn-bg: var(--danger-soft);
    --t-btn-fg: var(--danger-text);
}
.t-btn--subtle-danger:hover { --t-btn-bg: var(--danger); --t-btn-fg: #fff; }

.t-btn--success {
    --t-btn-bg: var(--success);
}

/* Sizes ------------------------------------------------------------------ */
.t-btn--sm {
    padding: .4rem .8rem;
    font-size: var(--fs-xs);
    border-radius: var(--r-sm);
}

.t-btn--lg {
    padding: .95rem 2rem;
    font-size: var(--fs-base);
    border-radius: var(--r-lg);
}

.t-btn--block { width: 100%; }

.t-btn--icon {
    padding: .55rem;
    aspect-ratio: 1;
}

/* ------------------------------------------------------------------- Cards */
.t-card {
    display: flex;
    flex-direction: column;
    padding: var(--sp-6);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-sm);
    transition: transform var(--dur-base) var(--ease-out),
                box-shadow var(--dur-base) var(--ease-out),
                border-color var(--dur-base) var(--ease-out);
}

.t-card--interactive:hover {
    transform: translateY(-6px);
    box-shadow: var(--sh-lg);
    border-color: var(--brand);
}

.t-card--flush  { padding: 0; overflow: hidden; }
.t-card--glass  { backdrop-filter: blur(20px); box-shadow: var(--sh-lg); }
.t-card--accent { background: var(--grad-surface); }
.t-card--pad-lg { padding: var(--sp-8); }

.t-card__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3.25rem;
    height: 3.25rem;
    margin-bottom: var(--sp-4);
    border-radius: var(--r-md);
    background: var(--grad-brand);
    color: #fff;
    font-size: 1.3rem;
    line-height: 1;
    box-shadow: var(--sh-brand);
}

.t-card__icon--soft {
    background: var(--brand-soft);
    color: var(--brand);
    box-shadow: none;
}

.t-card__title {
    margin-bottom: var(--sp-2);
    font-size: var(--fs-lg);
    font-weight: 700;
}

.t-card__text {
    color: var(--text-body);
    font-size: var(--fs-sm);
}

.t-card__footer {
    margin-top: auto;
    padding-top: var(--sp-4);
}

.t-card__link {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: var(--fs-sm);
    font-weight: 700;
    color: var(--brand);
}

.t-card__link i {
    transition: transform var(--dur-base) var(--ease-out);
}

.t-card__link:hover i {
    transform: translateX(4px);
}

/* ------------------------------------------------------------------- Forms */
.t-field {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    margin-bottom: var(--sp-5);
}

.t-label {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text-strong);
}

.t-input,
.t-select,
.t-textarea {
    width: 100%;
    padding: .7rem .9rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--r-sm);
    color: var(--text-strong);
    font-size: var(--fs-sm);
    transition: border-color var(--dur-fast) var(--ease-out),
                box-shadow var(--dur-fast) var(--ease-out),
                background-color var(--dur-fast) var(--ease-out);
}

.t-textarea { min-height: 7.5rem; resize: vertical; }

.t-input::placeholder,
.t-textarea::placeholder {
    color: var(--text-muted);
}

.t-input:focus,
.t-select:focus,
.t-textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}

.t-input[readonly],
.t-input:disabled,
.t-select:disabled {
    background: var(--bg-surface-2);
    color: var(--text-muted);
    cursor: not-allowed;
}

.t-select option {
    background: var(--bg-surface);
    color: var(--text-strong);
}

.t-help {
    font-size: var(--fs-xs);
    color: var(--text-muted);
}

/* Error state. Not colour alone: the border thickens and the message is
   announced, so the state survives a colour-blind or greyscale reading. */
.t-field--error .t-input,
.t-field--error .t-select,
.t-field--error .t-textarea {
    border-color: var(--danger);
    border-width: 2px;
    padding-block: calc(.7rem - 1px);
}

.t-error {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--danger-text);
}

.t-field-row {
    display: grid;
    gap: var(--sp-4);
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
}

/* Password input with a show/hide affordance. The button sits inside the field
   so the control reads as one visual unit. */
.password-field {
    position: relative;
    display: flex;
    align-items: center;
}

.password-field .t-input {
    padding-right: 3rem;
}

.password-toggle {
    position: absolute;
    right: .35rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.1rem;
    height: 2.1rem;
    border-radius: var(--r-xs);
    color: var(--text-muted);
    transition: color var(--dur-fast), background-color var(--dur-fast);
}

.password-toggle:hover {
    color: var(--text-strong);
    background: var(--bg-surface-2);
}

.password-toggle:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 1px;
}

/* Range slider ------------------------------------------------------------ */
.t-range {
    width: 100%;
    height: .35rem;
    margin: var(--sp-2) 0;
    padding: 0;
    background: var(--bg-surface-3);
    border-radius: var(--r-pill);
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.t-range::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    background: var(--brand);
    border: 2px solid var(--bg-surface);
    box-shadow: var(--sh-sm);
    transition: transform var(--dur-fast) var(--ease-out);
}

.t-range::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.t-range::-moz-range-thumb {
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    background: var(--brand);
    border: 2px solid var(--bg-surface);
    box-shadow: var(--sh-sm);
    cursor: pointer;
}

.t-range:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 4px;
}

/* Checkbox / radio ------------------------------------------------------- */
.t-check {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    font-size: var(--fs-sm);
    color: var(--text-body);
    cursor: pointer;
}

.t-check input {
    flex: none;
    width: 1.05rem;
    height: 1.05rem;
    margin-top: .15rem;
    accent-color: var(--brand);
    cursor: pointer;
}

/* ------------------------------------------------------------------ Badges */
.t-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    padding: .2rem .65rem;
    border-radius: var(--r-pill);
    background: var(--bg-surface-2);
    color: var(--text-body);
    font-size: var(--fs-xs);
    font-weight: 700;
    line-height: 1.5;
    white-space: nowrap;
}

.t-badge--brand   { background: var(--brand-soft);   color: var(--brand-soft-text); }
.t-badge--success { background: var(--success-soft); color: var(--success-text); }
.t-badge--warning { background: var(--warning-soft); color: var(--warning-text); }
.t-badge--danger  { background: var(--danger-soft);  color: var(--danger-text); }
.t-badge--info    { background: var(--info-soft);    color: var(--info-text); }
.t-badge--dot::before {
    content: "";
    width: .4rem;
    height: .4rem;
    border-radius: 50%;
    background: currentColor;
}

/* ------------------------------------------------------------------ Alerts */
.t-alert {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    margin-bottom: var(--sp-5);
    border: 1px solid var(--border-subtle);
    border-left: 4px solid var(--text-muted);
    border-radius: var(--r-sm);
    background: var(--bg-surface-2);
    color: var(--text-body);
    font-size: var(--fs-sm);
}

.t-alert i { flex: none; margin-top: .1rem; }

.t-alert--success { background: var(--success-soft); border-left-color: var(--success); color: var(--success-text); }
.t-alert--warning { background: var(--warning-soft); border-left-color: var(--warning); color: var(--warning-text); }
.t-alert--danger  { background: var(--danger-soft);  border-left-color: var(--danger);  color: var(--danger-text); }
.t-alert--info    { background: var(--info-soft);    border-left-color: var(--info);    color: var(--info-text); }

/* ------------------------------------------------------------------ Tables */
.t-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
    background: var(--bg-surface);
    -webkit-overflow-scrolling: touch;
}

.t-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-sm);
}

.t-table caption {
    padding: var(--sp-4);
    text-align: left;
    font-weight: 700;
    color: var(--text-strong);
}

.t-table th,
.t-table td {
    padding: var(--sp-3) var(--sp-4);
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}

.t-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-surface-2);
    color: var(--text-muted);
    font-size: var(--fs-2xs);
    font-weight: 700;
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    white-space: nowrap;
}

.t-table tbody tr:last-child td { border-bottom: 0; }
.t-table tbody tr:hover { background: var(--bg-surface-2); }

.t-table td.num,
.t-table th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.t-table__empty {
    padding: var(--sp-10);
    text-align: center;
    color: var(--text-muted);
}

/* --------------------------------------------------------------- Pagination */
.t-pagination {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
    align-items: center;
    justify-content: center;
    margin-top: var(--sp-6);
}

.t-pagination a,
.t-pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.4rem;
    height: 2.4rem;
    padding-inline: var(--sp-3);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-sm);
    background: var(--bg-surface);
    color: var(--text-body);
    font-size: var(--fs-sm);
    font-weight: 600;
}

.t-pagination a:hover {
    border-color: var(--brand);
    color: var(--brand);
}

.t-pagination .current {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--text-on-brand);
}

.t-pagination .disabled {
    opacity: .45;
    pointer-events: none;
}

/* ------------------------------------------------------------------- Modal */
.t-modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4);
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(4px);
}

.t-modal.is-open { display: flex; }

.t-modal__panel {
    width: min(100%, 34rem);
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    padding: var(--sp-6);
    background: var(--bg-surface);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-xl);
}

.t-modal__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-4);
    margin-bottom: var(--sp-5);
}

.t-modal__close {
    flex: none;
    width: 2rem;
    height: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-sm);
    color: var(--text-muted);
    transition: background-color var(--dur-fast), color var(--dur-fast);
}

.t-modal__close:hover {
    background: var(--bg-surface-2);
    color: var(--text-strong);
}

/* --------------------------------------------------------------------- Tabs */
.t-tabs {
    display: flex;
    gap: var(--sp-1);
    overflow-x: auto;
    border-bottom: 1px solid var(--border-subtle);
    scrollbar-width: thin;
}

.t-tab {
    flex: none;
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: var(--fs-sm);
    font-weight: 700;
    white-space: nowrap;
    transition: color var(--dur-fast), border-color var(--dur-fast);
}

.t-tab:hover { color: var(--text-strong); }

.t-tab.is-active {
    border-bottom-color: var(--brand);
    color: var(--brand);
}

.t-tab-panel { padding-top: var(--sp-6); }
.t-tab-panel[hidden] { display: none; }

/* ------------------------------------------------------------------ Details */
.t-details {
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-md);
    background: var(--bg-surface);
    overflow: hidden;
    transition: border-color var(--dur-base) var(--ease-out);
}

.t-details[open] {
    border-color: var(--brand);
}

.t-details + .t-details { margin-top: var(--sp-3); }

.t-details > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: var(--sp-4) var(--sp-5);
    font-weight: 700;
    color: var(--text-strong);
    cursor: pointer;
    list-style: none;
    transition: background-color var(--dur-fast), color var(--dur-fast);
}

.t-details > summary::-webkit-details-marker { display: none; }

.t-details > summary:hover {
    background: var(--bg-surface-2);
    color: var(--brand);
}

.t-details > summary i {
    flex: none;
    font-size: var(--fs-sm);
    color: var(--text-muted);
    transition: transform var(--dur-base) var(--ease-out);
}

.t-details[open] > summary i { transform: rotate(180deg); }

.t-details__body {
    padding: 0 var(--sp-5) var(--sp-5);
    border-top: 1px solid var(--border-subtle);
    padding-top: var(--sp-4);
    color: var(--text-body);
    font-size: var(--fs-sm);
    line-height: var(--lh-relaxed);
}

.t-details__body > :last-child { margin-bottom: 0; }
.t-details__body a { font-weight: 600; }

/* ------------------------------------------------------------------ Divider */
.t-divider {
    height: 1px;
    margin: var(--sp-6) 0;
    border: 0;
    background: var(--border-subtle);
}

/* --------------------------------------------------------------- Stat block */
.t-stat {
    padding: var(--sp-5);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-xs);
}

.t-stat__label {
    font-size: var(--fs-2xs);
    font-weight: 700;
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    color: var(--text-muted);
}

.t-stat__value {
    margin-top: var(--sp-1);
    font-size: clamp(1.5rem, 3vw, 2rem);
    font-weight: 800;
    line-height: 1.1;
    color: var(--text-strong);
    font-variant-numeric: tabular-nums;
}

.t-stat__meta { margin-top: var(--sp-2); font-size: var(--fs-xs); color: var(--text-muted); }

/* --------------------------------------------------------------- Empty state */
.t-empty {
    padding: var(--sp-12) var(--sp-5);
    text-align: center;
    border: 1px dashed var(--border-default);
    border-radius: var(--r-lg);
    background: var(--bg-surface);
    color: var(--text-muted);
}

.t-empty i {
    display: block;
    margin-bottom: var(--sp-3);
    font-size: 2rem;
    opacity: .5;
}

/* ---------------------------------------------------------------- Skeleton */
.t-skeleton {
    border-radius: var(--r-sm);
    background: linear-gradient(90deg,
        var(--bg-surface-2) 25%,
        var(--bg-surface-3) 37%,
        var(--bg-surface-2) 63%);
    background-size: 400% 100%;
    animation: t-shimmer 1.4s ease infinite;
}

@keyframes t-shimmer {
    0%   { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@media (max-width: 575.98px) {
    .t-card { padding: var(--sp-5); }
    .t-btn--block-sm { width: 100%; }
}
