/* ============================================
   TrustSpace Partner Portal - Clean Design
   ============================================ */

/* --- CSS Variables --- */
:root {
    --primary: #0055FF;
    --primary-light: #3377FF;
    --primary-dark: #0044CC;
    --primary-bg: rgba(0, 85, 255, 0.06);
    --primary-bg-hover: rgba(0, 85, 255, 0.10);
    --bg: #f5f5f7;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --border: #e5e5e7;
    --border-light: #f0f0f2;
    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --text-tertiary: #86868b;
    --text-on-primary: #ffffff;
    --success: #30D158;
    --success-bg: rgba(48, 209, 88, 0.10);
    --warning: #FF9F0A;
    --warning-bg: rgba(255, 159, 10, 0.10);
    --error: #FF3B30;
    --error-bg: rgba(255, 59, 48, 0.08);
    --info: #0055FF;
    --info-bg: rgba(0, 85, 255, 0.06);
    --emerald: #34C759;
    --emerald-bg: rgba(52, 199, 89, 0.10);
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 20px 40px -4px rgba(0, 0, 0, 0.10);
    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;
    --transition: 0.2s ease;
    --transition-slow: 0.3s ease;
    --sidebar-width: 260px;
    --header-height: 64px;
    --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', system-ui, sans-serif;
}

/* --- Reset --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg);
    overflow-x: hidden;
}

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ==================== LOGIN SCREEN ==================== */

.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    padding: 48px 40px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-light);
}

.login-logo {
    text-align: center;
    margin-bottom: 36px;
}

.login-logo-img {
    height: 48px;
    margin: 0 auto 16px;
    display: block;
    object-fit: contain;
}

.login-logo h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 14px;
    color: var(--primary);
    font-weight: 600;
}

.login-error {
    background: var(--error-bg);
    color: var(--error);
    font-size: 13px;
    font-weight: 500;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    text-align: center;
}

.login-forgot {
    text-align: center;
    margin-top: 16px;
}

.login-forgot a {
    color: var(--primary);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: color var(--transition);
}

.login-forgot a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

.login-info {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
    text-align: center;
    margin-bottom: 24px;
    padding: 0 8px;
}

.login-success {
    background: var(--success-bg);
    color: var(--success);
    font-size: 13px;
    font-weight: 500;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    text-align: center;
}

/* ==================== FORM ELEMENTS ==================== */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 85, 255, 0.12);
    background: var(--bg-card);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-tertiary);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1.5 1.5L6 6l4.5-4.5' stroke='%2386868b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ==================== BUTTONS ==================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    white-space: nowrap;
    cursor: pointer;
    border: none;
    line-height: 1.4;
}

.btn-primary {
    background: var(--primary);
    color: var(--text-on-primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: var(--shadow-sm);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1.5px solid var(--border);
}

.btn-ghost:hover {
    background: var(--bg);
    border-color: var(--text-tertiary);
    color: var(--text-primary);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}

.btn-xs {
    padding: 4px 10px;
    font-size: 12px;
}

.btn-full {
    width: 100%;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all var(--transition);
    border: none;
    background: none;
    cursor: pointer;
}

.btn-icon:hover {
    background: var(--bg);
    color: var(--text-primary);
}

.btn .btn-loading { display: none; }
.btn.loading .btn-text { display: none; }
.btn.loading .btn-loading { display: inline-flex; align-items: center; gap: 8px; }

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==================== APP LAYOUT ==================== */

.app {
    display: flex;
    min-height: 100vh;
}

/* ==================== SIDEBAR ==================== */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition-slow);
}

.sidebar-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-card);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo-img {
    height: 32px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
}

.sidebar-logo-text {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
}

.nav-section-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 16px 12px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
    cursor: pointer;
    margin-bottom: 2px;
}

.nav-item:hover {
    background: var(--bg);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--primary-bg);
    color: var(--primary);
    font-weight: 600;
}

.nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-item.active svg {
    opacity: 1;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-light);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.sidebar-user-avatar {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-full);
    background: var(--primary-bg);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}

.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
}

.sidebar-user-role {
    font-size: 11px;
    color: var(--text-tertiary);
    text-transform: capitalize;
}

