:root {
    --tt-primary: #2c5bd6;
    --tt-primary-hover: #2450bf;
    --tt-primary-active: #1e46ad;
    --tt-background: #f4f5f8;
    --tt-surface: #ffffff;
    --tt-text: #1f2430;
    --tt-text-muted: #64748b;
    --tt-border: #e4e7ee;
    --tt-border-soft: #eef0f4;
    --tt-success: #198754;
    --tt-danger: #c02937;
    --tt-warning: #8a6d1a;
    --tt-radius: 14px;
    --tt-shadow: 0 10px 28px rgba(20, 30, 60, .14);
}

html {
    min-width: 320px;
}

body {
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    background: var(--tt-background);
    color: var(--tt-text);
    font-family: "Open Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14.5px;
    line-height: 1.5;
}

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

a {
    color: var(--tt-primary);
}

a:hover {
    color: var(--tt-primary-active);
}

.btn {
    --bs-btn-border-radius: 8px;
    min-height: 38px;
    transition: color .18s ease, background-color .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.btn-sm {
    min-height: 34px;
}

.btn-primary {
    --bs-btn-bg: var(--tt-primary);
    --bs-btn-border-color: var(--tt-primary);
    --bs-btn-hover-bg: var(--tt-primary-hover);
    --bs-btn-hover-border-color: var(--tt-primary-hover);
    --bs-btn-active-bg: var(--tt-primary-active);
    --bs-btn-active-border-color: var(--tt-primary-active);
    --bs-btn-disabled-bg: #93aeea;
    --bs-btn-disabled-border-color: #93aeea;
}

.btn-outline-primary {
    --bs-btn-color: var(--tt-primary);
    --bs-btn-border-color: #b9c9ef;
    --bs-btn-hover-bg: #eef3fd;
    --bs-btn-hover-color: var(--tt-primary-hover);
    --bs-btn-hover-border-color: var(--tt-primary);
    --bs-btn-active-bg: var(--tt-primary);
    --bs-btn-active-border-color: var(--tt-primary);
}

.btn-outline-secondary {
    --bs-btn-color: #4a5265;
    --bs-btn-border-color: #dfe3ea;
    --bs-btn-hover-bg: #f2f4f9;
    --bs-btn-hover-color: var(--tt-text);
    --bs-btn-hover-border-color: #c9d2e2;
    --bs-btn-active-bg: var(--tt-primary);
    --bs-btn-active-border-color: var(--tt-primary);
    --bs-btn-active-color: #fff;
}

.form-control,
.form-select {
    min-height: 42px;
    border-color: #ced4da;
    border-radius: 8px;
    font-size: 14px;
}

.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: #8fa9e8;
    box-shadow: 0 0 0 .25rem rgba(44, 91, 214, .15);
}

.form-check-input:checked {
    border-color: var(--tt-primary);
    background-color: var(--tt-primary);
}

:focus-visible {
    outline: 3px solid rgba(44, 91, 214, .42);
    outline-offset: 2px;
}

.tt-skip-link {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 3000;
    padding: 9px 13px;
    border-radius: 8px;
    background: var(--tt-text);
    color: #fff;
    transform: translateY(-160%);
}

.tt-skip-link:focus {
    color: #fff;
    transform: translateY(0);
}

.tt-page-loader {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--tt-text-muted);
}

.tt-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.tt-header {
    position: sticky;
    top: 0;
    z-index: 1030;
    border-bottom: 1px solid var(--tt-border);
    background: rgba(255, 255, 255, .96);
    backdrop-filter: saturate(150%) blur(10px);
}

.tt-header-inner {
    width: 100%;
    max-width: 1200px;
    height: 60px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tt-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--tt-text);
    text-decoration: none;
}

.tt-brand:hover {
    color: var(--tt-text);
}

.tt-brand-icon {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    background: var(--tt-primary);
    color: #fff;
    font-size: 17px;
}

.tt-brand-name {
    font-size: 16.5px;
    font-weight: 700;
    letter-spacing: -.01em;
}

.tt-admin-wrap {
    position: relative;
}

.tt-avatar-button {
    width: 44px;
    height: 44px;
    border: 1px solid #dfe3ea;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #eef1f7;
    color: #40516e;
    font-size: 19px;
}

.tt-avatar-button:hover,
.tt-avatar-button[aria-expanded="true"] {
    border-color: #c9d2e2;
    background: #e3e8f2;
}

