/* 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;
    flex-wrap: wrap;
    gap: 1rem;
    flex-shrink: 0;
}

.input-actions-before {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

/* Circular icon buttons used by the composer and the chat header. */
.btn-icon {
    width: 38px;
    height: 38px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
}

.btn-icon:hover {
    background: rgba(217, 119, 87, 0.1);
    border-color: rgba(217, 119, 87, 0.25);
    color: var(--primary);
}

.btn-icon:active { transform: scale(0.94); }

.btn-icon:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    color: var(--primary);
}

.btn-icon:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.btn-icon i { pointer-events: none; }

.composer-popover-wrap { position: relative; display: inline-flex; }

.emoji-popover {
    position: absolute;
    bottom: calc(100% + 0.6rem);
    left: 0;
    width: 264px;
    padding: 0.75rem;
    background: #ffffff;
    border: 1px solid var(--border-peach);
    border-radius: var(--radius-md, 12px);
    box-shadow: 0 12px 32px rgba(60, 40, 30, 0.16);
    z-index: 40;
    animation: emoji-pop 0.14s ease-out;
}

@keyframes emoji-pop {
    from { opacity: 0; transform: translateY(6px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.emoji-popover-title {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.15rem;
}

.emoji-item {
    border: none;
    background: transparent;
    font-size: 1.25rem;
    line-height: 1;
    padding: 0.35rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.12s ease;
}

.emoji-item:hover { background: #f7ede7; transform: scale(1.12); }
.emoji-item:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

/* Attachment chip shown above the composer once a file is picked. */
.attachment-preview {
    width: 100%;
    padding: 0 0.25rem 0.5rem 0.25rem;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    max-width: 100%;
    padding: 0.45rem 0.5rem 0.45rem 0.75rem;
    background: #fdf6f2;
    border: 1px solid var(--border-peach);
    border-radius: 12px;
}

.attachment-chip-icon { font-size: 1.15rem; color: var(--primary); flex-shrink: 0; }

.attachment-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.25;
}

.attachment-name {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-main);
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-size { font-size: 0.7rem; color: var(--text-muted); }

.attachment-remove {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.attachment-remove:hover { background: rgba(217, 87, 87, 0.12); color: #c0392b; }

.chat-messages.drag-over {
    outline: 2px dashed var(--primary);
    outline-offset: -8px;
    background: rgba(217, 119, 87, 0.05);
}

.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: 9999;
}

.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);
}

/* 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: 1rem;
    color: var(--text-main);
    margin: 0;
    overflow-wrap: break-word;
    word-break: break-word;
    text-overflow: ellipsis;
    max-width: 100%;
}

.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); }

/* Broadcast Styles */
.campaign-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.campaign-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.88rem;
}

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

.campaign-table td {
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid rgba(244, 219, 204, 0.4);
    vertical-align: middle;
    color: var(--text-main);
}

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

.campaign-table tbody tr {
    transition: background 0.15s ease;
}

.campaign-table tbody tr:hover td {
    background: #faf9f7;
}

/* Campaign Name & Subtitle column */
.campaign-info-cell {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0; /* Enable flex child shrinking */
}

.campaign-title-text {
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.92rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.campaign-subtitle-text {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.campaign-subtitle-text span {
    background: #f7ede6;
    color: var(--accent);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 500;
    border: 1px solid var(--border-peach);
}

/* Date Cell */
.campaign-date-cell {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.campaign-date-cell i {
    color: var(--primary);
    opacity: 0.7;
}

/* Status Badges */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.65rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
    border: 1px solid transparent;
}

.status-pill.status-completed {
    background: rgba(45, 122, 95, 0.08);
    color: var(--success);
    border-color: rgba(45, 122, 95, 0.15);
}

.status-pill.status-running {
    background: rgba(217, 119, 87, 0.08);
    color: var(--primary);
    border-color: rgba(217, 119, 87, 0.15);
}

.status-pill.status-paused {
    background: rgba(180, 83, 9, 0.08);
    color: var(--warning);
    border-color: rgba(180, 83, 9, 0.15);
}

.status-pill.status-pending {
    background: rgba(99, 102, 241, 0.08);
    color: #6366f1;
    border-color: rgba(99, 102, 241, 0.15);
}

.status-pill.status-rejected {
    background: rgba(185, 28, 28, 0.08);
    color: var(--error);
    border-color: rgba(185, 28, 28, 0.15);
}

.template-preview-text {
    max-width: 350px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* Pulsing dot for Running status */
.status-pill-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.status-pill.status-running .status-pill-dot {
    animation: status-pulse-dot 1.5s infinite;
}

@keyframes status-pulse-dot {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.4; }
}

/* Progress Cell */
.campaign-progress-cell {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 150px;
    max-width: 220px;
}

.campaign-progress-bar-track {
    width: 100%;
    height: 6px;
    background: #f0eae6;
    border-radius: 4px;
    overflow: hidden;
}

.campaign-progress-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.4s ease;
    background: var(--primary);
}

.status-completed .campaign-progress-bar-fill {
    background: var(--success);
}

.status-running .campaign-progress-bar-fill {
    background: linear-gradient(90deg, var(--primary), #e68d70);
}

.status-paused .campaign-progress-bar-fill {
    background: var(--warning);
}

.campaign-progress-text {
    display: flex;
    justify-content: space-between;
    font-size: 0.74rem;
    color: var(--text-muted);
}

.campaign-progress-pct {
    font-weight: 600;
    color: var(--text-main);
}

/* Stats (Sent/Failed Badges) */
.campaign-stats-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.campaign-stat-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    font-size: 0.74rem;
    font-weight: 500;
}

.campaign-stat-badge.success {
    background: rgba(45, 122, 95, 0.05);
    color: var(--success);
}

.campaign-stat-badge.failed {
    background: rgba(185, 28, 28, 0.05);
    color: var(--error);
}

.campaign-stat-badge.total {
    background: #f7f5f2;
    color: var(--accent);
    border: 1px solid var(--border-peach);
}

/* Action Buttons */
.action-button-group {
    display: flex;
    justify-content: flex-end;
    gap: 0.4rem;
}

.action-btn-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1.5px solid var(--border-peach);
    background: #ffffff;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.95rem;
}

.action-btn-circle:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-glow);
    transform: scale(1.05);
}

