/* ==========================================================================
   CMS: management panel for the marketing sites
   ========================================================================== */

:root {
    --ink: #0f172a;
    --ink-2: #172036;
    --ink-3: #24304d;
    --text: #1e293b;
    --muted: #64748b;
    --line: #e2e8f0;
    --bg: #f5f7fb;
    --white: #fff;
    --accent: #3b6cff;
    --accent-soft: #e8eeff;
    --success: #0f9d6b;
    --success-soft: #e3f6ee;
    --danger: #d6384b;
    --danger-soft: #fdecee;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 1px 2px rgb(15 23 42 / 5%), 0 6px 20px rgb(15 23 42 / 5%);
    --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --sidebar-w: 260px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
}

h1,
h2 {
    margin: 0;
    color: var(--ink);
    letter-spacing: -0.01em;
}

h1 {
    font-size: 1.6rem;
}

h2 {
    font-size: 1rem;
}

p {
    margin: 0;
}

.icon {
    width: 1.2em;
    height: 1.2em;
    flex: none;
}

.muted {
    color: var(--muted);
}

.mono {
    font-family: var(--mono);
    font-size: 0.85em;
}

.small {
    font-size: 0.85em;
}

.nowrap {
    white-space: nowrap;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

:focus-visible {
    outline: 3px solid rgb(59 108 255 / 45%);
    outline-offset: 2px;
}

/* Buttons and fields ----------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: #2f5cf0;
}

.btn-ghost {
    border-color: var(--line);
    background: var(--white);
    color: var(--text);
}

.btn-ghost:hover {
    border-color: #cbd5e1;
}

.btn-block {
    width: 100%;
    min-height: 46px;
}

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.field {
    display: grid;
    gap: 6px;
}

.field span {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--muted);
}

.field input,
.field select {
    width: 100%;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--white);
    font: inherit;
    color: var(--text);
}

.field input:focus,
.field select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgb(59 108 255 / 15%);
}

.alert {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-weight: 600;
}

.alert-error {
    background: var(--danger-soft);
    color: var(--danger);
}

/* Brand ------------------------------------------------------------------ */

.brand-mark {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    flex: none;
    border-radius: 11px;
    background: linear-gradient(135deg, #3b6cff, #24d3c6);
    color: #fff;
}

.brand-mark .icon {
    width: 20px;
    height: 20px;
}

/* Login ------------------------------------------------------------------ */

.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px 16px;
    background:
        radial-gradient(600px 400px at 80% 0%, rgb(59 108 255 / 18%), transparent 70%),
        radial-gradient(500px 360px at 0% 100%, rgb(36 211 198 / 12%), transparent 70%),
        var(--ink);
}

.login {
    width: min(400px, 100%);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    color: #fff;
}

.login-brand strong,
.login-brand small {
    display: block;
    line-height: 1.25;
}

.login-brand small {
    color: rgb(255 255 255 / 55%);
}

.login-card {
    display: grid;
    gap: 16px;
    padding: 32px;
    border-radius: 18px;
    background: var(--white);
    box-shadow: 0 30px 80px rgb(0 0 0 / 35%);
}

.login-card h1 {
    font-size: 1.35rem;
}

.login-card .muted {
    margin-top: -10px;
}

/* App shell -------------------------------------------------------------- */

.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 20px 14px;
    background: var(--ink);
    color: rgb(255 255 255 / 75%);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 8px 22px;
    border-bottom: 1px solid rgb(255 255 255 / 8%);
    color: #fff;
    text-decoration: none;
}

.sidebar-brand strong,
.sidebar-brand small {
    display: block;
    line-height: 1.25;
}

.sidebar-brand small {
    font-size: 0.78rem;
    color: rgb(255 255 255 / 50%);
}

