/* Mail Admin styles, loaded after Water.css (automatic light/dark build).
   Water styles plain elements; this file adds the two-column shell (menu on
   the left, pane on the right), compact sizing, coloured buttons, form grids,
   and stacked table rows on narrow screens.

   Colour scheme "Aurora": a midnight-navy menu column lit by a teal, violet
   and magenta gradient; a bright pane in light mode, deep indigo in dark
   mode. All colours are variables here; Water's own variables
   (--background-body, --border, --links ...) are overridden so plain
   elements follow the scheme too. Text/background pairs meet WCAG AA
   (4.5:1), input borders 3:1. */

:root {
  /* the aurora itself */
  --teal: #14d8c4;
  --violet: #7c4dff;
  --magenta: #ff3d9a;
  --aurora: linear-gradient(115deg, var(--teal) 0%, var(--violet) 52%, var(--magenta) 100%);
  /* menu column: always dark */
  --rail-bg: #0b1026;
  --rail-text: #d5dbff;
  --rail-muted: #8f98c9;
  --rail-hover: rgba(255, 255, 255, 0.06);
  --rail-line: rgba(143, 152, 201, 0.18);
  /* pane surfaces */
  --background-body: #f4f5fb;
  --background: #ffffff;
  --background-alt: #f3f1fd;
  /* text */
  --text-main: #1b2040;
  --text-bright: #0b1026;
  --text-muted: #5b6290;
  --links: #5a2ee0;
  /* buttons: violet into orchid */
  --primary: #6236ef;
  --primary-2: #a93bd6;
  --on-primary: #fff;
  --focus: rgba(124, 77, 255, 0.4);
  --glow: 0 6px 22px -8px rgba(124, 77, 255, 0.65);
  /* lines */
  --border: #e0e2f2;
  --line-strong: #8a90b8;
  --line-tint: rgba(124, 77, 255, 0.07);
  /* status */
  --success: #08806f;
  --success-tint: rgba(20, 216, 196, 0.12);
  --warning: #a55800;
  --danger: #d1195a;
  --danger-hover: #a8124a;
  --on-danger: #fff;
  --danger-tint: rgba(255, 61, 154, 0.09);
  /* misc Water variables */
  --button-base: #ecebf8;
  --button-hover: #dedcf3;
  --form-text: var(--text-main);
  --form-placeholder: #7d84ad;
  --selection: #dcd2ff;
  --highlight: #ffe1f0;
  --code: #a3207a;
  --scrollbar-thumb: #c8cbe4;
  --scrollbar-thumb-hover: #a9addb;
  --radius: 8px;
  --heading-font: 'Sora Variable', system-ui, sans-serif;
}
/* Dark variant: the pane drops into deep indigo; the menu stays as it is.
   Must come after the light block, since Water's dark block has the same
   specificity. */
@media (prefers-color-scheme: dark) {
  :root {
    --background-body: #0d1230;
    --background: #141a3d;
    --background-alt: #18204a;
    --text-main: #e3e7ff;
    --text-bright: #ffffff;
    --text-muted: #a3abd9;
    --links: #b9a3ff;
    --primary: #7448ff;
    --primary-2: #c03cb5;
    --focus: rgba(185, 163, 255, 0.5);
    --glow: 0 6px 24px -6px rgba(124, 77, 255, 0.8);
    --border: #2a3366;
    --line-strong: #5d68a6;
    --line-tint: rgba(124, 77, 255, 0.12);
    --success: #2ee6cf;
    --success-tint: rgba(46, 230, 207, 0.1);
    --warning: #ffb35c;
    --danger: #ff6b9d;
    --danger-hover: #ff96ba;
    --on-danger: #0b1026;
    --danger-tint: rgba(255, 107, 157, 0.1);
    --button-base: #212a5a;
    --button-hover: #2b356c;
    --form-placeholder: #7880b3;
    --selection: #3b2c7a;
    --highlight: #5a1f45;
    --code: #ff9ad0;
    --scrollbar-thumb: #2f3870;
    --scrollbar-thumb-hover: #3d478a;
  }
}

/* ---- page and shell ---- */
html { background: var(--background-body); }
body { max-width: none; margin: 0; padding: 0; line-height: 1.5;
       background: var(--background-body); color: var(--text-main); }
@media (min-width: 701px) { body { font-size: 15px; } }  /* phones keep 16px: smaller inputs make iOS zoom */
.shell { display: grid; grid-template-columns: 272px minmax(0, 1fr); min-height: 100vh; }

