:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e5e9f0;
    --text: #111827;
    --muted: #697386;
    --primary: #5b5bd6;
    --primary-dark: #4747b8;
    --success: #159a62;
    --danger: #dc4b55;
    --warning: #d28a18;
    --sidebar: #111426;
    --sidebar-text: #aeb5c8;
    --sidebar-active: #252943;
    --radius: 16px;
    --shadow: 0 10px 35px rgba(17, 24, 39, .06);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

body {
    line-height: 1.5;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    opacity: .6;
    cursor: not-allowed;
}

a {
    color: inherit;
    text-decoration: none;
}

/* APP */

.app {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 250px;
    background: var(--sidebar);
    color: white;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform .25s ease;
}

.brand {
    height: 76px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,.07);
}

.brand-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: linear-gradient(135deg, #6c63ff, #8c7cff);
    font-weight: 800;
}

.brand-text strong {
    display: block;
    font-size: 15px;
}

.brand-text span {
    display: block;
    color: #7f879d;
    font-size: 11px;
    margin-top: 1px;
}

.sidebar-nav {
    padding: 22px 13px;
    flex: 1;
}

.nav-label {
    padding: 0 12px 9px;
    color: #666e84;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .12em;
}

.nav-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 0;
    background: transparent;
    color: var(--sidebar-text);
    padding: 12px 13px;
    border-radius: 11px;
    margin-bottom: 5px;
    text-align: left;
    transition: .2s;
}

.nav-item:hover {
    background: rgba(255,255,255,.05);
    color: white;
}

.nav-item.active {
    background: var(--sidebar-active);
    color: white;
}

.nav-icon {
    width: 21px;
    text-align: center;
    font-size: 17px;
}

.sidebar-bottom {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,.07);
}

.connection {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 11px 12px;
    margin-bottom: 12px;
    background: rgba(255,255,255,.04);
    border-radius: 10px;
    color: #9ea6bb;
    font-size: 12px;
}

.connection-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #29c77a;
    box-shadow: 0 0 0 4px rgba(41,199,122,.1);
}

.logout-button {
    width: 100%;
    border: 0;
    background: transparent;
    color: #8e96aa;
    padding: 10px;
    text-align: left;
    border-radius: 9px;
}

.logout-button:hover {
    color: white;
    background: rgba(255,255,255,.05);
}

/* MAIN */

.main {
    margin-left: 250px;
    min-height: 100vh;
}

.topbar {
    height: 76px;
    background: rgba(255,255,255,.92);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 34px;
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(12px);
}

.mobile-menu {
    display: none;
    border: 0;
    background: transparent;
    font-size: 24px;
}

.top-title small {
    display: block;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .1em;
    font-weight: 700;
}

.top-title h1 {
    margin: 1px 0 0;
    font-size: 21px;
}

.user-area {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: #ecebff;
    color: var(--primary);
    font-weight: 800;
}

.user-info strong {
    display: block;
    font-size: 13px;
}

.user-info span {
    display: block;
    font-size: 11px;
    color: var(--muted);
}

.content {
    max-width: 1500px;
    margin: 0 auto;
    padding: 34px;
}

.section {
    display: none;
}

.section.active {
    display: block;
}

.page-heading {
    margin-bottom: 25px;
}

.page-heading h2 {
    margin: 0;
    font-size: 25px;
}

.page-heading p {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 14px;
}

/* BUTTONS */

.btn {
    border: 1px solid var(--border);
    background: white;
    color: var(--text);
    min-height: 40px;
    padding: 0 14px;
    border-radius: 10px;
    font-weight: 650;
    font-size: 13px;
    transition: .18s;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 15px rgba(0,0,0,.06);
}

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

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

.btn-danger {
    color: var(--danger);
    border-color: rgba(220,75,85,.2);
}

.btn-success {
    color: var(--success);
    border-color: rgba(21,154,98,.2);
}

.btn-small {
    min-height: 34px;
    padding: 0 11px;
    font-size: 12px;
}

