/* Dashboard Grid */
.dashboard-grid {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.25rem;
}

.stat-card {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    border-radius: var(--radius-lg);
    background: #ffffff;
    border: 1.5px solid var(--border-peach);
    box-shadow: 0 2px 12px rgba(0,0,0,0.02);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #fbfaf8;
    border: 1.5px solid var(--border-peach);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 1.3rem;
}

.stat-info .value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-main);
}

.main-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.card {
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    background: white;
    border: 1.5px solid var(--border-peach);
    box-shadow: 0 4px 15px rgba(0,0,0,0.02);
}

.card h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    font-family: 'Lora', serif;
}

.qr-wrapper {
    aspect-ratio: 1;
    max-width: 240px;
    margin: 1rem auto;
    background: #fbfaf8;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    border: 1.5px solid var(--border-peach);
}

/* Page Layouts */
.page-container {
    padding: 2rem;
    background: white;
    border-radius: var(--radius-lg);
    border: 1.5px solid var(--border-peach);
    box-shadow: 0 4px 20px rgba(0,0,0,0.02);
}

.page-header { margin-bottom: 2rem; }
.page-header h3 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.page-header p { color: var(--text-muted); font-size: 0.95rem; }

.tag { padding: 0.25rem 0.6rem; background: #f3f0ec; color: var(--accent); border-radius: 4px; font-size: 0.75rem; font-weight: 600; border: 1px solid var(--border-peach); }
.status-active { color: var(--success); font-weight: 600; font-size: 0.85rem; }

/* Auth Page */
.auth-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-dark);
    padding: 1rem;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    padding: 2.5rem 2rem;
    border-radius: 20px;
    background: #ffffff;
    border: 1.5px solid var(--border-peach);
    box-shadow: 0 4px 24px -4px rgba(29, 24, 22, 0.04);
}

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

.auth-header .logo {
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: center;
}

.auth-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.5rem;
    font-family: 'Outfit', sans-serif;
}

.auth-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-form .form-group {
    margin-bottom: 0.25rem;
}

.auth-form label {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.6rem;
    color: var(--text-main);
}

.auth-form .form-control {
    background: #fdfcfb;
    border: 1.5px solid var(--border-peach);
    padding: 0.85rem 1rem;
    font-size: 1rem;
}

