/*
 * One hand-written stylesheet, no build step.
 *
 * Tailwind would mean a watch process and a compile stage for a twenty-view app;
 * a CDN framework would mean an external dependency that breaks offline. Custom
 * properties carry the whole theme, so every colour decision lives in one block.
 *
 * ## The palette
 *
 * A single dark theme on near-neutral grey, with orange doing the accent work.
 * The greys carry the faintest blue so they read as grey rather than as a
 * washed-out version of the accent - a warm-tinted neutral turns the whole
 * interface brown, which is the accent bleeding into surfaces that should stay
 * out of the way. Orange appears where something is interactive or worth
 * looking at, and nowhere else.
 *
 * Every pair below meets WCAG 2.1 AA - 4.5:1 for text, 3:1 for interface
 * borders and focus rings - and tests/cases/theme.php recomputes the ratios from
 * this file rather than trusting the comment.
 *
 * The one that catches people out: white text does not survive a bright orange.
 * White on #ff8a3d is 2.35:1, nowhere near readable. That is why there are two
 * oranges - a bright one for text and focus rings, and a deep one for fills
 * that carry a white label - rather than one colour asked to do both.
 */

:root {
    color-scheme: dark;

    --bg: #121417;
    --surface: #1a1d21;
    --surface-2: #282d33;
    --border: #333940;
    /* Edges of buttons and inputs, so it takes the 3:1 component threshold. */
    --border-strong: #6f7883;
    --text: #eef1f5;
    --muted: #a6afba;

    /*
     * Two oranges, because one cannot do both jobs.
     *
     * --accent is bright, for things that ARE the orange: link text, the focus
     * ring, the active nav underline, a progress fill. It needs 4.5:1 as text
     * against a dark card, which forces it light.
     *
     * --accent-fill is deep, for things that CARRY white text. White on the
     * bright one is 2.35:1 - unreadable. Making the fill dark enough for white
     * is the only way to have a white label, and it is bounded on both sides:
     * dark enough for the text (>=4.5:1), light enough that the button still
     * has a visible edge against the card behind it (>=3:1).
     */
    --accent: #ff8a3d;
    --accent-strong: #ffa564;

    --accent-fill: #c2410c;
    --accent-fill-hover: #cb4a0e;
    --accent-text: #ffffff;

    /*
     * Badge and alert fills: grey pulled a little towards the hue, not the hue
     * darkened. A saturated dark amber is brown and a saturated dark red is
     * maroon, and a row of those turns a status column into mud. The colour
     * that carries the meaning is the text and the border on top.
     */
    --danger: #ff8a80;
    --danger-bg: #3f272b;
    --success: #6fd79b;
    --success-bg: #1e332a;
    --warn: #f0c05a;
    --warn-bg: #332f20;

    --s1: 0.25rem;
    --s2: 0.5rem;
    --s3: 0.75rem;
    --s4: 1rem;
    --s5: 1.5rem;
    --s6: 2rem;

    --radius: 8px;
    --radius-sm: 5px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.45), 0 6px 18px rgba(0, 0, 0, 0.35);

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
}

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

h1 { font-size: 1.45rem; margin: 0 0 var(--s2); }
h2 { font-size: 1.1rem; margin: 0 0 var(--s3); }
h3 { font-size: 0.95rem; margin: 0 0 var(--s2); }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.container {
    max-width: 1180px;
    margin: 0 auto;
    padding: var(--s5) var(--s4) var(--s6);
}

.container-narrow {
    max-width: 560px;
    margin: 0 auto;
    padding: var(--s6) var(--s4);
}

/* ------------------------------------------------------------------- nav */

.nav {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.nav-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 var(--s4);
}

/*
 * The divider spans the window rather than the content column, so the two rows
 * read as bands rather than as a boxed-in strip.
 */
.nav-top { border-bottom: 1px solid var(--border); }

.nav-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s4);
    /*
     * Roomier than the row below it, deliberately. This band carries identity -
     * the mark, the name and which list you are working in - and giving it air
     * separates it from the run of links rather than making it look like a
     * first row of them.
     */
    padding: var(--s4) 0;
    min-height: 64px;
}

.nav-project {
    display: flex;
    align-items: center;
    gap: var(--s2);
}

.nav-project select {
    min-width: 11rem;
    min-height: 34px;
}

