* {
    box-sizing: border-box;
}

:root {
    color-scheme: light dark;
    --td-bg: #f4f7fb;
    --td-header: #232f3e;
    --td-header-text: #f8fafc;
    --tensor-banner-from: #0f766e;
    --tensor-banner-to: #14b8a6;
    --tensor-banner-shadow: rgba(15, 118, 110, 0.28);
    --td-card: #ffffff;
    --td-text: #0f172a;
    --td-muted: #64748b;
    --td-border: #e2e8f0;
    --td-shadow: 0 8px 28px rgba(15, 23, 42, 0.08);
}

@media (prefers-color-scheme: dark) {
    :root {
        --td-bg: #0f172a;
        --td-card: #1e293b;
        --td-text: #f1f5f9;
        --td-muted: #94a3b8;
        --td-border: #334155;
        --td-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
        --tensor-banner-from: #134e4a;
        --tensor-banner-to: #0d9488;
        --tensor-banner-shadow: rgba(6, 95, 87, 0.42);
    }
}

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--td-bg);
    color: var(--td-text);
    min-height: 100vh;
}

/* —— Login —— */
.td-login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.td-login {
    width: min(100%, 440px);
}

.td-login-card {
    background: var(--td-card);
    border: 1px solid var(--td-border);
    border-radius: 16px;
    padding: 32px;
    box-shadow: var(--td-shadow);
}

.td-eyebrow {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--td-muted);
    margin: 0 0 8px;
}

.td-login-card h1 {
    margin: 0 0 12px;
    font-size: 1.75rem;
}

.td-subtitle {
    margin: 0 0 24px;
    color: var(--td-muted);
    line-height: 1.55;
    font-size: 0.95rem;
}

.td-primary-btn {
    width: 100%;
    padding: 14px 20px;
    border: 0;
    border-radius: 10px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    background: #ff9900;
    color: #111827;
}

.td-primary-btn:hover {
    filter: brightness(1.05);
}

.td-msg {
    margin: 16px 0 0;
    min-height: 1.25em;
    font-size: 0.9rem;
    color: #b45309;
}

/* —— Console chrome —— */
.td-console-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 22px 26px;
    background: linear-gradient(135deg, var(--tensor-banner-from), var(--tensor-banner-to));
    color: var(--td-header-text);
    border-radius: 18px;
    box-shadow: 0 12px 28px var(--tensor-banner-shadow);
    margin: 18px 18px 0;
}

.td-console-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.td-console-logo-img {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: contain;
    display: block;
    background: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.td-console-title {
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
}

.td-console-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.td-user-pill {
    font-size: 0.875rem;
    opacity: 0.92;
    flex-basis: 100%;
    font-weight: 700;
    order: 2;
    overflow: hidden;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.td-logout-btn {
    padding: 8px 14px;
    border-radius: 10px;
    border: 1px solid rgba(248, 250, 252, 0.35);
    background: rgba(15, 23, 42, 0.22);
    color: var(--td-header-text);
    font-weight: 600;
    cursor: pointer;
    order: 1;
}

.td-logout-btn:hover {
    background: rgba(15, 23, 42, 0.38);
}

.td-console-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 36px 28px 56px;
}

.td-welcome h1 {
    margin: 0 0 8px;
    font-size: 1.75rem;
}

.td-welcome-meta {
    margin: 0 0 28px;
    color: var(--td-muted);
    font-size: 0.95rem;
}

/* —— Tiles (AWS-console style) —— */
.td-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
}

.td-tile {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    padding: 22px;
    background: var(--td-card);
    border: 1px solid var(--td-border);
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
    transition:
        transform 0.18s ease,
        box-shadow 0.18s ease,
        border-color 0.18s ease;
}