.auth-form .form-control:focus {
    background: #ffffff;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

.auth-footer {
    margin-top: 1.5rem;
    text-align: left;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.auth-footer a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 4px;
    text-decoration-thickness: 1.5px;
    transition: 0.2s;
}

.auth-footer a:hover {
    color: #c26549;
    text-decoration-color: var(--primary);
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    background: #ffffff;
    border: 1.5px solid var(--border-peach);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 0.95rem;
    transition: 0.2s;
    font-family: inherit;
}

.form-control:focus { 
    border-color: var(--primary); 
    outline: none; 
    box-shadow: 0 0 0 3px var(--primary-glow); 
}

.help-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Switch Toggle Component */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #e5e7eb;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

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

input:focus + .slider {
    box-shadow: 0 0 1px var(--primary);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

input:disabled + .slider {
    background-color: #f3f4f6;
    cursor: not-allowed;
    opacity: 0.6;
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

/* Chat Interface - Refined & Premium */
.chat-interface {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: calc(100vh - var(--header-height) - 4rem);
    border-radius: var(--radius-lg);
    background: white;
    border: 1.5px solid var(--border-peach);
    box-shadow: 0 10px 40px -10px rgba(0,0,0,0.05);
    overflow: hidden;
    margin-top: 0.5rem;
}

.chat-sidebar {
    border-right: 1.5px solid var(--border-peach);
    background: #fdfcfb;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    overflow: hidden; /* Added to constrain children */
}

.chat-sidebar-header {
    padding: 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chat-sidebar-header h3 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
}

.chat-search-container {
    padding: 0 1.25rem 1rem;
    flex-shrink: 0;
}

.search-box {
    background: #f3f0ec;
    border: 1.5px solid transparent;
    border-radius: 10px;
    padding: 0.6rem 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: 0.2s;
}

.search-box:focus-within {
    background: white;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.search-box input {
    border: none;
    background: transparent;
    outline: none;
    width: 100%;
    font-size: 0.875rem;
    color: var(--text-main);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0; /* Critical for flexbox scrolling */
}

.chat-item {
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    border-bottom: 1px solid var(--border-glass);
    cursor: pointer;
    transition: 0.2s;
}

.chat-item:hover { background: #fbfaf8; }
.chat-item.active { background: #f3f0ec; border-right: 3px solid var(--primary); }

.chat-item .chat-avatar {
    width: 40px;
    height: 40px;
    background: #f3f0ec;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--primary);
    flex-shrink: 0;
    border: 1.5px solid var(--border-peach);
}

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

.chat-item h4 {
    font-size: 0.9rem;
    margin-bottom: 0.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item p {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.empty-sidebar {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted);
    animation: fadeIn 0.3s ease;
}

.empty-sidebar i {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    opacity: 0.4;
    display: block;
}

.empty-sidebar p {
    font-size: 0.8rem;
}

.chat-item.new-chat-item {
    background: var(--primary-glow);
    border-bottom: 1.5px solid var(--border-peach);
}

.chat-item.new-chat-item:hover {
    background: rgba(217, 119, 87, 0.15);
}

/* Skeletons */
.chat-item-skeleton {
    padding: 0.75rem 1rem;
    display: flex;
    gap: 1rem;
    opacity: 0.6;
}

.avatar-skeleton { width: 48px; height: 48px; border-radius: 50%; background: #f3f0ec; }
.info-skeleton { flex: 1; display: flex; flex-direction: column; gap: 0.5rem; justify-content: center; }
.line { height: 8px; background: #f3f0ec; border-radius: 4px; }
.line.sm { width: 40%; }
.line.lg { width: 80%; }

.chat-main { 
    background: #ffffff;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.chat-header {
    padding: 0.75rem 1.5rem;
    border-bottom: 1.5px solid var(--border-peach);
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

.chat-recipient-info h3 { font-size: 1rem; font-weight: 600; margin: 0; }
.chat-recipient-info span { font-size: 0.75rem; color: var(--success); }

.chat-actions { margin-left: auto; display: flex; gap: 0.5rem; }

.chat-messages {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: #faf9f6;
    min-height: 0;
}

/* Welcome State */
.chat-welcome-state {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
}

.welcome-box { max-width: 320px; }
.welcome-icon { 
    width: 80px; height: 80px; 
    background: var(--primary-glow); 
    color: var(--primary); 
    border-radius: 50%; 
    display: flex; align-items: center; justify-content: center; 
    font-size: 2.5rem; margin: 0 auto 1.5rem;
}
.welcome-box h2 { font-size: 1.5rem; margin-bottom: 0.75rem; }
.welcome-box p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.5rem; }

.msg { 
    max-width: 70%; 
    padding: 0.75rem 1rem; 
    border-radius: 12px; 
    font-size: 0.9rem; 
    line-height: 1.5; 
    position: relative;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}

.msg.received { 
    background: white; 
    align-self: flex-start; 
    border: 1px solid var(--border-peach);
    border-bottom-left-radius: 2px;
}

.message-content {
    word-break: break-word;
}

.message-time {
    font-size: 0.65rem;
    margin-top: 0.25rem;
    opacity: 0.7;
    text-align: right;
}

.msg.received .message-time { color: var(--text-muted); }
.msg.sent .message-time { color: rgba(255,255,255,0.8); }

.msg.sent { 
    background: var(--primary); 
    color: white; 
    align-self: flex-end; 
    border-bottom-right-radius: 2px;
}

.chat-input-area { 
    padding: 1rem 1.5rem; 
    background: white; 
    border-top: 1.5px solid var(--border-peach);
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

.input-actions-before { display: flex; gap: 0.5rem; }

.chat-input-wrapper {
    flex: 1;
    background: #f3f0ec;
    border-radius: 12px;
    padding: 0.25rem 0.5rem;
}

.chat-input-wrapper input {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: transparent;
    border: none;
    outline: none;
    font-size: 0.95rem;
}

.btn-send {
    width: 44px; height: 44px;
    border-radius: 12px;
    background: var(--primary);
    color: white;
    border: none;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: 0.2s;
}

.btn-send:hover { transform: scale(1.05); background: #c26549; }
 
.btn-resolve {
    background: var(--success);
    color: white;
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: 0.2s;
}

.btn-resolve:hover {
    background: #24634d;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(45, 122, 95, 0.15);
}

/* Modal */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    z-index: 2000;
}

.modal-content {
    width: 90%; max-width: 400px;
    background: white;
    border-radius: var(--radius-lg);
    border: 1.5px solid var(--border-peach);
    box-shadow: 0 20px 60px rgba(0,0,0,0.1);
}

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

.modal-body { padding: 1.5rem; }

.btn-icon-round {
    width: 36px; height: 36px; border-radius: 50%;
    background: #f3f0ec; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-main); transition: 0.2s;
}

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

.btn-round { border-radius: 30px; padding-left: 1.5rem; padding-right: 1.5rem; }
.btn-full { width: 100%; margin-top: 1rem; }

/* CRM Table */
.crm-table { width: 100%; border-collapse: separate; border-spacing: 0; margin-top: 1rem; border: 1.5px solid var(--border-peach); border-radius: var(--radius-md); overflow: hidden; }

.crm-table th { 
    text-align: left; 
    padding: 0.75rem 1rem; 
    color: var(--text-muted); 
    font-weight: 600; 
    font-size: 0.7rem; 
    text-transform: uppercase; 
    letter-spacing: 0.08em; 
    border-bottom: 1.5px solid var(--border-peach);
    background: #fbfaf8;
}

.crm-table td { 
    padding: 1rem; 
    border-bottom: 1px solid var(--border-peach); 
    color: var(--text-main); 
    transition: 0.2s;
    font-size: 0.9rem;
}

.crm-table tr:hover td {
    background: #fdfcfb;
}

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

/* Buttons & Actions */
.btn-logout {
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #fdfcfb;
    border: 1.5px solid var(--border-peach);
    color: var(--text-muted);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-logout:hover {
    background: #fee2e2;
    color: var(--error);
    border-color: #fca5a5;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.08);
}

.btn-sm {
    border: 1.5px solid var(--border-peach);
    background: white;
    color: var(--text-main);
    border-radius: 4px;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
}

.btn-sm:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #fdfcfb;
    box-shadow: 0 2px 8px rgba(217, 119, 87, 0.1);
}

/* Templates */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
}

.template-card {
    padding: 1.5rem;
    background: white;
    border: 1.5px solid var(--border-peach);
    border-radius: var(--radius-lg);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.02);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.template-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: 0 12px 24px rgba(217, 119, 87, 0.12);
}

.template-card h4 {
    font-size: 1.1rem;
    color: var(--text-main);
    margin: 0;
}

.template-card .preview {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.template-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
    padding-top: 0.75rem;
    border-top: 1px solid #f9ebe0;
}

.template-footer .type {
    font-size: 0.75rem;
    color: var(--accent);
    background: #f3f0ec;
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
}

/* Interaction & Dynamic Stats */
.connection-success { color: var(--success); text-align: center; padding: 2rem; }
.connection-success p { color: var(--text-muted); margin-top: 0.5rem; }

.qr-container {
    padding: 2rem;
    background: #fbfaf8;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-glass);
    text-align: center;
}

.qr-container img { 
    border: 12px solid white; 
    box-shadow: 0 8px 30px rgba(0,0,0,0.06); 
    border-radius: var(--radius-md);
}

.code-block { 
    background: #2a2724; 
    color: #e5e2de; 
    padding: 1.5rem;
    border-radius: var(--radius-md);
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    overflow-x: auto;
    border: 1px solid #3d3935;
}

.code-block pre { margin: 0; }
.code-block .keyword { color: #d97757; }
.code-block .string { color: #a3be8c; }
.code-block .function { color: #88c0d0; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #dcd9d4; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-peach); }