.sidebar-powered {
    font-size: 11px;
    color: var(--text-tertiary);
    text-align: center;
    padding-top: 8px;
    border-top: 1px solid var(--border-light);
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 99;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.visible {
    display: block;
}

/* ==================== MAIN WRAPPER ==================== */

.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ==================== HEADER ==================== */

.header {
    position: sticky;
    top: 0;
    height: var(--header-height);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    z-index: 50;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.mobile-menu-btn {
    display: none;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-user-name {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ==================== CONTENT AREA ==================== */

.content {
    flex: 1;
    padding: 32px;
    max-width: 1400px;
    width: 100%;
}

/* ==================== STAT CARDS ==================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow-sm);
}

.stat-card-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-tertiary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.stat-card-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    line-height: 1.1;
}

/* ==================== ANALYTICS DASHBOARD ==================== */

.stats-grid-wide {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
    margin-bottom: 32px;
}

.stats-grid-wide .stat-card {
    padding: 20px;
}

.stats-grid-wide .stat-card-value {
    font-size: 28px;
}

.chart-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-xs);
    padding: 24px;
    margin-bottom: 24px;
}

.chart-container .card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.2px;
    margin-bottom: 20px;
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 140px;
    padding-top: 8px;
}

.chart-bar {
    flex: 1;
    min-width: 0;
    background: var(--primary);
    border-radius: 3px 3px 0 0;
    transition: opacity var(--transition);
    position: relative;
    cursor: default;
    opacity: 0.7;
}

.chart-bar:hover {
    opacity: 1;
}

.chart-bar-tooltip {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: var(--bg-card);
    font-size: 11px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    margin-bottom: 4px;
    pointer-events: none;
    z-index: 10;
}

.chart-bar:hover .chart-bar-tooltip {
    display: block;
}

.chart-bar-labels {
    display: flex;
    gap: 3px;
    margin-top: 8px;
}

.chart-bar-label {
    flex: 1;
    min-width: 0;
    text-align: center;
    font-size: 10px;
    color: var(--text-tertiary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.breakdown-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.breakdown-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-xs);
    padding: 24px;
}

.breakdown-card .card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.breakdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-light);
}

.breakdown-item:last-child {
    border-bottom: none;
}

.breakdown-item-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: capitalize;
}

.breakdown-item-count {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
}

.breakdown-empty {
    font-size: 13px;
    color: var(--text-tertiary);
    padding: 12px 0;
}

/* ==================== TABLES ==================== */

.table-wrapper {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
}

.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    flex-wrap: wrap;
}

.table-toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    flex: 1;
}

.table-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-input {
    padding: 8px 14px 8px 36px;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-primary);
    width: 260px;
    max-width: 100%;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
    background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 10-1.397 1.398h-.001l3.85 3.85a1 1 0 001.415-1.414l-3.85-3.85-.017.016zm-5.242.156a5 5 0 110-10 5 5 0 010 10z' fill='%2386868b'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
}

.search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 85, 255, 0.12);
    background-color: var(--bg-card);
}

.filter-select {
    padding: 8px 32px 8px 12px;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-primary);
    outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1.5 1.5L6 6l4.5-4.5' stroke='%2386868b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    cursor: pointer;
    transition: border-color var(--transition);
}

.filter-select:focus {
    border-color: var(--primary);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--bg);
}

th {
    text-align: left;
    padding: 12px 20px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
}

td {
    padding: 14px 20px;
    font-size: 14px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tbody tr {
    transition: background var(--transition);
}

tbody tr:hover {
    background: var(--bg);
}

tbody tr.clickable {
    cursor: pointer;
}

tbody tr.expanded {
    background: var(--primary-bg);
}

.table-empty {
    padding: 48px 20px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 14px;
}

.table-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-top: 1px solid var(--border-light);
}

.table-pagination-info {
    font-size: 13px;
    color: var(--text-tertiary);
}

.table-pagination-btns {
    display: flex;
    gap: 4px;
}

/* ==================== STATUS BADGES ==================== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}

.badge-new {
    background: var(--info-bg);
    color: var(--primary);
}

.badge-contacted {
    background: var(--warning-bg);
    color: #B87100;
}

.badge-qualified {
    background: var(--success-bg);
    color: #1B9E3E;
}

.badge-won {
    background: var(--emerald-bg);
    color: #1F8C3B;
}

.badge-lost {
    background: var(--error-bg);
    color: var(--error);
}

/* ==================== DETAIL PANEL ==================== */

.detail-row td {
    padding: 0;
    background: var(--bg);
}

.detail-panel {
    padding: 24px;
    border-top: 1px solid var(--border-light);
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.detail-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 4px;
}

.detail-field .value {
    font-size: 14px;
    color: var(--text-primary);
    word-break: break-word;
}

.detail-actions {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

/* ==================== CARDS ==================== */

.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-xs);
    padding: 24px;
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

/* ==================== CHAT LOG STYLES ==================== */

.chat-sessions-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-session-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
    transition: box-shadow var(--transition);
}