.td-tile:hover {
    transform: translateY(-3px);
    box-shadow: var(--td-shadow);
    border-color: color-mix(in srgb, var(--tile-accent, #2563eb) 35%, var(--td-border));
}

.td-tile:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--tile-accent, #2563eb) 55%, transparent);
    outline-offset: 2px;
}

.td-tile-icon {
    flex-shrink: 0;
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.72rem;
    letter-spacing: 0.02em;
    color: #fff;
    background: linear-gradient(145deg, var(--tile-banner-from, var(--tile-accent, #2563eb)), var(--tile-banner-to, var(--tile-accent, #2563eb)));
}

.td-tile-icon--photo {
    padding: 8px;
    background: linear-gradient(145deg, var(--tile-banner-from, var(--tile-accent, #2563eb)), var(--tile-banner-to, var(--tile-accent, #2563eb)));
    border: 1px solid color-mix(in srgb, var(--tile-banner-to, var(--tile-accent, #2563eb)) 55%, #ffffff);
    font-size: 0;
    line-height: 0;
}

.td-tile-icon--photo img {
    width: 36px;
    height: 36px;
    object-fit: contain;
    border-radius: 8px;
    display: block;
}

.td-tile-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.td-tile-title {
    font-weight: 700;
    font-size: 1.05rem;
}

.td-tile-desc {
    font-size: 0.875rem;
    color: var(--td-muted);
    line-height: 1.45;
}

.td-empty {
    margin-top: 12px;
    padding: 20px;
    border-radius: 12px;
    background: color-mix(in srgb, var(--td-muted) 12%, transparent);
    color: var(--td-muted);
    line-height: 1.5;
}

.hidden {
    display: none !important;
}

/* —— App navigation (Dashboard ↔ Applications) —— */
.td-app-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 28px;
    position: relative;
}

.td-app-nav-link {
    display: inline-flex;
    align-items: center;
    padding: 10px 18px;
    border-radius: 999px;
    border: 1px solid var(--td-border);
    background: var(--td-card);
    color: var(--td-text);
    font-weight: 600;
    font-size: 0.92rem;
    text-decoration: none;
    transition:
        background 0.15s ease,
        border-color 0.15s ease,
        transform 0.12s ease;
}

.td-app-nav-link:hover {
    border-color: color-mix(in srgb, #ff9900 45%, var(--td-border));
    transform: translateY(-1px);
}

.td-app-nav-link.active {
    border-color: transparent;
    background: linear-gradient(135deg, #ff9900, #f97316);
    color: #111827;
}

/* —— Company dashboard —— */
.td-dash-panels {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.td-dash-loading,
.td-dash-empty {
    margin: 0;
    padding: 18px;
    border-radius: 12px;
    border: 1px dashed var(--td-border);
    color: var(--td-muted);
}

.td-dash-panel {
    border-radius: 14px;
    border: 1px solid var(--td-border);
    background: var(--td-card);
    padding: 22px 24px;
    box-shadow: var(--td-shadow);
    border-left: 4px solid var(--dash-accent, #2563eb);
}

.td-dash-panel-head {
    margin-bottom: 18px;
}

.td-dash-panel-brand {
    display: flex;
    gap: 14px;
    align-items: center;
}

.td-dash-logo {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    object-fit: contain;
    background: color-mix(in srgb, var(--dash-accent, #2563eb) 12%, var(--td-card));
    border: 1px solid var(--td-border);
}

.td-dash-icon-fallback {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.75rem;
    color: #fff;
    background: linear-gradient(145deg, var(--dash-accent, #2563eb), color-mix(in srgb, var(--dash-accent, #2563eb) 55%, #000));
}

.td-dash-panel h2 {
    margin: 0;
    font-size: 1.2rem;
}

.td-dash-panel-meta {
    margin: 4px 0 0;
    font-size: 0.88rem;
}

.td-dash-panel-meta a {
    color: var(--dash-accent, #2563eb);
    font-weight: 600;
    text-decoration: none;
}

.td-dash-panel-meta a:hover {
    text-decoration: underline;
}

.td-dash-metrics {
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px 18px;
}

.td-dash-metric {
    margin: 0;
}

.td-dash-metric dt {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--td-muted);
    margin-bottom: 4px;
}

.td-dash-metric dd {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.2;
}

.td-dash-metric-note {
    display: block;
    margin-top: 4px;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--td-muted);
}

.td-dash-footnote {
    margin: 14px 0 0;
    font-size: 0.82rem;
    color: var(--td-muted);
    line-height: 1.45;
}

.td-dash-error {
    margin: 0;
    color: #b45309;
    font-size: 0.92rem;
}

.td-dash-error a {
    color: #c2410c;
    font-weight: 600;
}

.nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
    width: 46px;
    height: 42px;
    padding: 0;
    border-radius: 12px;
    border: 1px solid var(--td-border);
    background: var(--td-card);
    cursor: pointer;
}

.nav-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    border-radius: 999px;
    background: #ea580c;
}

@media (max-width: 768px) {
    .td-console-header {
        margin: 12px 12px 0;
        padding: 16px 18px;
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .td-console-brand {
        min-width: 0;
    }

    .td-console-title {
        word-break: break-word;
    }

    .td-console-actions {
        width: 100%;
        justify-content: flex-start;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .td-user-pill {
        order: 1;
        flex-basis: auto;
        white-space: normal;
        overflow: visible;
        text-align: left;
        word-break: break-word;
    }

    .td-logout-btn {
        order: 2;
        align-self: flex-start;
    }

    .td-console-main {
        padding: 16px 14px 32px;
    }

    .td-app-nav {
        flex-wrap: wrap;
        align-items: center;
        padding: 6px;
        gap: 8px;
        border: 1px solid var(--td-border);
        border-radius: 14px;
        background: var(--td-card);
    }

    .nav-toggle {
        display: inline-flex;
        flex: 0 0 46px;
    }

    .td-app-nav-link {
        flex: 1 1 calc(50% - 8px);
        justify-content: center;
    }

    .td-app-nav:not(.is-open) .td-app-nav-link {
        display: none;
    }
}