h1, h2, h3 { font-family: var(--heading-font); color: var(--text-bright); letter-spacing: -0.01em; }
h1, h2 { margin: 8px 0 14px; }
h2 { font-size: 1.65em; font-weight: 700; }
h3 { font-size: 1.1em; font-weight: 600; margin: 22px 0 8px; }
p { margin: 6px 0; }
hr { border: 0; border-top: 1px solid var(--border); }
a { color: var(--links); }
::selection { background: var(--selection); }
:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; }
[tabindex="-1"]:focus { outline: none; }

/* Gradient text for page titles and the welcome heading. */
.pane-inner > h2:first-of-type, .aurora-text, .error-code {
  background: var(--aurora); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.pane-inner > h2:first-of-type { display: inline-block; }

/* ---- the menu column ---- */
.rail {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  color: var(--rail-text); color-scheme: dark;
  background:
    radial-gradient(120% 50% at 0% 0%, rgba(20, 216, 196, 0.16), transparent 60%),
    radial-gradient(110% 45% at 100% 100%, rgba(255, 61, 154, 0.16), transparent 60%),
    radial-gradient(90% 40% at 100% 45%, rgba(124, 77, 255, 0.14), transparent 70%),
    var(--rail-bg);
  border-right: 1px solid rgba(124, 77, 255, 0.25);
  scrollbar-color: #2f3870 transparent;
}
.rail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px;
             padding: 20px 18px 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fff;
         font-family: var(--heading-font); font-weight: 700; font-size: 1.2em; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 32px; height: 32px; filter: drop-shadow(0 0 10px rgba(124, 77, 255, 0.6)); }
.rail-toggle { display: none; }

/* the links scroll; the brand and the user's name stay put */
.rail-menu { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 10px 16px; }
.rail-menu ul { list-style: none; margin: 0; padding: 0; }
/* Water draws <details> as a grey box with a full-width summary bar; the menu wants neither. */
.rail details { display: block; background: none; padding: 0; margin: 0; border-radius: 0; overflow: visible; }
.rail details > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
                          margin: 0; background: none; border-radius: var(--radius); user-select: none; }
.rail summary:hover, .rail summary:focus { text-decoration: none; }
.rail summary::-webkit-details-marker { display: none; }
/* chevron after the label, turned down when open */
.rail summary::after { content: ""; width: 6px; height: 6px; margin-left: auto; margin-right: 4px;
                       border-right: 1.6px solid currentColor; border-bottom: 1.6px solid currentColor;
                       transform: rotate(-45deg); transition: transform 0.18s ease; opacity: 0.7; }
.rail details[open] > summary::after { transform: rotate(45deg); }
.rail summary:hover { background: var(--rail-hover); }