.nav-bar {
    display: flex;
    align-items: center;
    /*
     * Tighter than the top row, and a smaller gap between wrapped lines than
     * along one: there are a dozen destinations here and they will wrap on a
     * laptop, so the second line should read as a continuation rather than as
     * a separate strip.
     */
    column-gap: var(--s3);
    row-gap: var(--s1);
    min-height: 48px;
    flex-wrap: wrap;
    /*
     * Equal above and below, so the links sit centred in the band rather than
     * pressed up against the divider. The bottom also leaves room for the
     * underline on the current item when the row wraps.
     */
    padding-top: var(--s2);
    padding-bottom: var(--s2);
}

.nav-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--s2);
    font-weight: 650;
    font-size: 1.05rem;
    color: var(--text);
    text-decoration: none;
}

/*
 * flex-shrink so the mark keeps its shape when the row is tight - a squashed
 * tentacle looks like a mistake rather than a logo.
 */
.tentacle {
    flex: 0 0 auto;
    display: block;
}

.nav-brand:hover .tentacle { opacity: 0.85; }

.nav a.nav-link,
.nav .nav-group > summary {
    color: var(--muted);
    text-decoration: none;
    padding: var(--s2) 0;
    border-bottom: 2px solid transparent;
    font-weight: 500;
}

.nav a.nav-link:hover,
.nav .nav-group > summary:hover { color: var(--text); }

/*
 * One rule for both, so a dropdown heading and a top-level link are marked
 * identically and cannot drift apart. Being inside a group looks exactly like
 * being on a page.
 *
 * The underline AND the weight, never colour alone - the rule that applies to
 * every status indicator here.
 */
.nav a.nav-link[aria-current="page"],
.nav .nav-group > summary[data-current="true"] {
    color: var(--text);
    font-weight: 600;
    border-bottom-color: var(--accent);
}

/* ------------------------------------------------------- nav dropdown */

.nav-group {
    position: relative;
    /* So the summary lines up with its siblings rather than sitting a
       baseline off, which <details> does by default. */
    display: inline-block;
}

.nav-group > summary {
    display: inline-flex;
    align-items: center;
    gap: var(--s1);
    cursor: pointer;
    /* The native triangle is replaced by one that can be rotated. */
    list-style: none;
}

.nav-group > summary::-webkit-details-marker { display: none; }

.nav-group > summary::after {
    content: "";
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    transition: transform 0.15s ease;
}

.nav-group[open] > summary::after { transform: rotate(180deg); }

.nav-menu {
    position: absolute;
    top: calc(100% + var(--s1));
    left: 0;
    z-index: 30;
    min-width: 12rem;
    display: flex;
    flex-direction: column;
    padding: var(--s1);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

.nav-menu a {
    padding: var(--s2) var(--s3);
    border-radius: var(--radius-sm);
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
}

.nav-menu a:hover { background: var(--surface-2); }

/*
 * No current-page styling inside the menu. The heading carries it, exactly as a
 * top-level link does, so there is one highlight rather than two saying the
 * same thing in different shapes.
 *
 * aria-current stays on the child in the markup. It costs nothing visually and
 * a screen reader still announces which item is the current page, so removing
 * the decoration does not remove the information.
 */

.nav-spacer { margin-left: auto; }

/* ---------------------------------------------------------------- layout */

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

.card-flush { padding: 0; overflow: hidden; }

.row {
    display: flex;
    gap: var(--s3);
    align-items: center;
    flex-wrap: wrap;
}

.row-between { justify-content: space-between; }
.grow { flex: 1 1 auto; }
.stack > * + * { margin-top: var(--s3); }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.mono { font-family: var(--mono); font-size: 0.85em; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--s3);
    flex-wrap: wrap;
    margin-bottom: var(--s4);
}

/* --------------------------------------------------------------- buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s2);
    min-height: 40px;
    padding: 0 var(--s3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: var(--accent-fill);
    border-color: var(--accent-fill);
    color: var(--accent-text);
    /*
     * The shadow is polish, not a crutch. Contrast algorithms ignore it
     * entirely, so the fill underneath has to carry white on its own - it
     * does, at 5.18:1. What this adds is a soft edge that stops the white
     * vibrating against a saturated orange, which is a real legibility effect
     * even where the numbers are already fine.
     */
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

/*
 * A measured colour rather than filter: brightness(), so the hover state is
 * covered by the contrast checks like everything else. Brighter, but only as
 * far as white text allows - past this it stops being readable.
 */
.btn-primary:hover {
    background: var(--accent-fill-hover);
    border-color: var(--accent-fill-hover);
}

.btn-primary:active {
    /* Pressed: the raised edge goes away rather than the colour changing. */
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.35);
}

.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-bg); }

.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }

.btn-sm { min-height: 32px; font-size: 0.86rem; padding: 0 var(--s2); }
.btn-block { width: 100%; }

/* ---------------------------------------------------------------- fields */

