:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --bg: #f8fafc;
    --bg-dark: #1e293b;
    --bg-darker: #0f172a;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --white: #ffffff;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* Top Header */
.top-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 1000;
    box-shadow: var(--shadow);
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 18px;
    color: var(--primary);
}

.logo i {
    font-size: 24px;
}

.version {
    font-size: 12px;
    color: var(--text-light);
    font-weight: normal;
}

.breadcrumbs {
    color: var(--text-light);
    font-size: 14px;
}

.breadcrumbs span:not(:last-child)::after {
    content: ' > ';
    margin: 0 8px;
}

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

.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    border-radius: 8px;
    background: var(--bg);
}

.user-menu i {
    font-size: 24px;
    color: var(--primary);
}

.btn-logout {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-logout:hover {
    background: var(--border);
    color: var(--danger);
}

/* App Container */
.app-container {
    display: flex;
    margin-top: 64px;
    min-height: calc(100vh - 64px);
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--white);
    border-right: 1px solid var(--border);
    position: fixed;
    left: 0;
    top: 64px;
    bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-nav {
    padding: 16px 0;
}

.nav-section {
    margin-bottom: 24px;
}

.nav-section-title {
    padding: 8px 24px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-light);
    letter-spacing: 0.5px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    text-decoration: none;
}

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

.nav-item.active {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 500;
}

.nav-item i {
    width: 20px;
    text-align: center;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 24px;
    min-height: calc(100vh - 64px);
}

.view {
    animation: fadeIn 0.3s;
}

.view.hidden {
    display: none;
}

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

/* Page Header */
.page-header {
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-header p {
    color: var(--text-light);
    font-size: 14px;
    margin-top: 4px;
}

/* Buttons */
.btn-primary, .btn-secondary {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

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

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-block {
    width: 100%;
    justify-content: center;
}

.btn-icon {
    background: none;
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text);
    transition: all 0.2s;
}

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

/* Login Page */
.login-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 400px;
}

.login-card {
    background: var(--white);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header i {
    font-size: 48px;
    color: var(--primary);
    margin-bottom: 16px;
}

.login-header h1 {
    font-size: 24px;
    margin-bottom: 8px;
}

.login-header p {
    color: var(--text-light);
    font-size: 14px;
}

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

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.form-group label i {
    margin-right: 8px;
    color: var(--text-light);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.2s;
    font-family: inherit;
}

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

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-light);
}

/* Form Container & Sections */
.form-container {
    max-width: 900px;
}

.form-section {
    background: var(--white);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.form-section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.form-section-header i {
    color: var(--primary);
    font-size: 20px;
}

.form-section-header h2 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.form-hint {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-light);
}

.form-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.form-actions-left,
.form-actions-right {
    display: flex;
    gap: 12px;
}

/* Header Row (for key-value inputs) */
.header-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
}

/* Sub-page Navigation */
.sub-page-header {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-bottom: 1px solid #e2e8f0;
    padding: 12px 24px;
    margin: -24px -24px 24px -24px;
}

.sub-page-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.sub-page-nav .back-link {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #3b82f6;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.sub-page-nav .back-link:hover {
    color: #2563eb;
}

.sub-page-nav .back-link i {
    font-size: 12px;
}

.sub-page-nav .nav-separator {
    color: #cbd5e1;
}

.sub-page-nav .current-customer {
    color: #64748b;
    font-weight: 500;
}

.sub-page-nav .current-page {
    color: #1e293b;
    font-weight: 600;
}

.text-muted {
    color: var(--text-light);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 500;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
}

.error-message {
    color: var(--danger);
    font-size: 14px;
    margin-top: 16px;
    text-align: center;
    display: none;
}

.error-message.show {
    display: block;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--white);
    border-radius: 12px;
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: var(--shadow);
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 64px;
    height: 64px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: var(--white);
}

