/* Midas Mail Monitor interface.
   The v0.7.1 visual language kept — sky blue, gold, deep navy — with the
   accessibility work that was missing: real focus states, 44px targets,
   a dark theme, and a designed state for loading, empty, offline and error. */

:root {
  --blue: #1267aa;
  --blue-strong: #0c528c;
  --brand-blue: #2593e8;
  --blue-soft: #e8f3fb;
  --gold: #f2ac19;
  --gold-soft: #fff6e0;
  --navy: #132d45;
  --navy-2: #1c4967;
  --teal: #157f79;
  --green: #12704f;
  --green-soft: #e3f6ee;
  --amber: #8a5a06;
  --amber-soft: #fdf1da;
  --red: #a52834;
  --red-soft: #fdeef0;

  --ink: #16293a;
  --ink-2: #4a6274;
  --ink-3: #6f8598;
  --line: #d6e2ec;
  --line-strong: #b9cdda;
  --surface: #ffffff;
  --surface-2: #f2f7fb;
  --ground: #f5f8fc;

  --shadow-sm: 0 1px 2px rgba(18, 52, 77, .06), 0 2px 8px -4px rgba(18, 52, 77, .18);
  --shadow: 0 2px 6px rgba(18, 52, 77, .07), 0 18px 36px -26px rgba(18, 52, 77, .5);
  --radius: 10px;
  --radius-sm: 7px;
  --focus: 0 0 0 3px rgba(27, 124, 192, .35);

  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", "Consolas", ui-monospace, "SFMono-Regular", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --blue: #56b1e6;
    --blue-strong: #7cc4f0;
    --blue-soft: #10293a;
    --gold: #f5bb45;
    --gold-soft: #33270d;
    --navy: #cfe2ee;
    --navy-2: #a9c6d8;
    --teal: #4fbfae;
    --green: #55c495;
    --green-soft: #102d23;
    --amber: #e0a94f;
    --amber-soft: #302408;
    --red: #f0838f;
    --red-soft: #33161b;

    --ink: #e6eef5;
    --ink-2: #a6bccc;
    --ink-3: #7f97a8;
    --line: #23394a;
    --line-strong: #335065;
    --surface: #12222e;
    --surface-2: #172c3a;
    --ground: #0c1821;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow: 0 2px 6px rgba(0, 0, 0, .5), 0 20px 40px -28px rgba(0, 0, 0, 1);
    --focus: 0 0 0 3px rgba(86, 177, 230, .45);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --blue: #56b1e6; --blue-strong: #7cc4f0; --blue-soft: #10293a;
  --gold: #f5bb45; --gold-soft: #33270d;
  --navy: #cfe2ee; --navy-2: #a9c6d8; --teal: #4fbfae;
  --green: #55c495; --green-soft: #102d23;
  --amber: #e0a94f; --amber-soft: #302408;
  --red: #f0838f; --red-soft: #33161b;
  --ink: #e6eef5; --ink-2: #a6bccc; --ink-3: #7f97a8;
  --line: #23394a; --line-strong: #335065;
  --surface: #12222e; --surface-2: #172c3a; --ground: #0c1821;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow: 0 2px 6px rgba(0, 0, 0, .5), 0 20px 40px -28px rgba(0, 0, 0, 1);
  --focus: 0 0 0 3px rgba(86, 177, 230, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body, #root { height: 100%; }

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

/* Text size preference, applied to the root element. */
:root[data-text="large"] body { font-size: 17px; }
:root[data-text="larger"] body { font-size: 19px; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  box-shadow: var(--focus);
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }

.noscript { padding: 24px; text-align: center; }

/* ------------------------------------------------------------------- boot */

.boot {
  height: 100%; display: grid; place-content: center; justify-items: center; gap: 16px;
  color: var(--ink-2);
}
.boot-mark {
  width: 52px; height: 52px; display: grid; place-items: center; border-radius: 14px;
  background: var(--gold); color: #12344d; font-weight: 800; letter-spacing: -.04em; font-size: 18px;
}

/* ------------------------------------------------------------------ shell */

.app { display: grid; grid-template-rows: auto 1fr; height: 100%; }

.topbar {
  display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 62px;
  background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 11px; margin-right: auto; min-width: 0; }
.brand img { width: 52px; height: 42px; object-fit: contain; background: #fff; border-radius: 7px; padding: 3px; }
.brand-text { display: grid; line-height: 1.2; }
.brand-text strong { font-size: 14px; color: var(--navy); }
.brand-text small { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }

.tabs { display: flex; gap: 2px; overflow-x: auto; }
.tabs button {
  display: flex; align-items: center; gap: 7px; min-height: 40px; padding: 0 13px;
  background: transparent; border: 0; border-radius: var(--radius-sm); cursor: pointer;
  color: var(--ink-2); font-weight: 600; font-size: 13px; white-space: nowrap;
}
.tabs button:hover { background: var(--blue-soft); color: var(--navy); }
.tabs button[aria-current="page"] { background: var(--navy); color: var(--surface); }
.tabs .badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--gold); color: #3d2b00; font-size: 11px; font-weight: 800;
  display: inline-grid; place-items: center;
}

.who { display: flex; align-items: center; gap: 10px; padding-left: 14px; border-left: 1px solid var(--line); }
.avatar {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px;
  background: linear-gradient(140deg, var(--blue), var(--teal)); color: #fff; font-weight: 800;
}
.who-text { display: grid; line-height: 1.25; }
.who-text strong { font-size: 13px; }
.who-text small { font-size: 11px; color: var(--ink-3); }

main { overflow: auto; min-height: 0; }
.page { max-width: 1360px; margin: 0 auto; padding: 24px 20px 56px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 4px 0 2px; font-size: 26px; letter-spacing: -.02em; color: var(--navy); }
.page-head p { margin: 0; color: var(--ink-2); font-size: 13px; }
.eyebrow { font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--blue-strong); }