.chat-session-card:hover {
    box-shadow: var(--shadow-sm);
}

.chat-session-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    cursor: pointer;
    transition: background var(--transition);
}

.chat-session-header:hover {
    background: var(--bg);
}

.chat-session-info {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    min-width: 0;
}

.chat-session-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--primary-bg);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-session-details {
    flex: 1;
    min-width: 0;
}

.chat-session-id {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-session-meta {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-session-toggle {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    color: var(--text-tertiary);
    transition: all var(--transition);
    flex-shrink: 0;
}

.chat-session-toggle.expanded {
    transform: rotate(180deg);
}

.chat-session-messages {
    display: none;
    padding: 0 20px 20px;
    border-top: 1px solid var(--border-light);
}

.chat-session-messages.visible {
    display: block;
}

.chat-bubble-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-top: 16px;
    max-height: 500px;
    overflow-y: auto;
}

.chat-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

.chat-bubble.user {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-bubble.assistant {
    align-self: flex-start;
    background: var(--bg);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    border-bottom-left-radius: 4px;
}

.chat-bubble-time {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 4px;
}

.chat-bubble.user .chat-bubble-time {
    color: rgba(255, 255, 255, 0.7);
    text-align: right;
}

/* ==================== TOAST NOTIFICATIONS ==================== */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 14px 20px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-light);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    min-width: 280px;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.2s ease;
}

.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error { border-left: 3px solid var(--error); }
.toast.toast-info { border-left: 3px solid var(--primary); }

@keyframes slideIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ==================== SECTION HEADER ==================== */

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.section-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

/* ==================== EMPTY STATE ==================== */

.empty-state {
    text-align: center;
    padding: 64px 24px;
    color: var(--text-tertiary);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state-text {
    font-size: 15px;
    margin-bottom: 20px;
}

/* ==================== LOADING ==================== */

.loading-view {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 80px 24px;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ==================== RESPONSIVE ==================== */

@media (max-width: 1200px) {
    .stats-grid-wide {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-wrapper {
        margin-left: 0;
    }

    .mobile-menu-btn {
        display: flex;
    }

    .header {
        padding: 0 16px;
    }

    .content {
        padding: 20px 16px;
    }

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

    .stats-grid-wide {
        grid-template-columns: repeat(2, 1fr);
    }

    .breakdown-grid {
        grid-template-columns: 1fr;
    }

    .chart-bars {
        height: 100px;
    }

    .table-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .table-toolbar-left {
        flex-direction: column;
    }

    .search-input {
        width: 100%;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .login-card {
        padding: 32px 24px;
    }

    td, th {
        padding: 10px 12px;
        font-size: 13px;
    }

    .header-user-name {
        display: none;
    }

    .chat-bubble {
        max-width: 90%;
    }
}

@media (max-width: 480px) {
    .stats-grid-wide {
        grid-template-columns: 1fr;
    }

    .chat-session-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
    }
}

/* ==================== UTILITY ==================== */

.text-muted { color: var(--text-tertiary); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.font-mono { font-family: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.hidden, [hidden] { display: none !important; }

/* ==================== A/B TESTS ==================== */

.ab-tests-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ab-test-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-xs);
    padding: 24px;
    transition: box-shadow var(--transition);
}

.ab-test-card:hover {
    box-shadow: var(--shadow-sm);
}

.ab-test-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 16px;
}

.ab-test-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.ab-test-element {
    font-size: 13px;
    color: var(--text-tertiary);
}

.ab-status-draft { background: var(--bg); color: var(--text-tertiary); padding: 3px 10px; border-radius: var(--radius-full); font-size: 12px; font-weight: 600; }
.ab-status-running { background: var(--success-bg); color: #1B9E3E; padding: 3px 10px; border-radius: var(--radius-full); font-size: 12px; font-weight: 600; }
.ab-status-paused { background: var(--warning-bg); color: #B87100; padding: 3px 10px; border-radius: var(--radius-full); font-size: 12px; font-weight: 600; }
.ab-status-completed { background: var(--info-bg); color: var(--primary); padding: 3px 10px; border-radius: var(--radius-full); font-size: 12px; font-weight: 600; }

.ab-variants {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ab-variant-row {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ab-variant-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.ab-variant-value {
    font-size: 13px;
    color: var(--text-secondary);
    word-break: break-word;
}

.ab-variant-stats {
    display: flex;
    gap: 16px;
    margin-top: 4px;
}

.ab-stat {
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 500;
}

.ab-stat-rate {
    font-weight: 700;
    color: var(--primary);
}

/* ==================== TRACKING ==================== */

.tracking-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.tracking-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-xs);
    padding: 24px;
    transition: box-shadow var(--transition);
}

.tracking-card:hover {
    box-shadow: var(--shadow-sm);
}

.tracking-card-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.tracking-service-icon {
    font-size: 28px;
    line-height: 1;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.tracking-service-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.tracking-status {
    font-size: 12px;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.status-dot.status-connected {
    background: var(--success);
}

.status-dot.status-disconnected {
    background: var(--error);
}

.status-dot.status-unknown {
    background: var(--text-tertiary);
}

.tracking-id-display {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    font-family: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
}

.ab-test-id {
    font-family: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-tertiary);
    margin-right: 4px;
}

/* ==================== A/B TEST ACTIONS ==================== */

.ab-test-actions {
    display: flex;
    gap: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
    margin-top: 16px;
}

/* ==================== EXTRA BUTTONS ==================== */

.btn-danger {
    background: var(--error);
    color: white;
}

.btn-danger:hover {
    background: #E5342A;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #28BD4E;
}

/* ==================== MODAL ==================== */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: fadeIn 0.15s ease;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: slideUp 0.2s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-light);
}

.modal-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    color: var(--text-tertiary);
    transition: all var(--transition);
    cursor: pointer;
    border: none;
    background: none;
}

.modal-close:hover {
    background: var(--bg);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-light);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==================== A/B VARIANT INPUTS ==================== */

.ab-variant-input {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.ab-variant-input input[type="text"] {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-primary);
    outline: none;
}

.ab-variant-input input[type="number"] {
    padding: 8px 12px;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-primary);
    outline: none;
}

.ab-variant-input input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 85, 255, 0.12);
}

