/**
 * ChatBot AI Platform - Main Styles
 * Design Philosophy: Steve Jobs meets Leonardo da Vinci
 * "Simplicity is the ultimate sophistication"
 *
 * Palette inspired by:
 * - Apple's design language (pure white, subtle shadows)
 * - Da Vinci's chiaroscuro (light/shadow contrast)
 * - Picasso's confident restraint (one accent, masterfully used)
 */

:root {
    /* The Accent - Like a single brushstroke of Venetian Red */
    --primary: #a50034;
    --primary-dark: #8a002b;
    --primary-light: #fdf2f4;

    /* The Canvas - Pure, like da Vinci's gesso */
    --black: #1d1d1f;
    --white: #ffffff;

    /* Warm Grays - Apple's signature (not cold, but alive) */
    --gray-50: #fbfbfd;
    --gray-100: #f5f5f7;
    --gray-200: #e8e8ed;
    --gray-300: #d2d2d7;
    --gray-400: #aeaeb2;
    --gray-500: #86868b;
    --gray-600: #6e6e73;
    --gray-700: #515154;
    --gray-800: #3a3a3c;
    --gray-900: #1d1d1f;

    /* Status - Muted, sophisticated (not screaming) */
    --success: #34c759;
    --success-light: #f0fdf4;
    --warning: #ff9500;
    --warning-light: #fffbeb;
    --danger: #a50034;
    --danger-light: #fdf2f4;
    --info: #5856d6;
    --info-light: #f5f5ff;

    /* Layout */
    --sidebar-width: 260px;
    --header-height: 64px;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-lg: 20px;

    /* Shadows - Da Vinci's sfumato: soft, barely there, but giving depth */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
    --shadow: 0 2px 8px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.04);
    --shadow-hover: 0 8px 30px rgba(0,0,0,0.12);

    /* Transitions - Smooth, organic */
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.65;
    color: var(--black);
    background: var(--white);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: -0.01em;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}

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

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--black);
    line-height: 1.3;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }

/* Buttons - Confident, minimal */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 980px; /* Apple's pill shape */
    border: none;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    letter-spacing: -0.01em;
}

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

.btn-primary:hover {
    background: var(--gray-800);
    color: var(--white);
    transform: scale(1.02);
}

.btn-secondary {
    background: var(--gray-100);
    color: var(--black);
}

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

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--gray-300);
    color: var(--black);
}

.btn-outline:hover {
    background: var(--gray-50);
    border-color: var(--black);
}

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

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

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

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
}

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

/* Cards - Clean, floating like Apple's design */
.card {
    background: var(--white);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow);
    border: none;
    transition: var(--transition);
}

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

.card-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.card-body {
    padding: 2rem;
}

.card-footer {
    padding: 1.25rem 2rem;
    border-top: 1px solid var(--gray-100);
    background: var(--gray-50);
    border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
}

.form-control {
    width: 100%;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius-sm);
    background: var(--white);
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}

.form-control::placeholder {
    color: var(--gray-400);
}

