/* Admin: mail log, traffic dashboard and the email queue's sender check. */

/* ---------- Emails in the queue ---------- */
.email-from {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    color: var(--ink-soft);
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

.email-subject {
    font-weight: 500;
}

.email-view header h1 {
    font-size: 1.5rem;
    margin: 0.3rem 0;
}

.email-body {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-family: var(--sans);
    font-size: 1rem;
    background: var(--field);
    border: 1px solid var(--rule);
    padding: 1rem;
    margin: 0.75rem 0 0;
    max-height: 50vh;
    overflow-y: auto;
    border-radius: var(--radius);
}

/* Admin mail log */

.mail-log {
    list-style: none;
    padding: 0;
    margin: 0;
}

.mail-log li {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--rule);
}

.mail-log summary {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    cursor: pointer;
    overflow-wrap: anywhere;
}

.mail-log .email-body {
    max-height: 40vh;
}

/* MailBox: one line per email, as in a mail app. Phones stack sender and time over subject and snippet;
   wider screens put sender, text and time side by side. */

.mailbox-folders a.has-problem:not(.active) {
    border-color: var(--danger);
    color: var(--danger);
}

.mailbox-folders a.has-work:not(.active) {
    border-color: var(--gold);
    font-weight: 700;
}

.mailbox-list {
    list-style: none;
    padding: 0;
    margin: 0;
    border: 1px solid var(--rule);
    border-radius: 8px;
    background: var(--field);
    overflow: hidden;
}

.mailbox-list > li + li {
    border-top: 1px solid var(--rule);
}

.mailbox-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "who time" "text text";
    gap: 0.15rem 0.75rem;
    padding: 0.65rem 0.9rem;
    color: var(--ink-soft);
    text-decoration: none;
}

.mailbox-row:hover,
.mailbox-row:focus-visible {
    background: var(--paper-deep);
}

.mailbox-who {
    grid-area: who;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ink);
}

.mailbox-text {
    grid-area: text;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mailbox-subject {
    color: var(--ink);
}

.mailbox-time {
    grid-area: time;
    font-size: 0.85rem;
    white-space: nowrap;
}

.mailbox-tags {
    grid-column: 1 / -1;
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
}

.mailbox-tags:empty {
    display: none;
}

.mailbox-row.unread .mailbox-who,
.mailbox-row.unread .mailbox-subject {
    font-weight: 700;
}

.mailbox-problem {
    margin: 0;
    padding: 0 0.9rem 0.65rem;
    color: var(--danger);
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

.mailbox-problem .button {
    margin-left: 0.5rem;
}

/* A row's tick box, the row, and its Archive / Delete / Restore buttons beside it; an Outbox problem line goes
   underneath them all. Emails waiting to be classified have an empty space instead of a box. */
.mailbox-item {
    display: grid;
    grid-template-columns: 2.25rem minmax(0, 1fr) auto;
    align-items: center;
}

.mailbox-check {
    justify-self: center;
    width: 1.1rem;
    height: 1.1rem;
    margin: 0;
}

/* Above a list: tick all, and the buttons for the ticked rows. */
.mailbox-bulk {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.75rem;
    margin: 0 0 0.5rem;
}

.mailbox-bulk .note {
    margin: 0;
}

.mailbox-item > .mailbox-problem {
    grid-column: 1 / -1;
}

.mailbox-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.3rem;
    padding: 0 0.6rem 0 0.2rem;
}

.mailbox-actions:empty {
    display: none;
}

.mailbox-row.selected {
    background: var(--paper-deep);
    box-shadow: inset 3px 0 0 var(--gold);
}

/* Reading pane: the open email. Phones show it above the list; wide screens put it beside the list, both
   scrolling on their own, and the page widens to make room. */
.site-main:has(.mailbox.reading) { max-width: 1600px; }

.mailbox-split {
    display: flex;
    flex-direction: column-reverse;
    gap: 1.25rem;
}

.mailbox-folder {
    min-width: 0;
}

.mailbox-pane {
    min-width: 0;
    padding: 0.75rem 1rem 1rem;
    border: 1px solid var(--rule);
    border-radius: 8px;
    background: var(--paper);
}

.mailbox-pane-bar {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin: 0 0 0.5rem;
    font-size: 0.9rem;
}

.mailbox-pane .email-view header h1 {
    font-size: 1.3rem;
}

.mailbox-frame {
    display: block;
    width: 100%;
    height: 75vh;
    border: 1px solid var(--rule);
    border-radius: 6px;
    background: #fff;
}

@media (min-width: 1100px) {
    .mailbox.reading .mailbox-split {
        display: grid;
        grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
        align-items: start;
    }

    .mailbox.reading .mailbox-folder {
        max-height: calc(100vh - 8rem);
        overflow-y: auto;
    }

    .mailbox.reading .mailbox-pane {
        position: sticky;
        top: 1rem;
        max-height: calc(100vh - 2rem);
        overflow-y: auto;
    }

    /* Beside the pane the list is narrow: stack sender and time over the text, as on phones. */
    .mailbox.reading .mailbox-row {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "who time" "text text" "tags tags";
    }
}

.mailbox-footer {
    margin-top: 1.5rem;
}

@media (min-width: 760px) {
    .mailbox-row {
        grid-template-columns: 14rem minmax(0, 1fr) auto auto;
        grid-template-areas: "who text tags time";
        align-items: baseline;
    }

    .mailbox-tags {
        grid-area: tags;
        flex-wrap: nowrap;
    }
}

/* Traffic dashboard. Bar colour checked for contrast: 4.7:1 on the light surface, 8.7:1 on dark. */

:root {
    --chart-bar: #8a6a2b;
    --chart-bar-track: #ece4d3;
}

@media (prefers-color-scheme: dark) {
    :root {
        --chart-bar: #d9b25f;
        --chart-bar-track: #222b42;
    }
}

/* People, bots and hacking attempts are three tabs, each with its own bar colour. */
.traffic-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin: 1rem 0 0;
    border-bottom: 2px solid var(--rule);
}

