:root {
    --primary: #25d366;
    --primary-hover: #128c7e;
    --secondary: #34b7f1;
    --danger: #dc2626;
    --success: #25d366;
    --warning: #f59e0b;
    --bg-body: #f0f2f5;
    --bg-card: #ffffff;
    --bg-sidebar: #111b21;
    --text-main: #111b21;
    --text-muted: #667781;
    --border-color: #e9edef;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    font-family: var(--font-family);
    background-color: #f1f5f9;
    color: var(--text-main);
    margin: 0;
    line-height: 1.5;
}

/* --- Layout (App Style) --- */
.dashboard-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    color: #aeBAC1;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid #202c33;
    height: 100%;
    overflow-y: auto;
    /* Hide scrollbar for sidebar */
    -ms-overflow-style: none;
    /* IE and Edge */
    scrollbar-width: none;
    /* Firefox */
}

.sidebar::-webkit-scrollbar {
    display: none;
}

/* ... existing sidebar-header/nav ... */
.sidebar-header {
    padding: 1.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: #e9edef;
    border-bottom: 1px solid #202c33;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-nav {
    flex: 1;
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.75rem 1rem;
    color: #aeBAC1;
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.2s;
    margin-bottom: 4px;
    font-weight: 500;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: #f1f5f9;
    color: var(--primary);
    border-left: none;
}

.nav-icon {
    color: inherit;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.sidebar-nav a:hover .nav-icon,
.sidebar-nav a.active .nav-icon {
    color: var(--primary);
}

.main-content {
    flex: 1;
    padding: 2.5rem;
    height: 100%;
    overflow-y: auto;
}

/* --- Common Components --- */

/* Page Headers */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.page-title h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0;
}

.page-title p {
    color: var(--text-muted);
    margin-top: 0.25rem;
    font-size: 0.95rem;
}

/* Navigation Links */
.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--primary);
}

/* Cards */
.card,
.form-card,
.table-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    /* Softer shadow */
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.table-card {
    padding: 0;
    overflow: hidden;
}

/* Forms */
.form-card {
    width: 100%;
    padding: 2.5rem;
    box-sizing: border-box;
}

.form-section-title {
    font-size: 1rem;
    color: var(--text-main);
    font-weight: 600;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    margin-top: 2.5rem;
}

.form-section-title:first-of-type {
    margin-top: 0;
}

.section-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(99, 102, 241, 0.1);
    color: #6366f1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

/* In Grid context, reset margin */
.form-grid .form-group {
    margin-bottom: 0;
}

.form-group-full {
    grid-column: 1 / -1;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-main);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
select,
textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #d1d7db;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.1);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.2rem;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: background-color 0.2s, transform 0.1s;
    gap: 0.5rem;
}

.btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #128c7e);
    box-shadow: 0 2px 4px rgba(37, 211, 102, 0.2);
}

.btn-create {
    background: linear-gradient(135deg, var(--primary), #4f46e5);
    /* Special gradient for create actions */
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-create:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background-color: #f8fafc;
    border-color: #cbd5e1;
}

.action-btn {
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.btn-suspend {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
}

.btn-suspend:hover {
    background: rgba(239, 68, 68, 0.2);
}

.btn-activate {
    background: rgba(16, 185, 129, 0.1);
    color: #34d399;
}

.btn-activate:hover {
    background: rgba(16, 185, 129, 0.2);
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

th {
    text-align: left;
    padding: 1rem 1.5rem;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    background: rgba(248, 250, 252, 0.5);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: #f8fafc;
}

/* Table Components */
.client-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.client-avatar {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), #818cf8);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    text-transform: uppercase;
    flex-shrink: 0;
}

.client-details h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-main);
}

.client-details span {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: block;
}

/* Badges */
.badge,
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-success,
.status-active {
    background: rgba(16, 185, 129, 0.15);
    color: #059669;
}

.badge-danger,
.status-suspended {
    background: rgba(239, 68, 68, 0.15);
    color: #dc2626;
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: #d97706;
}

/* Utils */
.text-muted {
    color: var(--text-muted);
}

.text-right {
    text-align: right;
}

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