/* ==================== FEATURE FLAGS ==================== */

.flags-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.flag-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-xs);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    transition: box-shadow var(--transition);
}

.flag-card:hover {
    box-shadow: var(--shadow-sm);
}

.flag-info {
    flex: 1;
    min-width: 0;
}

.flag-key {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
    margin-bottom: 2px;
}

.flag-description {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.flag-value {
    font-size: 12px;
    color: var(--text-tertiary);
}

/* Toggle switch */
.toggle {
    position: relative;
    display: inline-block;
    flex-shrink: 0;
}

.toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    display: block;
    width: 46px;
    height: 26px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 26px;
    cursor: pointer;
    transition: background 0.3s ease;
    position: relative;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    transition: transform 0.3s ease;
}

.toggle input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle input:checked + .toggle-slider::after {
    transform: translateX(20px);
}

/* ==================== MARKET MONITOR ==================== */

.competitor-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.competitor-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-xs);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: box-shadow var(--transition);
}

.competitor-card:hover {
    box-shadow: var(--shadow-md);
}

.competitor-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.competitor-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

.competitor-url {
    font-size: 12px;
    color: var(--text-tertiary);
    text-decoration: none;
    display: inline-block;
    margin-top: 2px;
    transition: color var(--transition);
}

.competitor-url:hover {
    color: var(--primary);
    text-decoration: underline;
}

.competitor-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.competitor-pricing {
    display: inline-block;
    padding: 4px 12px;
    background: var(--primary-bg);
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
    border-radius: var(--radius-full);
    align-self: flex-start;
}

.competitor-diff {
    font-size: 12px;
    color: var(--text-tertiary);
    line-height: 1.5;
}

.competitor-diff strong {
    font-weight: 600;
    color: var(--text-secondary);
}

@media (max-width: 1024px) {
    .competitor-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .tracking-grid {
        grid-template-columns: 1fr;
    }

    .ab-variant-stats {
        flex-wrap: wrap;
        gap: 8px;
    }

    .ab-variant-input {
        flex-direction: column;
    }

    .ab-variant-input input[type="number"] {
        width: 100% !important;
    }

    .modal {
        max-width: 100%;
        border-radius: var(--radius) var(--radius) 0 0;
    }

    .partner-ai-container {
        height: 50vh;
    }

    .knowledge-files-partner {
        grid-template-columns: 1fr;
    }
}