.action-btn-circle:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background: #faf9f8;
}

.action-btn-circle.delete:hover:not(:disabled) {
    border-color: var(--error);
    color: var(--error);
    background: rgba(185, 28, 28, 0.05);
}

/* Empty State Styling */
.empty-state-card {
    text-align: center;
    padding: 4rem 2rem;
    background: #ffffff;
    border: 1.5px dashed var(--border-peach);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    color: var(--text-muted);
}

.empty-state-icon-wrapper {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--primary-glow);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.empty-state-card h4 {
    font-family: 'Lora', serif;
    font-size: 1.25rem;
    color: var(--text-main);
    margin: 0;
}

.empty-state-card p {
    font-size: 0.88rem;
    max-width: 320px;
    margin: 0 auto 0.5rem;
}

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

.campaign-stat-card {
    background: #ffffff;
    border: 1.5px solid var(--border-peach);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: default;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-premium);
}

.campaign-stat-card::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: transparent;
    transition: background 0.25s ease;
}

.campaign-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px -4px rgba(217, 119, 87, 0.08), 0 4px 12px -2px rgba(0, 0, 0, 0.02);
    border-color: var(--primary);
}

.campaign-stat-card.total:hover::after { background: var(--primary); }
.campaign-stat-card.sent:hover::after { background: var(--success); }
.campaign-stat-card.failed:hover::after { background: var(--error); }
.campaign-stat-card.rate:hover::after { background: #6366f1; }
.campaign-stat-card.messages:hover::after { background: #3b82f6; }
.campaign-stat-card.ai:hover::after { background: #8b5cf6; }
.campaign-stat-card.contacts:hover::after { background: #10b981; }

.campaign-stat-card-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

/* Custom icon themes */
.campaign-stat-card.total .campaign-stat-card-icon {
    background: rgba(217, 119, 87, 0.1);
    color: var(--primary);
}
.campaign-stat-card.sent .campaign-stat-card-icon {
    background: rgba(45, 122, 95, 0.1);
    color: var(--success);
}
.campaign-stat-card.failed .campaign-stat-card-icon {
    background: rgba(185, 28, 28, 0.1);
    color: var(--error);
}
.campaign-stat-card.rate .campaign-stat-card-icon {
    background: rgba(99, 102, 241, 0.1);
    color: #6366f1;
}
.campaign-stat-card.messages .campaign-stat-card-icon {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}
.campaign-stat-card.ai .campaign-stat-card-icon {
    background: rgba(139, 92, 246, 0.1);
    color: #8b5cf6;
}
.campaign-stat-card.contacts .campaign-stat-card-icon {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.campaign-stat-card-info {
    display: flex;
    flex-direction: column;
}

.campaign-stat-card-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.2;
    font-family: 'Outfit', sans-serif;
}

.campaign-stat-card-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.2rem;
}

/* Search & Filter Controls Bar */
.campaign-controls-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
    padding: 0.25rem 0;
}

.campaign-search-wrapper {
    position: relative;
    flex: 1;
    min-width: 260px;
    max-width: 400px;
}

.campaign-search-wrapper i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1rem;
    pointer-events: none;
}

.campaign-search-input {
    width: 100%;
    padding: 0.65rem 1rem 0.65rem 2.25rem;
    border: 1.5px solid var(--border-peach);
    border-radius: var(--radius-md);
    background: #ffffff;
    font-size: 0.88rem;
    color: var(--text-main);
    transition: all 0.2s ease;
}

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

.campaign-filter-tabs {
    display: flex;
    gap: 0.35rem;
    background: #fcfaf8;
    padding: 0.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-peach);
}