.alert-success {
    background-color: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert-error {
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* Auth (Legacy support until refactored) */
.auth-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: var(--bg-body);
}

.auth-container {
    width: 100%;
    max-width: 420px;
    background: white;
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

/* --- Modals --- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.2s;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal {
    background: white;
    width: 90%;
    max-width: 450px;
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    transform: scale(0.95);
    transition: transform 0.2s;
    overflow: hidden;
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.5rem;
    border-radius: 50%;
    transition: background 0.2s;
}

.modal-close:hover {
    background: #f1f5f9;
}

.modal-body {
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.6;
}

.modal-footer {
    padding: 1rem 1.5rem;
    background: #f8fafc;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Modal Grid Logic */
.modal-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.modal-section-header {
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 1rem;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

@media (max-width: 768px) {
    .modal-form-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .modal {
        width: 95%;
        margin: 1rem;
        max-height: 90vh;
        overflow-y: auto;
    }
}

/* --- Inbox Split View --- */
.inbox-layout {
    display: flex;
    height: calc(100vh - 7rem);
    background: white;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.inbox-sidebar {
    width: 350px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: white;
}

.inbox-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #efe7dd;
    /* WhatsApp beige */
    position: relative;
    overflow: hidden;
    /* Ensure chat scroll is internal */
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
}

.conversation-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
    color: inherit;
}

.conversation-item:hover,
.conversation-item.active {
    background: #f0f2f5;
}

.conversation-item.active {
    border-left: 4px solid var(--primary);
}

/* Chat Components */
.chat-header {
    background: #f0f2f5;
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid #d1d7db;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
}

.chat-messages {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    background-repeat: repeat;
    background-size: 300px;
}

.message {
    padding: 0.5rem 0.8rem;
    border-radius: 8px;
    max-width: 65%;
    position: relative;
    font-size: 0.95rem;
    line-height: 1.4;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.message.inbound {
    background: white;
    align-self: flex-start;
    border-top-left-radius: 0;
}

.message.outbound {
    background: #d9fdd3;
    align-self: flex-end;
    border-top-right-radius: 0;
}

.chat-input-area {
    background: #f0f2f5;
    padding: 0.75rem;
    display: flex;
    align-items: center;
    border-top: 1px solid #d1d7db;
}

.chat-input {
    flex: 1;
    border-radius: 8px;
    border: 1px solid white;
    padding: 0.8rem 1rem;
    font-size: 0.95rem;
    background: white;
}

.empty-chat-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f0f2f5;
    color: var(--text-muted);
    text-align: center;
    border-bottom: 6px solid var(--primary);
    /* Decorative bottom strip */
}

/* --- Premium Polish --- */

/* Custom Scrollbars */
.conversation-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.conversation-list::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.conversation-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}

.conversation-list:hover::-webkit-scrollbar-thumb,
.chat-messages:hover::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
}

/* Chat Search */
.chat-search-container {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    background: #fcfcfc;
}

.chat-search-input {
    width: 100%;
    padding: 0.6rem 1rem 0.6rem 3rem;
    /* Space for icon */
    border-radius: 20px;
    border: 1px solid #e9edef;
    background-color: #f0f2f5;
    font-size: 0.9rem;
    transition: all 0.2s;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='16' height='16' fill='%2354656f'%3E%3Cpath d='M10.25 2a8.25 8.25 0 0 1 6.34 13.53l5.69 5.69a.75.75 0 1 1-1.06 1.06l-5.69-5.69A8.25 8.25 0 1 1 10.25 2ZM3.5 10.25a6.75 6.75 0 1 0 13.5 0 6.75 6.75 0 0 0-13.5 0Z'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
}

.chat-search-input:focus {
    background-color: white;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 211, 102, 0.1);
}

/* Filtered hidden state */
.conversation-item.hidden {
    display: none !important;
}

/* Refined Bubbles */
.message {
    padding: 0.6rem 0.9rem;
    border-radius: 12px;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
    border: none;
    /* remove old debug styling if any */
}



.message.outbound {
    background-color: #d9fdd3;
    border-top-right-radius: 0;
}

.message.inbound {
    background-color: #ffffff;
    border-top-left-radius: 0;
}


/* --- Settings Page (Compact) --- */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    align-items: stretch;
    margin-bottom: 2rem;
}

.settings-grid .card {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 1.25rem;
    /* Reduced padding */
    margin-bottom: 0;
}

.settings-grid .form-group {
    margin-bottom: 0.75rem;
    /* Compact inputs */
}

.settings-grid .form-section-title {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    margin-top: 1rem;
}

.settings-grid input {
    padding: 0.5rem 0.75rem;
    /* Smaller inputs */
}

.settings-grid .btn {
    padding: 0.5rem 1rem;
}

/* Push last child (stats) to bottom */
.settings-grid .card>div:last-child {
    margin-top: auto;
}

@media (max-width: 768px) {
    .settings-grid {
        grid-template-columns: 1fr;
    }
}