/* Partner Chatbot Config (read-only) */
.code-preview {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 12px;
    line-height: 1.6;
    padding: 16px;
    background: var(--bg-secondary, #f5f5f7);
    border: 1px solid var(--border, #e5e5ea);
    border-radius: 8px;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 400px;
    overflow-y: auto;
    color: var(--text-secondary, #6e6e73);
}

.knowledge-files-partner {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    padding: 0 20px 20px;
}

.knowledge-file-card-partner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border: 1px solid var(--border, #e5e5ea);
    border-radius: 8px;
    background: var(--bg-primary, #fff);
}

.knowledge-file-header-partner {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.knowledge-file-name-partner {
    font-family: 'SF Mono', monospace;
    font-weight: 600;
    font-size: 13px;
    color: var(--primary, #0055FF);
}

.knowledge-file-meta-partner {
    font-size: 11px;
    color: var(--text-tertiary, #aeaeb2);
}

.knowledge-edit-textarea {
    width: 100%;
    min-height: 400px;
    font-family: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 13px;
    line-height: 1.6;
    padding: 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text-primary);
    resize: vertical;
    outline: none;
    transition: border-color var(--transition);
}

.knowledge-edit-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 85, 255, 0.12);
}

/* Partner AI Chat */
.partner-ai-container {
    display: flex;
    flex-direction: column;
    height: 65vh;
    border: 1px solid var(--border, #e5e5ea);
    border-radius: 12px;
    background: var(--bg-primary, #fff);
    overflow: hidden;
}

.partner-ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.partner-ai-welcome {
    text-align: center;
    color: var(--text-tertiary, #aeaeb2);
    padding: 40px 20px;
}

.partner-ai-welcome-icon {
    margin-bottom: 12px;
    color: var(--primary, #0055FF);
    opacity: 0.5;
}

.partner-ai-welcome p {
    font-size: 14px;
    margin-bottom: 12px;
}

.partner-ai-welcome ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.partner-ai-welcome li {
    font-size: 13px;
    padding: 6px 0;
    color: var(--text-secondary, #6e6e73);
}

.partner-ai-welcome li::before {
    content: '\2192 ';
    color: var(--primary, #0055FF);
}

.partner-ai-msg {
    max-width: 85%;
}

.partner-ai-msg-user {
    align-self: flex-end;
}

.partner-ai-msg-assistant {
    align-self: flex-start;
}

.partner-ai-msg-content {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.partner-ai-msg-user .partner-ai-msg-content {
    background: var(--primary, #0055FF);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.partner-ai-msg-assistant .partner-ai-msg-content {
    background: var(--bg-secondary, #f5f5f7);
    color: var(--text-primary, #1d1d1f);
    border-bottom-left-radius: 4px;
}

.partner-ai-typing {
    color: var(--text-tertiary, #aeaeb2) !important;
    font-style: italic;
}

.partner-ai-input-bar {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border, #e5e5ea);
    background: var(--bg-secondary, #f5f5f7);
}

.partner-ai-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border, #e5e5ea);
    border-radius: 8px;
    font-size: 13px;
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #1d1d1f);
    outline: none;
}

.partner-ai-input:focus {
    border-color: var(--primary, #0055FF);
    box-shadow: 0 0 0 3px rgba(0, 85, 255, 0.1);
}

.section-subtitle {
    font-size: 13px;
    color: var(--text-tertiary, #aeaeb2);
    margin-top: 4px;
}

/* ==================== Agentic A/B Test ==================== */
.agentic-badge { display: inline-block; background: #0055FF; color: #fff; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; margin-left: 8px; vertical-align: middle; }
.btn-agentic { background: linear-gradient(135deg, #0055FF, #00C2FF); color: #fff; border: none; }
.btn-agentic:hover { opacity: 0.9; }
.evolution-log { margin-top: 16px; }
.evolution-entry { border-left: 3px solid #0055FF; padding: 8px 16px; margin-bottom: 12px; background: #f8f9fa; border-radius: 0 8px 8px 0; }
.evolution-entry .gen { font-weight: 600; color: #0055FF; font-size: 14px; }
.evolution-entry .date { color: #888; font-size: 12px; margin-top: 2px; }
.evolution-entry .details { margin-top: 6px; font-size: 13px; color: #444; line-height: 1.4; }
.evolution-entry .details strong { color: #222; }
.ab-test-gen { display: inline-block; background: #e8f0fe; color: #0055FF; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; margin-left: 8px; }

/* Agentic modal overlay (used by modal-overlay pattern) */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 24px; animation: fadeIn 0.15s ease; }
.modal-content { background: var(--bg-card); border-radius: var(--radius-lg); padding: 32px; width: 100%; max-width: 520px; box-shadow: var(--shadow-xl); animation: slideUp 0.2s ease; }
.modal-content h3 { font-size: 17px; font-weight: 700; color: var(--text-primary); margin-bottom: 12px; }
.modal-content .form-input { width: 100%; padding: 10px 14px; background: var(--bg); border: 1.5px solid var(--border); border-radius: var(--radius-sm); color: var(--text-primary); font-size: 14px; outline: none; transition: border-color var(--transition); }
.modal-content .form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0, 85, 255, 0.12); }