.stat-icon.blue {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.stat-icon.green {
    background: linear-gradient(135deg, #10b981, #059669);
}

.stat-icon.orange {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

.stat-icon.purple {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
}

/* Activity Page Stat Icons */
.stat-icon.total {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.stat-icon.success {
    background: linear-gradient(135deg, #10b981, #059669);
}

.stat-icon.error {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

.stat-icon.blocked {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

.stat-icon.tokens {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
}

.stat-icon.time {
    background: linear-gradient(135deg, #06b6d4, #0891b2);
}

.stat-icon.api {
    background: linear-gradient(135deg, #ec4899, #db2777);
}

.stat-icon.channels {
    background: linear-gradient(135deg, #14b8a6, #0d9488);
}

/* Stat Card Variations */
.stat-card.wide {
    grid-column: span 2;
}

.stat-card .token-breakdown {
    display: block;
    font-size: 11px;
    color: var(--text-light);
    margin-top: 4px;
}

.stat-card h3 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.stat-card p {
    font-size: 13px;
    color: var(--text-light);
    margin: 4px 0 0 0;
}

/* Channel Stats */
.channel-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.channel-stat-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    text-transform: capitalize;
}

.channel-stat-badge.telegram {
    background: rgba(0, 136, 204, 0.1);
    color: #0088cc;
}

.channel-stat-badge.whatsapp {
    background: rgba(37, 211, 102, 0.1);
    color: #25D366;
}

.channel-stat-badge.instagram {
    background: rgba(225, 48, 108, 0.1);
    color: #E1306C;
}

.channel-stat-badge.messenger {
    background: rgba(0, 132, 255, 0.1);
    color: #0084FF;
}

/* Channel Badges (Activity Table) */
.channel-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-transform: capitalize;
}

.channel-badge.telegram {
    background: rgba(0, 136, 204, 0.1);
    color: #0088cc;
}

.channel-badge.whatsapp {
    background: rgba(37, 211, 102, 0.1);
    color: #25D366;
}

.channel-badge.instagram {
    background: rgba(225, 48, 108, 0.1);
    color: #E1306C;
}

.channel-badge.messenger {
    background: rgba(0, 132, 255, 0.1);
    color: #0084FF;
}

/* Activity Status Badges */
.status-badge.success {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.status-badge.error {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.status-badge.blocked {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
}

/* Activity Table Cells */
.time-cell {
    color: var(--text-light);
    font-size: 13px;
    white-space: nowrap;
}

.visitor-cell {
    font-family: monospace;
    font-size: 12px;
    color: var(--text-light);
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.processing-time {
    font-family: monospace;
    font-size: 12px;
    color: var(--info);
}

.tokens-value {
    font-family: monospace;
    font-size: 12px;
    color: var(--text);
}

.tokens-cell {
    text-align: right;
}

/* Tool Tags */
.tool-tag {
    display: inline-block;
    padding: 2px 8px;
    margin: 2px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.tool-tag.completed {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.tool-tag.failed {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.tools-cell {
    max-width: 200px;
}

/* Error Info */
.error-info {
    max-width: 250px;
}

.error-cell {
    font-size: 12px;
}

.stage-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.error-type {
    font-weight: 500;
    color: var(--danger);
    font-size: 11px;
}

.error-message {
    display: block;
    color: var(--text-light);
    font-size: 11px;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Tool Usage Section */
.tool-usage-section {
    margin-bottom: 24px;
}

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

.tool-card {
    background: var(--white);
    border-radius: 8px;
    padding: 16px;
    box-shadow: var(--shadow);
}

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

.tool-card h4 i {
    color: var(--primary);
}

.tool-card .count {
    font-size: 24px;
    font-weight: 600;
    color: var(--text);
}

.tool-card .success-rate {
    font-size: 12px;
    color: var(--success);
    margin-top: 4px;
}

/* Period Selector */
.period-selector {
    display: flex;
    gap: 8px;
}

.period-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--white);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.period-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.period-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

/* Filter Select */
.filter-select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    background: var(--white);
    cursor: pointer;
}

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

/* Pagination Button */
.pagination-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--white);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.pagination-btn:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

/* Card wrapper for tables */
.card {
    background: var(--white);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card .table-toolbar {
    margin-bottom: 0;
    border-radius: 0;
    box-shadow: none;
    border-bottom: 1px solid var(--border);
}

.card .table-container {
    border-radius: 0;
    box-shadow: none;
}

.stat-value {
    font-size: 28px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 14px;
    color: var(--text-light);
}

/* Table Toolbar */
.table-toolbar {
    background: var(--white);
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    box-shadow: var(--shadow);
}

.search-box {
    flex: 1;
    position: relative;
    max-width: 400px;
}

.search-box i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
}

.search-box input {
    width: 100%;
    padding: 10px 12px 10px 40px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}

.toolbar-actions {
    display: flex;
    gap: 8px;
}

/* Table */
.table-container {
    background: var(--white);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

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

.data-table thead {
    background: var(--bg);
}

.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-light);
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

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

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.empty-state {
    text-align: center;
    padding: 40px !important;
    color: var(--text-light);
}

/* Status Badge */
.status-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    display: inline-block;
}

/* General Badge */
.badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    display: inline-block;
    background: rgba(59, 130, 246, 0.1);
    color: var(--info);
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.badge-error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.badge-info {
    background: rgba(59, 130, 246, 0.1);
    color: var(--info);
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 12px;
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.alert-info {
    background: rgba(59, 130, 246, 0.1);
    color: var(--info);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.status-badge.active {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.status-badge.inactive {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.status-badge.audited {
    background: rgba(59, 130, 246, 0.1);
    color: var(--info);
}

/* Actions */
.action-buttons {
    display: flex;
    gap: 8px;
}

.action-btn {
    background: none;
    border: none;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-light);
    transition: all 0.2s;
    margin: 0 2px;
}

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

.action-btn.danger:hover {
    color: var(--danger);
}

.action-btn.whatsapp-btn:hover {
    color: #25D366;
    background: rgba(37, 211, 102, 0.1);
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 16px;
    padding: 16px;
    background: var(--white);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

/* Modal */
.modal,
.modal-overlay {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal {
    display: none;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--white);
    border-radius: 12px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

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

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-light);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

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

.modal form {
    padding: 24px;
}

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

.modal form .modal-footer {
    margin: 24px -24px -24px -24px;
    padding: 16px 24px;
}

/* Modal body */
.modal-body {
    padding: 24px;
}

/* Modal buttons for duplicate warning */
.modal-btn {
    padding: 10px 16px;
    border-radius: 6px;
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid var(--border);
    background: var(--white);
    color: var(--text);
}

.modal-btn:hover {
    background: var(--bg);
}

.modal-btn-cancel {
    background: var(--bg);
    color: var(--text-light);
}

.modal-btn-cancel:hover {
    background: #e5e7eb;
}

.modal-btn-confirm {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.modal-btn-confirm:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

/* Profile */
.profile-container {
    max-width: 600px;
}

.profile-card {
    background: var(--white);
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow);
}

.profile-card h2 {
    font-size: 18px;
    margin-bottom: 24px;
}

/* Notification Animation */
@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* ========================================
   CRM / Contact Management Styles
   ======================================== */

/* Contact Status Selector */
.contact-status-container {
    margin: 12px 0;
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
}

.contact-status-container label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-light);
    margin-bottom: 6px;
    display: block;
}

.contact-status-select {
    width: 100%;
    padding: 8px 12px;
    border: 2px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    background: var(--white);
    cursor: pointer;
    transition: all 0.2s;
}

.contact-status-select:hover {
    border-color: var(--primary);
}

/* Merged contact badge */
.merged-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    font-size: 11px;
    background: var(--info);
    color: white;
    border-radius: 12px;
    margin-left: 8px;
}

/* Profile stats row */
.profile-stats {
    display: flex;
    gap: 16px;
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-light);
}

.profile-stats span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Custom Fields Section */
.custom-fields-view,
.custom-fields-edit {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

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

.custom-field-label {
    font-size: 12px;
    color: var(--text-light);
}

.custom-field-value {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.custom-field-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
}

.custom-field-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* History Tab */
.history-section {
    padding: 0;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.history-header h4 {
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-count {
    font-size: 12px;
    color: var(--text-light);
}

.history-list {
    max-height: calc(100vh - 350px);
    overflow-y: auto;
}

.history-loading,
.history-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-light);
}

.history-empty i {
    font-size: 32px;
    margin-bottom: 12px;
    display: block;
}

.history-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}

.history-item:hover {
    background: var(--bg);
}

.history-item.current {
    background: rgba(37, 99, 235, 0.1);
    border-left: 3px solid var(--primary);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.history-date {
    font-size: 13px;
    font-weight: 600;
}

.history-state {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    text-transform: uppercase;
    font-weight: 600;
}

.history-state.closed {
    background: #e2e8f0;
    color: #64748b;
}

.history-state.active,
.history-item.current .history-state {
    background: #dcfce7;
    color: #166534;
}

.history-item-body {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-light);
}

.history-item-body i {
    width: 12px;
}

.history-closed-by {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 4px;
}

/* Transcript Viewer */
.transcript-viewer {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.transcript-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.btn-back-to-history {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-back-to-history:hover {
    text-decoration: underline;
}

.transcript-title {
    font-size: 14px;
    font-weight: 600;
}

/* Transcript messages container - matches main messages container */
.transcript-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f8fafc;
}

/* Message styles for transcript (inheriting from agent-dashboard) */
.transcript-messages .message {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
}

.transcript-messages .message-content {
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.transcript-messages .message.user {
    align-self: flex-start;
    background: white;
    color: #111827;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.transcript-messages .message.agent,
.transcript-messages .message.ai,
.transcript-messages .message.tool {
    align-self: flex-end;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.transcript-messages .message-time {
    font-size: 10px;
    opacity: 0.7;
}

.transcript-messages .message-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 6px;
}

.transcript-messages .message-footer .message-time {
    margin-left: auto;
}

.transcript-messages .message-sender-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    font-size: 11px;
    font-weight: 500;
    opacity: 0.85;
}

.transcript-messages .message-sender-icon {
    font-size: 10px;
}

.transcript-messages .message-sender-label {
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.transcript-messages .message.user .message-sender-row {
    color: #6b7280;
}

.transcript-messages .message.agent .message-sender-row,
.transcript-messages .message.ai .message-sender-row,
.transcript-messages .message.tool .message-sender-row {
    color: rgba(255, 255, 255, 0.8);
}

/* Transcript attachments */
.transcript-messages .message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.transcript-messages .attachment {
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.transcript-messages .attachment-image img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
    display: block;
}

.transcript-messages .attachment-video {
    max-width: 250px;
    position: relative;
}

.transcript-messages .attachment-video video {
    max-width: 100%;
    border-radius: 8px;
    display: block;
}

.transcript-messages .attachment-audio audio {
    max-width: 220px;
}

.transcript-messages .attachment-sticker img {
    max-width: 120px;
    max-height: 120px;
}

.transcript-messages .attachment-document {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    font-size: 13px;
}

.transcript-messages .message.agent .attachment-document,
.transcript-messages .message.ai .attachment-document {
    background: rgba(255, 255, 255, 0.15);
}

.transcript-messages .attachment-document a {
    display: flex;
    align-items: center;
    gap: 8px;
    color: inherit;
    text-decoration: none;
}

.transcript-messages .attachment-document .download-icon {
    margin-left: 8px;
    opacity: 0.6;
}

.transcript-messages .attachment-document:hover .download-icon {
    opacity: 1;
}

.transcript-messages .attachment-loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    gap: 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    min-width: 120px;
    min-height: 80px;
}

.transcript-messages .attachment-loading-state .loading-icon {
    font-size: 24px;
    opacity: 0.5;
}

.transcript-messages .attachment-loading-state .loading-text {
    font-size: 11px;
    opacity: 0.6;
}

.transcript-messages .attachment-error {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border-radius: 8px;
    font-size: 12px;
}

/* Video play indicator for transcript */
.transcript-messages .video-play-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    pointer-events: none;
}

/* Tool message formatting in transcript */
.transcript-messages .tool-json,
.transcript-messages .tool-code {
    margin: 0;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 11px;
    overflow-x: auto;
    max-height: 200px;
    white-space: pre;
}

/* Duplicate Warning Modal */
.duplicate-contact-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    margin: 12px 0;
}

.dup-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
}

.dup-name i,
.dup-channel i {
    width: 16px;
    color: var(--text-light);
}

.dup-channel {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 8px;
}

.dup-stats {
    display: flex;
    gap: 16px;
    font-size: 11px;
    color: var(--text-light);
}

/* Inline duplicate warning (below phone/email fields) */
.duplicate-warning {
    margin-top: 4px;
}

.duplicate-inline-warning {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: 6px;
    font-size: 12px;
    color: #92400e;
}

.duplicate-inline-warning i {
    color: #f59e0b;
    flex-shrink: 0;
}

.duplicate-inline-warning span {
    flex: 1;
}

.duplicate-inline-warning .btn-link {
    background: none;
    border: none;
    color: #d97706;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    font-size: 12px;
    text-decoration: underline;
    flex-shrink: 0;
}

.duplicate-inline-warning .btn-link:hover {
    color: #b45309;
}

/* Tab content for history */
.tab-content-history {
    display: none;
    height: 100%;
}

.tab-content-history.active {
    display: block;
}

/* Custom Field Settings Page */
.custom-field-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.custom-field-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.custom-field-card-info {
    flex: 1;
}

.custom-field-card-label {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
}

.custom-field-card-meta {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-light);
}

.custom-field-card-actions {
    display: flex;
    gap: 8px;
}

.custom-field-type-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    background: var(--bg);
    color: var(--text-light);
}

/* Location Message Styles */
.message-location {
    margin-top: 8px;
    max-width: 300px;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border);
}

.message-location .location-map-preview {
    position: relative;
    width: 100%;
    height: 150px;
    background: linear-gradient(135deg, #e5e7eb 0%, #f3f4f6 100%);
    overflow: hidden;
}

.message-location .location-map-preview iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    pointer-events: auto;
}

.message-location .location-info {
    padding: 10px 12px 0;
}

.message-location .location-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
    line-height: 1.3;
}

.message-location .location-address {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 2px;
    line-height: 1.4;
}

.message-location .location-coords {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    font-size: 11px;
    color: var(--text-light);
}

.message-location .location-coords i {
    color: var(--danger);
    font-size: 12px;
}

.message-location .location-actions {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    border-top: 1px solid var(--border);
}

.message-location .location-action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    color: var(--primary);
    background: rgba(37, 99, 235, 0.08);
    border-radius: 6px;
    transition: all 0.2s ease;
}

.message-location .location-action-btn:hover {
    background: rgba(37, 99, 235, 0.15);
    color: var(--primary-dark);
}

.message-location .location-action-btn i {
    font-size: 11px;
}

/* Agent/AI message location styles (darker background) */
.message.agent .message-location,
.message.ai .message-location {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.message.agent .message-location .location-name,
.message.ai .message-location .location-name {
    color: white;
}

.message.agent .message-location .location-address,
.message.agent .message-location .location-coords,
.message.ai .message-location .location-address,
.message.ai .message-location .location-coords {
    color: rgba(255, 255, 255, 0.7);
}

.message.agent .message-location .location-actions,
.message.ai .message-location .location-actions {
    border-top-color: rgba(255, 255, 255, 0.15);
}

.message.agent .message-location .location-action-btn,
.message.ai .message-location .location-action-btn {
    color: white;
    background: rgba(255, 255, 255, 0.15);
}

.message.agent .message-location .location-action-btn:hover,
.message.ai .message-location .location-action-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

/* Transcript location styles */
.transcript-messages .message-location {
    margin-top: 8px;
    max-width: 250px;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s;
    }

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

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

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

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .history-item-body {
        flex-direction: column;
        gap: 4px;
    }
}

/* Close Rating Modal */
.close-rating-modal-content {
    max-width: 420px;
}

.close-rating-modal-content .modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.close-rating-modal-content .modal-header i {
    font-size: 20px;
    color: var(--warning);
}

.close-rating-modal-content .modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.rating-instruction {
    color: var(--text-light);
    font-size: 14px;
    margin-bottom: 24px;
    text-align: center;
}

.star-rating-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 24px;
}

.star-rating {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.star-rating .star {
    font-size: 32px;
    color: #d1d5db;
    cursor: pointer;
    transition: all 0.15s ease;
}

.star-rating .star:hover {
    transform: scale(1.1);
}

.star-rating .star.active i,
.star-rating .star:hover i {
    color: #f59e0b;
}

.star-rating .star i {
    transition: color 0.15s ease;
}

.rating-label {
    font-size: 14px;
    color: var(--text-light);
    font-weight: 500;
    min-height: 20px;
}

.feedback-container label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 8px;
}

.feedback-container textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 80px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.feedback-container textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.feedback-container textarea::placeholder {
    color: var(--text-light);
}

.feedback-container .char-count {
    display: block;
    text-align: right;
    font-size: 12px;
    color: var(--text-light);
    margin-top: 4px;
}

.close-rating-modal-content .modal-footer {
    justify-content: flex-end;
}

.close-rating-modal-content .modal-btn-confirm:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.close-rating-modal-content .modal-btn-confirm i {
    margin-right: 6px;
}