.tt-admin-menu {
    position: absolute;
    top: 50px;
    right: 0;
    z-index: 1040;
    min-width: 220px;
    padding: 6px;
    border: 1px solid var(--tt-border);
    border-radius: 10px;
    background: #fff;
    box-shadow: var(--tt-shadow);
}

.tt-admin-meta {
    padding: 8px 12px 7px;
    color: var(--tt-text-muted);
    font-size: 12px;
}

.tt-admin-meta strong {
    color: var(--tt-text);
    font-size: 13px;
}

.tt-menu-divider {
    height: 1px;
    margin: 4px;
    background: #eceef2;
}

.tt-menu-link {
    min-height: 42px;
    padding: 9px 12px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--tt-text);
    text-decoration: none;
}

.tt-menu-link:hover {
    background: #f2f4f9;
    color: var(--tt-text);
}

.tt-menu-link-danger {
    color: var(--tt-danger);
}

.tt-menu-link-danger:hover {
    background: #fbeef0;
    color: var(--tt-danger);
}

.tt-main {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 26px 20px 60px;
    flex: 1;
}

.tt-main-narrow {
    max-width: 760px;
}

.tt-main-medium {
    max-width: 960px;
}

.tt-page-heading {
    margin: 0 0 3px;
    font-size: 21px;
    font-weight: 700;
    letter-spacing: -.01em;
}

.tt-page-subtitle {
    color: var(--tt-text-muted);
    font-size: 13px;
}

.tt-card {
    border: 1px solid #e6e9f0;
    border-radius: var(--tt-radius);
    background: var(--tt-surface);
}

.tt-login-page {
    min-height: 100vh;
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tt-login-wrap {
    width: 100%;
    max-width: 400px;
}

.tt-login-brand {
    margin-bottom: 22px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.tt-login-brand .tt-brand-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    box-shadow: 0 8px 20px rgba(44, 91, 214, .3);
    font-size: 26px;
}

.tt-login-title {
    font-size: 20px;
    font-weight: 700;
}

.tt-login-subtitle {
    margin-top: -6px;
    color: var(--tt-text-muted);
    font-size: 13.5px;
}

.tt-login-form {
    padding: 26px 26px 24px;
    border: 1px solid #e6e9f0;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 4px 16px rgba(20, 30, 60, .05);
}

.tt-section-card {
    margin-bottom: 16px;
    padding: 20px 22px;
}

.tt-section-heading {
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tt-section-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    background: #e9effc;
    color: var(--tt-primary);
    font-size: 15px;
}

.tt-section-title {
    margin: 0;
    font-size: 15.5px;
    font-weight: 700;
}

.tt-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 14px;
}

.tt-form-stack {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.tt-required {
    color: var(--tt-danger);
}

.tt-secret-toggle {
    width: 46px;
    min-height: 42px;
    border-color: #ced4da;
    color: #5b6472;
}

.tt-dashboard-top {
    margin-bottom: 18px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.tt-search {
    position: relative;
    width: min(420px, 100%);
}

.tt-search > i {
    position: absolute;
    top: 50%;
    left: 12px;
    z-index: 2;
    color: #8a93a6;
    transform: translateY(-50%);
}

.tt-search .form-control {
    padding-left: 36px;
    background: #fff;
}

.tt-stats {
    margin-bottom: 18px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px;
}

.tt-stat-card {
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.tt-stat-label {
    color: var(--tt-text-muted);
    font-size: 12.5px;
    font-weight: 600;
}

.tt-stat-value {
    font-size: 24px;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    letter-spacing: -.02em;
}

.tt-stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    font-size: 18px;
}

.tt-stat-icon-blue {
    background: #e9effc;
    color: var(--tt-primary);
}

.tt-stat-icon-green {
    background: #e6f4ec;
    color: var(--tt-success);
}

.tt-stat-icon-amber {
    background: #fdf3e2;
    color: #a6620c;
}

.tt-table-card {
    overflow: hidden;
}

.tt-table-card .table-responsive {
    scrollbar-width: thin;
}

.tt-table {
    min-width: 920px;
    margin: 0;
    font-size: 14px;
}

.tt-table thead th {
    padding: 12px;
    border-bottom: 1px solid #e9ebf1;
    background: #fafbfd;
    color: var(--tt-text-muted);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    white-space: nowrap;
}

.tt-table tbody td {
    padding: 13px 12px;
}

.tt-table tbody tr {
    cursor: pointer;
}

.tt-table tbody tr:hover > * {
    background: #f6f8fd;
}

.tt-mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-variant-numeric: tabular-nums;
}

.tt-badge {
    padding: 4px 11px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
}

.tt-badge-active {
    background: #e6f4ec;
    color: #14663f;
}

.tt-badge-ended {
    background: #eceef2;
    color: #5b6472;
}

.tt-badge-sent {
    background: #e7f0ff;
    color: #1d4fc4;
}

.tt-badge-pending {
    background: #fff6e0;
    color: #7c6114;
}

.tt-active-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--tt-success);
    animation: tt-pulse 1.6s infinite;
}

