/* MailFlow CRM — Main Styles */

:root {
    --sidebar-width: 260px;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --sidebar-bg: #1e1b4b;
    --sidebar-hover: #312e81;
    --body-bg: #f1f5f9;
    --card-shadow: 0 1px 3px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--body-bg);
    margin: 0;
    color: #334155;
    overflow-x: hidden;
}

/* Layout */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transition: transform .3s ease;
}

.sidebar-brand {
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    border-bottom: 1px solid rgba(255,255,255,.08);
    color: #e2e8f0;
    text-decoration: none;
    overflow: hidden;
    flex-shrink: 0;
    min-height: 72px;
    max-height: 72px;
    background: #0b0b0f;
}

.sidebar-brand:hover {
    color: #fff;
}

.sidebar-logo {
    display: block;
    width: auto;
    max-width: 100%;
    max-height: 48px;
    height: auto;
    object-fit: contain;
}

.sidebar-brand i { font-size: 1.5rem; color: #818cf8; }

.sidebar-nav {
    flex: 1;
    padding: 1rem .75rem;
    overflow-y: auto;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .7rem 1rem;
    color: #cbd5e1;
    text-decoration: none;
    border-radius: .5rem;
    margin-bottom: .25rem;
    transition: all .2s;
    font-size: .925rem;
}

.sidebar-nav .nav-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-nav .nav-link.active {
    background: var(--primary);
    color: #fff;
}

.sidebar-nav .nav-link i { font-size: 1.1rem; width: 1.25rem; }

.sidebar-divider {
    height: 1px;
    background: rgba(255,255,255,.08);
    margin: .75rem 0;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,.08);
}

.user-info {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: .9rem;
}

.user-name { font-size: .875rem; font-weight: 600; }
.user-email { font-size: .75rem; color: #94a3b8; }

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.top-bar {
    background: #fff;
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.page-heading {
    font-size: 1.35rem;
    font-weight: 600;
    margin: 0;
    flex: 1;
}

.top-bar-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.sidebar-toggle {
    text-decoration: none;
    flex-shrink: 0;
}

.content-area { padding: 1.5rem; }

/* Cards */
.card {
    border: none;
    border-radius: .75rem;
    box-shadow: var(--card-shadow);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid #f1f5f9;
    padding: 1rem 1.25rem;
    font-weight: 500;
}

/* Stat Cards */
.stat-card {
    background: #fff;
    border-radius: .75rem;
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--card-shadow);
    transition: transform .2s;
}

.stat-card:hover { transform: translateY(-2px); }

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: .75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1e293b;
    line-height: 1.2;
}

.stat-label {
    font-size: .8rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .03em;
}

/* List Cards */
.list-card { transition: transform .2s, box-shadow .2s; }
.list-card:hover { transform: translateY(-3px); box-shadow: 0 4px 12px rgba(0,0,0,.1); }