.form-control:disabled {
    background: var(--gray-100);
    cursor: not-allowed;
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

.form-text {
    font-size: 0.8125rem;
    color: var(--gray-500);
    margin-top: 0.375rem;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-check-input {
    width: 1rem;
    height: 1rem;
    accent-color: var(--primary);
}

/* Alerts */
.alert {
    padding: 1rem 1.25rem;
    border-radius: var(--border-radius-sm);
    margin-bottom: 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.alert-success {
    background: var(--success-light);
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-error, .alert-danger {
    background: var(--danger-light);
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.alert-warning {
    background: var(--warning-light);
    color: #856404;
    border: 1px solid #ffeeba;
}

.alert-info {
    background: var(--info-light);
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* Badge */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 999px;
}

.badge-success {
    background: var(--gray-200);
    color: var(--gray-700);
}

.badge-warning {
    background: var(--gray-300);
    color: var(--gray-800);
}

.badge-danger {
    background: #fde8e8;
    color: var(--danger);
}

.badge-info {
    background: var(--gray-200);
    color: var(--gray-600);
}

.badge-secondary {
    background: var(--gray-100);
    color: var(--gray-600);
}

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

/* Tables */
.table-responsive {
    overflow-x: auto;
}

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

.table th,
.table td {
    padding: 0.875rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

.table th {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-600);
    background: var(--gray-50);
}

.table tbody tr:hover {
    background: var(--gray-50);
}

/* Auth Layout */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: linear-gradient(135deg, var(--gray-100) 0%, var(--white) 100%);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--white);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--black);
}

.auth-logo h1 span {
    color: var(--primary);
}

.auth-title {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-title h2 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.auth-title p {
    color: var(--gray-500);
    font-size: 0.875rem;
}

.auth-footer {
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--gray-200);
    font-size: 0.875rem;
    color: var(--gray-600);
}

/* Dashboard Layout */
.dashboard-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar - Elegant, sophisticated */
.sidebar {
    width: var(--sidebar-width);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: var(--transition);

    /* Elegant gradient - like morning light through a window */
    background:
        linear-gradient(180deg,
            rgba(255,255,255,0.95) 0%,
            rgba(251,251,253,0.98) 50%,
            rgba(245,245,247,1) 100%
        );

    /* Subtle right edge shadow - da Vinci's sfumato */
    box-shadow:
        inset -1px 0 0 rgba(0,0,0,0.04),
        4px 0 24px -12px rgba(0,0,0,0.08);

    /* Gentle backdrop blur for depth */
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.sidebar-header {
    padding: 1.75rem 1.5rem;
    border-bottom: none;
    position: relative;
}

/* Subtle accent line under logo */
.sidebar-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 1.5rem;
    right: 1.5rem;
    height: 1px;
    background: linear-gradient(90deg,
        var(--primary) 0%,
        rgba(165,0,52,0.3) 30%,
        transparent 100%
    );
    opacity: 0.6;
}

.sidebar-logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--black);
    letter-spacing: -0.03em;
}

.sidebar-logo span {
    color: var(--primary);
}

.sidebar-nav {
    flex: 1;
    padding: 0.5rem 0.75rem;
    overflow-y: auto;
}

.nav-section {
    padding: 0.75rem 0.75rem 0.25rem;
    margin-top: 0.5rem;
}

.nav-section-title {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--gray-500);
    margin-bottom: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--gray-600);
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
    border-radius: 10px;
    margin-bottom: 2px;
}

.nav-item:hover {
    background: var(--white);
    color: var(--black);
    box-shadow: var(--shadow-sm);
}

.nav-item.active {
    background: var(--white);
    color: var(--black);
    box-shadow: var(--shadow);
    font-weight: 600;
    position: relative;
}

/* Elegant accent indicator on active item */
.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--primary);
    border-radius: 0 3px 3px 0;
}

.nav-item svg {
    width: 20px;
    height: 20px;
    opacity: 0.6;
}

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

.nav-badge {
    margin-left: auto;
    background: #dc3545;
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.45rem;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    line-height: 1.2;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: none;
    position: relative;
    background: linear-gradient(180deg,
        transparent 0%,
        rgba(245,245,247,0.5) 100%
    );
}

/* Subtle top line on footer */
.sidebar-footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 1.5rem;
    right: 1.5rem;
    height: 1px;
    background: linear-gradient(90deg,
        transparent 0%,
        var(--gray-200) 50%,
        transparent 100%
    );
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    max-width: calc(100vw - var(--sidebar-width));
}

/* Header */
.header {
    height: var(--header-height);
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.header.header-sticky {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header.header-hidden {
    transform: translateY(-100%);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.header-user:hover {
    background: var(--gray-100);
}

.header-user-avatar {
    width: 36px;
    height: 36px;
    background: var(--primary);
    color: var(--white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.header-user-info {
    text-align: left;
}

.header-user-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--black);
}

.header-user-plan {
    font-size: 0.75rem;
    color: var(--gray-500);
}

/* Language Switcher */
.lang-switcher {
    display: flex;
    gap: 0.25rem;
    background: var(--gray-100);
    padding: 0.25rem;
    border-radius: var(--border-radius-sm);
}

.lang-btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: none;
    background: transparent;
    color: var(--gray-600);
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
}

.lang-btn.active {
    background: var(--white);
    color: var(--black);
    box-shadow: var(--shadow-sm);
}

/* Page Content */
.page-content {
    flex: 1;
    padding: 1.5rem;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--white);
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    border: none;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

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

.stat-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.stat-card-title {
    font-size: 0.8125rem;
    color: var(--gray-500);
    font-weight: 500;
    letter-spacing: 0.01em;
}

.stat-card-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-100);
    color: var(--gray-600);
}