/* DASHBOARD */

.hero {
    background: linear-gradient(135deg, #171a32, #292d52);
    color: white;
    border-radius: 20px;
    padding: 27px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    box-shadow: 0 16px 45px rgba(20,24,55,.16);
}

.hero h2 {
    margin: 0;
    font-size: 25px;
}

.hero p {
    margin: 6px 0 0;
    color: #b9bfd2;
    font-size: 13px;
}

.hero .btn {
    background: white;
    color: #20233e;
    border: 0;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 19px;
    box-shadow: var(--shadow);
}

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

.stat-label {
    color: var(--muted);
    font-size: 12px;
}

.stat-icon {
    width: 35px;
    height: 35px;
    display: grid;
    place-items: center;
    background: #f0efff;
    color: var(--primary);
    border-radius: 10px;
}

.stat strong {
    display: block;
    font-size: 28px;
    margin-top: 11px;
}

.stat-status {
    color: var(--success);
    font-size: 12px;
    font-weight: 700;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1.55fr 1fr;
    gap: 18px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-header {
    min-height: 62px;
    padding: 17px 19px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.card-header h3 {
    margin: 0;
    font-size: 15px;
}

.card-header span {
    color: var(--muted);
    font-size: 12px;
}

.card-body {
    padding: 19px;
}

/* QUICK ACTIONS */

.quick-actions {
    display: grid;
    gap: 10px;
}

.quick-action {
    border: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 12px;
    padding: 14px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 12px;
}

.quick-action:hover {
    border-color: #c8c5ff;
    background: #fafaff;
}

.quick-action-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    background: #ecebff;
    color: var(--primary);
}

.quick-action strong {
    display: block;
    font-size: 13px;
}

.quick-action span {
    display: block;
    font-size: 11px;
    color: var(--muted);
}

/* ACTIVITY */

.activity {
    display: grid;
}

.activity-item {
    display: flex;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.activity-item:last-child {
    border-bottom: 0;
}

.activity-avatar {
    width: 37px;
    height: 37px;
    flex: 0 0 37px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    background: #f0efff;
    color: var(--primary);
    font-size: 11px;
    font-weight: 800;
}

.activity-main {
    min-width: 0;
    flex: 1;
}

.activity-main strong,
.activity-main span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.activity-main strong {
    font-size: 12px;
}

.activity-main span {
    font-size: 11px;
    color: var(--muted);
    margin-top: 3px;
}

.activity-date {
    color: var(--muted);
    font-size: 10px;
}

/* TOOLBAR */

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 18px;
}

.toolbar-left {
    display: flex;
    gap: 9px;
    align-items: center;
}

.search {
    width: 250px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: white;
    padding: 0 13px;
    outline: none;
}

.search:focus {
    border-color: #aaa7ff;
}

/* MAILBOXES */

.mailbox-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 17px;
}

.mailbox-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 19px;
    box-shadow: var(--shadow);
}

.mailbox-head {
    display: flex;
    justify-content: space-between;
    gap: 15px;
}

.mailbox-identity {
    display: flex;
    gap: 11px;
    min-width: 0;
}

.mailbox-avatar {
    width: 43px;
    height: 43px;
    flex: 0 0 43px;
    display: grid;
    place-items: center;
    background: #eeedff;
    color: var(--primary);
    border-radius: 13px;
    font-weight: 800;
}

.mailbox-identity h3 {
    margin: 1px 0 2px;
    font-size: 14px;
}

.mailbox-identity p {
    margin: 0;
    color: var(--muted);
    font-size: 11px;
    overflow-wrap: anywhere;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 25px;
    padding: 0 8px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 750;
}

.badge-success {
    color: var(--success);
    background: #eaf9f2;
}

.badge-muted {
    color: #7b8495;
    background: #f0f2f5;
}

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

.mailbox-details {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 9px;
    margin: 18px 0;
}

.detail {
    padding: 11px;
    border-radius: 10px;
    background: var(--surface-2);
}