.campaign-filter-tab {
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--text-muted);
    transition: all 0.2s ease;
}

.campaign-filter-tab:hover {
    color: var(--text-main);
    background: rgba(0, 0, 0, 0.02);
}

.campaign-filter-tab.active {
    background: var(--primary);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(217, 119, 87, 0.25);
}

/* Table layout and containers */
.campaign-table-container {
    background: #ffffff;
    border: 1.5px solid var(--border-peach);
    border-radius: var(--radius-lg);
    overflow-x: auto;
    overflow-y: hidden;
    box-shadow: var(--shadow-premium);
    width: 100%;
}

.campaign-table {
    table-layout: fixed;
}

/* Campaign table columns width distribution */
.campaign-table.campaigns-list-table th:nth-child(1),
.campaign-table.campaigns-list-table td:nth-child(1) { width: 22%; min-width: 160px; }
.campaign-table.campaigns-list-table th:nth-child(2),
.campaign-table.campaigns-list-table td:nth-child(2) { width: 17%; min-width: 150px; }
.campaign-table.campaigns-list-table th:nth-child(3),
.campaign-table.campaigns-list-table td:nth-child(3) { width: 12%; min-width: 115px; }
.campaign-table.campaigns-list-table th:nth-child(4),
.campaign-table.campaigns-list-table td:nth-child(4) { width: 16%; min-width: 140px; }
.campaign-table.campaigns-list-table th:nth-child(5),
.campaign-table.campaigns-list-table td:nth-child(5) { width: 14%; min-width: 120px; }
.campaign-table.campaigns-list-table th:nth-child(6),
.campaign-table.campaigns-list-table td:nth-child(6) { width: 19%; min-width: 175px; text-align: right; }
.campaign-table.campaigns-list-table .campaign-stats-cell,
.campaign-table.campaigns-list-table .action-button-group { flex-wrap: nowrap; white-space: nowrap; }

/* Templates table columns width distribution */
.campaign-table.templates-list-table th:nth-child(1),
.campaign-table.templates-list-table td:nth-child(1) { width: 35%; min-width: 200px; }
.campaign-table.templates-list-table th:nth-child(2),
.campaign-table.templates-list-table td:nth-child(2) { width: 14%; min-width: 100px; }
.campaign-table.templates-list-table th:nth-child(3),
.campaign-table.templates-list-table td:nth-child(3) { width: 16%; min-width: 110px; }
.campaign-table.templates-list-table th:nth-child(4),
.campaign-table.templates-list-table td:nth-child(4) { width: 16%; min-width: 110px; }
.campaign-table.templates-list-table th:nth-child(5),
.campaign-table.templates-list-table td:nth-child(5) { width: 10%; min-width: 90px; text-align: right; }

/* Template Type Icons */
.type-icon {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    flex-shrink: 0;
}
.type-icon.type-text {
    background: rgba(99, 102, 241, 0.1);
    color: #6366f1;
}
.type-icon.type-image {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}
.type-icon.type-video {
    background: rgba(217, 119, 87, 0.1);
    color: var(--primary);
}
.type-icon.type-document {
    background: rgba(45, 122, 95, 0.1);
    color: var(--success);
}