/* ---------------------------------------------------------------- controls */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-weight: 650; font-size: 13px; text-decoration: none;
}
.btn:hover:not(:disabled) { border-color: var(--blue); color: var(--blue-strong); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--blue-strong); border-color: var(--blue-strong); color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); color: #fff; }
.btn.danger { background: var(--red-soft); border-color: transparent; color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 12px; }
.btn.block { width: 100%; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > label { font-size: 12px; font-weight: 700; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--ink-3); font-weight: 400; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], select, textarea {
  width: 100%; min-height: 40px; padding: 9px 11px; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
}
textarea { min-height: 76px; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: var(--blue); }
.checkbox { display: flex; align-items: flex-start; gap: 10px; padding: 9px 0; cursor: pointer; }
.checkbox input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--blue-strong); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 180px; }
.row > .shrink { flex: 0 0 auto; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: var(--radius-sm); }
.segmented button {
  min-height: 32px; padding: 0 12px; border: 0; border-radius: 5px; cursor: pointer;
  background: transparent; color: var(--ink-2); font-size: 12px; font-weight: 700;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--navy); box-shadow: var(--shadow-sm); }

/* ------------------------------------------------------------------ cards */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); }
.card + .card { margin-top: 14px; }
.card h2 { margin: 0 0 3px; font-size: 16px; color: var(--navy); }
.card h3 { margin: 0 0 3px; font-size: 14px; color: var(--navy); }
.card .sub { margin: 0 0 14px; font-size: 12px; color: var(--ink-2); }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.four { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.stat { display: grid; gap: 4px; }
.stat .value { font-size: 30px; font-weight: 700; letter-spacing: -.03em; color: var(--navy); font-variant-numeric: tabular-nums; }
.stat .label { font-size: 11px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-3); }
.stat .note { font-size: 12px; color: var(--ink-2); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 800; white-space: nowrap;
}
.pill.ok { background: var(--green-soft); color: var(--green); }
.pill.warn { background: var(--amber-soft); color: var(--amber); }
.pill.bad { background: var(--red-soft); color: var(--red); }
.pill.info { background: var(--blue-soft); color: var(--blue-strong); }
.pill.mute { background: var(--surface-2); color: var(--ink-3); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.brief {
  display: flex; gap: 16px; align-items: flex-start; justify-content: space-between;
  padding: 18px 20px; border-radius: var(--radius); color: #eaf3f9;
  background: linear-gradient(135deg, #12344d, #1c4967);
}
.brief p { margin: 6px 0 0; font-size: 13px; line-height: 1.6; }
.brief .eyebrow { color: #82cdf7; }

.bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.bar span { display: block; }
.bar .complete { background: var(--green); }
.bar .partial { background: var(--blue); }
.bar .pending { background: var(--gold); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 50%; }

table { width: 100%; border-collapse: collapse; }
.table-wrap { overflow-x: auto; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: top; }
th { font-size: 10px; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3); background: var(--surface-2); position: sticky; top: 0; }
td small { display: block; color: var(--ink-3); font-size: 11px; }
tbody tr:hover { background: var(--surface-2); }

.empty, .loading, .error-state {
  display: grid; place-items: center; gap: 8px; padding: 34px 18px; text-align: center;
  color: var(--ink-2); font-size: 13px;
}
.error-state { color: var(--red); }
.notice { padding: 11px 13px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 12px; }
.notice.error { background: var(--red-soft); color: var(--red); }
.notice.ok { background: var(--green-soft); color: var(--green); }
.notice.warn { background: var(--amber-soft); color: var(--amber); }
.notice.info { background: var(--blue-soft); color: var(--blue-strong); }

/* ------------------------------------------------------------------- mail */

.mail { display: grid; grid-template-columns: 250px minmax(320px, 420px) 1fr; height: calc(100vh - 62px); }
.mail > * { min-height: 0; overflow: auto; }
.rail { background: var(--surface-2); border-right: 1px solid var(--line); padding: 16px 10px 30px; }
.rail h2 { margin: 0 0 12px; padding: 0 8px; font-size: 15px; color: var(--navy); }
.rail .country { margin-top: 14px; }
.rail .country h3 { margin: 0 8px 5px; font-size: 10px; letter-spacing: .11em; text-transform: uppercase; color: var(--ink-3); }
.rail button {
  display: grid; gap: 2px; width: 100%; text-align: left; min-height: 44px; padding: 8px 10px;
  border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; cursor: pointer;
}
.rail button:hover { background: var(--surface); }
.rail button[aria-current="true"] { background: var(--surface); border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.rail button strong { font-size: 13px; color: var(--ink); }
.rail button small { font-size: 11px; color: var(--ink-3); }
.rail .flags { display: flex; gap: 4px; margin-top: 3px; }

.list { border-right: 1px solid var(--line); background: var(--surface); }
.list-head { position: sticky; top: 0; z-index: 2; background: var(--surface); border-bottom: 1px solid var(--line); padding: 14px 16px; display: grid; gap: 10px; }
.list-head h2 { margin: 0; font-size: 17px; color: var(--navy); }
.list-head .meta { font-size: 12px; color: var(--ink-2); }
.msg {
  display: grid; gap: 3px; width: 100%; text-align: left; padding: 12px 16px; cursor: pointer;
  background: transparent; border: 0; border-bottom: 1px solid var(--line); border-left: 3px solid transparent;
}
.msg:hover { background: var(--surface-2); }
.msg[aria-current="true"] { background: var(--blue-soft); border-left-color: var(--blue); }
.msg.unread { border-left-color: var(--gold); }
.msg .top { display: flex; justify-content: space-between; gap: 10px; }
.msg strong { font-size: 13px; }
.msg.unread strong { font-weight: 800; }
.msg time { font-size: 11px; color: var(--ink-3); white-space: nowrap; }
.msg .subject { font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .from { font-size: 11px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.reader { background: var(--surface); display: grid; grid-template-rows: auto 1fr; }
.reader-head { padding: 20px 24px 16px; border-bottom: 1px solid var(--line); }
.reader-head h2 { margin: 0 0 10px; font-size: 20px; line-height: 1.35; color: var(--navy); }
.reader-meta { display: grid; gap: 3px; font-size: 12px; color: var(--ink-2); }
.reader-body { padding: 0; overflow: auto; }
.reader-body pre { margin: 0; padding: 22px 24px; white-space: pre-wrap; word-wrap: break-word; font-family: var(--font); font-size: 14px; line-height: 1.7; }
.reader iframe { width: 100%; height: 100%; min-height: 420px; border: 0; background: #fff; }
.attachments { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 24px; border-top: 1px solid var(--line); background: var(--surface-2); }
.attachment { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font-size: 12px; background: var(--surface); }
.auth-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.checkbar { padding: 14px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); display: grid; gap: 10px; }

/* ------------------------------------------------------------------ login */

.auth-screen {
  min-height: 100%; display: grid; place-items: center; padding: 28px;
  background: linear-gradient(140deg, #0d3552 0%, #14648f 55%, #2296dd 100%);
}
.auth-card {
  width: min(880px, 100%); display: grid; grid-template-columns: 1fr 1fr; overflow: hidden;
  border-radius: 20px; background: var(--surface); box-shadow: 0 30px 70px rgba(4, 30, 48, .35);
}
.auth-story { padding: 44px 40px; background: linear-gradient(160deg, #12344d, #17567c); color: #fff; display: grid; align-content: center; gap: 14px; }
.auth-story h2 { margin: 0; font-size: 27px; line-height: 1.2; letter-spacing: -.03em; }
.auth-story p { margin: 0; color: #c6dced; font-size: 13px; line-height: 1.65; }
.auth-story .mark { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 13px; background: var(--gold); color: #12344d; font-weight: 800; }
.auth-story .trust { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #dcecf7; margin-top: 10px; }
.auth-story .trust i { width: 8px; height: 8px; border-radius: 50%; background: #4fd6a8; }
.auth-form { padding: 40px 38px; display: grid; align-content: center; }
.auth-form h1 { margin: 6px 0 4px; font-size: 24px; color: var(--navy); }
.auth-form > p { margin: 0 0 18px; color: var(--ink-2); font-size: 13px; }
.auth-note { margin-top: 16px; text-align: center; font-size: 11px; color: var(--ink-3); }

.secret-key {
  font-family: var(--mono); font-size: 15px; letter-spacing: .06em; word-break: break-all;
  padding: 12px 14px; background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: var(--radius-sm);
}
.qr { display: grid; place-items: center; padding: 14px; background: #fff; border-radius: var(--radius-sm); border: 1px solid var(--line); }
.qr svg { width: 190px; height: 190px; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; font-family: var(--mono); font-size: 14px; }
.codes span { padding: 7px 10px; background: var(--surface-2); border-radius: 5px; text-align: center; }

/* ----------------------------------------------------------------- toasts */

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--line-strong); box-shadow: var(--shadow); font-size: 13px; }
.toast.ok { border-left: 4px solid var(--green); }
.toast.error { border-left: 4px solid var(--red); }
.toast.info { border-left: 4px solid var(--blue); }

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

.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--ink-3); }
.stack { display: grid; gap: 12px; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
details.disclosure { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; }
details.disclosure summary { cursor: pointer; font-weight: 650; font-size: 13px; }
.list-rows { display: grid; }
.list-row { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.list-row:first-child { border-top: 0; }
.list-row > .grow { flex: 1 1 220px; min-width: 0; }
.list-row strong { font-size: 13px; }
.list-row small { display: block; color: var(--ink-3); font-size: 11px; overflow-wrap: anywhere; }

.health-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.health-row:first-child { border-top: 0; }
.health-row .grow { flex: 1; }
.health-row strong { display: block; font-size: 13px; }
.health-row small { color: var(--ink-2); font-size: 12px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(8, 26, 38, .55); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { width: min(560px, 100%); max-height: 86vh; overflow: auto; background: var(--surface); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 4px; font-size: 18px; color: var(--navy); }
.modal .sub { margin: 0 0 16px; font-size: 13px; color: var(--ink-2); }

@media (max-width: 1100px) {
  .mail { grid-template-columns: 210px minmax(280px, 1fr); }
  .mail .reader { display: none; }
  .mail.reading { grid-template-columns: 1fr; }
  .mail.reading .rail, .mail.reading .list { display: none; }
  .mail.reading .reader { display: grid; }
}
@media (max-width: 780px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 14px; gap: 10px; }
  .tabs { order: 3; width: 100%; }
  .auth-card { grid-template-columns: 1fr; }
  .auth-story { display: none; }
  .mail { grid-template-columns: 1fr; height: auto; }
  .mail .rail { border-right: 0; border-bottom: 1px solid var(--line); }
  .page { padding: 16px 14px 40px; }
}