.stat-card-icon.primary,
.stat-card-icon.success,
.stat-card-icon.info {
    background: var(--gray-100);
    color: var(--gray-600);
}

.stat-card-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--black);
    letter-spacing: -0.03em;
}

.stat-card-footer {
    font-size: 0.8125rem;
    color: var(--gray-500);
    margin-top: 0.75rem;
}

/* Chatbot List */
.bot-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 1.5rem;
}

.bot-card {
    background: var(--white);
    border-radius: var(--border-radius-lg);
    border: none;
    box-shadow: var(--shadow);
    transition: var(--transition);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.bot-card:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-4px);
}

.bot-card-header {
    padding: 1.5rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    border-bottom: 1px solid var(--gray-100);
}

.bot-avatar {
    width: 52px;
    height: 52px;
    min-width: 52px;
    background: var(--gray-100);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-600);
    font-size: 1.25rem;
    overflow: hidden;
}

.bot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

.bot-info h3 {
    font-size: 1rem;
    margin-bottom: 0.375rem;
    word-wrap: break-word;
}

.bot-info p {
    font-size: 0.8125rem;
    color: var(--gray-500);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.bot-card-body {
    padding: 1.25rem;
    flex: 1;
}

.bot-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    text-align: center;
}

.bot-stat-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--black);
}

.bot-stat-label {
    font-size: 0.6875rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.bot-card-footer {
    padding: 1rem 1.25rem;
    background: var(--gray-50);
    border-top: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.bot-card-footer .btn {
    width: 100%;
    text-align: center;
    font-size: 0.8125rem;
    padding: 0.5rem 1rem;
    justify-content: center;
}

.bot-card-footer .btn-row {
    display: flex;
    gap: 0.5rem;
}

.bot-card-footer .btn-row .btn {
    flex: 1;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
}

.empty-state-icon {
    width: 80px;
    height: 80px;
    background: var(--gray-100);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
    color: var(--gray-400);
}

.empty-state h3 {
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--gray-500);
    margin-bottom: 1.5rem;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 1.5rem;
}

.tab-btn {
    padding: 0.875rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-600);
    background: none;
    border: none;
    cursor: pointer;
    position: relative;
    transition: var(--transition);
}

.tab-btn:hover {
    color: var(--black);
}

.tab-btn.active {
    color: var(--primary);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
}

.tab-content {
    display: none;
}

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

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-backdrop.show {
    display: flex;
}

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

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

.modal-header h3 {
    font-size: 1.125rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--gray-500);
    cursor: pointer;
    line-height: 1;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Dropdown */
.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--white);
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--gray-200);
    min-width: 180px;
    padding: 0.5rem 0;
    z-index: 100;
    display: none;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    color: var(--gray-700);
    transition: var(--transition);
}

.dropdown-item:hover {
    background: var(--gray-100);
    color: var(--black);
}

.dropdown-item.danger {
    color: var(--danger);
}

.dropdown-divider {
    height: 1px;
    background: var(--gray-200);
    margin: 0.5rem 0;
}

/* Progress Bar */
.progress {
    height: 8px;
    background: var(--gray-200);
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 999px;
    transition: width 0.5s ease;
}

.progress-bar.success {
    background: var(--success);
}

.progress-bar.warning {
    background: var(--warning);
}

.progress-bar.danger {
    background: var(--danger);
}

/* Loading Spinner */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--gray-300);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Utilities */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--gray-500); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-primary { color: var(--primary); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }

.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }

.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 1rem; }

.w-100 { width: 100%; }

/* Flex utilities */
.flex-wrap { flex-wrap: wrap; }
.flex-nowrap { flex-wrap: nowrap; }
.flex-1 { flex: 1; }
.flex-shrink-0 { flex-shrink: 0; }

/* Additional responsive utilities */
.hide-mobile { display: block; }
.show-mobile { display: none; }

@media (max-width: 768px) {
    .hide-mobile { display: none !important; }
    .show-mobile { display: block !important; }
}

/* Smooth transitions for all interactive elements */
.sidebar,
.main-content,
.card,
.btn,
.nav-item,
.form-control {
    transition: var(--transition);
}

/* Better focus states for accessibility */
.btn:focus,
.form-control:focus,
.nav-item:focus,
.tab-btn:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn:focus:not(:focus-visible),
.form-control:focus:not(:focus-visible),
.nav-item:focus:not(:focus-visible),
.tab-btn:focus:not(:focus-visible) {
    outline: none;
}

