/* ==========================================================================
   Redirect Manager - shared layout (top bar) + optional dark mode
   Loaded AFTER each page's own <style> block so these rules take priority.
   ========================================================================== */

:root {
    --rm-bg: #f3f5fa;
    --rm-surface: #ffffff;
    --rm-surface-2: #f7f8fc;
    --rm-text: #1f2638;
    --rm-text-soft: #3c4558;
    --rm-muted: #6b7488;
    --rm-border: #e4e7f0;
    --rm-border-strong: #d3d8e6;
    --rm-primary: #5a67d8;
    --rm-primary-hover: #4c57c4;
    --rm-primary-text: #4a56c4;
    --rm-primary-soft: rgba(90, 103, 216, 0.10);
    --rm-ring: rgba(90, 103, 216, 0.22);
    --rm-success: #2f9e6e;
    --rm-danger: #e5484d;
    --rm-warning: #e88a2d;
    --rm-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 4px 14px rgba(16, 24, 40, 0.05);
    --rm-page-width: 1400px;
    --rm-font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
    --rm-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --rm-bg: #0e1218;
    --rm-surface: #171d27;
    --rm-surface-2: #1e2531;
    --rm-text: #e6e9ef;
    --rm-text-soft: #c5ccd8;
    --rm-muted: #96a1b3;
    --rm-border: #2a3342;
    --rm-border-strong: #364156;
    --rm-primary: #6573e6;
    --rm-primary-hover: #7684ee;
    --rm-primary-text: #94a2fa;
    --rm-primary-soft: rgba(124, 138, 247, 0.16);
    --rm-ring: rgba(124, 138, 247, 0.30);
    --rm-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.28);
}

/* --------------------------------------------------------------------------
   1. PAGE FRAME - identical on every page
   -------------------------------------------------------------------------- */
html body:not(.rm-login) {
    padding: 0;
    background: var(--rm-bg);
    color: var(--rm-text);
}

html body > .container {
    max-width: var(--rm-page-width);
    width: calc(100% - 40px);
    margin: 24px auto;
}
/* pages whose container carries its own side padding (home) */
html body.rm-flat > .container { width: 100%; padding: 0 20px; }
/* documentation page: narrower reading column under the same top bar */
html body.rm-narrow > .container { max-width: 1000px; }

.rm-page-title {
    margin: 0 0 20px;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.25;
    color: var(--rm-text);
}

/* --------------------------------------------------------------------------
   2. TOP BAR  [ brand | menu links ............ theme toggle | logout ]
   -------------------------------------------------------------------------- */