/* === Create Template Page — Redesigned === */
.create-tmpl-page {
    max-width: 1100px;
    height: 100%;
    display: flex;
    flex-direction: column;
}
/* The form and the preview scroll independently; the page itself does not. */
#page-content:has(.create-tmpl-page) { overflow: hidden; }

.create-tmpl-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
    margin-bottom: 1.5rem;
    color: var(--text-muted);
}
.crumb-link {
    color: var(--primary);
    cursor: pointer;
    font-weight: 500;
    transition: 0.2s;
}
.crumb-link:hover { opacity: 0.8; }
.crumb-sep { font-size: 0.7rem; opacity: 0.5; display: flex; }
.crumb-sep i { line-height: 1; }
.crumb-current { font-weight: 600; color: var(--text-main); }

.create-tmpl-layout {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 1.5rem;
    align-items: stretch;
    flex: 1;
    min-height: 0;
}

.create-tmpl-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    min-height: 0;
    overflow-y: auto;
    padding-right: 0.5rem;
}
.create-tmpl-form > * { flex-shrink: 0; }

.create-tmpl-section {
    background: white;
    border: 1.5px solid var(--border-peach);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.create-tmpl-section-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: #fdfbfa;
    border-bottom: 1px solid var(--border-peach);
}
.create-tmpl-section-header i {
    font-size: 1.2rem;
    color: var(--primary);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-glow);
    border-radius: 8px;
    flex-shrink: 0;
}
.create-tmpl-section-header h4 {
    font-family: 'Inter', sans-serif;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
}
.create-tmpl-section-header p {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin: 0;
}

.create-tmpl-section-body {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.create-tmpl-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.create-tmpl-field label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.create-tmpl-optional {
    font-weight: 400;
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.75rem;
}

.create-tmpl-input,
.create-tmpl-textarea,
.create-tmpl-select {
    width: 100%;
    padding: 0.7rem 0.9rem;
    background: #fcfbfa;
    border: 1.5px solid #ede5df;
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-size: 0.9rem;
    transition: all 0.2s ease;
    font-family: inherit;
}
.create-tmpl-input:focus,
.create-tmpl-textarea:focus,
.create-tmpl-select:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.create-tmpl-input::placeholder,
.create-tmpl-textarea::placeholder { color: #b5aaa3; }

.create-tmpl-textarea {
    resize: vertical;
    min-height: 100px;
    line-height: 1.6;
}

.create-tmpl-hint {
    font-size: 0.74rem;
    color: var(--text-muted);
    opacity: 0.7;
}

/* Media URL field: upload button + inline preview of the uploaded file. */
.create-tmpl-media-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.create-tmpl-media-input-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
}

.create-tmpl-media-icon {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.95rem;
    color: var(--text-muted);
    pointer-events: none;
}

.create-tmpl-media-input-wrap .create-tmpl-input { padding-left: 2.4rem; }

.create-tmpl-upload-btn {
    flex-shrink: 0;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.7rem 1rem;
}

.create-tmpl-media-preview { margin-top: 0.35rem; }

.create-tmpl-media-thumb {
    margin: 0;
    display: inline-block;
    max-width: 100%;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-peach);
    background: #fcfbfa;
}

.create-tmpl-media-thumb img,
.create-tmpl-media-thumb video {
    display: block;
    max-width: 100%;
    max-height: 180px;
    object-fit: cover;
}

.create-tmpl-media-file {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border-peach);
    border-radius: 10px;
    background: #fdf6f2;
    font-size: 0.82rem;
    color: var(--text-main);
}

.create-tmpl-media-file i { color: var(--primary); font-size: 1.1rem; }
.create-tmpl-media-file a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
    margin-left: 0.35rem;
}

.create-tmpl-select-wrap {
    position: relative;
}
.create-tmpl-select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 2rem;
    cursor: pointer;
}
.create-tmpl-select-arrow {
    position: absolute;
    right: 0.8rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.8rem;
    pointer-events: none;
}

.create-tmpl-row {
    display: grid;
    gap: 1rem;
}
.create-tmpl-row-3 {
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
}
.create-tmpl-stack {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}
.create-tmpl-field-type { display: flex; flex-direction: column; }
.create-tmpl-field-type .create-tmpl-type-selector { flex: 1; }