.field { display: block; margin-bottom: var(--s3); }

.field > label,
.label {
    display: block;
    font-weight: 550;
    font-size: 0.86rem;
    margin-bottom: var(--s1);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="number"],
input[type="color"],
select,
textarea {
    width: 100%;
    min-height: 40px;
    padding: var(--s2) var(--s3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

textarea { min-height: 220px; resize: vertical; font-family: var(--mono); font-size: 0.88rem; }
select { min-width: 8rem; }
input[type="color"] { padding: 2px; width: 44px; min-height: 34px; }

.hint { font-size: 0.82rem; color: var(--muted); margin-top: var(--s1); }

.inline-form { display: inline; }

/* Honeypot: hidden with CSS rather than type="hidden", which bots detect. */
.hp {
    position: absolute !important;
    left: -9999px !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* --------------------------------------------------------------- tables */

.table { width: 100%; border-collapse: collapse; }

.table th,
.table td {
    padding: var(--s3);
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.table th {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    background: var(--surface-2);

    /*
     * top MUST stay 0.
     *
     * .table-scroll sets overflow-x: auto, and CSS computes the other axis to
     * auto whenever one axis is not visible - so .table-scroll is a scroll
     * container, and that, not the viewport, is what this sticky header offsets
     * against. Its scrollTop is always 0 (the table is never taller than its own
     * box), so any non-zero top displaced the header downwards by exactly that
     * many pixels: a blank band appeared above it and the header was painted
     * over the first row of the table.
     *
     * The row was in the DOM and in the HTML the whole time - it was simply
     * covered by an opaque header, so the list appeared to be permanently one
     * subscriber short, and the missing one was always the newest.
     */
    position: sticky;
    top: 0;
}

.table th a { color: inherit; text-decoration: none; }
.table th a:hover { color: var(--text); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table td.shrink { width: 1%; white-space: nowrap; }

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

.empty {
    padding: var(--s6) var(--s4);
    text-align: center;
    color: var(--muted);
}

/* ---------------------------------------------------------------- chips */

.chip {
    display: inline-flex;
    align-items: center;
    gap: var(--s1);
    padding: 2px var(--s2);
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 550;
    line-height: 1.6;
    border: 1px solid transparent;
    background: var(--surface-2);
    color: var(--text);
    white-space: nowrap;
}

.chip-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: none;
}

.chip-remove {
    border: 0;
    background: none;
    color: inherit;
    cursor: pointer;
    font: inherit;
    line-height: 1;
    padding: 0 0 0 2px;
    opacity: 0.7;
}

.chip-remove:hover { opacity: 1; }

.chips { display: flex; flex-wrap: wrap; gap: var(--s1); }

/*
 * Tri-state filter toggle. Status is never carried by colour alone: the
 * excluded state also gets a line through the text.
 */
.chip-toggle {
    cursor: pointer;
    border-color: var(--border);
    background: var(--surface);
    color: var(--muted);
    min-height: 30px;
}

/*
 * An included tag chip carries a white label, so it takes the deep fill for
 * the same reason the primary button does.
 */
.chip-toggle[data-state="include"] {
    background: var(--accent-fill);
    border-color: var(--accent-fill);
    color: var(--accent-text);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.chip-toggle[data-state="exclude"] {
    background: var(--danger-bg);
    border-color: var(--danger);
    color: var(--danger);
    text-decoration: line-through;
}

/* --------------------------------------------------------------- badges */

.badge {
    display: inline-block;
    padding: 1px var(--s2);
    border-radius: var(--radius-sm);
    font-size: 0.76rem;
    font-weight: 600;
    border: 1px solid transparent;
}

.badge-confirmed { background: var(--success-bg); color: var(--success); }
.badge-pending { background: var(--warn-bg); color: var(--warn); }
.badge-unsubscribed { background: var(--surface-2); color: var(--muted); }
.badge-bounced { background: var(--danger-bg); color: var(--danger); }
.badge-deleted { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }

/* --------------------------------------------------------------- alerts */

.alert {
    padding: var(--s3);
    border-radius: var(--radius-sm);
    border: 1px solid;
    margin-bottom: var(--s4);
}

.alert-success { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.alert-error { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.alert-warn { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
/*
 * Neutral fill, orange edge. An orange-tinted panel is a brown panel, and this
 * one is common enough that it would tint whole screens.
 */
.alert-info { background: var(--surface-2); border-color: var(--accent); color: var(--text); }

/*
 * A link inside a coloured alert keeps the accent, so it still reads as a link
 * rather than as more body copy. Checked against every alert background.
 */
.alert a { color: var(--accent); }

/* ------------------------------------------------------------ statistics */

.stats { display: flex; gap: var(--s4); flex-wrap: wrap; }

.stat { min-width: 92px; }
.stat-value { font-size: 1.5rem; font-weight: 650; line-height: 1.1; }
.stat-label { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/*
 * Boxed figures, equal width.
 *
 * Grid rather than flex, because the columns have to be the same size whatever
 * is in them. Sized by their contents, "Unsubscribed 4" would sit narrower than
 * "Total subscribers 1,234" and the row would read as a ranking rather than a
 * set. auto-fit means they reflow onto fewer columns on a narrow screen instead
 * of being squeezed.
 */
.statgrid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--s3);
    margin-bottom: var(--s4);
}

.statbox {
    padding: var(--s3) var(--s4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.statbox .stat-value {
    font-size: 1.7rem;
    /* Lining figures line up in a column; proportional ones stagger. */
    font-variant-numeric: tabular-nums;
}

.statbox .stat-label { margin-top: var(--s1); }

.statbox .stat-note {
    margin-top: var(--s1);
    font-size: 0.78rem;
    color: var(--muted);
}

/* A box that is a link stays a panel, not a wall of underlined blue. */
a.statbox {
    display: block;
    color: inherit;
    text-decoration: none;
}

a.statbox:hover {
    border-color: var(--border-strong);
    background: var(--surface-2);
}

/* ----------------------------------------------------------- bulk action */

.bulkbar {
    position: sticky;
    bottom: 0;
    z-index: 15;
    display: flex;
    align-items: center;
    gap: var(--s3);
    flex-wrap: wrap;
    padding: var(--s3);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-top: var(--s3);
}

.selectall {
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    padding: var(--s2) var(--s3);
    font-size: 0.88rem;
}

/* ------------------------------------------------------------ pagination */

.pagination {
    display: flex;
    align-items: center;
    gap: var(--s2);
    padding: var(--s3);
    flex-wrap: wrap;
}

/* ---------------------------------------------------------------- drawer */

.drawer-row > td {
    background: var(--surface-2);
    padding: var(--s4);
}

/* --------------------------------------------------------------- editor */

.editor-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--s4);
}

.preview-frame {
    width: 100%;
    min-height: 420px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
}

.mergefields { display: flex; gap: var(--s1); flex-wrap: wrap; margin-bottom: var(--s2); }

/* ------------------------------------------------------------- progress */

.bar {
    height: 12px;
    border-radius: 999px;
    background: var(--surface-2);
    overflow: hidden;
    border: 1px solid var(--border);
}

.bar-fill {
    height: 100%;
    background: var(--accent);
    width: 0;
    transition: width 0.3s ease;
}

/* --------------------------------------------------------------- combobox */

.combo { position: relative; }

.combo-list {
    position: absolute;
    z-index: 30;
    left: 0;
    right: 0;
    top: calc(100% + 2px);
    max-height: 240px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: var(--s1);
    margin: 0;
    list-style: none;
}

.combo-list li {
    padding: var(--s2);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.combo-list li[aria-selected="true"],
.combo-list li:hover {
    background: var(--surface-2);
}

/* ---------------------------------------------------------------- misc */

.codeblock {
    font-family: var(--mono);
    font-size: 0.82rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--s3);
    overflow-x: auto;
    white-space: pre;
}

.divider { height: 1px; background: var(--border); margin: var(--s4) 0; }

/* ---------------------------------------------------------- responsive */

@media (max-width: 820px) {
    .editor-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 700px) {
    /*
     * The brand and the project selector stop sharing a line and stack, rather
     * than the selector being squeezed to a few characters - it is how you tell
     * which list you are about to email.
     */
    .nav-top-row {
        flex-wrap: wrap;
        min-height: 0;
        gap: var(--s2);
        /*
         * Between the old value and the desktop one. The row already stacks
         * here, so it has height from that; matching the desktop padding on top
         * would spend scarce screen on empty space.
         */
        padding: var(--s3) 0;
    }

    .nav-project { width: 100%; }
    .nav-project select { flex: 1; min-width: 0; }

    .table thead { display: none; }

    .table,
    .table tbody,
    .table tr,
    .table td { display: block; width: 100%; }

    .table tr {
        border-bottom: 1px solid var(--border);
        padding: var(--s2) 0;
    }

    .table td {
        border: none;
        padding: var(--s1) var(--s3);
    }

    .table td.shrink { width: auto; }

    .table td[data-label]::before {
        content: attr(data-label) ": ";
        font-weight: 600;
        color: var(--muted);
    }
}

@media print {
    .nav, .bulkbar, .pagination, .btn { display: none; }
}