.traffic-tabs a {
    margin-bottom: -2px;
    padding: 0.6rem 1rem;
    border-bottom: 3px solid transparent;
    color: var(--ink-soft);
    text-decoration: none;
}

.traffic-tabs a strong {
    margin-left: 0.3rem;
    color: var(--ink);
}

.traffic-tabs a:hover {
    color: var(--ink);
    border-bottom-color: var(--rule);
}

.traffic-tabs a.active {
    color: var(--ink);
    font-weight: 600;
    border-bottom-color: var(--gold);
}

.traffic-tabs a.alert strong {
    color: var(--danger);
}

.traffic-tabs a.alert.active {
    border-bottom-color: var(--danger);
}

.admin-tile.alert {
    border-color: var(--danger);
    box-shadow: inset 4px 0 0 var(--danger);
}

.traffic-section {
    margin-top: 1.5rem;
}

.traffic-section > h2 {
    margin-top: 0;
    font-size: 1.9rem;
}

.traffic-section > h3 {
    margin: 1.5rem 0 0.25rem;
}

.traffic-section.bots {
    --chart-bar: var(--ink-soft);
    --chart-bar-track: var(--mark-muted);
}

.traffic-section.hacking {
    --chart-bar: var(--danger);
    --chart-bar-track: var(--danger-bg);
}

.tile-number.small {
    font-size: 1.4rem;
    line-height: 1.55;
}

.range-form {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 0.5rem 0.75rem;
    margin-bottom: 1rem;
}

.range-form label {
    display: flex;
    flex-direction: column;
    font-size: 0.85rem;
    color: var(--ink-soft);
}

.range-form input {
    font: inherit;
    padding: 0.45rem 0.5rem;
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    background: var(--field);
}

.bar-chart {
    margin: 0.5rem 0 0;
    position: relative;
}

.bar-chart svg {
    display: block;
    width: 100%;
    height: 160px;
    overflow: visible;
}

.chart-baseline {
    stroke: var(--rule);
    stroke-width: 1;
    vector-effect: non-scaling-stroke;
}

.chart-bar rect:not(.chart-hit) {
    fill: var(--chart-bar);
}

.chart-hit {
    fill: transparent;
}

.chart-bar:hover rect:not(.chart-hit) {
    opacity: 0.75;
}

.chart-bar:hover .chart-hit {
    fill: var(--chart-bar-track);
}

.chart-max {
    margin: 0;
    font-size: 0.8rem;
    color: var(--ink-soft);
}

.chart-axis {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--ink-soft);
    margin-top: 0.3rem;
}

.chart-table {
    margin: 0.75rem 0 1.5rem;
}

.chart-table summary {
    cursor: pointer;
    color: var(--ink-soft);
}

.chart-table table {
    border-collapse: collapse;
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

.chart-table th,
.chart-table td {
    padding: 0.2rem 0.9rem 0.2rem 0;
    text-align: left;
    border-bottom: 1px solid var(--rule);
}

.traffic-lists {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem 2rem;
}

.traffic-list h3 {
    font-size: 1.2rem;
    margin: 1rem 0 0.4rem;
}

.traffic-list ol {
    list-style: none;
    padding: 0;
    margin: 0;
}

.traffic-list li {
    position: relative;
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.35rem 0.5rem;
    margin-bottom: 2px;
    overflow-wrap: anywhere;
}

.traffic-bar {
    position: absolute;
    inset: 0 auto 0 0;
    background: var(--chart-bar-track);
    border-radius: 0 4px 4px 0;
    z-index: 0;
}

.traffic-name,
.traffic-count {
    position: relative;
    z-index: 1;
}

.traffic-count {
    font-variant-numeric: tabular-nums;
    color: var(--ink-soft);
}

/* ---------- Admin puzzles: the answers picked, as traffic-list bars; the right answer in the "win" colour ---------- */
.puzzle-stats {
    max-width: 720px;
}

.puzzle-stats li.right .traffic-name {
    color: var(--win);
    font-weight: 600;
}

/* ---------- Admin queue: is the sender genuine? ---------- */
.sender-check {
    margin: 0.5rem 0 0;
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-sm);
    font: 0.92rem/1.5 var(--sans);
}

.sender-check.verified { background: #e7f3ea; color: #1f5e33; }
.sender-check.unverified { background: var(--danger-bg); color: var(--danger); border-left: 4px solid #b3261e; }
.sender-check.unverified strong { display: block; }
.confirm-genuine { font-weight: 600; color: var(--danger); }
.tag.unverified { background: var(--danger-bg); color: var(--danger); }


/* Chess Coach page: plain tables that scroll sideways on phones. */
.coach-table {
    overflow-x: auto;
    margin: 0.5rem 0 1.5rem;
}

.coach-table table {
    border-collapse: collapse;
    font-size: 0.9rem;
}

.coach-table th,
.coach-table td {
    padding: 0.25rem 1rem 0.25rem 0;
    text-align: left;
    border-bottom: 1px solid var(--rule);
    white-space: nowrap;
}

/* The traffic page's "don't count this browser" switch. */
.this-browser {
    align-items: center;
}

.this-browser .note {
    margin: 0;
}