.detail span {
    display: block;
    color: var(--muted);
    font-size: 10px;
}

.detail strong {
    display: block;
    font-size: 12px;
    margin-top: 2px;
}

.card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

/* TEMPLATES */

.template-layout {
    display: grid;
    grid-template-columns: 270px 1fr;
    gap: 17px;
}

.mailbox-selector {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 13px;
    height: fit-content;
}

.mailbox-selector h3 {
    margin: 6px 8px 12px;
    font-size: 13px;
}

.selector-item {
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    padding: 11px;
    border-radius: 10px;
    margin-bottom: 4px;
}

.selector-item:hover {
    background: var(--surface-2);
}

.selector-item.active {
    background: #eeedff;
    color: var(--primary);
}

.selector-item strong {
    display: block;
    font-size: 12px;
}

.selector-item span {
    display: block;
    color: var(--muted);
    font-size: 10px;
    margin-top: 2px;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.template-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}

.template-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.template-head h3 {
    margin: 6px 0 0;
    font-size: 14px;
}

.template-subject {
    margin: 16px 0 8px;
    font-weight: 700;
    font-size: 12px;
}

.template-preview {
    min-height: 85px;
    padding: 12px;
    background: var(--surface-2);
    border-radius: 10px;
    color: var(--muted);
    font-size: 11px;
    white-space: pre-wrap;
    overflow: hidden;
}

.template-actions {
    display: flex;
    gap: 7px;
    margin-top: 13px;
}

/* TABLE */

.table-card {
    overflow: hidden;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th,
td {
    padding: 14px 18px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .08em;
}

td {
    font-size: 12px;
}

/* SETTINGS */

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 17px;
}

.settings-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.settings-card.full {
    grid-column: 1 / -1;
}

.settings-card h3 {
    margin: 0;
    font-size: 15px;
}

.settings-card > p {
    margin: 5px 0 20px;
    color: var(--muted);
    font-size: 12px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    padding: 13px 0;
    border-bottom: 1px solid var(--border);
}

.setting-row:last-child {
    border-bottom: 0;
}

.setting-row span {
    color: var(--muted);
    font-size: 12px;
}

.setting-row strong {
    font-size: 12px;
    text-align: right;
}

.form {
    display: grid;
    gap: 14px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0 12px;
    background: white;
    color: var(--text);
    outline: none;
}

textarea.form-control {
    height: auto;
    min-height: 170px;
    padding: 12px;
    resize: vertical;
}

.form-control:focus {
    border-color: #aaa7ff;
    box-shadow: 0 0 0 3px rgba(91,91,214,.08);
}

.form-error {
    color: var(--danger);
    font-size: 12px;
}

.form-success {
    color: var(--success);
    font-size: 12px;
}

/* MODAL */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(10,13,25,.58);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

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

.modal {
    width: min(570px, 100%);
    max-height: 90vh;
    overflow: auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 30px 80px rgba(0,0,0,.25);
}

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

.modal-header h3 {
    margin: 0;
    font-size: 17px;
}

.modal-close {
    border: 0;
    background: transparent;
    font-size: 23px;
    color: var(--muted);
}

.modal-body {
    padding: 22px;
}