/* Live Meta-rule warnings under the body text */
.create-tmpl-issues {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0.6rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    background: rgba(180, 83, 9, 0.07);
    border: 1px solid rgba(180, 83, 9, 0.25);
    border-radius: var(--radius-md);
}
.create-tmpl-issues[hidden] { display: none; }
.create-tmpl-issues li {
    display: flex;
    gap: 0.45rem;
    align-items: flex-start;
    font-size: 0.78rem;
    line-height: 1.4;
    color: #92400e;
}
.create-tmpl-issues li i { margin-top: 0.1rem; flex-shrink: 0; }

/* One sample input per body placeholder */
.create-tmpl-samples {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.create-tmpl-sample-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0;
}
.create-tmpl-sample-var {
    flex: 0 0 auto;
    min-width: 3.4rem;
    padding: 0.5rem 0.6rem;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-glow);
    border-radius: var(--radius-md);
}
.create-tmpl-sample-row .create-tmpl-input { flex: 1; }

/* Type selector visual cards */
.create-tmpl-type-selector {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: 1fr;
    gap: 0.5rem;
}
.create-tmpl-type-card {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.45rem;
    justify-content: center;
    padding: 0.45rem 0.4rem;
    background: #fcfbfa;
    border: 1.5px solid #ede5df;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}
.create-tmpl-type-card i {
    font-size: 1.2rem;
    color: var(--text-muted);
    transition: 0.2s;
}
.create-tmpl-type-card span {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: 0.2s;
}
.create-tmpl-type-card:hover {
    border-color: var(--border-peach);
    background: white;
}
.create-tmpl-type-card.active {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.create-tmpl-type-card.active i {
    color: var(--primary);
}
.create-tmpl-type-card.active span {
    color: var(--text-main);
}

.create-tmpl-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
}
.create-tmpl-actions .btn {
    flex: 1;
    justify-content: center;
    padding: 0.75rem 1rem;
    font-weight: 600;
}

/* Preview Panel */
.create-tmpl-preview-panel {
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: none;
}
.create-tmpl-preview-panel::-webkit-scrollbar { display: none; }
.create-tmpl-phone-frame {
    padding: 0.25rem 0.25rem 1rem;
    display: flex;
    justify-content: center;
}

/* Phone device with a WhatsApp conversation inside. */
.wa-phone {
    position: relative;
    width: 100%;
    max-width: 300px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 9px solid #1f1d1b;
    border-radius: 38px;
    background: #efe7dd;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
}
.wa-phone-notch {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 96px;
    height: 18px;
    background: #1f1d1b;
    border-radius: 0 0 12px 12px;
    z-index: 2;
}
.wa-phone-header {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 1.7rem 0.75rem 0.6rem;
    background: #008069;
    color: #ffffff;
}
.wa-phone-header > i { font-size: 1rem; }
.wa-phone-avatar {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #d9fdd3;
    color: #008069;
    font-size: 1.1rem;
}
.wa-phone-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.wa-phone-title strong { font-size: 0.85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-phone-title strong i { font-size: 0.8rem; color: #8ef0c9; vertical-align: -1px; }
.wa-phone-title span { font-size: 0.68rem; opacity: 0.8; }
.wa-phone-input {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0.4rem 0.5rem 0.55rem;
    padding: 0.5rem 0.8rem;
    border-radius: 999px;
    background: #ffffff;
    color: #8696a0;
    font-size: 0.78rem;
}
.wa-phone-input span { flex: 1; }
.wa-phone-input i { font-size: 1rem; }

.create-tmpl-phone-content {
    flex: 1;
    min-height: 360px;
    padding: 0.8rem 0.55rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    overflow-y: auto;
    background-color: #efe7dd;
    background-image: radial-gradient(rgba(0, 0, 0, 0.045) 1px, transparent 1px);
    background-size: 14px 14px;
}

.create-tmpl-preview-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-muted);
    gap: 0.75rem;
    padding: 2rem 0;
}
.create-tmpl-preview-empty i {
    font-size: 2.5rem;
    opacity: 0.2;
}
.create-tmpl-preview-empty p {
    font-size: 0.82rem;
    line-height: 1.5;
    opacity: 0.6;
}

/* Chat surface that mimics a WhatsApp conversation. */
.preview-chat {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: 0 0.35rem 0 0.5rem;
}

.preview-bubble {
    position: relative;
    align-self: flex-start;
    width: 100%;
    max-width: 100%;
    padding: 0.25rem 0.25rem 0.3rem;
    background: #ffffff;
    border-radius: 0 10px 10px 10px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
    overflow: hidden;
}
.preview-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    left: -6px;
    border-top: 8px solid #ffffff;
    border-left: 6px solid transparent;
}