details.group { margin-top: 4px; }
details.group > summary { padding: 9px 10px; font-family: var(--heading-font); font-weight: 600;
                          font-size: 0.95em; color: #fff; }
details.group > summary .icon { width: 19px; height: 19px; flex: none; fill: none; stroke: var(--teal);
                                stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
details.group[data-id="domains"] > summary .icon, details.group[data-id="admin"] > summary .icon { stroke: #a98bff; }
details.group[data-id="mail"] > summary .icon, details.group[data-id="help"] > summary .icon { stroke: #ff7ab8; }
details.group > ul { margin: 2px 0 8px 19px; padding-left: 10px; border-left: 1px solid var(--rail-line); }

/* direct-link group (webmail): styled like a group header, but a plain link */
.rail a.group-link { display: flex; align-items: center; gap: 10px; margin-top: 4px; padding: 9px 10px;
  font-family: var(--heading-font); font-weight: 600; font-size: 0.95em; color: #fff; border-radius: var(--radius); }
.rail a.group-link .icon { width: 19px; height: 19px; flex: none; fill: none; stroke: #6fe3ff;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.rail a.group-link .ext { width: 13px; height: 13px; margin-left: auto; fill: none; stroke: var(--rail-muted);
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rail a.group-link:hover { background: var(--rail-hover); color: #fff; }
.rail a.group-link:hover .ext { stroke: #fff; }

.rail a { display: block; padding: 6px 10px; border-radius: 6px; color: var(--rail-text);
          text-decoration: none; font-size: 0.93em; position: relative; overflow-wrap: anywhere; }
.rail a:hover { background: var(--rail-hover); color: #fff; text-decoration: none; }
.rail a[aria-current="page"] { color: #fff; font-weight: 600;
  background: linear-gradient(90deg, rgba(124, 77, 255, 0.38), rgba(255, 61, 154, 0.12)); }
.rail a[aria-current="page"]::before { content: ""; position: absolute; left: -11px; top: 6px; bottom: 6px;
  width: 3px; border-radius: 3px; background: var(--aurora); box-shadow: 0 0 10px rgba(124, 77, 255, 0.9); }

/* one sub-group per domain */
li.sub > details > summary { padding: 6px 10px; font-size: 0.93em; color: var(--rail-text); overflow-wrap: anywhere; }
li.sub > details > summary::before { content: ""; width: 7px; height: 7px; flex: none; border-radius: 50%;
                                      background: var(--rail-muted); }
li.sub > details[open] > summary { color: #fff; }
li.sub > details[open] > summary::before { background: var(--aurora); box-shadow: 0 0 8px rgba(20, 216, 196, 0.8); }
li.sub ul { margin: 0 0 4px 13px; padding-left: 10px; border-left: 1px dashed var(--rail-line); }
.rail-filter { width: 100%; box-sizing: border-box; margin: 4px 0 6px; background: rgba(255, 255, 255, 0.06);
               color: #fff; border: 1px solid var(--rail-line); }
.rail-filter::placeholder { color: var(--rail-muted); }

.rail-foot { padding: 14px 18px 18px; border-top: 1px solid var(--rail-line);
             display: flex; flex-direction: column; align-items: stretch; gap: 12px; }
.who { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.who-email { font-size: 0.85em; color: #fff; overflow-wrap: anywhere; }
.role-pill { align-self: flex-start; font-size: 0.72em; text-transform: uppercase; letter-spacing: 0.08em;
             padding: 1px 8px; border-radius: 99px; color: var(--rail-bg); background: var(--aurora); font-weight: 700; }
.rail a.logout { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 12px;
                 border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 8px; font-weight: 600; }
.rail a.logout .icon { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2;
                       stroke-linecap: round; stroke-linejoin: round; }
.rail a.logout:hover { border-color: var(--magenta); background: rgba(255, 61, 154, 0.15); color: #fff; }

/* ---- help pages: the three pages as tabs ---- */
.help-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 18px; }
.help-tabs a { padding: 4px 14px; border: 1px solid var(--border); border-radius: 99px; text-decoration: none; }
.help-tabs a[aria-current="page"] { background: var(--aurora); color: #0b1026; border-color: transparent; font-weight: 600; }

/* ---- help: the database page ---- */
.muted { color: var(--text-muted); }
.db-toc li { margin-bottom: 6px; }
.db-toc small { display: block; color: var(--text-muted); }
.db-section { margin-top: 28px; padding-top: 4px; border-top: 1px solid var(--border); }
.db-object { margin: 18px 0 26px; scroll-margin-top: 12px; }
.db-object h4 { margin-bottom: 4px; overflow-wrap: anywhere; }
.db-object h4 small, .db-meta { color: var(--text-muted); font-weight: normal; }
.db-meta { font-size: 0.88em; }
.db-label { margin: 10px 0 2px; font-weight: 600; font-size: 0.9em; }
.db-list { margin-top: 0; }
.db-list li, .db-columns td { overflow-wrap: anywhere; }
.db-function { margin: 12px 0 18px; }
pre.sql { font-size: 0.8em; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 30em; overflow: auto; }

/* ---- the pane ---- */
.pane { position: relative; min-width: 0;
        background: radial-gradient(60% 300px at 100% 0%, var(--line-tint), transparent 70%); }
.pane::before { content: ""; display: block; height: 4px; background: var(--aurora); }
.pane-inner { max-width: 1180px; padding: 26px 36px 56px; }
/* shimmering bar while the next page loads (assets/app.js) */
.pane-progress { position: absolute; top: 0; left: 0; right: 0; height: 4px; opacity: 0;
                 background: linear-gradient(90deg, transparent, #fff 50%, transparent) 0 0 / 40% 100% no-repeat;
                 transition: opacity 0.15s; pointer-events: none; }
.is-loading .pane-progress { opacity: 0.9; animation: shimmer 0.9s linear infinite; }
.is-loading .pane-inner { opacity: 0.6; transition: opacity 0.2s 0.15s; }
@keyframes shimmer { from { background-position: -40% 0; } to { background-position: 140% 0; } }
@media (prefers-reduced-motion: reduce) {
  .is-loading .pane-progress { animation: none; }
  .rail summary::after { transition: none; }
}

/* ---- panels and messages ---- */
article { background: var(--background); border: 1px solid var(--border); border-radius: var(--radius);
          padding: 12px 16px; margin: 14px 0; box-shadow: 0 1px 2px rgba(11, 16, 38, 0.04); }
article > :first-child { margin-top: 0; }
article > :last-child { margin-bottom: 0; }
article h2 { font-size: 1.3em; }
/* Flash banners: coloured left edge so the type reads at a glance. */
.flash { padding: 10px 14px; border: 1px solid; border-left-width: 5px; }
.flash-success { background: var(--success-tint); border-color: var(--success); }
.flash-error { background: var(--danger-tint); border-color: var(--danger); }
.flash-error strong, .flash-error h3 { color: var(--danger); }
.flash-info { background: var(--line-tint); border-color: var(--violet); }
.badge-suspended { color: var(--danger); font-weight: 600; }

/* ---- logged out: login card, then the welcome ---- */
.login-wrap { max-width: 440px; margin: 18px 0 8px; }
.login-card, .login-wrap > article { padding: 22px 26px; border: 1.5px solid transparent;
  background: linear-gradient(var(--background), var(--background)) padding-box, var(--aurora) border-box;
  box-shadow: 0 18px 50px -24px rgba(124, 77, 255, 0.55); }
.login-wrap button[type=submit] { width: 100%; margin-top: 6px; padding: 9px 14px; }
.welcome { margin-top: 40px; max-width: 920px; }
.welcome h2 { font-size: 2em; margin-bottom: 8px; }
.lede { font-size: 1.1em; color: var(--text-muted); max-width: 62ch; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin: 22px 0 14px; }
.feature { position: relative; padding: 16px 16px 14px; border-radius: var(--radius); overflow: hidden;
           background: var(--background); border: 1px solid var(--border); }
.feature::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--aurora); }
.feature:nth-child(2)::before { background: linear-gradient(90deg, var(--violet), var(--magenta)); }
.feature:nth-child(3)::before { background: linear-gradient(90deg, var(--magenta), var(--teal)); }
.feature:nth-child(4)::before { background: linear-gradient(90deg, var(--teal), var(--violet)); }
.feature h3 { margin: 0 0 6px; }
.feature p { margin: 0; color: var(--text-muted); font-size: 0.95em; }

/* ---- error pages and help guides ---- */
.error-page { padding: 30px 0; }
.error-code { font-family: var(--heading-font); font-size: 4.5em; font-weight: 800; line-height: 1; margin: 0; display: inline-block; }
.prose { max-width: 800px; line-height: 1.65; }
.prose h1 { font-size: 1.9em; background: var(--aurora); -webkit-background-clip: text; background-clip: text;
            color: transparent; display: inline-block; }
.prose h2 { font-size: 1.35em; margin-top: 28px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.crumb { font-size: 0.88em; color: var(--text-muted); margin: 0 0 4px; }

/* ---- forms ---- */
label { display: block; margin-bottom: 8px; }
label > input:not([type=checkbox]):not([type=radio]), label > select {
  width: 100%; box-sizing: border-box; margin-top: 3px; }
label > input[type=checkbox] { display: inline; margin: 0 6px 0 0; vertical-align: middle; accent-color: var(--violet); }
label small { display: block; color: var(--text-muted); }
input, select, textarea { padding: 7px 9px; margin-bottom: 6px; background: var(--background);
  color: var(--form-text); border: 1px solid var(--line-strong); border-radius: 6px; }
input:focus, select:focus, textarea:focus { border-color: var(--violet); box-shadow: 0 0 0 3px var(--focus); outline: none; }
::placeholder { color: var(--form-placeholder); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 12px; }
.grid > button { width: 100%; margin: 0 0 6px; }
form.inline { display: inline; margin: 0; }

/* ---- buttons: gradient by default, class="outline" for secondary,
        class="danger" (with outline) for destructive actions ---- */
button, [role=button] {
  display: inline-block; font: inherit; font-weight: 600; line-height: 1.3; text-decoration: none; cursor: pointer;
  padding: 7px 15px; margin: 0 4px 4px 0; border-radius: 6px; color: var(--on-primary);
  border: 1px solid transparent; background: linear-gradient(135deg, var(--primary), var(--primary-2));
  transition: box-shadow 0.15s, filter 0.15s, background-color 0.15s;
}
button:hover, [role=button]:hover { filter: brightness(1.08); box-shadow: var(--glow);
  color: var(--on-primary); text-decoration: none; }
.outline { background: transparent; color: var(--links); border-color: var(--links); }
.outline:hover { background: var(--line-tint); color: var(--links); box-shadow: none; }
.danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
.danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); color: var(--on-danger);
                box-shadow: 0 6px 22px -8px rgba(255, 61, 154, 0.7); }
.danger.outline { background: transparent; color: var(--danger); border-color: var(--danger); }
.danger.outline:hover { background: var(--danger-tint); color: var(--danger); }
/* Water colours buttons in striped rows with a more specific selector; match it. */
tbody tr:nth-child(even) button { background: linear-gradient(135deg, var(--primary), var(--primary-2)); }
tbody tr:nth-child(even) button.outline, tbody tr:nth-child(even) button.danger.outline { background: transparent; }
tbody tr:nth-child(even) button.danger:not(.outline) { background: var(--danger); }

/* ---- mail trace: status words and the event list in each message's Details ---- */
.status-delivered, .status-completed { color: var(--success); font-weight: 600; }
.status-failed, .status-partly, .status-rejected { color: var(--danger); font-weight: 600; }
.status-deferred { color: var(--warning); font-weight: 600; }
ul.trace-events { margin: 0 0 6px; padding-left: 18px; }
ul.trace-events li { margin-bottom: 4px; overflow-wrap: anywhere; }
table.trace td { overflow-wrap: anywhere; }
pre.trace-raw { font-size: 0.8em; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 20em; overflow: auto; }

/* ---- tables ---- */
table { border-collapse: collapse; }
table.mailadmin { width: 100%; table-layout: auto; font-size: 0.93em; background: var(--background);
                  border: 1px solid var(--border); border-radius: var(--radius); border-collapse: separate;
                  border-spacing: 0; overflow: hidden; }
table.mailadmin th, table.mailadmin td { padding: 7px 10px; vertical-align: middle;
                                         border-bottom: 1px solid var(--border); }
table.mailadmin tbody tr:last-child td { border-bottom: 0; }
table.mailadmin thead th { color: var(--text-bright); font-family: var(--heading-font); font-weight: 600;
                           font-size: 0.92em; background: var(--line-tint);
                           border-bottom: 2px solid rgba(124, 77, 255, 0.55); }
table.mailadmin tbody tr:nth-child(even) { background: var(--background-alt); }
table.mailadmin tbody tr:hover { background: var(--line-tint); }
table.mailadmin td.actions { text-align: right; }
td.actions button, td.actions [role=button] { padding: 4px 10px; font-size: 0.9em; }

/* Expandable row forms (Edit, Recovery, Reset password): the summary is the button. */
td.actions details { display: inline-block; vertical-align: top; background: none;
                     padding: 0; margin: 0 4px 4px 0; overflow: visible; }
td.actions details > summary { display: inline-block; list-style: none; margin: 0; }
td.actions details > summary::-webkit-details-marker { display: none; }
td.actions details[open] { display: block; text-align: left; padding: 8px;
                           background: var(--background-alt); border: 1px solid var(--border);
                           border-radius: var(--radius); }
td.actions details[open] > summary { margin-bottom: 6px; }
td.actions details input:not([type=checkbox]) { width: 100%; box-sizing: border-box; }

/* ---- narrow screens: the menu sits on top and folds behind a button ---- */
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; border-right: 0; border-bottom: 1px solid rgba(124, 77, 255, 0.35); }
  .rail-head { padding: 12px 16px; }
  .rail-menu { overflow: visible; }
  .rail.has-toggle .rail-toggle { display: inline-block; margin: 0; padding: 5px 14px; font-size: 0.9em; }
  .rail.has-toggle:not(.menu-open) .rail-menu { display: none; }
  /* the user and log out stay visible, on one line */
  .rail-foot { flex-direction: row; align-items: center; justify-content: space-between; padding: 10px 16px; }
  .rail a.logout { flex: none; padding: 6px 12px; }
  .pane-inner { padding: 18px 16px 40px; }
  .welcome { margin-top: 28px; }
}

/* Narrow screens: each table row becomes a card; cells show their data-label. */
@media (max-width: 700px) {
  table.mailadmin, table.mailadmin tbody, table.mailadmin tr, table.mailadmin td {
    display: block; width: 100%; box-sizing: border-box; }
  table.mailadmin { border: 0; background: none; overflow: visible; }
  table.mailadmin thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.mailadmin tr, table.mailadmin tbody tr:nth-child(even) {
    background: var(--background); border: 1px solid var(--border); border-left: 4px solid var(--violet);
    border-radius: var(--radius); padding: 8px 12px; margin-bottom: 10px; }
  table.mailadmin td { padding: 3px 0; border-bottom: 0; }
  table.mailadmin td[data-label] { position: relative; padding-left: 7.5em; min-height: 1.4em; }
  table.mailadmin td[data-label]::before { content: attr(data-label); position: absolute; left: 0;
                                            width: 7em; font-weight: 600; color: var(--text-muted); }
  table.mailadmin td.actions { text-align: left; padding-top: 6px; }
  td.actions button, td.actions [role=button] { padding: 8px 12px; font-size: 1em; }  /* tap size */
}
