/* ==========================================================================
   OMS Mailer — single source of truth for the UI.
   Linked from header.php (app shell) and the auth pages.
   ========================================================================== */

:root {
    /* Layout */
    --sidebar-width: 260px;
    --topbar-height: 56px;
    --content-padding: 2rem;

    /* Accent (kept from the existing app — low migration) */
    --primary: #2563eb;
    --primary-light: #3b82f6;
    --primary-dark: #1d4ed8;
    --primary-subtle: #eaf0fe;

    /* Cool slate neutral ramp (biased toward the accent, not default grey) */
    --gray-50: #f7f8fa;
    --gray-100: #eef1f6;
    --gray-200: #e3e8ef;
    --gray-300: #cdd5e0;
    --gray-400: #9aa6b8;
    --gray-500: #6b7686;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #0b1220;

    /* Semantic state colours + soft tints for pills/alerts */
    --success: #0e9f6e;
    --success-light: #10b981;
    --success-bg: #e6f6ef;
    --warning: #d97706;
    --warning-bg: #fdf2e3;
    --danger: #e02424;
    --danger-bg: #fdeaea;
    --info: #0891b2;
    --info-bg: #e4f5f9;

    /* Elevation + shape */
    --shadow-sm: 0 1px 2px rgba(11, 18, 32, .06);
    --shadow: 0 1px 3px rgba(11, 18, 32, .09), 0 1px 2px rgba(11, 18, 32, .05);
    --shadow-md: 0 6px 16px -4px rgba(11, 18, 32, .12);
    --shadow-lg: 0 12px 28px -6px rgba(11, 18, 32, .18);

    --radius-sm: 7px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 16px;

    --sans: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    font-family: var(--sans);
    background-color: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Numbers that stack in columns should never jitter */
.table, .stats-card, .display-4, .pagination, .num-cell, .stat-value {
    font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   App shell: sidebar + responsive drawer
   ========================================================================== */

body.app-shell {
    min-height: 100vh;
    padding-left: calc(var(--sidebar-width) + var(--content-padding));
    padding-right: var(--content-padding);
}

.sidebar {
    width: var(--sidebar-width);
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1040;
    background: #fff;
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    transition: transform .25s ease;
}

.sidebar .nav-link {
    color: var(--gray-600);
    padding: 0.8rem 1.5rem;
    font-size: 0.9375rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
    border-left: 3px solid transparent;
    margin: 1px 0;
    text-decoration: none;
}

.sidebar .nav-link:hover {
    color: var(--primary);
    background: var(--primary-subtle);
}

.sidebar .nav-link.active {
    color: var(--primary-dark);
    background: var(--primary-subtle);
    border-left-color: var(--primary);
    font-weight: 600;
}

.sidebar .nav-link i {
    margin-right: 0.75rem;
    font-size: 1.25rem;
    width: 1.5rem;
    text-align: center;
}

.sidebar-logo,
.sidebar .brand {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 0.5rem;
    text-align: center;
}

.sidebar-logo img,
.sidebar .brand img {
    max-width: 150px;
    width: auto;
    height: auto;
}

/* User chip pinned to the bottom */
.user-menu {
    margin-top: auto;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
}

.user-menu .user-info {
    font-weight: 600;
    color: var(--gray-800);
    font-size: 0.875rem;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    flex: none;
    background: var(--primary-subtle);
    color: var(--primary-dark);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.8rem;
}

/* Mobile top bar + drawer backdrop (hidden on desktop) */
.topbar {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    align-items: center;
    gap: 0.75rem;
    padding: 0 1rem;
    z-index: 1030;
}

.topbar .menu-btn {
    border: 1px solid var(--gray-300);
    background: #fff;
    border-radius: var(--radius-sm);
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    font-size: 1.5rem;
    color: var(--gray-700);
    cursor: pointer;
}

.topbar img { max-height: 30px; width: auto; }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(11, 18, 32, .45);
    z-index: 1035;
}

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

main {
    padding: 1.5rem 0 4rem;
    width: 100%;
    max-width: none;
}

/* ==========================================================================
   Typography / page header
   ========================================================================== */

.page-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.page-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--gray-900);
    margin-bottom: 0;
}

