/* ==========================================================================
   EmailerTool - design system
   ========================================================================== */

:root {
    --brand: #4f46e5;
    --brand-dark: #4338ca;
    --brand-darker: #3730a3;
    --brand-light: #eef2ff;
    --brand-contrast: #ffffff;

    --ink: #111827;
    --ink-soft: #374151;
    --muted: #6b7280;
    --muted-light: #9ca3af;

    --bg: #f4f6fb;
    --surface: #ffffff;
    --border: #e6e8f0;
    --border-soft: #eef0f6;

    --success: #16a34a;
    --success-bg: #ecfdf3;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --warning: #d97706;
    --warning-bg: #fffbeb;
    --info: #2563eb;
    --info-bg: #eff6ff;

    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 18px;

    --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.05);
    --shadow: 0 2px 8px rgba(17, 24, 39, 0.06), 0 1px 2px rgba(17, 24, 39, 0.04);
    --shadow-md: 0 8px 24px rgba(17, 24, 39, 0.10);

    --sidebar-w: 264px;
    --topbar-h: 64px;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--ink);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 0.95rem;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--ink);
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }

.text-muted { color: var(--muted) !important; }

/* ---------- App shell: sidebar + topbar ---------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: linear-gradient(180deg, #1e1b4b 0%, #312e81 100%);
    color: #e0e7ff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1030;
}

.app-sidebar .brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1.25rem 1.25rem;
    color: #fff;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.01em;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.app-sidebar .brand .brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--brand);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.55);
    font-size: 1rem;
}

.app-sidebar .nav-section-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #a5b4fc;
    padding: 1rem 1.25rem 0.35rem;
    font-weight: 600;
}

.app-sidebar .nav {
    padding: 0.25rem 0.75rem;
    flex: 1 1 auto;
    overflow-y: auto;
}

.app-sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: #c7d2fe;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 2px;
    transition: background 0.15s ease, color 0.15s ease;
}

.app-sidebar .nav-link i { font-size: 1.05rem; width: 1.25rem; text-align: center; }

.app-sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.app-sidebar .nav-link.active {
    background: var(--brand);
    color: #fff;
    box-shadow: 0 2px 10px rgba(79, 70, 229, 0.45);
}

.app-sidebar .sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.78rem;
    color: #a5b4fc;
}

.app-main {
    margin-left: var(--sidebar-w);
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.app-topbar .page-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--ink);
    margin: 0;
}

.app-topbar .user-chip {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.app-topbar .avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--brand-light);
    color: var(--brand-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

.app-content {
    padding: 1.75rem;
    flex: 1 1 auto;
}

.sidebar-toggle-btn {
    display: none;
}

@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }
    .app-sidebar.open {
        transform: translateX(0);
    }
    .app-main {
        margin-left: 0;
    }
    .sidebar-toggle-btn {
        display: inline-flex;
    }
}

/* ---------- Cards ---------- */

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

.card-body { padding: 1.25rem 1.4rem; }

.card-flat { box-shadow: none; }

/* Stat cards on dashboards */
.stat-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem 1.4rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-card .stat-icon {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.stat-card .stat-value {
    font-size: 1.6rem;
    font-weight: 800;
    line-height: 1.1;
    color: var(--ink);
}

.stat-card .stat-label {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 500;
}

.stat-icon.bg-brand { background: var(--brand-light); color: var(--brand-dark); }
.stat-icon.bg-success { background: var(--success-bg); color: var(--success); }
.stat-icon.bg-warning { background: var(--warning-bg); color: var(--warning); }
.stat-icon.bg-info { background: var(--info-bg); color: var(--info); }

/* Action / quick-link cards */
.action-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.4rem;
    height: 100%;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.action-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.action-card .action-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--brand-light);
    color: var(--brand-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    margin-bottom: 0.9rem;
}

.action-card h5 { font-size: 1.02rem; margin-bottom: 0.35rem; }
.action-card p { font-size: 0.85rem; }

/* ---------- Buttons ---------- */

.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.88rem;
    padding: 0.5rem 1rem;
}

.btn-lg { padding: 0.7rem 1.4rem; font-size: 0.95rem; }
.btn-sm { padding: 0.32rem 0.7rem; font-size: 0.8rem; }

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

.btn-primary:hover, .btn-primary:focus {
    background: var(--brand-dark);
    border-color: var(--brand-dark);
}

.btn-outline-primary {
    color: var(--brand);
    border-color: var(--brand);
}

.btn-outline-primary:hover {
    background: var(--brand);
    border-color: var(--brand);
}

.btn-link { font-weight: 500; }

/* ---------- Forms ---------- */

.form-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--ink-soft);
    margin-bottom: 0.35rem;
}

.form-control, .form-select {
    border-radius: var(--radius-sm);
    border-color: var(--border);
    padding: 0.55rem 0.8rem;
    font-size: 0.9rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.15);
}

.form-text { font-size: 0.78rem; color: var(--muted); }

/* ---------- Tables ---------- */

table.log-table {
    font-size: 0.88rem;
}

