/* ---------------------------------------------------------------------------
   IT Solution MailGuard

   Hand-written, no framework. A security product should read as calm and
   precise rather than colourful: one accent, generous whitespace, real
   typographic hierarchy, and colour reserved for meaning (a risk pill, a
   status) rather than decoration.

   The palette is deliberately restrained so that the ONE thing rendered in a
   warning colour on a page is the thing that matters.
   --------------------------------------------------------------------------- */

:root {
    --ink:        #14181f;
    --ink-soft:   #4a5262;
    --ink-faint:  #767f90;
    --line:       #e2e6ed;
    --line-soft:  #eef1f5;
    --paper:      #ffffff;
    --shade:      #f6f8fb;

    --navy:       #16233a;
    --navy-soft:  #23324c;

    --accent:     #1f5fd0;
    --accent-ink: #16408f;

    --ok:         #0f7a4d;
    --ok-bg:      #e7f5ee;
    --warn:       #9a6206;
    --warn-bg:    #fdf3e2;
    --bad:        #b3261e;
    --bad-bg:     #fdecea;
    --unknown:    #5b5f86;
    --unknown-bg: #eeeefb;

    --radius:     8px;
    --radius-lg:  12px;

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

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

html { -webkit-text-size-adjust: 100%; }

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

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; font-weight: 640; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.075rem; }
p  { margin: 0 0 1rem; }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: .875em; }

.muted  { color: var(--ink-faint); }
.small  { font-size: .8125rem; }
.nowrap { white-space: nowrap; }
.lede   { font-size: 1.0625rem; color: var(--ink-soft); }
.inline { display: inline; }

/* --- development banner -------------------------------------------------
   Loud on purpose. Section 38 requires the development mechanism to be
   visibly marked, and a subtle marker is one that gets cropped out of a
   screenshot and mistaken for production. */