.modal-footer {
    padding: 15px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* EMPTY / LOADING */

.empty {
    padding: 55px 25px;
    text-align: center;
    color: var(--muted);
}

.empty-icon {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    margin: 0 auto 12px;
    border-radius: 15px;
    background: #eeedff;
    color: var(--primary);
    font-size: 22px;
}

.empty strong {
    display: block;
    color: var(--text);
    font-size: 14px;
}

.empty p {
    margin: 5px 0 16px;
    font-size: 12px;
}

.loading {
    padding: 45px;
    text-align: center;
    color: var(--muted);
}

.spinner {
    width: 19px;
    height: 19px;
    border: 2px solid #dfe2e8;
    border-top-color: var(--primary);
    border-radius: 50%;
    display: inline-block;
    animation: spin .7s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

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

/* TOAST */

.toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 500;
    min-width: 280px;
    max-width: calc(100vw - 48px);
    background: #171a29;
    color: white;
    border-radius: 12px;
    padding: 14px 17px;
    box-shadow: 0 15px 40px rgba(0,0,0,.2);
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: .25s;
    font-size: 13px;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* LOGIN */

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 25px;
    background:
        radial-gradient(circle at 15% 20%, rgba(91,91,214,.18), transparent 30%),
        radial-gradient(circle at 85% 80%, rgba(111,95,255,.13), transparent 30%),
        #f4f6fb;
}

.auth-box {
    width: min(430px, 100%);
}

.auth-brand {
    text-align: center;
    margin-bottom: 25px;
}

.auth-brand .brand-icon {
    margin: 0 auto 12px;
    color: white;
}

.auth-brand h1 {
    margin: 0;
    font-size: 23px;
}

.auth-brand p {
    color: var(--muted);
    font-size: 12px;
    margin: 5px 0 0;
}

.auth-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 28px;
    box-shadow: 0 25px 70px rgba(25,31,55,.1);
}

.auth-card h2 {
    margin: 0;
    font-size: 19px;
}

.auth-card > p {
    color: var(--muted);
    font-size: 12px;
    margin: 5px 0 22px;
}

.auth-footer {
    text-align: center;
    color: var(--muted);
    font-size: 11px;
    margin-top: 18px;
}

/* OVERLAY */

.sidebar-overlay {
    display: none;
}

/* RESPONSIVE */

@media (max-width: 1100px) {
    .stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .mailbox-grid,
    .template-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 800px) {
    .sidebar {
        transform: translateX(-100%);
    }

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

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        z-index: 90;
        background: rgba(0,0,0,.4);
    }

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

    .main {
        margin-left: 0;
    }

    .topbar {
        padding: 0 18px;
    }

    .mobile-menu {
        display: block;
    }

    .content {
        padding: 22px 17px;
    }

    .user-info {
        display: none;
    }

    .template-layout,
    .settings-grid {
        grid-template-columns: 1fr;
    }

    .settings-card.full {
        grid-column: auto;
    }
}

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

    .hero {
        align-items: flex-start;
        flex-direction: column;
    }

    .toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar-left {
        flex-direction: column;
    }

    .search {
        width: 100%;
    }

    .mailbox-details {
        grid-template-columns: 1fr;
    }

    .card-actions,
    .template-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .modal-backdrop {
        padding: 10px;
    }

    .auth-card {
        padding: 22px;
    }
}

/* =========================================================
   TEMPLATE HTML EDITOR
   ========================================================= */

.template-editor-modal {
    width: min(920px, calc(100vw - 30px));
    max-width: 920px;
}

.modal-subtitle {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 11px;
}

.template-editor-section {
    margin-top: 20px;
}

.template-editor-toolbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 10px;
}

.template-editor-toolbar label {
    display: block;
    margin-bottom: 3px;
}

.editor-help {
    margin: 0;
    color: var(--muted);
    font-size: 10px;
}

.editor-mode-switch {
    display: flex;
    padding: 3px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 9px;
}

.editor-mode {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 7px 13px;
    border-radius: 7px;
    font-size: 11px;
    cursor: pointer;
}

.editor-mode:hover {
    color: var(--text);
}

.editor-mode.active {
    background: white;
    color: var(--primary);
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    font-weight: 700;
}

.variable-section {
    border: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 11px;
    padding: 12px;
    margin-bottom: 10px;
}

.variable-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.variable-heading strong {
    font-size: 11px;
}

.variable-heading span {
    color: var(--muted);
    font-size: 9px;
}

.variable-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.variable-btn {
    border: 1px solid var(--border);
    background: white;
    border-radius: 8px;
    padding: 7px 9px;
    cursor: pointer;
    text-align: left;
    transition: .15s ease;
}

.variable-btn:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
}