table.log-table thead th {
    background: #fafbfd;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
    padding: 0.85rem 1rem;
}

table.log-table td {
    padding: 0.85rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-soft);
    color: var(--ink-soft);
}

table.log-table tbody tr:hover { background: #fafbff; }
table.log-table tbody tr:last-child td { border-bottom: none; }

/* ---------- Badges ---------- */

.badge { font-weight: 600; font-size: 0.72rem; padding: 0.38em 0.65em; border-radius: 999px; }
.badge.bg-success { background: var(--success-bg) !important; color: var(--success) !important; }
.badge.bg-danger { background: var(--danger-bg) !important; color: var(--danger) !important; }
.badge.bg-warning { background: var(--warning-bg) !important; color: var(--warning) !important; }
.badge.bg-info { background: var(--info-bg) !important; color: var(--info) !important; }
.badge.bg-secondary { background: #f1f2f6 !important; color: var(--muted) !important; }

/* ---------- Alerts ---------- */

.alert { border: none; border-radius: var(--radius-sm); font-size: 0.88rem; }
.alert-info { background: var(--info-bg); color: #1d4ed8; }
.alert-danger { background: var(--danger-bg); color: #b91c1c; }
.alert-warning { background: var(--warning-bg); color: #b45309; }

/* ---------- Auth pages (login/register) ---------- */

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(1200px 600px at 15% -10%, rgba(99, 102, 241, 0.25), transparent),
        radial-gradient(1000px 500px at 110% 10%, rgba(129, 140, 248, 0.20), transparent),
        linear-gradient(180deg, #0f172a 0%, #1e1b4b 100%);
    padding: 2rem 1rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 2.25rem 2rem;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.auth-brand .brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 11px;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
}

.auth-brand .brand-name {
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--ink);
    letter-spacing: -0.01em;
}

.auth-card h3 {
    font-size: 1.3rem;
    text-align: center;
    margin-bottom: 0.25rem;
}

.auth-subtitle {
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
}

/* ---------- Compose / email designer page ---------- */

.compose-toolbar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.1rem 1.4rem;
    margin-bottom: 1.25rem;
}

.compose-toolbar .field-group label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.compose-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.compose-header .compose-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.compose-header .compose-title .icon-badge {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--brand-light);
    color: var(--brand-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.compose-header h2 { margin: 0; font-size: 1.35rem; }
.compose-header .compose-subtitle { color: var(--muted); font-size: 0.85rem; margin: 0; }

.designer-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.designer-toolbar-strip {
    background: #fafbff;
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.designer-toolbar-strip .designer-hint {
    font-size: 0.8rem;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

#gjs {
    border: none;
    border-radius: 0;
    min-height: 480px;
}

/* GrapesJS's canvas viewport (the area holding the editable iframe) scrolls internally once
   your design is taller than the visible area - so you can add as many/long sections as you
   want and just scroll down to keep working, nothing gets clipped or cut off.
   IMPORTANT: we do NOT force height:100% here. #gjs *is* the ".gjs-editor" element (GrapesJS
   adds that class directly onto the container we pass in), and it already gets an explicit
   inline height from email-designer.js (height: calc(100vh - <offset>px)). A height:100%
   !important rule on .gjs-editor would override that inline style (important beats inline)
   and instead ask for 100% of .designer-card, which has no defined height of its own - an
   indeterminate reference that different browsers/window sizes resolve inconsistently. That
   mismatch is exactly what made the canvas behave in a maximized window but not a normal one.
   Leaving height to the inline style (with the min-height floor below as a safety net) and
   only forcing overflow here lets GrapesJS's own resize logic size the canvas correctly at
   any window size. */
.gjs-cv-canvas {
    overflow: auto !important;
}

/* "Full Screen" toggle on the designer card (see email-designer.js #btnFullscreen) - expands
   the canvas to fill the entire viewport so long/complex emails always have maximum room to
   work in, no matter how small the browser window is. */
.designer-card.is-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 2000;
    border-radius: 0;
    margin: 0 !important;
    display: flex;
    flex-direction: column;
}

body.designer-fullscreen-active {
    overflow: hidden;
}

.compose-actions {
    position: sticky;
    bottom: 0;
    background: linear-gradient(180deg, rgba(244,246,251,0) 0%, var(--bg) 35%);
    padding: 1.25rem 0 0.25rem;
    margin-top: 0.5rem;
}

.compose-actions .card {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.4rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

/* GrapesJS chrome tweaks so it doesn't clash visually */
.gjs-one-bg { background-color: #fafbff !important; }
.gjs-two-color { color: var(--ink-soft) !important; }
.gjs-four-color, .gjs-four-color-h:hover { color: var(--brand) !important; }
.gjs-pn-btn.gjs-pn-active { color: var(--brand) !important; }

/* ---------- Misc ---------- */

.page-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.page-heading h2 { margin: 0; font-size: 1.4rem; }
.page-heading p { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.87rem; }

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--muted);
}

.empty-state i { font-size: 2rem; color: var(--muted-light); margin-bottom: 0.75rem; display: block; }