.preview-header-text {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-main);
    padding: 0.35rem 0.45rem 0;
}
.preview-media-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 90px;
    background: #f0f2f5;
    border-radius: 8px;
    font-size: 0.78rem;
    color: var(--text-muted);
}
.preview-media-badge i { font-size: 1.3rem; color: var(--text-muted); }
.preview-media-empty { opacity: 0.8; }

/* Real media shown in the live preview once a URL is present. */
.preview-media-image {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: #f0f2f5;
}

.preview-media-image img,
.preview-media-image video {
    display: block;
    width: 100%;
    height: auto;
    max-height: 240px;
    object-fit: cover;
}

.preview-media-play {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 1.6rem;
    background: rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

.preview-media-doc {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.7rem;
    background: #f0f2f5;
    border-radius: 8px;
}

.preview-media-doc i { color: var(--primary); font-size: 1.4rem; }
.preview-media-doc > div { display: flex; flex-direction: column; min-width: 0; }
.preview-media-doc-name {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-main);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.preview-media-doc-action { font-size: 0.68rem; color: var(--text-muted); }
.preview-body-text {
    font-size: 0.86rem;
    line-height: 1.5;
    color: var(--text-main);
    padding: 0.35rem 0.45rem 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.preview-param {
    display: inline-block;
    background: rgba(217, 119, 87, 0.12);
    color: var(--primary);
    font-weight: 600;
    padding: 0 0.3rem;
    border-radius: 3px;
    font-size: 0.8rem;
}
.preview-footer-text {
    font-size: 0.74rem;
    color: var(--text-muted);
    padding: 0.2rem 0.45rem 0;
}
.preview-time {
    text-align: right;
    font-size: 0.64rem;
    color: #8696a0;
    padding: 0.15rem 0.45rem 0;
}
.preview-muted {
    color: var(--text-muted);
    font-style: italic;
    opacity: 0.6;
}

/* Button Rows */
.create-tmpl-btn-row {
    margin-bottom: 0.6rem;
}
.create-tmpl-btn-fields {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
}
.create-tmpl-btn-fields .form-control-sm {
    padding: 0.45rem 0.6rem;
    font-size: 0.8rem;
    border-radius: 6px;
    background: #fcfbfa;
    border: 1.5px solid #ede5df;
    transition: all 0.2s ease;
    font-family: inherit;
    color: var(--text-main);
}
.create-tmpl-btn-fields .form-control-sm:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.create-tmpl-btn-type {
    min-width: 120px;
    flex-shrink: 0;
}
.create-tmpl-btn-text {
    min-width: 150px;
    flex: 1;
}
.create-tmpl-btn-url {
    min-width: 200px;
    flex: 1.5;
}
.create-tmpl-btn-phone {
    min-width: 140px;
    flex: 1;
}
.create-tmpl-btn-remove {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1.5px solid transparent;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}
.create-tmpl-btn-remove:hover {
    background: rgba(185,28,28,0.06);
    color: var(--error);
    border-color: rgba(185,28,28,0.15);
}
.btn-secondary.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.78rem;
}

/* Preview Buttons: separate cards under the bubble, as WhatsApp renders them. */
.preview-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.preview-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.55rem 0.75rem;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
    font-size: 0.82rem;
    font-weight: 600;
    color: #027eb5;
}
.preview-btn i { font-size: 0.9rem; }