.sidebar-nav {
    display: grid;
    gap: 4px;
    margin-top: 18px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: rgb(255 255 255 / 72%);
    font-weight: 550;
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-nav a:hover {
    background: rgb(255 255 255 / 6%);
    color: #fff;
}

.sidebar-nav a.is-active {
    background: var(--ink-3);
    color: #fff;
    box-shadow: inset 3px 0 0 #24d3c6;
}

.badge {
    margin-left: auto;
    min-width: 22px;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    text-align: center;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: auto;
    padding: 14px 8px 0;
    border-top: 1px solid rgb(255 255 255 / 8%);
}

.sidebar-user form {
    margin-left: auto;
}

.sidebar-user .icon-btn {
    color: rgb(255 255 255 / 60%);
}

.sidebar-user .icon-btn:hover {
    background: rgb(255 255 255 / 8%);
    color: #fff;
}

.avatar {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex: none;
    border-radius: 50%;
    background: var(--ink-3);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
}

.user-name {
    overflow: hidden;
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.main {
    min-width: 0;
}

.topbar {
    display: none;
}

.content {
    padding: 32px clamp(16px, 3vw, 40px) 48px;
}

.sidebar-backdrop {
    display: none;
}

/* Phones and small tablets: sidebar slides in */
@media (max-width: 900px) {
    .app {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 40;
        width: min(var(--sidebar-w), 82vw);
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    .nav-toggle-input:checked ~ .sidebar {
        transform: none;
    }

    .nav-toggle-input:checked ~ .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 30;
        display: block;
        background: rgb(15 23 42 / 45%);
    }

    .topbar {
        position: sticky;
        top: 0;
        z-index: 20;
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 16px;
        background: var(--ink);
        color: #fff;
    }

    .content {
        padding-top: 22px;
    }
}

/* Page ------------------------------------------------------------------- */

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

.page-head .muted {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.count {
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--white);
    border: 1px solid var(--line);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
}

.back-link {
    display: inline-block;
    margin-bottom: 14px;
    font-weight: 600;
    text-decoration: none;
}

.filters {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr auto;
    align-items: end;
    gap: 14px;
    margin-bottom: 18px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--white);
}

.filter-actions {
    display: flex;
    gap: 8px;
}

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

    .filters .field:first-child,
    .filter-actions {
        grid-column: 1 / -1;
    }
}

/* Table ------------------------------------------------------------------ */

.table-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--white);
    box-shadow: var(--shadow);
    overflow: hidden;
}

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

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table th {
    position: sticky;
    top: 0;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    background: #f8fafc;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-align: left;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
}

.table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

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

.table tbody tr:hover {
    background: #f8fafc;
}

.table td small {
    display: block;
}

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

.table a:hover {
    color: var(--accent);
}

.sender {
    font-weight: 600;
}

.is-unread td {
    background: #fbfcff;
}

.is-unread .sender {
    font-weight: 800;
    color: var(--ink);
}

.col-message {
    min-width: 260px;
    max-width: 420px;
}

.dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 6px;
    border-radius: 50%;
    background: var(--accent);
    vertical-align: 1px;
}

.site-badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
}

.site-ai {
    background: #efeaff;
    color: #6a4be0;
}

.site-automation {
    background: #e2f4ed;
    color: #0b7257;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}

.status .icon {
    width: 14px;
    height: 14px;
}

.status-ok {
    background: var(--success-soft);
    color: var(--success);
}

.status-fail {
    background: var(--danger-soft);
    color: var(--danger);
}

.empty {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 56px 16px;
    color: var(--muted);
}

/* Pagination (CodeIgniter default_full template) */
.pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin: 0;
    padding: 14px;
    border-top: 1px solid var(--line);
    list-style: none;
}

.pagination a {
    display: grid;
    place-items: center;
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
}

.pagination .active a {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

/* Message detail --------------------------------------------------------- */

.detail {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    align-items: start;
    gap: 20px;
}

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

.card h2 {
    margin-bottom: 14px;
    font-size: 0.8rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.message-body p {
    font-size: 1rem;
    line-height: 1.7;
    white-space: normal;
    overflow-wrap: anywhere;
}

.details {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px 16px;
    margin: 0;
}

.details dt {
    font-size: 0.85rem;
    color: var(--muted);
}

.details dd {
    margin: 0;
    overflow-wrap: anywhere;
}

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

@media (max-width: 480px) {
    .details {
        grid-template-columns: 1fr;
        gap: 2px;
    }

    .details dd {
        margin-bottom: 10px;
    }
}