.variable-btn span {
    display: block;
    font-size: 9px;
    color: var(--muted);
    margin-bottom: 2px;
}

.variable-btn code {
    font-size: 9px;
    color: var(--primary);
    font-family: monospace;
}

.template-editor-workspace {
    min-height: 390px;
}

.template-code-panel,
.template-preview-panel {
    width: 100%;
}

.template-code-editor {
    width: 100%;
    min-height: 330px;
    resize: vertical;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 12px;
    line-height: 1.65;
    background: #111827;
    color: #e5e7eb;
    border-color: #1f2937;
    padding: 16px;
    tab-size: 2;
}

.template-code-editor:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(91, 76, 219, .10);
}

.editor-footer {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-top: 0;
    border-radius: 0 0 8px 8px;
    color: var(--muted);
    font-size: 9px;
}

.preview-browser {
    border: 1px solid var(--border);
    border-radius: 11px;
    overflow: hidden;
    background: white;
}

.preview-browser-bar {
    height: 38px;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 12px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.preview-browser-bar > span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #c7ccd6;
}

.preview-browser-bar strong {
    margin-left: 8px;
    font-size: 10px;
    color: var(--muted);
}

.template-live-preview {
    min-height: 330px;
    padding: 24px;
    background: white;
    overflow: auto;
    color: #222;
}

.template-live-preview img {
    max-width: 100%;
}

.template-live-preview table {
    min-width: 0;
}

.template-live-preview pre {
    white-space: pre-wrap;
}

.template-live-preview .preview-empty {
    min-height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--muted);
    font-size: 11px;
}

.template-preview {
    white-space: normal;
}

.template-preview.template-rendered {
    background: white;
    border: 1px solid var(--border);
    color: #222;
}

.template-preview.template-rendered img {
    max-width: 100%;
    height: auto;
}

@media (max-width: 700px) {

    .template-editor-modal {
        width: calc(100vw - 16px);
    }

    .template-editor-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .editor-mode-switch {
        width: 100%;
    }

    .editor-mode {
        flex: 1;
    }

    .variable-heading {
        flex-direction: column;
        align-items: flex-start;
    }

    .variable-btn {
        flex: 1 1 calc(50% - 7px);
    }

    .template-live-preview {
        padding: 14px;
    }

}


/* =========================================================
   FULL PAGE TEMPLATE BUILDER
   ========================================================= */

.template-builder-page {
    width: 100%;
    min-height: calc(100vh - 120px);
}

.template-builder-page[hidden] {
    display: none !important;
}

.template-builder-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.template-builder-heading {
    display: flex;
    align-items: center;
    gap: 18px;
}

.template-builder-heading h2 {
    margin: 0 0 5px;
}