.rm-topbar {
    line-height: 1.4; /* same on every page (help.php sets its own body line-height) */
    position: sticky;
    top: 0;
    z-index: 900;
    background: var(--rm-surface);
    border-bottom: 1px solid var(--rm-border);
    box-shadow: 0 1px 3px rgba(16, 24, 40, 0.04);
}
.rm-topbar-inner {
    max-width: var(--rm-page-width);
    margin: 0 auto;
    padding: 0 20px;
    min-height: 60px;
    display: flex;
    align-items: center;
    gap: 28px;
}
.rm-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.2;
    color: var(--rm-text);
    text-decoration: none;
    white-space: nowrap;
}
.rm-menu {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}
.rm-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}
.rm-nav a {
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    color: var(--rm-muted);
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}
.rm-nav a:hover {
    background: var(--rm-surface-2);
    color: var(--rm-text);
}
.rm-nav a.active {
    background: var(--rm-primary-soft);
    color: var(--rm-primary-text);
    font-weight: 600;
}
.rm-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}
.rm-theme-toggle {
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--rm-border);
    border-radius: 8px;
    background: var(--rm-surface-2);
    color: var(--rm-text);
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.rm-theme-toggle:hover { border-color: var(--rm-primary); }
.rm-logout {
    padding: 9px 16px;
    border-radius: 8px;
    background: #64748b;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    transition: background 0.15s;
}
.rm-logout:hover { background: #545b62; }

.rm-burger {
    display: none;
    margin-left: auto;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--rm-border);
    border-radius: 8px;
    background: var(--rm-surface-2);
    color: var(--rm-text);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

/* Floating toggle for the login screen (no top bar there) */
.rm-theme-toggle.rm-floating {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1000;
    background: var(--rm-surface);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Mobile: collapse the menu behind a button */
@media (max-width: 960px) {
    .rm-topbar-inner { flex-wrap: wrap; gap: 0; padding-top: 10px; padding-bottom: 10px; }
    .rm-burger { display: inline-block; }
    .rm-menu {
        display: none;
        flex: 1 1 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 12px 0 4px;
        margin-top: 10px;
        border-top: 1px solid var(--rm-border);
    }
    .rm-topbar.rm-open .rm-menu { display: flex; }
    .rm-nav { flex-direction: column; align-items: stretch; }
    .rm-nav a { padding: 11px 14px; }
    .rm-actions { margin-left: 0; justify-content: space-between; }
}
@media (max-width: 768px) {
    .rm-page-title { font-size: 22px; }
}

/* ==========================================================================
   2b. COMPONENT POLISH - one look for cards, buttons, forms, tables
   ========================================================================== */
html body {
    font-family: var(--rm-font);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}
html body h1, html body h2, html body h3 { letter-spacing: -0.01em; }

/* ---- cards ---- */
html body .card,
html body .stat-card,
html body:not(.rm-flat):not(.rm-login) > .container {
    border: 1px solid var(--rm-border);
    border-radius: 14px;
    box-shadow: var(--rm-shadow);
}
html body:not(.rm-flat):not(.rm-login) > .container { padding: 28px; }
html body .card { padding: 24px; margin-bottom: 20px; }
html body .card-header {
    padding-bottom: 14px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--rm-border);
}
html body .card-title { font-size: 17px; font-weight: 650; }
html body .stats-grid { gap: 16px; margin-bottom: 20px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
html body .stat-card { padding: 18px 22px; position: relative; overflow: hidden; }
html body .stat-card::before {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    background: var(--rm-primary);
    opacity: 0.85;
}
html body .stat-value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; margin-bottom: 2px; }
html body .stat-label { font-size: 11.5px; font-weight: 600; letter-spacing: 0.07em; }

/* collapsible card (Add New Redirect) */
.card-toggle {
    border: 1px solid var(--rm-border-strong);
    background: var(--rm-surface-2);
    color: var(--rm-muted);
    border-radius: 8px;
    padding: 5px 12px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
}
.card-toggle:hover { color: var(--rm-text); border-color: var(--rm-primary); }
.card.collapsed > form,
.card.collapsed > .card-body { display: none; }
.card.collapsed > .card-header { margin-bottom: 0; padding-bottom: 0; border-bottom: 0; }

/* ---- buttons ---- */
html body .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: var(--rm-primary);
    color: #fff;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.25;
    text-decoration: none;
    box-shadow: 0 1px 1px rgba(16, 24, 40, 0.08);
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.05s;
}
html body .btn:hover { background: var(--rm-primary-hover); }
html body .btn:active { transform: translateY(1px); }
html body .btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--rm-ring); }
html body .btn-primary   { background: var(--rm-primary); }
html body .btn-primary:hover { background: var(--rm-primary-hover); }
html body .btn-success   { background: var(--rm-success); }
html body .btn-success:hover { background: #26855c; }
html body .btn-danger    { background: var(--rm-danger); }
html body .btn-danger:hover { background: #d03a3f; }
html body .btn-secondary { background: #64748b; }
html body .btn-secondary:hover { background: #526074; }
html body .btn-warning   { background: var(--rm-warning); }
html body .btn-warning:hover { background: #d27a22; }
html body .btn-small { padding: 5px 11px; font-size: 12.5px; border-radius: 7px; }

/* plain small buttons (Clear, pagination) become quiet "ghost" buttons */
html body .btn.btn-small:not(.btn-primary):not(.btn-success):not(.btn-danger):not(.btn-secondary):not(.btn-warning) {
    background: var(--rm-surface);
    color: var(--rm-text-soft);
    border-color: var(--rm-border-strong);
    box-shadow: none;
}
html body .btn.btn-small:not(.btn-primary):not(.btn-success):not(.btn-danger):not(.btn-secondary):not(.btn-warning):hover {
    background: var(--rm-surface-2);
    border-color: var(--rm-primary);
    color: var(--rm-primary-text);
}
/* toolbar above the table: quiet outline buttons, only destructive ones stay red */
html body .action-buttons .btn.btn-primary,
html body .action-buttons .btn.btn-success {
    background: var(--rm-surface);
    color: var(--rm-text-soft);
    border-color: var(--rm-border-strong);
    box-shadow: none;
}
html body .action-buttons .btn.btn-primary:hover,
html body .action-buttons .btn.btn-success:hover {
    background: var(--rm-surface-2);
    border-color: var(--rm-primary);
    color: var(--rm-primary-text);
}
html body .action-buttons .btn.btn-danger {
    background: transparent;
    color: var(--rm-danger);
    border-color: rgba(229, 72, 77, 0.45);
    box-shadow: none;
}
html body .action-buttons .btn.btn-danger:hover { background: rgba(229, 72, 77, 0.10); }

/* ---- form controls ---- */
html body :is(input[type="text"], input[type="url"], input[type="password"], input[type="email"],
              input[type="number"], input[type="date"], input[type="search"], select, textarea) {
    padding: 9px 12px;
    border: 1px solid var(--rm-border-strong);
    border-radius: 8px;
    background: var(--rm-surface);
    color: var(--rm-text);
    font-size: 14px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
html body :is(input[type="text"], input[type="url"], input[type="password"], input[type="email"],
              input[type="number"], input[type="date"], input[type="search"], select, textarea):focus {
    outline: none;
    border-color: var(--rm-primary);
    box-shadow: 0 0 0 3px var(--rm-ring);
}
html body label { font-size: 13px; font-weight: 600; color: var(--rm-text-soft); margin-bottom: 6px; }
html body .help-text { font-size: 12px; margin-top: 4px; }
html body textarea { min-height: 52px; }
html body .per-page-select { padding: 7px 10px; font-size: 13px; width: auto; }

/* Add-redirect form: keyword | type | destination on ONE row */
html body .form-grid { gap: 14px 16px; margin-bottom: 14px; }
html body .form-group { margin-bottom: 0; }
html body .form-grid.form-grid-add { grid-template-columns: minmax(170px, 1fr) 170px minmax(260px, 2.4fr); }

/* ---- tables ---- */
html body :is(.redirects-table, .analytics-table, .param-table) { border-collapse: separate; border-spacing: 0; }
html body :is(.redirects-table, .analytics-table, .param-table) th {
    padding: 10px 12px;
    background: var(--rm-surface-2);
    color: var(--rm-muted);
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
    border-bottom: 1px solid var(--rm-border);
}
html body :is(.redirects-table, .analytics-table, .param-table) td {
    padding: 11px 12px;
    font-size: 13.5px;
    vertical-align: middle;
    border-bottom: 1px solid var(--rm-border);
}
html body :is(.redirects-table, .analytics-table) tbody tr:last-child td { border-bottom: 0; }
html body :is(.redirects-table, .analytics-table) tbody tr:hover { background: var(--rm-surface-2); }
html body .table-container {
    border: 1px solid var(--rm-border);
    border-radius: 12px;
    overflow-x: auto;
}
html body .sort-header { color: inherit; }

/* Redirects table: fit the screen. URL column absorbs the spare width and truncates. */
html body .redirects-table { width: 100%; }
html body .redirects-table td:has(> .url-wrap) { width: 100%; max-width: 0; }
html body .redirects-table .url-wrap { display: flex; align-items: flex-start; gap: 6px; }
html body .redirects-table .url-cell {
    flex: 1;
    min-width: 0;
    max-width: none;
    font-size: 13px;
    cursor: pointer;
}
/* clicked: show the whole URL, already selected, ready for Ctrl+C */
html body .redirects-table .url-cell.expanded {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: anywhere;
    padding: 6px 9px;
    margin: -6px 0;
    background: var(--rm-surface-2);
    border: 1px solid var(--rm-primary);
    border-radius: 8px;
    box-shadow: 0 0 0 3px var(--rm-ring);
    color: var(--rm-text);
    cursor: text;
    user-select: text;
}
html body .url-copy {
    flex: none;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid var(--rm-border-strong);
    border-radius: 7px;
    background: var(--rm-surface);
    color: var(--rm-text);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
html body .url-copy:hover { border-color: var(--rm-primary); background: var(--rm-surface-2); }
html body .url-copy.copied { border-color: var(--rm-success); color: var(--rm-success); font-weight: 700; }
html body .redirects-table td:nth-child(2) { min-width: 130px; max-width: 230px; }
html body .redirects-table .keyword-cell {
    font-family: var(--rm-mono);
    font-size: 13px;
    overflow-wrap: anywhere;
}
html body .redirects-table td:nth-child(n+4):nth-child(-n+8) { white-space: nowrap; }
html body .redirects-table td:nth-child(7) { font-size: 12px; line-height: 1.35; }
html body .redirects-table .test-link { font-size: 12px; }
html body .redirects-table .actions-cell { display: flex; flex-wrap: nowrap; gap: 6px; }
html body .redirects-table .actions-cell { align-items: center; flex-direction: row; }

/* ⋯ row menu (Reset / Delete). The list is position:fixed so the table never clips it. */
.row-menu { position: relative; display: inline-block; }
.row-menu-btn {
    width: 30px;
    height: 29px;
    padding: 0;
    border: 1px solid var(--rm-border-strong);
    border-radius: 7px;
    background: var(--rm-surface);
    color: var(--rm-text-soft);
    font-size: 17px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 1px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.row-menu-btn:hover,
.row-menu.open .row-menu-btn { border-color: var(--rm-primary); background: var(--rm-surface-2); color: var(--rm-primary-text); }
.row-menu-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--rm-ring); }
.row-menu-list {
    display: none;
    position: fixed;
    z-index: 950;
    min-width: 178px;
    padding: 6px;
    background: var(--rm-surface);
    border: 1px solid var(--rm-border-strong);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(16, 24, 40, 0.18), 0 2px 6px rgba(16, 24, 40, 0.08);
}
.row-menu.open .row-menu-list { display: block; }
.row-menu-list form { margin: 0; display: block; }
.row-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--rm-text);
    font: inherit;
    font-size: 13.5px;
    font-weight: 500;
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
}
a.row-menu-item { text-decoration: none; }
.row-menu-item:hover,
.row-menu-item:focus-visible { background: var(--rm-surface-2); outline: none; }
.row-menu-item.danger { color: var(--rm-danger); }
.row-menu-item.danger:hover,
.row-menu-item.danger:focus-visible { background: rgba(229, 72, 77, 0.12); }
.row-menu-sep { height: 1px; margin: 5px 4px; background: var(--rm-border); }
.row-menu-backdrop { display: none; position: fixed; inset: 0; z-index: 940; background: rgba(0, 0, 0, 0.45); }

/* touch screens: bigger targets */
@media (pointer: coarse) {
    .row-menu-btn { width: 40px; height: 38px; }
    html body .redirects-table .actions-cell .btn-small { padding: 9px 14px; font-size: 13.5px; }
}
/* phones: the menu becomes a bottom sheet with a dimmed backdrop */
@media (max-width: 640px) {
    .row-menu-list {
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        bottom: 0 !important;
        min-width: 0;
        padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
        border-radius: 18px 18px 0 0;
        border-width: 1px 0 0;
    }
    .row-menu-item { padding: 15px 14px; font-size: 16px; }
    body.rm-menu-open .row-menu-backdrop { display: block; }
}

/* compact toggle switch */
html body .toggle-switch { width: 40px; height: 22px; }
html body .toggle-slider:before { height: 16px; width: 16px; left: 3px; bottom: 3px; }
html body input:checked + .toggle-slider:before { transform: translateX(18px); }

/* tag chip checkboxes in the forms (inline-styled) - slimmer */
html body label[style*="border: 2px solid #e0e0e0"] {
    border-width: 1px !important;
    border-radius: 8px !important;
    padding: 5px 10px !important;
    margin: 0;
}

/* "No tags created yet" placeholder: one slim row instead of a tall box */
html body [style*="border: 2px dashed #ddd"] {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 14px !important;
    margin-top: 6px !important;
    border-width: 1px !important;
}
html body [style*="border: 2px dashed #ddd"] > div { font-size: 22px !important; margin: 0 !important; }
html body [style*="border: 2px dashed #ddd"] > p { margin: 0 !important; }

/* analytics / conversions: use the brand colour instead of default bootstrap blue */
html body .analytics-section h2,
html body h2 { border-bottom-color: var(--rm-border); }
html body .analytics-table .metric { color: var(--rm-primary-text); }
html body .progress-fill { background: linear-gradient(90deg, var(--rm-primary), #8b7cf0); }
html body .progress-bar { border-radius: 6px; }

/* badges / alerts / boxes */
html body .alert { border-radius: 10px; padding: 12px 16px; margin-bottom: 18px; }
html body :is(.info-box, .warning-box, .success-box, .reset-section, .filter-section, .toc, .test-form, .redirect-card) { border-radius: 10px; }
html body .filter-section { border: 1px solid var(--rm-border); }
html body .summary-card { border-radius: 14px; box-shadow: var(--rm-shadow); }
html body .status-badge { padding: 3px 10px; font-size: 11.5px; }
html body .tag-badge { border-radius: 6px; }
html body .modal-content { border-radius: 14px; border: 1px solid var(--rm-border); }
html body .modal-header { border-bottom: 1px solid var(--rm-border); }
html body .pagination { border-top: 1px solid var(--rm-border); margin-top: 16px; padding-top: 16px; }
html body .login-container { border-radius: 16px; }
html body .login-container button { border-radius: 8px; background: var(--rm-primary); font-weight: 600; }
html body .login-container button:hover { background: var(--rm-primary-hover); }

/* Toolbar above the table */
html body .actions-bar { gap: 10px; margin-bottom: 14px; }
html body .search-box { min-width: 260px; }
html body .action-buttons { gap: 8px; }

/* ---- laptop screens (13-15"): denser layout so everything fits ---- */
@media (max-width: 1440px) {
    html body { font-size: 13.5px; }
    html body:not(.rm-flat):not(.rm-login) > .container { padding: 22px; }
    html body .card { padding: 20px; margin-bottom: 16px; }
    html body .card-header { margin-bottom: 14px; padding-bottom: 12px; }
    html body .stat-card { padding: 14px 18px; }
    html body .stat-value { font-size: 26px; }
    html body :is(.redirects-table, .analytics-table, .param-table) td { padding: 9px 10px; font-size: 13px; }
    html body :is(.redirects-table, .analytics-table, .param-table) th { padding: 9px 10px; }
    html body .redirects-table td:nth-child(2) { max-width: 200px; }
}
/* narrower windows: drop the least important columns instead of scrolling sideways */
@media (max-width: 1180px) {
    html body .redirects-table :is(th, td):nth-child(7) { display: none; }   /* Last accessed */
}
@media (max-width: 960px) {
    html body .redirects-table :is(th, td):nth-child(4),
    html body .redirects-table :is(th, td):nth-child(6) { display: none; }   /* Type, Unique */
    html body .form-grid.form-grid-add { grid-template-columns: 1fr 1fr; }
    html body .form-grid.form-grid-add > .form-group:nth-child(3) { grid-column: 1 / -1; }
}
@media (max-width: 768px) {
    html body:not(.rm-flat):not(.rm-login) > .container { padding: 16px; }
    html body .card { padding: 16px; }
}

/* ==========================================================================
   Campaign links window
   ========================================================================== */
html body .modal-content.cl-modal { max-width: 860px; }
.cl-intro { margin: -6px 0 16px; }
.cl-empty {
    padding: 16px;
    border: 1px dashed var(--rm-border-strong);
    border-radius: 10px;
    color: var(--rm-muted);
    text-align: center;
    margin-bottom: 18px;
}
.cl-table-wrap { border: 1px solid var(--rm-border); border-radius: 10px; overflow-x: auto; margin-bottom: 18px; }
html body .cl-table { width: 100%; border-collapse: separate; border-spacing: 0; }
html body .cl-table th {
    padding: 8px 10px; background: var(--rm-surface-2); color: var(--rm-muted);
    font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
    text-align: left; border-bottom: 1px solid var(--rm-border); white-space: nowrap;
}
html body .cl-table td { padding: 8px 10px; font-size: 13px; border-bottom: 1px solid var(--rm-border); vertical-align: middle; }
html body .cl-table tbody tr:last-child td { border-bottom: 0; }
html body .cl-table .num { text-align: right; white-space: nowrap; }
.cl-table tr.cl-off td { opacity: 0.55; }
.cl-link { display: flex; align-items: center; gap: 6px; }
.cl-link a { font-family: var(--rm-mono); font-weight: 600; color: var(--rm-primary-text); text-decoration: none; }
.cl-link a:hover { text-decoration: underline; }
.cl-badge { display: inline-block; margin-top: 3px; padding: 1px 7px; border-radius: 6px; font-size: 11px; background: var(--rm-surface-2); color: var(--rm-muted); border: 1px solid var(--rm-border); }
.cl-row-actions { white-space: nowrap; text-align: right; }
.cl-row-actions form { display: inline; margin: 0 0 0 4px; }
html body .cl-row-actions .btn.cl-del { padding: 5px 8px; }
.cl-tabs { display: flex; gap: 6px; margin-bottom: 14px; border-bottom: 1px solid var(--rm-border); }
.cl-tab {
    padding: 8px 12px; border: 0; border-bottom: 2px solid transparent; background: transparent;
    color: var(--rm-muted); font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; margin-bottom: -1px;
}
.cl-tab.active { color: var(--rm-primary-text); border-bottom-color: var(--rm-primary); }
.cl-grid { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 12px 14px; margin-bottom: 12px; }
.cl-grid.cl-grid-2 { grid-template-columns: 1fr 1fr; }
.cl-pane .form-group { margin-bottom: 0; }
.cl-pane > .form-group { margin-bottom: 12px; }
.cl-pane input[type="text"], .cl-pane textarea { width: 100%; }
.cl-slug-wrap { display: flex; align-items: stretch; }
.cl-slug-base {
    display: flex; align-items: center; padding: 0 8px; font-size: 12px; color: var(--rm-muted);
    background: var(--rm-surface-2); border: 1px solid var(--rm-border-strong); border-right: 0;
    border-radius: 8px 0 0 8px; white-space: nowrap; max-width: 55%; overflow: hidden; text-overflow: ellipsis;
}
html body .cl-slug-wrap input[type="text"] { border-radius: 0 8px 8px 0; min-width: 0; }
.cl-more { margin-bottom: 14px; font-size: 13px; color: var(--rm-muted); }
.cl-more summary { cursor: pointer; margin-bottom: 8px; }
.cl-enabled { display: flex !important; align-items: center; gap: 8px; margin: 4px 0 12px; font-weight: 500 !important; }
.cl-actions { display: flex; gap: 8px; align-items: center; }
@media (max-width: 640px) {
    .cl-grid, .cl-grid.cl-grid-2 { grid-template-columns: 1fr; }
    .cl-table th:nth-child(2), .cl-table td:nth-child(2) { display: none; }
}

/* Campaign Performance table (Analytics) */
.cp-note { margin: -6px 0 12px; font-size: 13px; color: var(--rm-muted) !important; }
.cp-toggle { display: inline-flex !important; align-items: center; gap: 8px; margin: 0 0 10px; font-weight: 500 !important; font-size: 13px !important; cursor: pointer; }
.cp-wrap { overflow-x: auto; border: 1px solid var(--rm-border); border-radius: 10px; }
html body .cp-table { width: 100%; margin: 0; }
html body .cp-table .num { text-align: right; white-space: nowrap; }
html body .cp-table th.num { text-align: right; }
html body .cp-table th.sorted-asc::after { content: " ▲"; }
html body .cp-table th.sorted-desc::after { content: " ▼"; }
html body .cp-table tfoot td { font-weight: 700; background: var(--rm-surface-2); border-top: 1px solid var(--rm-border-strong); }
html body .cp-table tr.cp-untagged td { color: var(--rm-muted); font-style: italic; }
html body .cp-table .cp-money { color: var(--rm-success); font-weight: 600; }

/* ==========================================================================
   3. DARK MODE overrides (only active when <html data-theme="dark">)
   ========================================================================== */

/* ---- surfaces ---- */
html[data-theme="dark"] body:not(.rm-flat) > .container,
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .card,
html[data-theme="dark"] .modal-content,
html[data-theme="dark"] .login-container,
html[data-theme="dark"] .redirect-card {
    background: var(--rm-surface);
    box-shadow: var(--rm-shadow);
}
html[data-theme="dark"] .modal { background-color: rgba(0, 0, 0, 0.75); }

html[data-theme="dark"] thead,
html[data-theme="dark"] tr:hover,
html[data-theme="dark"] .filter-section,
html[data-theme="dark"] .analytics-table th,
html[data-theme="dark"] .analytics-table tr:hover,
html[data-theme="dark"] .code-block,
html[data-theme="dark"] .param-table th,
html[data-theme="dark"] .param-table code,
html[data-theme="dark"] .test-form,
html[data-theme="dark"] .toc,
html[data-theme="dark"] .comparison-table tr:nth-child(even),
html[data-theme="dark"] [style*="background: #f8f9fa"],
html[data-theme="dark"] [style*="background: #fff;"] {
    background: var(--rm-surface-2) !important;
}
/* keep the coloured header row of the help comparison table */
html[data-theme="dark"] .comparison-table th { background: var(--rm-primary) !important; color: #fff !important; }

/* ---- text ---- */
html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] label,
html[data-theme="dark"] .card-title,
html[data-theme="dark"] .modal-header h2,
html[data-theme="dark"] .empty-state h3,
html[data-theme="dark"] .analytics-section h2,
html[data-theme="dark"] .redirect-card h3,
html[data-theme="dark"] .toc h3,
html[data-theme="dark"] .section h2,
html[data-theme="dark"] .close:hover,
html[data-theme="dark"] .code-block,
html[data-theme="dark"] [style*="color: #333"] {
    color: var(--rm-text) !important;
}
html[data-theme="dark"] p,
html[data-theme="dark"] ul,
html[data-theme="dark"] ol,
html[data-theme="dark"] li,
html[data-theme="dark"] .section h3,
html[data-theme="dark"] .filter-group label,
html[data-theme="dark"] .analytics-table th {
    color: var(--rm-text-soft);
}
html[data-theme="dark"] .section h4,
html[data-theme="dark"] .stat-label,
html[data-theme="dark"] .help-text,
html[data-theme="dark"] .url-cell,
html[data-theme="dark"] .empty-state,
html[data-theme="dark"] .pagination-info,
html[data-theme="dark"] .subtitle,
html[data-theme="dark"] th,
html[data-theme="dark"] .sort-header,
html[data-theme="dark"] .no-data,
html[data-theme="dark"] [style*="color: #666"],
html[data-theme="dark"] [style*="color: #999"],
html[data-theme="dark"] [style*="color:#999"] {
    color: var(--rm-muted) !important;
}
/* accent / link colours: lighter so they stay readable on dark */
html[data-theme="dark"] .stat-value,
html[data-theme="dark"] .keyword-cell,
html[data-theme="dark"] .test-link,
html[data-theme="dark"] .toc a,
html[data-theme="dark"] .sort-header:hover,
html[data-theme="dark"] .analytics-table .metric,
html[data-theme="dark"] [style*="color: #667eea"],
html[data-theme="dark"] [style*="color:#667eea"],
html[data-theme="dark"] [style*="color: #0056b3"] {
    color: var(--rm-primary-text) !important;
}
html[data-theme="dark"] .section a { color: var(--rm-primary-text); }
html[data-theme="dark"] .param-table code { color: #f78fb3; }
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #6b7686; }

/* ---- form controls ---- */
html[data-theme="dark"] input[type="text"],
html[data-theme="dark"] input[type="password"],
html[data-theme="dark"] input[type="url"],
html[data-theme="dark"] input[type="email"],
html[data-theme="dark"] input[type="number"],
html[data-theme="dark"] input[type="date"],
html[data-theme="dark"] input[type="search"],
html[data-theme="dark"] input:not([type]),
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] .per-page-select {
    background: var(--rm-surface-2);
    color: var(--rm-text);
    border-color: var(--rm-border);
}
html[data-theme="dark"] textarea[readonly] { color: var(--rm-text) !important; }
html[data-theme="dark"] input:focus,
html[data-theme="dark"] select:focus,
html[data-theme="dark"] textarea:focus { border-color: var(--rm-primary); }

/* ---- borders / dividers ---- */
html[data-theme="dark"] .card-header,
html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .pagination,
html[data-theme="dark"] td,
html[data-theme="dark"] th,
html[data-theme="dark"] .analytics-table td,
html[data-theme="dark"] .analytics-table th,
html[data-theme="dark"] .param-table td,
html[data-theme="dark"] .param-table th,
html[data-theme="dark"] .comparison-table td,
html[data-theme="dark"] .section h2,
html[data-theme="dark"] .code-block,
html[data-theme="dark"] .redirect-card {
    border-color: var(--rm-border) !important;
}
html[data-theme="dark"] [style*="border-top: 2px solid #e0e0e0"],
html[data-theme="dark"] [style*="border: 2px solid #e0e0e0"],
html[data-theme="dark"] [style*="border: 1px solid #e0e0e0"],
html[data-theme="dark"] [style*="border: 2px dashed #ddd"],
html[data-theme="dark"] [style*="border-bottom: 2px solid #e2e8f0"] {
    border-color: var(--rm-border) !important;
}
html[data-theme="dark"] .progress-bar { background: #2e3745; }
html[data-theme="dark"] input:not(:checked) + .toggle-slider { background-color: #4a5568; }

/* ---- alerts & status chips ---- */
html[data-theme="dark"] .alert-success,
html[data-theme="dark"] .test-result.success,
html[data-theme="dark"] .success-box {
    background: rgba(72, 187, 120, 0.14);
    border-color: rgba(72, 187, 120, 0.45);
    color: #9ae6b4;
}
html[data-theme="dark"] .alert-error,
html[data-theme="dark"] .test-result.error {
    background: rgba(245, 101, 101, 0.14);
    border-color: rgba(245, 101, 101, 0.45);
    color: #feb2b2;
}
html[data-theme="dark"] .status-active   { background: rgba(72, 187, 120, 0.18); color: #9ae6b4; }
html[data-theme="dark"] .status-disabled { background: rgba(245, 101, 101, 0.18); color: #feb2b2; }
html[data-theme="dark"] .success-box h4,
html[data-theme="dark"] .success-box p { color: #9ae6b4; }

/* ---- info / warning boxes ---- */
html[data-theme="dark"] .info-box,
html[data-theme="dark"] [style*="background: #e7f3ff"],
html[data-theme="dark"] [style*="background: #f0f8ff"] {
    background: rgba(66, 153, 225, 0.14) !important;
    border-color: rgba(66, 153, 225, 0.5);
}
html[data-theme="dark"] .info-box h3,
html[data-theme="dark"] .info-box h4,
html[data-theme="dark"] .info-box p,
html[data-theme="dark"] [style*="color: #1976d2"],
html[data-theme="dark"] [style*="color: #2196f3"] {
    color: #90cdf4 !important;
}
html[data-theme="dark"] [style*="background: #f0fff4"] { background: rgba(72, 187, 120, 0.14) !important; }
html[data-theme="dark"] [style*="color: #4caf50"] { color: #9ae6b4 !important; }

html[data-theme="dark"] .reset-section,
html[data-theme="dark"] .warning-box {
    background: rgba(255, 193, 7, 0.12);
}
html[data-theme="dark"] .reset-section h3,
html[data-theme="dark"] .warning-box h4,
html[data-theme="dark"] .warning-box p,
html[data-theme="dark"] [style*="color: #856404"] {
    color: #f6d776 !important;
}

/* ---- tag chips in the redirect forms (existing :has() rules use !important) ---- */
html[data-theme="dark"] label:has(input[type="checkbox"][name="tags[]"]):hover {
    background: #2a3350 !important;
    border-color: var(--rm-primary) !important;
}
html[data-theme="dark"] label:has(input[type="checkbox"][name="tags[]"]:checked) {
    background: #2f3a66 !important;
    border-color: var(--rm-primary) !important;
}