h1, h2, h3, h4 { text-wrap: balance; }

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    background: #fff;
    transition: box-shadow .2s ease;
}

.card:hover { box-shadow: var(--shadow); }

.card-header {
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    padding: 1rem 1.25rem;
    font-weight: 600;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.card-body { padding: 1.25rem; }

.card-title {
    color: var(--gray-500);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

/* Stat cards — flat, with a left accent rail and a big tabular number.
   (Replaces the old full-bleed blue gradient.) */
.stats-card {
    background: #fff;
    color: var(--gray-900);
    border: 1px solid var(--gray-200);
    border-left: 3px solid var(--primary);
}

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

.stats-card .card-title { color: var(--gray-500); }

.stats-card .display-4 {
    font-weight: 700;
    font-size: 2rem;
    letter-spacing: -0.02em;
    color: var(--gray-900);
    margin-bottom: 0;
}

/* ==========================================================================
   Segmented tabs (Active / Archived / Deleted toggles)
   Replaces Bootstrap's lopsided solid-pill look. Scoped to .nav-pills, which
   the sidebar does not use, so the main nav is unaffected.
   ========================================================================== */

.nav-pills {
    display: inline-flex;
    gap: 2px;
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 3px;
}

.nav-pills .nav-item + .nav-item { margin: 0; }

.nav-pills .nav-link {
    color: var(--gray-600);
    font-weight: 600;
    font-size: 0.85rem;
    line-height: 1.2;
    padding: 0.4rem 0.95rem;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    transition: background .15s ease, color .15s ease;
}

.nav-pills .nav-link:hover {
    color: var(--gray-900);
    background: transparent;
}

.nav-pills .nav-link.active {
    background: #fff;
    color: var(--primary-dark);
    box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   Tables
   ========================================================================== */

.table {
    background: #fff;
    margin-bottom: 0;
}

.table thead th {
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    color: var(--gray-500);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem 0.8rem;
    white-space: nowrap;
}

.table thead th a { color: inherit; text-decoration: none; }
.table thead th a:hover { color: var(--primary); }

.table tbody td {
    padding: 0.75rem 0.8rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-700);
    white-space: nowrap;          /* keep each cell on one line */
}

/* Long free-text columns truncate with an ellipsis instead of forcing the
   whole table wide; hover shows the full value via the title attribute. */
.table td.truncate {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background-color: var(--gray-50); }

.table-responsive {
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    overflow-x: auto;
}

.num-cell { text-align: right; }

/* Initials avatar for table rows */
.row-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex: none;
    background: var(--primary-subtle);
    color: var(--primary-dark);
    display: inline-grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
}

/* ==========================================================================
   Status pills + badges
   Existing markup uses Bootstrap badges (.badge.bg-*). We restyle those into
   pills so no template changes are required.
   ========================================================================== */

.badge {
    font-weight: 600;
    font-size: 0.72rem;
    padding: 0.32rem 0.6rem 0.32rem 0.55rem;
    border-radius: 999px;
    letter-spacing: 0.01em;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    line-height: 1.2;
}

/* dot marker for the soft-tinted state badges */
.badge.bg-success::before,
.badge.bg-danger::before,
.badge.bg-warning::before,
.badge.bg-info::before,
.badge.bg-secondary::before,
.badge.bg-draft::before,
.badge.bg-sent::before,
.badge.bg-failed::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex: none;
}