.template-builder-heading p {
    margin: 0;
    color: var(--text-muted, #6b7280);
}

.template-builder-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.template-builder-form {
    width: 100%;
}

.template-builder-field {
    margin-bottom: 20px;
}

.template-builder-field label {
    display: block;
    margin-bottom: 8px;
    font-weight: 700;
}

.template-builder-variables {
    margin: 8px 0 22px;
    padding: 18px;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 14px;
    background: var(--card-bg, #ffffff);
}

.template-builder-section-title {
    margin-bottom: 14px;
}

.template-builder-section-title strong {
    display: block;
    font-size: 15px;
}

.template-builder-section-title p {
    margin: 4px 0 0;
    color: var(--text-muted, #6b7280);
    font-size: 13px;
}

.variable-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
}

.variable-button {
    appearance: none;
    border: 1px solid #d7dee8;
    background: #f8fafc;
    color: #1f2937;
    border-radius: 9px;
    padding: 9px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: .15s ease;
}

.variable-button:hover {
    border-color: #9ca3af;
    background: #f1f5f9;
    transform: translateY(-1px);
}

.variable-button span {
    font-size: 12px;
    font-weight: 600;
}

.variable-button code {
    font-size: 11px;
    color: #475569;
}

.template-builder-workspace {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(380px, .85fr);
    gap: 20px;
    align-items: stretch;
}

.template-builder-editor-column,
.template-builder-preview-column {
    min-width: 0;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 16px;
    background: #ffffff;
    overflow: hidden;
}

.template-editor-topbar,
.template-preview-header {
    min-height: 62px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    border-bottom: 1px solid #e5e7eb;
    background: #f8fafc;
}

.template-editor-topbar strong,
.template-preview-header strong {
    display: block;
}

#templateEditorStatus,
.template-preview-header span:not(.preview-live-indicator) {
    display: block;
    margin-top: 3px;
    color: #64748b;
    font-size: 12px;
}

.editor-mode-switch {
    display: flex;
    gap: 4px;
    padding: 4px;
    border-radius: 9px;
    background: #e2e8f0;
}

.editor-mode {
    border: 0;
    background: transparent;
    color: #475569;
    padding: 8px 12px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
}

.editor-mode.active {
    background: #ffffff;
    color: #111827;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .12);
}

.template-visual-panel,
.template-html-panel {
    min-height: 560px;
}

.template-visual-panel[hidden],
.template-html-panel[hidden] {
    display: none !important;
}

.template-visual-editor {
    min-height: 560px;
    padding: 26px;
    outline: none;
    background: #ffffff;
    color: #111827;
    line-height: 1.6;
    overflow: auto;
}

.template-visual-editor:empty::before {
    content: attr(data-placeholder);
    color: #94a3b8;
    pointer-events: none;
}

.template-visual-editor:focus {
    box-shadow: inset 0 0 0 2px rgba(59, 130, 246, .15);
}

.template-html-editor {
    display: block;
    width: 100%;
    min-height: 560px;
    resize: vertical;
    box-sizing: border-box;
    border: 0;
    outline: 0;
    border-radius: 0;
    padding: 24px;
    background: #f8fafc;
    color: #172033;
    caret-color: #2563eb;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 13px;
    line-height: 1.65;
    tab-size: 2;
}

.template-html-editor:focus {
    background: #ffffff;
    box-shadow: inset 0 0 0 2px rgba(37, 99, 235, .12);
}

.template-editor-footer {
    min-height: 42px;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    gap: 15px;
    border-top: 1px solid #e5e7eb;
    background: #f8fafc;
    color: #64748b;
    font-size: 11px;
}

.template-preview-browser {
    min-height: 602px;
    background: #eef2f7;
}

.preview-browser-bar {
    height: 38px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    border-bottom: 1px solid #d9e0e8;
    background: #ffffff;
}

.preview-browser-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #cbd5e1;
}

.preview-browser-address {
    margin-left: 7px;
    flex: 1;
    padding: 5px 10px;
    border-radius: 6px;
    background: #f1f5f9;
    color: #64748b;
    font-size: 11px;
}

.template-preview-email-meta {
    padding: 15px 18px;
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    font-size: 12px;
    color: #475569;
}

.template-preview-email-meta > div {
    display: flex;
    gap: 7px;
    margin-bottom: 5px;
}

.template-preview-email-meta > div:last-child {
    margin-bottom: 0;
}

.template-preview-email-meta strong {
    min-width: 55px;
    color: #1e293b;
}

.template-live-preview {
    min-height: 480px;
    padding: 24px;
    background: #ffffff;
    color: #111827;
    overflow: auto;
}

.preview-live-indicator {
    display: inline-flex !important;
    align-items: center;
    gap: 5px;
    margin: 0 !important;
    color: #16a34a !important;
    font-size: 11px !important;
    font-weight: 800;
}

.preview-empty {
    padding: 60px 20px;
    text-align: center;
    color: #94a3b8;
}

@media (max-width: 1050px) {
    .template-builder-workspace {
        grid-template-columns: 1fr;
    }

    .template-builder-preview-column {
        order: 2;
    }

    .template-builder-editor-column {
        order: 1;
    }
}

@media (max-width: 720px) {
    .template-builder-header,
    .template-builder-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .template-builder-actions {
        width: 100%;
    }

    .template-builder-actions .btn {
        flex: 1;
    }

    .variable-buttons {
        flex-direction: column;
    }

    .variable-button {
        width: 100%;
        justify-content: space-between;
    }

    .template-visual-panel,
    .template-html-panel,
    .template-visual-editor,
    .template-html-editor {
        min-height: 450px;
    }

    .template-editor-footer {
        flex-direction: column;
    }
}


/* Legacy template modal is no longer used.
   The template editor is now a full-page builder. */
#templateModal {
    display: none !important;
}