@media (max-width: 900px) {
    #page-content:has(.create-tmpl-page) { overflow-y: auto; }
    .create-tmpl-page { height: auto; display: block; }
    .create-tmpl-layout {
        grid-template-columns: 1fr;
    }
    .create-tmpl-form { overflow: visible; padding-right: 0; }
    .create-tmpl-preview-panel {
        overflow: visible;
        order: -1;
    }
    .create-tmpl-phone-frame {
        min-height: 320px;
    }
    .create-tmpl-row-3 {
        grid-template-columns: 1fr;
    }
    .create-tmpl-type-selector {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ---------------------------------------------------------------- Inbox extras */
.unread-badge {
    margin-left: auto;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.message-status {
    margin-left: 0.4rem;
    font-size: 0.65rem;
    opacity: 0.7;
    text-transform: lowercase;
}

.message-media {
    margin-bottom: 0.35rem;
    max-width: 320px;
}

.message-media a {
    color: var(--primary);
    font-size: 0.8rem;
    text-decoration: none;
}

.message-media img {
    display: block;
    max-width: 100%;
    max-height: 280px;
    border-radius: 10px;
    object-fit: cover;
}

.message-media video {
    display: block;
    width: 100%;
    max-height: 280px;
    border-radius: 10px;
    background: #000;
}

.message-media audio { width: 100%; }

/* Document card inside a chat bubble. */
.message-document a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.7rem;
    color: inherit;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 10px;
    transition: background 0.18s ease;
}

.msg.received .message-document a {
    background: #fdf6f2;
    border-color: var(--border-peach);
}

.message-document a:hover { background: rgba(255, 255, 255, 0.26); }
.msg.received .message-document a:hover { background: #f7ede7; }

.doc-icon {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.24);
    font-size: 1.1rem;
}

.msg.received .doc-icon {
    background: rgba(217, 119, 87, 0.14);
    color: var(--primary);
}

.doc-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.3;
}

.doc-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: inherit;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-action {
    font-size: 0.68rem;
    opacity: 0.75;
    color: inherit;
}

.doc-download { font-size: 1.05rem; opacity: 0.8; margin-left: auto; flex-shrink: 0; }

/* Campaign lifecycle states added by the durable queue. */
.status-pill.status-scheduled,
.status-pill.status-queued {
    background: #eef4ff;
    color: #2b5cd9;
}

.status-pill.status-scheduled .status-pill-dot,
.status-pill.status-queued .status-pill-dot {
    background: #2b5cd9;
}

.status-pill.status-cancelled,
.status-pill.status-failed {
    background: #fdecec;
    color: #c0392b;
}

.status-pill.status-cancelled .status-pill-dot,
.status-pill.status-failed .status-pill-dot {
    background: #c0392b;
}

.status-scheduled .campaign-progress-bar-fill,
.status-queued .campaign-progress-bar-fill {
    background: #2b5cd9;
}

.status-cancelled .campaign-progress-bar-fill,
.status-failed .campaign-progress-bar-fill {
    background: #c0392b;
}

/* ---------------------------------------------------------- template picker */
/* Opened by typing "/" in the chat composer or clicking the Template button. */
.chat-input-area { position: relative; }

.template-picker {
    position: absolute;
    left: 1.5rem;
    right: 1.5rem;
    bottom: calc(100% + 10px);
    max-height: 340px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1.5px solid var(--border-peach);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(29, 24, 22, 0.14);
    padding: 0.4rem;
    z-index: 50;
}

.template-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.45rem 0.7rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-peach);
    margin-bottom: 0.25rem;
}

.template-picker-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem 0.7rem;
    border-radius: 10px;
    cursor: pointer;
}

.template-picker-item:hover,
.template-picker-item.active { background: var(--primary-glow); }

.template-picker-item .tp-name { font-weight: 600; font-size: 0.9rem; }
.template-picker-item .tp-meta { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }

.template-picker-empty { padding: 0.9rem 0.7rem; font-size: 0.85rem; color: var(--text-muted); }

.template-picker-params { display: grid; gap: 0.5rem; padding: 0.5rem 0.7rem; }
.template-picker-params label { display: grid; gap: 0.25rem; font-size: 0.72rem; color: var(--text-muted); }
.template-picker-actions { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 0.4rem 0.7rem 0.5rem; }

/* Template preview modal: the phone mock-up floats over a dimmed page. */
.template-preview-dialog {
    position: relative;
    width: 320px;
    max-width: 92vw;
    max-height: 92vh;
    overflow-y: auto;
    scrollbar-width: none;
}
.template-preview-dialog::-webkit-scrollbar { display: none; }
.template-preview-dialog .wa-phone { max-width: none; }
.template-preview-dialog .create-tmpl-phone-content { min-height: 380px; }
.template-preview-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: #ffffff;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 3;
}