.badge.bg-success, .badge.bg-sent { background: var(--success-bg) !important; color: var(--success) !important; }
.badge.bg-danger,  .badge.bg-failed { background: var(--danger-bg) !important; color: var(--danger) !important; }
.badge.bg-warning, .badge.bg-draft { 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: var(--gray-100) !important; color: var(--gray-500) !important; }
.badge.bg-primary { background: var(--primary-subtle) !important; color: var(--primary-dark) !important; }

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    border-radius: var(--radius-sm);
    padding: 0.5rem 1rem;
    font-weight: 600;
    font-size: 0.875rem;
    transition: background .15s ease, box-shadow .15s ease, transform .05s ease, border-color .15s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    line-height: 1.2;
}

.btn i { font-size: 1.05rem; }
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 1px 2px rgba(37, 99, 235, .25);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-success { background: var(--success); border-color: var(--success); }
.btn-success:hover { background: var(--success-light); border-color: var(--success-light); }

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

.btn-sm { padding: 0.35rem 0.6rem; font-size: 0.8125rem; }
.btn-sm i { font-size: 1rem; }

/* Neutral "ghost" buttons — the default for secondary toolbar actions, so a
   page has ONE accent (primary) instead of a rainbow of solid colours. */
.btn-outline-secondary,
.btn-light {
    background: #fff;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}
.btn-outline-secondary:hover,
.btn-light:hover {
    background: var(--gray-100);
    color: var(--gray-900);
    border-color: var(--gray-400);
}

.btn-secondary {
    background: var(--gray-100);
    border-color: var(--gray-200);
    color: var(--gray-700);
}
.btn-secondary:hover { background: var(--gray-200); color: var(--gray-900); }

/* Destructive actions: quiet by default, loud on hover */
.btn-outline-danger {
    background: #fff;
    color: var(--danger);
    border: 1px solid var(--danger);
}
.btn-outline-danger:hover { background: var(--danger); color: #fff; }

.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-info { background: var(--info); border-color: var(--info); color: #fff; }

/* Icon-only action buttons in tables: soft tinted square that fills on hover */
td .btn-sm.btn-primary,
td .btn-sm.btn-info,
td .btn-sm.btn-danger,
td .btn-sm.btn-secondary,
td .btn-sm.btn-success,
td .btn-sm.btn-warning {
    width: 30px;
    height: 30px;
    padding: 0;
    justify-content: center;
    border-color: transparent;
    box-shadow: none;
}

td .btn-sm.btn-primary { background: var(--primary-subtle); color: var(--primary-dark); }
td .btn-sm.btn-primary:hover { background: var(--primary); color: #fff; }
td .btn-sm.btn-info { background: var(--info-bg); color: var(--info); }
td .btn-sm.btn-info:hover { background: var(--info); color: #fff; }
td .btn-sm.btn-success { background: var(--success-bg); color: var(--success); }
td .btn-sm.btn-success:hover { background: var(--success); color: #fff; }
td .btn-sm.btn-danger { background: var(--danger-bg); color: var(--danger); }
td .btn-sm.btn-danger:hover { background: var(--danger); color: #fff; }
td .btn-sm.btn-warning { background: var(--warning-bg); color: var(--warning); }
td .btn-sm.btn-warning:hover { background: var(--warning); color: #fff; }

/* Keep all row action buttons on a single line (site-wide). The actions cell
   is the only place that mixes bare buttons with inline <form> wrappers. */
.table td:has(.btn-sm) {
    white-space: nowrap;
    text-align: right;
    width: 1%;            /* shrink-to-fit so the column only takes what it needs */
}
.table td:has(.btn-sm) form {
    display: inline-flex;
    margin: 0;
    vertical-align: middle;
}
.table td:has(.btn-sm) .btn-sm {
    vertical-align: middle;
    margin: 0 0 0 4px;    /* even spacing; overrides Bootstrap me-1 */
}
.table td:has(.btn-sm) .btn-sm:first-child { margin-left: 0; }

/* ==========================================================================
   Forms
   ========================================================================== */

.form-control,
.form-select {
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-300);
    padding: 0.6rem 0.85rem;
    font-size: 0.9375rem;
    color: var(--gray-800);
    transition: border-color .15s ease, box-shadow .15s ease;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-subtle);
}

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

/* ==========================================================================
   Alerts
   ========================================================================== */

.alert {
    border-radius: var(--radius);
    border: none;
    padding: 0.85rem 1.2rem;
    font-weight: 500;
}

.alert-info { background: var(--info-bg); color: #06657e; }
.alert-success { background: var(--success-bg); color: #0a7a54; }
.alert-danger { background: var(--danger-bg); color: #b81c1c; }
.alert-warning { background: var(--warning-bg); color: #a85d04; }

/* ==========================================================================
   Modals
   ========================================================================== */

.modal-content {
    border: none;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
}

.modal-header {
    border-bottom: 1px solid var(--gray-200);
    padding: 1.25rem 1.5rem;
}

.modal-title { font-weight: 600; color: var(--gray-900); }
.modal-body { padding: 1.5rem; }

.modal-footer {
    border-top: 1px solid var(--gray-200);
    padding: 1rem 1.5rem;
    background: var(--gray-50);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* ==========================================================================
   Pagination
   ========================================================================== */

.pagination { gap: 0.25rem; }

.page-link {
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
    padding: 0.45rem 0.8rem;
    font-weight: 500;
    font-size: 0.875rem;
}

.page-link:hover { background: var(--gray-100); border-color: var(--gray-400); color: var(--gray-900); }
.page-item.active .page-link { background: var(--primary); border-color: var(--primary); }
.page-item.disabled .page-link { background: var(--gray-50); color: var(--gray-400); }

/* ==========================================================================
   Empty state (for blank tables / lists)
   ========================================================================== */

.empty-state {
    text-align: center;
    padding: 3rem 1.25rem;
    color: var(--gray-500);
}

.empty-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--primary-subtle);
    color: var(--primary);
    display: grid;
    place-items: center;
    font-size: 2rem;
    margin: 0 auto 1rem;
}

.empty-state h3 { font-size: 1.1rem; color: var(--gray-800); margin-bottom: 0.35rem; }
.empty-state p { margin-bottom: 1.1rem; }

/* ==========================================================================
   Auth pages (login / forgot / reset / unsubscribe)
   ========================================================================== */

body.auth,
body.auth-grid {
    background:
        radial-gradient(1200px 400px at 50% -10%, var(--primary-subtle), transparent 70%),
        var(--gray-50);
    min-height: 100vh;
}

/* Flex-centred variant (login) */
body.auth {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

/* Grid-based pages (forgot/reset/unsubscribe) keep their own centring;
   give the card a logo + tighter look via the shared .card styles. */
body.auth-grid .auth-mark {
    text-align: center;
    margin-bottom: 1.25rem;
}
body.auth-grid .auth-mark img { max-width: 170px; height: auto; }

.auth-card {
    width: 100%;
    max-width: 420px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-logo img { max-width: 190px; height: auto; }

.auth-card .card {
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
}

.auth-card .card-body { padding: 2rem; }

.auth-card h1,
.auth-card h4 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--gray-900);
    text-align: center;
    margin-bottom: 0.35rem;
}

.auth-card .subtitle {
    text-align: center;
    color: var(--gray-500);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

/* ==========================================================================
   Focus visibility + motion
   ========================================================================== */

a:focus-visible,
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.page-link:focus-visible,
.nav-link:focus-visible,
.menu-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Custom scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: var(--gray-100); }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* ==========================================================================
   Responsive: collapse sidebar into a drawer
   ========================================================================== */

@media (max-width: 860px) {
    body.app-shell {
        padding-left: var(--content-padding);
        padding-top: calc(var(--topbar-height) + 0.5rem);
    }

    .topbar { display: flex; }

    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

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

@media (max-width: 480px) {
    :root { --content-padding: 1rem; }
    .page-header h1 { font-size: 1.4rem; }
}