/* Scrollbar - Minimal, Apple-style */
* {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}

*:hover {
    scrollbar-color: rgba(0,0,0,0.2) transparent;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 10px;
    transition: background 0.3s;
}

*:hover::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
}

*:hover::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.3);
}

/* Sidebar specific - even more subtle */
.sidebar-nav {
    scrollbar-width: none;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav:hover::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.1);
}

/* Selection color */
::selection {
    background: var(--primary-light);
    color: var(--primary-dark);
}

/* =====================================================
   RESPONSIVE STYLES - Mobile First Approach
   ===================================================== */

/* Mobile Menu Toggle Button */
.header-menu-toggle {
    display: none;
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--border-radius-sm);
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    cursor: pointer;
    flex-shrink: 0;
}

.header-menu-toggle svg {
    width: 20px;
    height: 20px;
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

/* ===== LARGE TABLETS & SMALL DESKTOPS (max-width: 1200px) ===== */
@media (max-width: 1200px) {
    :root {
        --sidebar-width: 240px;
    }

    .bot-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    }

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

/* ===== TABLETS (max-width: 992px) ===== */
@media (max-width: 992px) {
    /* Sidebar transforms to off-canvas */
    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        z-index: 100;
    }

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

    .main-content {
        margin-left: 0;
        max-width: 100vw;
        height: 100vh;
        overflow-y: auto;
    }

    .header-menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }

    /* Header adjustments */
    .header {
        padding: 0 1rem;
    }

    .header-title {
        font-size: 1rem;
        max-width: 200px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

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

    .header-user-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.75rem;
    }

    /* Page content */
    .page-content {
        padding: 1rem;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .page-header h1 {
        font-size: 1.25rem;
    }

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

    /* Stats grid */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-card-value {
        font-size: 1.5rem;
    }

    .stat-card-icon {
        width: 36px;
        height: 36px;
    }

    .stat-card-icon svg {
        width: 18px;
        height: 18px;
    }

    /* Bot grid */
    .bot-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Cards */
    .card-header {
        padding: 1rem;
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .card-body {
        padding: 1rem;
    }

    .card-footer {
        padding: 0.875rem 1rem;
    }

    /* Tabs - make scrollable */
    .tabs {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        margin: 0 -1rem;
        padding: 0 1rem;
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        white-space: nowrap;
        flex-shrink: 0;
        padding: 0.75rem 1rem;
    }

    /* Tables - responsive wrapper */
    .table-responsive {
        margin: 0 -1rem;
        padding: 0 1rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table {
        min-width: 600px;
    }

    .table th,
    .table td {
        padding: 0.75rem;
        font-size: 0.8125rem;
    }

    /* Dropdown menu positioning */
    .dropdown-menu {
        right: -0.5rem;
    }
}

/* ===== MOBILE PHONES (max-width: 768px) ===== */
@media (max-width: 768px) {
    /* Body adjustments */
    body {
        font-size: 14px;
    }

    /* Header */
    .header {
        height: 56px;
        padding: 0 0.75rem;
    }

    .header-left {
        gap: 0.5rem;
        flex: 1;
        min-width: 0;
    }

    .header-title {
        font-size: 0.9375rem;
        max-width: 150px;
    }

    .header-right {
        gap: 0.5rem;
    }

    /* Language switcher compact */
    .lang-switcher {
        padding: 0.125rem;
    }

    .lang-btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.6875rem;
    }

    /* Page content */
    .page-content {
        padding: 0.75rem;
    }

    .page-header {
        margin-bottom: 1rem;
    }

    .page-header h1 {
        font-size: 1.125rem;
    }

    /* Stats grid - 2 columns on mobile */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .stat-card {
        padding: 0.875rem;
    }

    .stat-card-header {
        flex-direction: column-reverse;
        align-items: flex-start;
        gap: 0.5rem;
        margin-bottom: 0.5rem;
    }

    .stat-card-title {
        font-size: 0.75rem;
    }

    .stat-card-value {
        font-size: 1.25rem;
    }

    .stat-card-icon {
        width: 32px;
        height: 32px;
    }

    .stat-card-icon svg {
        width: 16px;
        height: 16px;
    }

    .stat-card-footer {
        font-size: 0.6875rem;
    }

    /* Bot cards */
    .bot-card-header {
        padding: 1rem;
    }

    .bot-avatar {
        width: 40px;
        height: 40px;
        min-width: 40px;
        font-size: 1rem;
    }

    .bot-info h3 {
        font-size: 0.9375rem;
    }

    .bot-card-body {
        padding: 1rem;
    }

    .bot-stats {
        gap: 0.375rem;
    }

    .bot-stat-value {
        font-size: 1rem;
    }

    .bot-stat-label {
        font-size: 0.625rem;
    }

    .bot-card-footer {
        padding: 0.875rem 1rem;
    }

    .bot-card-footer .btn-row {
        flex-direction: column;
    }

    /* Cards */
    .card {
        border-radius: var(--border-radius-sm);
    }

    .card-header {
        padding: 0.875rem 1rem;
    }

    .card-header h3 {
        font-size: 0.9375rem;
    }

    .card-body {
        padding: 0.875rem 1rem;
    }

    /* Buttons */
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.8125rem;
    }

    .btn-sm {
        padding: 0.375rem 0.625rem;
        font-size: 0.75rem;
    }

    .btn-lg {
        padding: 0.75rem 1.25rem;
        font-size: 0.9375rem;
    }

    /* Forms */
    .form-control {
        padding: 0.625rem 0.875rem;
        font-size: 16px; /* Prevents iOS zoom */
    }

    .form-label {
        font-size: 0.8125rem;
    }

    .form-group {
        margin-bottom: 1rem;
    }

    /* Tabs container */
    .tabs-container {
        margin: 0 -0.75rem;
    }

    .tabs {
        padding: 0 0.75rem;
        margin: 0;
    }

    .tab-content {
        padding: 0 0.75rem;
    }

    .tab-content.active {
        padding: 0 0.75rem;
    }

    /* Modals */
    .modal-backdrop {
        padding: 0.5rem;
    }

    .modal {
        max-width: 100%;
        max-height: 100vh;
        border-radius: var(--border-radius);
        margin: 0.5rem;
    }

    .modal-header {
        padding: 1rem;
    }

    .modal-header h3 {
        font-size: 1rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-footer {
        padding: 0.875rem 1rem;
        flex-direction: column-reverse;
    }

    .modal-footer .btn {
        width: 100%;
    }

    /* Alerts */
    .alert {
        padding: 0.875rem 1rem;
        font-size: 0.8125rem;
    }

    /* Empty state */
    .empty-state {
        padding: 2rem 1rem;
    }

    .empty-state-icon {
        width: 64px;
        height: 64px;
    }

    .empty-state h3 {
        font-size: 1rem;
    }

    .empty-state p {
        font-size: 0.875rem;
    }

    /* Tables - card style on mobile */
    .table-responsive {
        margin: 0 -1rem;
        padding: 0;
    }

    .table {
        min-width: 500px;
    }

    .table th,
    .table td {
        padding: 0.625rem 0.75rem;
        font-size: 0.75rem;
    }

    .table th {
        font-size: 0.6875rem;
    }

    /* Badges */
    .badge {
        padding: 0.1875rem 0.5rem;
        font-size: 0.6875rem;
    }

    /* Progress */
    .progress {
        height: 6px;
    }

    /* Utilities - flex wrap for mobile */
    .d-flex {
        flex-wrap: wrap;
    }

    .d-flex.gap-2 {
        gap: 0.375rem;
    }

    /* Pagination */
    .pagination-wrapper {
        margin-top: 1rem;
    }

    .pagination {
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .pagination-btn {
        min-width: 32px;
        height: 32px;
        padding: 0 0.5rem;
        font-size: 0.75rem;
    }

    /* Hide text on small pagination buttons */
    .pagination-btn:first-child,
    .pagination-btn:last-child {
        padding: 0 0.375rem;
    }

    /* Dropdown */
    .dropdown-menu {
        min-width: 160px;
        right: 0;
    }

    .dropdown-item {
        padding: 0.625rem 0.875rem;
        font-size: 0.8125rem;
    }
}

/* ===== SMALL MOBILE PHONES (max-width: 480px) ===== */
@media (max-width: 480px) {
    .header-title {
        max-width: 120px;
        font-size: 0.875rem;
    }

    /* Stats - single column option */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stat-card-value {
        font-size: 1.125rem;
    }

    /* Bot card adjustments */
    .bot-card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .bot-avatar {
        margin-bottom: 0.5rem;
    }

    /* Page header with button */
    .page-header > div:first-child {
        width: 100%;
    }

    /* Forms side by side fix */
    .d-flex.gap-2 {
        flex-direction: column;
    }

    .d-flex.gap-2 > * {
        width: 100%;
    }

    .d-flex.gap-2 input[style*="flex: 1"] {
        width: 100%;
    }

    /* Card header buttons */
    .card-header {
        flex-direction: column;
        align-items: stretch;
    }

    .card-header h3 {
        margin-bottom: 0.5rem;
    }

    .card-header .btn,
    .card-header form {
        width: 100%;
    }

    .card-header .btn {
        justify-content: center;
    }

    /* Search in card header */
    .card-header .d-flex.gap-2 {
        width: 100%;
    }

    .card-header .d-flex.gap-2 input[type="text"] {
        flex: 1 !important;
        width: auto !important;
    }
}

/* ===== VERY SMALL SCREENS (max-width: 360px) ===== */
@media (max-width: 360px) {
    .page-content {
        padding: 0.5rem;
    }

    .stats-grid {
        gap: 0.375rem;
    }

    .stat-card {
        padding: 0.75rem;
    }

    .stat-card-value {
        font-size: 1rem;
    }

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

    .bot-stat-value {
        font-size: 0.9375rem;
    }

    .lang-switcher {
        display: none;
    }

    .header-menu-toggle {
        width: 36px;
        height: 36px;
    }
}

/* ===== LANDSCAPE MODE ADJUSTMENTS ===== */
@media (max-height: 500px) and (orientation: landscape) {
    .sidebar {
        overflow-y: auto;
    }

    .sidebar-nav {
        padding: 0.5rem 0;
    }

    .nav-item {
        padding: 0.5rem 1.25rem;
    }

    .modal {
        max-height: 95vh;
    }

    .modal-body {
        max-height: 50vh;
        overflow-y: auto;
    }
}

/* ===== TOUCH DEVICE OPTIMIZATIONS ===== */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .btn {
        min-height: 44px;
    }

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

    .nav-item {
        min-height: 44px;
    }

    .dropdown-item {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .form-check {
        min-height: 44px;
    }

    .form-check-input {
        width: 1.25rem;
        height: 1.25rem;
    }

    /* Remove hover effects on touch */
    .bot-card:hover {
        border-color: var(--gray-200);
        box-shadow: var(--shadow-sm);
    }

    .bot-card:active {
        border-color: var(--primary);
        box-shadow: var(--shadow-md);
    }

    .btn:hover {
        transform: none;
    }

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

/* ===== PRINT STYLES ===== */
@media print {
    .sidebar,
    .header,
    .header-menu-toggle,
    .sidebar-overlay {
        display: none !important;
    }

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

    .page-content {
        padding: 0;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* ===== DARK MODE SUPPORT (if needed in future) ===== */
@media (prefers-color-scheme: dark) {
    /* Add dark mode variables here when needed */
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .sidebar {
        transition: none;
    }
}

/* ===== ADDITIONAL COMPONENT STYLES ===== */

/* Page header with multiple elements */
.page-header > div {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* Admin panel specific fixes */
.table select.form-control {
    min-width: 100px;
    padding: 0.375rem 0.5rem;
    font-size: 0.8125rem;
}

/* Card header with search and buttons */
.card-header .d-flex.justify-between {
    width: 100%;
}

/* Form row improvements */
.form-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.form-row > * {
    flex: 1;
    min-width: 200px;
}

/* Inline form adjustments */
form[style*="display: inline"],
form[style*="display:inline"] {
    display: inline-flex !important;
    align-items: center;
}

/* Button group spacing */
.btn-group {
    display: inline-flex;
    gap: 0.25rem;
}

/* Tabs improvements */
.tabs-container {
    position: relative;
}

.tabs {
    display: flex;
    flex-wrap: nowrap;
}

/* Card margin utilities */
.mb-4 {
    margin-bottom: 1.5rem;
}

/* Action buttons in tables */
.table td .d-flex.gap-1 {
    flex-wrap: nowrap;
}

/* Mobile table action buttons */
@media (max-width: 768px) {
    .table td .d-flex.gap-1 {
        flex-direction: column;
        align-items: flex-start;
    }

    .table td .d-flex.gap-1 form,
    .table td .d-flex.gap-1 .btn {
        width: 100%;
    }

    .table td .d-flex.gap-1 .btn {
        justify-content: center;
    }
}

/* Sidebar close button for mobile */
.sidebar-close {
    display: none;
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--gray-100);
    border: none;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

@media (max-width: 992px) {
    .sidebar-close {
        display: flex;
    }

    .sidebar-header {
        padding-right: 3rem;
    }
}

/* Auth page responsive */
@media (max-width: 480px) {
    .auth-wrapper {
        padding: 1rem;
    }

    .auth-card {
        padding: 1.5rem;
        border-radius: var(--border-radius);
    }

    .auth-logo h1 {
        font-size: 1.5rem;
    }

    .auth-title h2 {
        font-size: 1.125rem;
    }
}

/* Empty state responsive */
@media (max-width: 480px) {
    .empty-state {
        padding: 1.5rem 1rem;
    }

    .empty-state-icon {
        width: 56px;
        height: 56px;
        margin-bottom: 1rem;
    }

    .empty-state-icon svg {
        width: 28px;
        height: 28px;
    }
}

/* Fixes for flex containers on small screens */
@media (max-width: 480px) {
    .d-flex.gap-2.align-center,
    .d-flex.justify-between.align-center {
        flex-direction: column;
        align-items: stretch;
    }

    .d-flex.gap-2.align-center > *,
    .d-flex.justify-between.align-center > * {
        width: 100%;
    }

    /* Keep inline buttons in a row */
    .d-flex.gap-1 {
        flex-direction: row;
        flex-wrap: wrap;
    }
}

/* Improved spacing for nested flex containers */
.card-header .d-flex.gap-2.align-center {
    margin-top: 0;
}

@media (max-width: 768px) {
    .card-header .d-flex.gap-2.align-center {
        margin-top: 0.5rem;
    }
}

/* Search form in header */
.card-header form.d-flex {
    flex-wrap: nowrap;
}

@media (max-width: 576px) {
    .card-header form.d-flex {
        flex-wrap: wrap;
    }

    .card-header form.d-flex input[type="text"] {
        width: 100% !important;
        margin-bottom: 0.5rem;
    }

    .card-header form.d-flex .btn {
        flex: 1;
    }
}

/* ===== PAGE SPECIFIC RESPONSIVE STYLES ===== */

/* Settings page - Bot ID text overflow */
.table td {
    word-break: break-all;
}

/* Appearance page - Two column layout */
.appearance-layout {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 1.5rem;
}

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

    .appearance-layout .preview-card {
        position: static !important;
        order: -1;
    }

    .appearance-layout .preview-card iframe {
        height: 400px !important;
    }
}

@media (max-width: 768px) {
    .appearance-layout .preview-card iframe {
        height: 350px !important;
    }
}

/* Color picker responsive */
.color-picker-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 600px) {
    .color-picker-grid {
        grid-template-columns: 1fr;
    }
}

/* Lead fields grid */
.lead-fields-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

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

/* Analytics page - Two column grid */
.analytics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

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

    .analytics-grid > .card {
        margin-bottom: 0;
    }
}

/* Hourly heatmap responsive */
.hourly-heatmap {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 4px;
}

@media (max-width: 768px) {
    .hourly-heatmap {
        grid-template-columns: repeat(8, 1fr);
    }
}

@media (max-width: 480px) {
    .hourly-heatmap {
        grid-template-columns: repeat(6, 1fr);
    }

    .hour-cell {
        font-size: 0.65rem;
    }
}

/* Live chat page - Two column layout */
.live-chat-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 1.5rem;
    height: calc(100vh - 200px);
    min-height: 500px;
}

@media (max-width: 900px) {
    .live-chat-layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    .live-chat-layout .conversations-list {
        max-height: 300px;
    }

    .live-chat-layout .chat-window {
        min-height: 400px;
    }
}

@media (max-width: 480px) {
    .live-chat-layout .conversations-list {
        max-height: 250px;
    }
}

/* Mobile Cards for Tables */
.mobile-cards {
    display: none;
}

.desktop-table {
    display: block;
}

@media (max-width: 768px) {
    .mobile-cards {
        display: block;
    }

    .desktop-table {
        display: none;
    }
}

/* Conversation/Lead Card Style */
.data-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius-sm);
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.data-card:last-child {
    margin-bottom: 0;
}

.data-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.data-card-title {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--black);
}