.tt-message-count {
    min-width: 34px;
    padding: 3px 9px;
    border-radius: 999px;
    display: inline-block;
    background: #f1f3f7;
    color: #4a5265;
    font-size: 12.5px;
    font-weight: 600;
    text-align: center;
}

.tt-table-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--tt-border-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

.pagination {
    --bs-pagination-active-bg: var(--tt-primary);
    --bs-pagination-active-border-color: var(--tt-primary);
    --bs-pagination-color: var(--tt-primary);
    --bs-pagination-hover-color: var(--tt-primary-active);
}

.tt-empty-state {
    padding: 64px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
}

.tt-empty-icon {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #f1f3f7;
    color: #8a94a7;
    font-size: 28px;
}

.tt-empty-title {
    margin-top: 6px;
    font-size: 15.5px;
    font-weight: 600;
}

.tt-empty-copy {
    max-width: 390px;
    color: var(--tt-text-muted);
    font-size: 13.5px;
}

.tt-skeleton-list {
    padding: 8px 0;
}

.tt-skeleton-row {
    padding: 15px 20px;
    border-bottom: 1px solid #f1f3f7;
    display: flex;
    align-items: center;
    gap: 18px;
}

.tt-skeleton {
    height: 13px;
    border-radius: 6px;
    background: linear-gradient(90deg, #eef0f4 25%, #f8f9fb 50%, #eef0f4 75%);
    background-size: 200% 100%;
    animation: tt-shimmer 1.2s infinite linear;
}

.tt-conversation-main {
    max-width: 920px;
    padding-top: 20px;
    padding-bottom: 40px;
    display: flex;
    flex-direction: column;
}

.tt-conversation-toolbar {
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.tt-conversation-meta {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.tt-chat {
    height: calc(100vh - 178px);
    min-height: 420px;
    padding: 18px 18px 14px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.tt-day-divider {
    margin: 16px 0 10px;
    display: flex;
    justify-content: center;
}

.tt-day-divider span {
    padding: 3px 13px;
    border-radius: 999px;
    background: #eef0f4;
    color: #5b6472;
    font-size: 12px;
    font-weight: 600;
}

.tt-message-row {
    margin: 4px 0;
    display: flex;
    align-items: center;
    gap: 9px;
}

.tt-message-row-user {
    justify-content: flex-start;
}

.tt-message-row-bot {
    justify-content: flex-end;
}

.tt-message-wrap {
    position: relative;
    max-width: min(68%, 560px);
}

.tt-message-bubble {
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.55;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.tt-message-row-user .tt-message-bubble {
    border-bottom-left-radius: 4px;
    background: #eef0f4;
    color: var(--tt-text);
}

.tt-message-row-bot .tt-message-bubble {
    border-bottom-right-radius: 4px;
    background: var(--tt-primary);
    color: #fff;
}

.tt-message-time,
.tt-agent-label {
    margin-top: 3px;
    color: var(--tt-text-muted);
    font-size: 11px;
}

.tt-message-row-bot .tt-message-time,
.tt-agent-label {
    text-align: right;
}

.tt-message-row[data-selectable="true"] {
    cursor: pointer;
}

.tt-message-selection {
    position: absolute;
    inset: -3px -3px 14px;
    min-height: 100%;
    border: 2px solid var(--tt-primary);
    border-radius: 16px;
    background: rgba(44, 91, 214, .07);
    pointer-events: none;
}

.tt-message-row-bot .tt-message-selection {
    border-color: var(--tt-primary-active);
    background: rgba(255, 255, 255, .12);
}

.tt-check-icon {
    flex: 0 0 auto;
    color: #a4adbe;
    font-size: 18px;
}

.tt-check-icon-selected {
    color: var(--tt-primary);
}

.tt-selection-bar {
    position: fixed;
    bottom: 18px;
    left: 50%;
    z-index: 1500;
    max-width: calc(100vw - 24px);
    padding: 10px 12px 10px 18px;
    border-radius: 13px;
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--tt-text);
    color: #fff;
    box-shadow: 0 14px 36px rgba(20, 30, 60, .35);
    transform: translateX(-50%);
    white-space: nowrap;
}

.tt-logs-list {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    scrollbar-width: thin;
}

.tt-log-row {
    padding: 12px 18px;
    border-bottom: 1px solid #f1f3f7;
}

.tt-log-summary {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
}

.tt-log-level {
    min-width: 54px;
    padding: 4px 8px;
    border-radius: 6px;
    display: inline-block;
    font-family: ui-monospace, Menlo, monospace;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .05em;
    text-align: center;
}

.tt-log-info {
    background: #e7f0ff;
    color: #1d4fc4;
}

.tt-log-warn {
    background: #fff3cd;
    color: #7c6114;
}

.tt-log-error {
    background: #fdeaea;
    color: #b02a37;
}

.tt-log-context {
    margin-top: 1px;
    padding: 3px 9px;
    border-radius: 6px;
    background: #f1f3f7;
    color: #4a5265;
    font-family: ui-monospace, Menlo, monospace;
    font-size: 12px;
}

.tt-log-message {
    min-width: 220px;
    padding-top: 2px;
    flex: 1;
    font-size: 13.5px;
}

.tt-log-detail {
    margin: 10px 0 2px;
    padding: 12px 14px;
    overflow: auto;
    border: 1px solid #e6e9f0;
    border-radius: 9px;
    background: #f7f9fc;
    color: #37415a;
    font-size: 12px;
    line-height: 1.55;
    white-space: pre-wrap;
}

.tt-list-end {
    padding: 16px;
    color: #8b94a7;
    font-size: 12.5px;
    text-align: center;
}

.tt-toast-region {
    position: fixed;
    top: 74px;
    right: 18px;
    z-index: 2100;
    width: min(370px, calc(100vw - 36px));
}

.tt-toast {
    margin-bottom: 10px;
    padding: 13px 16px;
    border: 1px solid var(--tt-border);
    border-left: 4px solid var(--tt-success);
    border-radius: 10px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: #fff;
    box-shadow: 0 12px 30px rgba(20, 30, 60, .16);
    font-size: 13.5px;
}

.tt-toast-error {
    border-left-color: #dc3545;
}

.tt-modal-content {
    overflow: hidden;
    border: 0;
    border-radius: var(--tt-radius);
    box-shadow: var(--tt-shadow);
}

.modal-backdrop.show {
    opacity: .52;
}

@keyframes tt-pulse {
    0% { box-shadow: 0 0 0 0 rgba(25, 135, 84, .45); }
    70% { box-shadow: 0 0 0 6px rgba(25, 135, 84, 0); }
    100% { box-shadow: 0 0 0 0 rgba(25, 135, 84, 0); }
}

@keyframes tt-shimmer {
    0% { background-position: 150% 0; }
    100% { background-position: -150% 0; }
}

@media (max-width: 767.98px) {
    body {
        font-size: 14px;
    }

    .tt-header-inner,
    .tt-main {
        padding-right: 16px;
        padding-left: 16px;
    }

    .tt-main {
        padding-top: 20px;
        padding-bottom: 40px;
    }

    .tt-brand-name {
        font-size: 15.5px;
    }

    .tt-section-card {
        padding: 18px 16px;
    }

    .btn,
    .btn-sm,
    .form-control,
    .form-select,
    .tt-secret-toggle {
        min-height: 44px;
    }

    .tt-form-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .tt-stats {
        grid-template-columns: 1fr;
    }

    .tt-chat {
        height: calc(100dvh - 226px);
        min-height: 360px;
        padding: 14px 12px;
    }

    .tt-message-wrap {
        max-width: 82%;
    }

    .tt-selection-bar {
        right: 12px;
        bottom: 12px;
        left: 12px;
        max-width: none;
        justify-content: space-between;
        gap: 8px;
        transform: none;
        white-space: normal;
    }

    .tt-selection-bar .btn {
        font-size: 12px;
    }

    .tt-log-summary {
        gap: 8px;
    }

    .tt-log-message {
        min-width: 100%;
        order: 5;
    }

    .tt-logs-list {
        max-height: calc(100dvh - 190px);
    }
}

@media (max-width: 420px) {
    .tt-login-page {
        padding: 18px 14px;
    }

    .tt-login-form {
        padding: 22px 18px;
    }

    .tt-conversation-toolbar > div:last-child {
        width: 100%;
    }

    .tt-conversation-toolbar > div:last-child .btn {
        flex: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