.devbar {
    display: flex; flex-wrap: wrap; gap: .75rem; align-items: center;
    padding: .5rem 1rem;
    background: repeating-linear-gradient(135deg, #3a2c05, #3a2c05 12px, #453509 12px, #453509 24px);
    color: #ffd873;
    font-size: .8125rem;
    border-bottom: 2px solid #7a5e10;
}
.devbar strong { letter-spacing: .08em; color: #ffe9a8; }
.devbar a { color: #ffe9a8; text-decoration: underline; margin-left: auto; }

/* --- brand ---------------------------------------------------------------- */
.brandmark { display: flex; align-items: center; gap: .625rem; margin-bottom: 1.75rem; }
.brandmark__text { font-size: .9375rem; color: var(--ink-soft); }
.brandmark__text strong { color: var(--ink); font-weight: 660; }

.brandmark__glyph {
    width: 26px; height: 26px; flex: none; border-radius: 6px;
    background: linear-gradient(150deg, var(--accent), var(--accent-ink));
    position: relative;
}
.brandmark__glyph::after {
    content: ""; position: absolute; inset: 7px 8px;
    border: 2px solid rgba(255,255,255,.92);
    border-bottom-width: 0; border-radius: 2px 2px 6px 6px;
}
.brandmark__glyph--admin { background: linear-gradient(150deg, #55648a, #2b3852); }

/* --- minimal / auth ------------------------------------------------------- */
.centre { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 2rem 1rem; }
.card {
    background: var(--paper); border: 1px solid var(--line);
    border-radius: var(--radius-lg); padding: 2rem;
    box-shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 24px rgba(16,24,40,.05);
}
.card--auth { width: 100%; max-width: 27rem; }
.footnote { margin-top: 1.25rem; font-size: .75rem; color: var(--ink-faint); }

/* --- topbar --------------------------------------------------------------- */
.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .75rem 1.25rem;
    background: var(--paper); border-bottom: 1px solid var(--line);
}
.topbar--admin { background: var(--navy); border-bottom-color: var(--navy-soft); }
.topbar--admin .topbar__tenant { color: #fff; }
.topbar--admin .topbar__vendor,
.topbar--admin .topbar__mailbox { color: #9fb0cc; }
.topbar--admin .btn--quiet { color: #cdd8ea; border-color: var(--navy-soft); }
.topbar--admin .btn--quiet:hover { background: var(--navy-soft); }

.topbar__brand { display: flex; align-items: center; gap: .625rem; }
.topbar__tenant { display: block; font-weight: 660; font-size: .9375rem; }
.topbar__vendor { display: block; font-size: .75rem; color: var(--ink-faint); }
.topbar__actions { display: flex; align-items: center; gap: .75rem; }
.topbar__mailbox { font-size: .8125rem; color: var(--ink-soft); }

/* --- layout --------------------------------------------------------------- */
.layout { display: grid; grid-template-columns: 216px minmax(0, 1fr); align-items: start; }
.sidenav { padding: 1.25rem .75rem; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; }
.sidenav__item {
    padding: .5rem .75rem; border-radius: var(--radius);
    color: var(--ink-soft); font-size: .875rem; font-weight: 500;
}
.sidenav__item:hover { background: var(--line-soft); text-decoration: none; color: var(--ink); }
.sidenav__item.is-active { background: var(--paper); color: var(--ink); box-shadow: inset 2px 0 0 var(--accent); font-weight: 620; }
.sidenav--admin .sidenav__item { color: #55617a; }
.sidenav--admin .sidenav__item.is-active { box-shadow: inset 2px 0 0 var(--navy); }

.content { padding: 1.5rem 1.75rem 4rem; min-width: 0; max-width: 68rem; }

.page-head { margin-bottom: 1.5rem; }
.page-head__sub { color: var(--ink-faint); font-size: .875rem; margin: 0; }
.section-title { margin-top: 2rem; font-size: .9375rem; }

/* --- panels / notices ----------------------------------------------------- */
.panel {
    background: var(--paper); border: 1px solid var(--line);
    border-radius: var(--radius-lg); padding: 1.25rem 1.375rem; margin-bottom: 1.25rem;
}

.notice {
    border: 1px solid var(--line); border-left: 3px solid var(--accent);
    background: var(--paper); border-radius: var(--radius);
    padding: .75rem 1rem; margin-bottom: 1.25rem; font-size: .875rem;
}
.notice--dev { border-left-color: var(--warn); background: var(--warn-bg); color: #6b4604; }
.notice--dev a { color: var(--accent-ink); }

.flash { border-radius: var(--radius); padding: .625rem .875rem; margin-bottom: 1rem; font-size: .875rem; }
.flash--info { background: #eaf1fd; color: var(--accent-ink); }
.flash--warn { background: var(--warn-bg); color: var(--warn); }
.flash--bad  { background: var(--bad-bg);  color: var(--bad); }

.empty {
    background: var(--paper); border: 1px dashed var(--line);
    border-radius: var(--radius-lg); padding: 2.5rem 1.5rem; text-align: center;
}
.empty h2 { color: var(--ink-soft); }
.empty p { max-width: 34rem; margin-inline: auto; color: var(--ink-faint); }

/* --- stats ---------------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1rem 1.125rem; }
.stat__value { display: block; font-size: 1.625rem; font-weight: 660; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat__label { display: block; font-size: .75rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .04em; }
.stat--alert .stat__value { color: var(--bad); }

/* --- tables --------------------------------------------------------------- */
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th {
    text-align: left; font-size: .6875rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--ink-faint); font-weight: 620; padding: .5rem .625rem; border-bottom: 1px solid var(--line);
}
.table td { padding: .625rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table--compact td { padding: .4375rem .625rem; }

.risk { font-variant-numeric: tabular-nums; font-weight: 660; }

/* --- pills ---------------------------------------------------------------- */
.pill {
    display: inline-block; padding: .125rem .5rem; border-radius: 999px;
    font-size: .6875rem; font-weight: 640; letter-spacing: .03em; white-space: nowrap;
}
.pill--ok      { background: var(--ok-bg);      color: var(--ok); }
.pill--warn    { background: var(--warn-bg);    color: var(--warn); }
.pill--bad     { background: var(--bad-bg);     color: var(--bad); }
.pill--unknown { background: var(--unknown-bg); color: var(--unknown); }
.pill--muted   { background: var(--line-soft);  color: var(--ink-faint); }

/* --- forms ---------------------------------------------------------------- */
.form { margin: 1.25rem 0; }
.field { display: block; margin-bottom: 1rem; }
.field__label { display: block; font-size: .8125rem; font-weight: 560; margin-bottom: .3125rem; color: var(--ink-soft); }

input[type="email"], input[type="text"], select {
    width: 100%; padding: .5625rem .75rem; font: inherit; color: var(--ink);
    background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
}
input:focus, select:focus, .btn:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
.input--code { font-family: var(--mono); font-size: 1.25rem; letter-spacing: .35em; text-align: center; }

.btn {
    display: inline-block; padding: .5625rem 1rem; font: inherit; font-weight: 560;
    color: var(--ink); background: var(--paper);
    border: 1px solid var(--line); border-radius: var(--radius);
    cursor: pointer; text-align: center;
}
.btn:hover { background: var(--shade); text-decoration: none; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn--block { display: block; width: 100%; }
.btn--quiet { background: transparent; border-color: var(--line); color: var(--ink-soft); font-size: .8125rem; padding: .375rem .75rem; }

/* --- misc ----------------------------------------------------------------- */
.deflist { display: grid; grid-template-columns: minmax(9rem, auto) 1fr; gap: .375rem 1.25rem; margin: 0; font-size: .875rem; }
.deflist dt { color: var(--ink-faint); }
.deflist dd { margin: 0; }

.trace {
    background: var(--navy); color: #cfe0ff; padding: .875rem;
    border-radius: var(--radius); overflow-x: auto; font-family: var(--mono); font-size: .75rem;
}

@media (max-width: 720px) {
    .layout { grid-template-columns: 1fr; }
    .sidenav { flex-direction: row; overflow-x: auto; position: static; border-bottom: 1px solid var(--line); background: var(--paper); }
    .sidenav__item { white-space: nowrap; }
    .content { padding: 1.25rem 1rem 3rem; }
    .topbar { flex-wrap: wrap; }
}

/* --- Phase 2: admin forms -------------------------------------------------
   Field-level errors and hints. The error sits directly under its input, not
   in a summary at the top: a summary makes the operator hunt for which of
   twelve fields it meant. */
.field__hint  { display: block; font-size: .75rem; color: var(--ink-faint); margin-top: .25rem; }
.field__error { display: block; font-size: .75rem; color: var(--bad); margin-top: .25rem; font-weight: 560; }
.field:has(.field__error) input,
.field:has(.field__error) select { border-color: var(--bad); }

.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 0 1rem; }

.field--check { display: grid; grid-template-columns: auto 1fr; gap: .25rem .5rem; align-items: start; }
.field--check input { margin-top: .25rem; }
.field--check .field__hint { grid-column: 2; }

input[type="number"] {
    width: 100%; padding: .5625rem .75rem; font: inherit; color: var(--ink);
    background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
}

/* Forms sitting inside a table cell must not add block spacing. */
.inline-form { display: inline-flex; gap: .375rem; align-items: center; margin: 0; }
.select--inline { width: auto; padding: .3125rem .5rem; font-size: .8125rem; }

.page-head--split { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* Suspension is destructive to a customer's access, so its control is not a
   neutral grey button among neutral grey buttons. */
.btn--danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn--danger:hover { background: #8f1e17; border-color: #8f1e17; }

/* --- Phase 4: quarantine ---------------------------------------------------
   The risk number is the first thing a reader looks at, so it carries the
   colour. Everything else stays quiet, or the page becomes a wall of red and
   the reader stops seeing any of it. */
.risk { font-variant-numeric: tabular-nums; font-weight: 660; padding: .0625rem .375rem; border-radius: 4px; }
.risk--bad   { background: var(--bad-bg);   color: var(--bad); }
.risk--warn  { background: var(--warn-bg);  color: var(--warn); }
.risk--muted { background: var(--line-soft); color: var(--ink-soft); }

.sender__name { font-weight: 560; }
.sender__addr { font-size: .8125rem; color: var(--ink-faint); }

.table--quarantine td { vertical-align: top; }

/* --- filters --------------------------------------------------------------- */
.filters {
    display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end;
    background: var(--paper); border: 1px solid var(--line);
    border-radius: var(--radius-lg); padding: 1rem; margin-bottom: 1.25rem;
}
.filters__field { display: block; flex: 0 1 9rem; margin: 0; }
.filters__field--wide { flex: 1 1 16rem; }
.filters__field input, .filters__field select { width: 100%; }
.filters__actions { display: flex; gap: .5rem; }

input[type="search"], input[type="date"] {
    width: 100%; padding: .5625rem .75rem; font: inherit; color: var(--ink);
    background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
}

.pager { display: flex; align-items: center; gap: .75rem; margin-top: 1rem; }
.pager__state { font-size: .8125rem; color: var(--ink-faint); }

.backlink { font-size: .875rem; margin-bottom: .5rem; }

/* --- risk badge ------------------------------------------------------------ */
.riskbadge {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-width: 5.5rem; padding: .625rem 1rem; border-radius: var(--radius-lg);
    background: var(--line-soft);
}
.riskbadge__score { font-size: 1.75rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.riskbadge__label { font-size: .6875rem; text-transform: uppercase; letter-spacing: .05em; margin-top: .25rem; }
.riskbadge--bad  { background: var(--bad-bg);  color: var(--bad); }
.riskbadge--warn { background: var(--warn-bg); color: var(--warn); }

/* --- reasons: the explainability panel (§42) ------------------------------- */
.panel--reasons { border-left: 3px solid var(--bad); }
.reasons { margin: .5rem 0 0; padding-left: 1.25rem; }
.reasons li { margin-bottom: .5rem; }
.reasons__code {
    display: inline-block; margin-left: .375rem; padding: 0 .375rem;
    background: var(--line-soft); color: var(--ink-faint);
    border-radius: 3px; font-family: var(--mono); font-size: .6875rem;
}

/* --- URLs ------------------------------------------------------------------ */
.url { word-break: break-all; }

/* --- the safe preview -------------------------------------------------------
   A sandboxed iframe cannot be auto-sized without script and same-origin
   access, neither of which it gets. A fixed height with internal scrolling is
   the correct trade: the sandbox is worth more than the convenience. */
.preview {
    width: 100%; height: 26rem; border: 1px solid var(--line);
    border-radius: var(--radius); background: var(--paper);
}
.preview--text {
    height: auto; max-height: 26rem; overflow: auto; padding: .875rem;
    white-space: pre-wrap; word-wrap: break-word; font-family: var(--mono); font-size: .8125rem;
}

/* A margin close to a threshold: the verdict is one small change from
   flipping, so the number is coloured rather than left to be noticed. */
.is-warn { color: var(--warn); font-weight: 600; }

/* Screen-reader-only label for a column whose header would be noise on
   screen (an actions column). Clipped rather than display:none, which
   removes it from the accessibility tree as well as from view. */
.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0; border: 0;
    clip: rect(0 0 0 0); clip-path: inset(50%);
    overflow: hidden; white-space: nowrap;
}

/* Phase 8: the action panel on a held message. Given visual weight because
   releasing is the one irreversible thing a customer can do here. */
.panel--actions { border-left: 3px solid var(--warn); }
.actions-row { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: .75rem; }

/* The filter row on the cross-tenant quarantine screen. */
.form--filters { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; margin-bottom: 1.25rem; }
.form--filters .field { margin: 0; }