.list-icon {
    width: 44px;
    height: 44px;
    background: #eef2ff;
    color: var(--primary);
    border-radius: .5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

/* Tables */
.table th {
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #64748b;
    font-weight: 600;
    border-bottom-width: 1px;
    padding: .75rem 1rem;
}

.table td {
    padding: .85rem 1rem;
    vertical-align: middle;
    font-size: .9rem;
}

/* Empty State */
.empty-state {
    text-align: center;
    color: #94a3b8;
}

.empty-state i {
    font-size: 3rem;
    display: block;
    margin-bottom: 1rem;
    opacity: .5;
}

/* Auth Pages */
.auth-page {
    background: linear-gradient(135deg, #1e1b4b 0%, #4f46e5 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.auth-container { width: 100%; max-width: 420px; }

.auth-card {
    background: #fff;
    border-radius: 1rem;
    padding: 2.5rem;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.auth-brand {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-brand-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* background: #0b0b0f; */
    border-radius: .75rem;
    padding: .85rem 1.25rem;
    margin-bottom: .75rem;
}

.auth-brand-logo img {
    display: block;
    width: auto;
    max-width: min(200px, 100%);
    max-height: 56px;
    height: auto;
    object-fit: contain;
}

.auth-brand i {
    font-size: 2.5rem;
    color: var(--primary);
}

.auth-brand h2 {
    margin: .5rem 0 0;
    font-weight: 700;
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

/* Badges */
.badge { font-weight: 500; font-size: .75rem; padding: .35em .65em; }

/* Responsive */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0, 0, 0, .15);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, .45);
        z-index: 999;
        backdrop-filter: blur(2px);
    }

    .sidebar-backdrop.show {
        display: block;
    }
}

@media (max-width: 767.98px) {
    .top-bar {
        flex-wrap: wrap;
        padding: .75rem 1rem;
        gap: .5rem .75rem;
    }

    .page-heading {
        font-size: 1.15rem;
        flex: 1;
        min-width: 0;
        line-height: 1.3;
    }

    .top-bar-actions {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: .5rem;
    }

    .top-bar-actions .btn {
        flex: 1 1 auto;
        white-space: nowrap;
    }

    .content-area {
        padding: 1rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-icon {
        width: 44px;
        height: 44px;
        font-size: 1.2rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .card-header {
        flex-wrap: wrap;
        gap: .5rem;
    }

    .card-header .btn,
    .card-header .btn-group {
        width: 100%;
    }

    .auth-page {
        padding: 1rem;
        align-items: flex-start;
        padding-top: 2rem;
    }

    .auth-card {
        padding: 1.75rem 1.25rem;
    }

    .toast-container {
        left: .75rem;
        right: .75rem;
        top: auto;
        bottom: 1rem;
    }

    .toast-container .toast {
        width: 100%;
    }

    .table th,
    .table td {
        padding: .65rem .75rem;
        font-size: .85rem;
    }

    .table .btn-sm {
        padding: .2rem .45rem;
    }

    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }

    .pagination .page-link {
        padding: .35rem .6rem;
    }

    .filter-actions {
        display: flex;
        flex-wrap: wrap;
        gap: .5rem;
    }

    .filter-actions .btn {
        flex: 1 1 calc(50% - .25rem);
        min-width: 0;
    }

    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl {
        max-width: calc(100% - 1rem);
        margin: .5rem auto;
        max-height: calc(100% - 1rem);
    }
}

.campaign-contact-picker {
    max-height: 160px;
    overflow-y: auto;
}

.campaign-body-input {
    min-height: 120px;
    max-height: 220px;
    resize: vertical;
}

@media (max-width: 575.98px) {
    .sidebar-brand {
        min-height: 64px;
        max-height: 64px;
        padding: .75rem 1rem;
    }

    .sidebar-logo {
        max-height: 40px;
    }

    .user-email {
        max-width: 140px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .top-bar-actions .btn {
        flex: 1 1 100%;
    }

    .filter-actions .btn {
        flex: 1 1 100%;
    }

    .list-card .d-flex.justify-content-between.align-items-center {
        flex-direction: column;
        align-items: flex-start !important;
        gap: .5rem;
    }

    .template-card .btn-group .btn {
        font-size: .75rem;
        padding: .25rem .4rem;
    }

    .empty-state {
        padding: 2rem 1rem !important;
    }

    .empty-state i {
        font-size: 2.25rem;
    }
}

body.sidebar-open {
    overflow: hidden;
}

/* Scroll hint for wide tables */
.table-responsive {
    -webkit-overflow-scrolling: touch;
}

.table-responsive::-webkit-scrollbar {
    height: 6px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

/* Template cards on list page */
.template-card {
    transition: transform .2s, box-shadow .2s;
    overflow: hidden;
}

.template-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0,0,0,.1);
}

.template-thumb {
    height: 160px;
    overflow: hidden;
    background: #f8fafc;
    border-bottom: 1px solid #f1f5f9;
    position: relative;
}

.template-thumb-inner {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #eef2ff, #f8fafc);
    color: #818cf8;
    font-size: 2.5rem;
}

.template-thumb iframe {
    width: 200%;
    height: 200%;
    border: none;
    transform: scale(0.5);
    transform-origin: top left;
    pointer-events: none;
}

.template-create-card {
    border: 2px dashed #cbd5e1;
    background: #f8fafc;
    transition: all .2s;
    cursor: pointer;
}

.template-create-card:hover {
    border-color: var(--primary);
    background: #eef2ff;
}

.create-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #eef2ff;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

/* Toast notification */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
}

/* Form */
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 .2rem rgba(79,70,229,.15);
}

/* Modal */
.modal-content { border: none; border-radius: .75rem; }
.modal-header { border-bottom: 1px solid #f1f5f9; }

.modal-dialog-scrollable .modal-content {
    max-height: calc(100vh - 2rem);
    overflow: hidden;
}

.modal-dialog-scrollable .modal-content > form {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 2rem);
    min-height: 0;
    overflow: hidden;
}

.modal-dialog-scrollable .modal-content > form .modal-body {
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}

.modal-dialog-scrollable .modal-content > form .modal-header,
.modal-dialog-scrollable .modal-content > form .modal-footer {
    flex-shrink: 0;
}

.modal-dialog-scrollable .modal-footer {
    border-top: 1px solid #f1f5f9;
    background: #fff;
}

.modal-dialog.modal-dialog-scrollable {
    max-height: calc(100% - 1rem);
}
