/* mini-webmail (Rick Gift Shop): responsive, no third-party assets, no inline styles
   (CSP style-src 'self'). Brand tokens taken from rickgift.shop's own design system.
   v2.1 (owner feedback after live use): LIGHT theme only, like the shop site itself -
   no prefers-color-scheme override. A dark OS theme must not turn the UI dark (it made
   plain white HTML mail look wrong against a dark surrounding chrome); color-scheme:
   light (here and in the <meta> tag in base.html) also stops browsers auto-darkening
   form controls (inputs, buttons) on a dark-mode system. */
:root {
  color-scheme: light;
  --brand: hsl(184 45% 32%);
  --brand-soft: hsl(184 45% 96%);
  --ink: hsl(210 15% 20%);
  --muted: hsl(210 10% 45%);
  --bg: #f4f5f7;
  --card: #fff;
  --line: #dde1e6;
  --danger: #b3261e;
  --danger-soft: #fdecea;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, .button { font: inherit; font-size: .9rem; padding: .35rem .75rem; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--ink); cursor: pointer; display: inline-block; }
button:hover, .button:hover { background: var(--brand-soft); text-decoration: none; }
.danger { color: var(--danger); border-color: #e7b4b0; }
form { display: inline; margin: 0; }

/* Logo mark: rounded square, brand fill, white "R" (favicon mirrors this design). */
.logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 68px; height: 68px; border-radius: 18px;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 2rem;
  box-shadow: 0 10px 30px hsl(184 45% 32% / .25);
  flex-shrink: 0;
}
.logo--sm { width: 32px; height: 32px; border-radius: 9px; font-size: 1rem; box-shadow: none; }

/* Shell: sidebar + content. Anonymous pages (login) get no sidebar, just centred content. */
.shell { display: flex; min-height: 100vh; align-items: stretch; }
.shell--anon { display: block; min-height: 100vh; }
.sidebar {
  width: 240px; flex-shrink: 0; display: flex; flex-direction: column; gap: 1rem;
  padding: 1.1rem 1rem; background: var(--card); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .6rem; color: var(--ink); }
.brand-name { font-weight: 700; }
.who { margin: 0; color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.nav { display: flex; flex-direction: column; gap: .2rem; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem .7rem; border-radius: 8px; color: var(--ink); }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.badge { min-width: 1.4em; padding: 0 .35em; border-radius: 999px; background: var(--brand); color: #fff; font-size: .75rem; line-height: 1.4em; text-align: center; }
.badge:empty { display: none; }
.logout { margin-top: auto; }
.logout button { width: 100%; }

.content { flex: 1; min-width: 0; padding: 1.25rem; }
.content--anon, .shell--anon .content { max-width: 480px; margin: 8vh auto 0; padding: 1rem; }
main.content { display: block; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.25rem; }
h1 { font-size: 1.25rem; margin: 0 0 .75rem; overflow-wrap: anywhere; }
.bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; }
.bar h1 { margin: 0; }
.count { color: var(--muted); font-weight: 400; font-size: 1rem; }
.alert { background: var(--danger-soft); color: var(--danger); padding: .6rem .8rem; border-radius: 6px; }
.note { color: var(--muted); font-size: .9rem; }
.empty { color: var(--muted); }

/* Login */
.login { max-width: 380px; margin: 0 auto; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.login-brand .brand-name { color: var(--muted); font-size: .95rem; }
.login h1 { text-align: center; }
.login form { display: flex; flex-direction: column; gap: .4rem; }
.login input { font: inherit; padding: .55rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--ink); }
.login button { margin-top: .6rem; padding: .6rem; background: var(--brand); color: #fff; border-color: var(--brand); }
/* Honeypot: hidden from sighted humans, still present in the DOM/tab order trap for bots. */
.hp { position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden; }

/* Mail view: list pane + (on message pages) a reading pane beside it. */
.mailview { display: grid; gap: 1rem; }
.mailview.reading { grid-template-columns: 320px 1fr; align-items: start; }
.list-pane { min-width: 0; }
.reading-pane { min-width: 0; }

.messages { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.messages li { display: flex; align-items: center; gap: .5rem; padding: .55rem .75rem; border-top: 1px solid var(--line); }
.messages li:first-child { border-top: 0; }
.messages li.active { background: var(--brand-soft); }
.open { flex: 1; min-width: 0; display: grid; grid-template-columns: 1fr auto; gap: 0 .75rem; color: var(--ink); }
.open span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* v2.1: subject is the primary line (bold when unread), sender name the secondary,
   muted line below it (source order: subject, then from, then the preview stub). */
.open .subject, .open .from { grid-column: 1; }
.open .from { color: var(--muted); font-size: .85rem; }
.open .meta { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
.open .preview { display: none; }
.unread .subject { font-weight: 700; color: var(--ink); }
.meta { color: var(--muted); font-size: .85rem; }
.clip { margin-right: .3rem; }
.row-actions { display: flex; gap: .3rem; flex-shrink: 0; }
.pager { display: flex; justify-content: center; gap: 1rem; margin-top: 1rem; color: var(--muted); }

.reading-pane .bar { align-items: center; }
.back { color: var(--ink); font-weight: 600; }
.headers { display: grid; grid-template-columns: max-content 1fr; gap: .2rem .8rem; margin: 0 0 1rem; }
.headers dt { color: var(--muted); }
.headers dd { margin: 0; overflow-wrap: anywhere; }
.attachments { margin: 0 0 1rem; padding-left: 1.2rem; }
.size { color: var(--muted); font-size: .85rem; }
iframe.body { width: 100%; height: 65vh; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
pre.text { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; margin: 0; }
.actions { display: flex; gap: .4rem; }
.confirm { display: flex; gap: .5rem; }

/* Wide screens: the mini list beside the reading pane shows single-line rows only. */
@media (min-width: 900px) {
  .mailview.reading .list-pane .attachments,
  .mailview.reading .list-pane .row-actions { display: none; }
}

@media (max-width: 899px) {
  /* Reading a message on a narrow screen: full width, the mini list is reached via
     the "back" link instead of being shown beside the reading pane (FR-9). */
  .mailview.reading { grid-template-columns: 1fr; }
  .mailview.reading .list-pane { display: none; }
}

@media (max-width: 640px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; padding: .6rem .75rem; gap: .6rem; }
  .brand { order: 1; }
  .who { order: 2; flex: 1 1 auto; text-align: right; }
  .nav { order: 3; flex-direction: row; width: 100%; }
  .nav a { flex: 1; justify-content: center; }
  .logout { order: 1; margin-top: 0; margin-left: auto; width: auto; }
  .logout button { width: auto; }
  .content { padding: .6rem; }
  .open { grid-template-columns: 1fr; }
  .open .meta { grid-row: auto; }
  .messages li { flex-direction: column; align-items: stretch; }
  .row-actions { justify-content: flex-end; }
}