.data-card-meta {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.data-card-body {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.data-card-item {
    font-size: 0.8125rem;
}

.data-card-item .label {
    color: var(--gray-500);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    display: block;
    margin-bottom: 0.125rem;
}

.data-card-item .value {
    color: var(--gray-800);
    word-break: break-word;
}

.data-card-actions {
    display: flex;
    gap: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray-100);
}

.data-card-actions .btn {
    flex: 1;
    justify-content: center;
    font-size: 0.75rem;
    padding: 0.5rem;
}

/* Bot Avatar Upload */
.avatar-upload {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.avatar-preview {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 2px solid var(--gray-200);
    flex-shrink: 0;
}

.avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-preview svg {
    width: 40px;
    height: 40px;
    color: var(--gray-400);
}

.avatar-upload-controls {
    flex: 1;
}

.avatar-upload-controls input[type="file"] {
    display: none;
}

@media (max-width: 480px) {
    .avatar-upload {
        flex-direction: column;
        text-align: center;
    }

    .avatar-upload-controls {
        width: 100%;
    }
}

/* Progress bar mini for analytics */
.progress-bar-mini {
    width: 100%;
    max-width: 100px;
    height: 6px;
    background: var(--gray-200);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-mini div {
    height: 100%;
    background: linear-gradient(90deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-radius: 3px;
}

/* Keywords cloud responsive */
.keywords-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

@media (max-width: 480px) {
    .keyword-tag {
        font-size: 0.75rem !important;
        padding: 0.25rem 0.5rem;
    }
}

/* Chat message bubbles responsive */
.chat-bubble {
    max-width: 85%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
}

@media (max-width: 480px) {
    .chat-bubble {
        max-width: 90%;
    }
}

/* ===== GLOBAL MOBILE FIXES ===== */
/* Prevent horizontal overflow */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Ensure all containers don't overflow */
.page-content,
.card,
.card-body,
.card-header {
    max-width: 100%;
    overflow-x: hidden;
}

/* Fix flex containers on mobile */
@media (max-width: 768px) {
    /* Page headers */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .page-header .d-flex {
        width: 100%;
        flex-direction: column;
        gap: 0.5rem;
    }

    .page-header form {
        width: 100%;
    }

    .page-header form .form-control {
        flex: 1;
    }

    /* Card headers */
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .card-header > .d-flex,
    .card-header > form {
        width: 100%;
    }

    /* Two column grids to single column */
    .grid-2,
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns: repeat(2"] {
        grid-template-columns: 1fr !important;
    }

    /* Full width buttons in flex containers */
    .d-flex.gap-2 > .btn {
        flex: 1;
        justify-content: center;
    }

    /* Forms in flex containers */
    form.d-flex {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    form.d-flex .form-control {
        min-width: 0;
        flex: 1 1 200px;
    }

    /* Justify between on mobile becomes column */
    .justify-between.align-center {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    /* Fix table containers */
    .table-responsive {
        margin: 0;
        border-radius: 0;
    }

    /* Fix select dropdowns */
    select.form-control {
        width: 100%;
    }

    /* Ensure images don't overflow */
    img {
        max-width: 100%;
        height: auto;
    }

    /* Fix long text overflow */
    td, th {
        word-break: break-word;
    }
}

@media (max-width: 480px) {
    /* Extra small screen fixes */
    .page-content {
        padding: 0.5rem;
    }

    .card-body,
    .card-header {
        padding: 0.75rem;
    }

    h1 {
        font-size: 1.25rem;
    }

    h2 {
        font-size: 1.125rem;
    }

    h3 {
        font-size: 1rem;
    }

    /* Button groups stack */
    .btn-group,
    .d-flex.gap-1,
    .d-flex.gap-2:not(.flex-nowrap) {
        flex-direction: column;
        width: 100%;
    }

    .btn-group > .btn,
    .d-flex.gap-1 > .btn,
    .d-flex.gap-2:not(.flex-nowrap) > .btn {
        width: 100%;
    }

    /* Fix modal on very small screens */
    .modal {
        margin: 0;
        max-height: 100vh;
        border-radius: 0;
    }
}

/* Prevent text overflow */
.text-truncate,
.visitor-name,
.conv-name,
.search-result-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
    .page-content {
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }

    .header {
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
    }
}