/* EMAILWINGS FOOTER */

.app-footer {
    width: 100%;
    padding: 22px 30px 26px;
    text-align: center;
    color: #697386;
    font-size: 12px;
    line-height: 1.6;
}

.app-footer a {
    color: inherit;
    font-weight: 700;
    text-decoration: none;
    margin-left: 4px;
}

.app-footer a:hover {
    text-decoration: underline;
}

@media (max-width: 700px) {
    .app-footer {
        padding: 20px 18px 24px;
    }
}


/* External navigation buttons */
.nav-external-button {
    cursor: pointer;
}

.visit-website-button {
    margin-top: 8px;
    cursor: pointer;
}

/* Application footer */
.app-footer {
    width: 100%;
    box-sizing: border-box;
    padding: 22px 24px;
    margin-top: 30px;
    text-align: center;
    font-size: 13px;
    line-height: 1.6;
    color: var(--muted, #8b93a7);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.app-footer a {
    margin-left: 5px;
    color: inherit;
    text-decoration: none;
    font-weight: 600;
}

.app-footer a:hover {
    text-decoration: underline;
}

/* =========================================================
   SCROLLABLE SIDEBAR NAVIGATION
   ========================================================= */

.sidebar {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sidebar-nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 6px;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}

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

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.18);
    border-radius: 10px;
}

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

.sidebar-bottom {
    flex: 0 0 auto;
}

/* =========================================================
   QUICK ACTION SVG ICONS
   ========================================================= */

.quick-action-icon {
    width: 42px;
    height: 42px;
    min-width: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.quick-action-icon svg {
    width: 21px;
    height: 21px;
    display: block;
}

/* =========================================================
   TOP RIGHT ACCOUNT LOGOUT
   ========================================================= */

.user-area {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-area-main {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-logout {
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #ef4444;
    background: rgba(239, 68, 68, 0.10);
    transition: all 0.2s ease;
}

.topbar-logout:hover {
    color: #fff;
    background: #ef4444;
    transform: translateY(-1px);
}

.topbar-logout svg {
    width: 19px;
    height: 19px;
}

.mobile-account-logout {
    display: none;
}

/* =========================================================
   MOBILE ACCOUNT LOGOUT
   ========================================================= */

@media (max-width: 768px) {

    .user-area {
        flex-direction: column;
        align-items: stretch;
        gap: 0;
    }

    .user-area-main {
        cursor: pointer;
    }

    .topbar-logout {
        display: none;
    }

    .mobile-account-logout {
        width: 100%;
        margin-top: 8px;
        padding: 10px 14px;
        border: 1px solid rgba(239, 68, 68, 0.25);
        border-radius: 9px;
        display: none;
        align-items: center;
        justify-content: center;
        gap: 8px;
        color: #ef4444;
        background: rgba(239, 68, 68, 0.08);
        font-size: 13px;
        font-weight: 600;
        cursor: pointer;
    }

    .mobile-account-logout svg {
        width: 17px;
        height: 17px;
    }

    .user-area.open .mobile-account-logout {
        display: flex;
    }
}


/* Clear reply history button */
.dashboard-card-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-clear-history {
    background: #dc2626;
    color: #ffffff;
    border-color: #dc2626;
}

.btn-clear-history:hover {
    background: #b91c1c;
    border-color: #b91c1c;
}

.btn-clear-history:disabled {
    opacity: 0.7;
    cursor: wait;
}
