/* ============================================================================
   Mittera Webmail — "The Writing Desk"
   A calm, editorial mail interface for CoParentPilot. Warm paper, ink text,
   evergreen accent, terracotta for unread/actions. Fraunces (display) + IBM Plex
   Sans (UI). Fonts are loaded in partials/styles.html.
   ========================================================================== */

:root {
  /* paper & ink */
  --paper:        #f4eee1;
  --paper-2:      #efe7d6;
  --card:         #fffdf7;
  --ink:          #21271f;
  --ink-soft:     #51584c;
  --ink-faint:    #8a8e80;
  --line:         #e4dcc7;
  --line-strong:  #d6cbb0;

  /* accents */
  --evergreen:    #2f5d50;
  --evergreen-dk: #244a40;
  --evergreen-tint:#e7efe9;
  --terracotta:   #bd5638;
  --terracotta-dk:#a3472c;
  --terracotta-tint:#f6e6dd;

  /* status */
  --ok:    #3a7a5b;  --ok-bg:#e3f0e6;
  --err:   #b23a2a;  --err-bg:#f7e3df;
  --info:  #2f5d50;  --info-bg:#e7efe9;

  /* type */
  --display: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(33,39,31,.05), 0 8px 24px -12px rgba(33,39,31,.18);
  --shadow-lg: 0 24px 60px -28px rgba(33,39,31,.38);
  --topbar-h: 60px;
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background-color: var(--paper);
  /* soft paper depth */
  background-image:
    radial-gradient(120% 80% at 100% 0%, rgba(47,93,80,.06), transparent 60%),
    radial-gradient(120% 90% at 0% 100%, rgba(189,86,56,.05), transparent 55%);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--evergreen-dk); text-decoration: none; }
a:hover { color: var(--terracotta-dk); }

::selection { background: var(--evergreen); color: #fff; }

/* ---- top bar -------------------------------------------------------------- */
.header {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; z-index: 50;
  background: rgba(255,253,247,.85);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand .mark {
  font-family: var(--display); font-weight: 600; font-size: 22px;
  letter-spacing: -.02em; color: var(--ink);
}
.brand .mark em { color: var(--evergreen); font-style: italic; }
.brand .tag {
  font-size: 11px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--ink-faint);
}
.header .who { display: flex; align-items: center; gap: 14px; color: var(--ink-soft); font-size: 13px; }
.header .who .me { display: inline-flex; align-items: center; gap: 8px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--evergreen); color: #fff;
  display: grid; place-items: center; font-weight: 600; font-size: 13px;
  font-family: var(--display);
}
.logout {
  font-size: 12px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink-soft); border: 1px solid var(--line-strong);
  padding: 6px 12px; border-radius: 999px; transition: .15s;
}
.logout:hover { background: var(--terracotta-tint); border-color: var(--terracotta); color: var(--terracotta-dk); }

/* ---- layout shell --------------------------------------------------------- */
.shell { display: flex; padding-top: var(--topbar-h); min-height: 100vh; }

.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; width: var(--sidebar-w);
  padding: 26px 18px; overflow-y: auto;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,253,247,.6), transparent 30%);
}
.compose-btn {
  display: flex; align-items: center; justify-content: center; gap: 9px; width: 100%;
  font-family: var(--sans); font-weight: 600; font-size: 14px;
  color: #fff; background: var(--evergreen);
  border: 0; border-radius: 999px; padding: 12px 16px; cursor: pointer;
  box-shadow: 0 6px 16px -8px rgba(47,93,80,.7); transition: .18s;
}
.compose-btn:hover { background: var(--evergreen-dk); transform: translateY(-1px); }
.compose-btn svg { width: 16px; height: 16px; }

.folders-label {
  margin: 28px 8px 10px; font-size: 11px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--ink-faint);
}
.folders { list-style: none; margin: 0; padding: 0; }
.folders li { margin: 2px 0; }
.folders a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--ink-soft); font-weight: 500; transition: .14s;
}
.folders a .fi { width: 17px; height: 17px; opacity: .75; flex: none; }
.folders a:hover { background: var(--paper-2); color: var(--ink); }
.folders a.active { background: var(--evergreen-tint); color: var(--evergreen-dk); }
.folders a.active .fi { opacity: 1; }

.main {
  flex: 1; margin-left: var(--sidebar-w);
  padding: 34px clamp(20px, 4vw, 56px) 64px; min-width: 0;
  animation: rise .5s cubic-bezier(.2,.7,.2,1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .main { animation: none; } }

/* ---- page heading --------------------------------------------------------- */
.page-head { margin: 0 0 22px; }
.page-head h1, .folder-title {
  font-family: var(--display); font-weight: 540; font-size: clamp(28px, 4vw, 40px);
  letter-spacing: -.02em; margin: 0; color: var(--ink);
}
.page-head .sub { color: var(--ink-faint); font-size: 13px; margin-top: 4px; }
.rule { height: 1px; background: linear-gradient(90deg, var(--line-strong), transparent); border: 0; margin: 18px 0 24px; }

/* welcome / empty intro */
.intro {
  max-width: 560px; margin: 8vh auto; text-align: center;
}
.intro .glyph { font-family: var(--display); font-size: 64px; color: var(--evergreen); font-style: italic; }
.intro h2 { font-family: var(--display); font-weight: 500; font-size: 30px; margin: 8px 0 6px; }
.intro p { color: var(--ink-soft); }

/* ---- filter / search bar -------------------------------------------------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 22px;
  box-shadow: var(--shadow);
}
.filters .search { flex: 1 1 240px; min-width: 200px; }
input[type=text], input[type=password], input[type=search], select, textarea {
  font-family: var(--sans); font-size: 14px; color: var(--ink);
  background: #fff; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 9px 12px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 220px; line-height: 1.6; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--evergreen);
  box-shadow: 0 0 0 3px var(--evergreen-tint);
}
.filters label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-soft); white-space: nowrap; }
.filters input[type=checkbox] { accent-color: var(--evergreen); width: 15px; height: 15px; }
.filters select, .filters .narrow { width: auto; }
.filters .narrow { flex: 0 1 150px; }

/* ---- buttons -------------------------------------------------------------- */
.btn, button {
  font-family: var(--sans); font-size: 13px; font-weight: 600; letter-spacing: .01em;
  color: var(--ink); background: var(--paper-2); border: 1px solid var(--line-strong);
  border-radius: 999px; padding: 9px 16px; cursor: pointer; transition: .15s;
}
.btn:hover, button:hover { background: #fff; border-color: var(--ink-faint); }
.btn-primary, button.primary {
  background: var(--evergreen); color: #fff; border-color: var(--evergreen);
}
.btn-primary:hover, button.primary:hover { background: var(--evergreen-dk); border-color: var(--evergreen-dk); color:#fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--evergreen-dk); padding-left: 6px; padding-right: 6px; }
.btn-danger { background: transparent; color: var(--terracotta-dk); border-color: var(--terracotta); }
.btn-danger:hover { background: var(--terracotta); color: #fff; }
button:focus-visible, a:focus-visible, .btn:focus-visible { outline: 2px solid var(--evergreen); outline-offset: 2px; }

/* ---- message list (as a "ledger" of correspondence) ----------------------- */
.maillist { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--card); box-shadow: var(--shadow); }
.mailrow {
  display: grid; grid-template-columns: 14px minmax(140px, 1.1fr) minmax(0, 2fr) auto;
  gap: 16px; align-items: center; padding: 14px 18px;
  border-bottom: 1px solid var(--line); transition: background .12s; position: relative;
}
.mailrow:last-child { border-bottom: 0; }
.mailrow:hover { background: var(--paper); }
.mailrow .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--terracotta); box-shadow: 0 0 0 3px var(--terracotta-tint); }
.mailrow.read .dot { background: transparent; box-shadow: none; }
.mailrow .who2 { font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mailrow.read .who2 { font-weight: 500; color: var(--ink-soft); }
.mailrow .subj { min-width: 0; }
.mailrow .subj a { color: var(--ink); font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mailrow.read .subj a { font-weight: 500; color: var(--ink-soft); }
.mailrow .subj a:hover { color: var(--terracotta-dk); }
.mailrow .meta { display: flex; align-items: center; gap: 14px; color: var(--ink-faint); font-size: 12px; white-space: nowrap; }
.mailrow .meta .clip { color: var(--evergreen); }
.mailrow .rowactions { display: flex; align-items: center; gap: 6px; opacity: 0; transition: opacity .12s; }
.mailrow:hover .rowactions, .mailrow:focus-within .rowactions { opacity: 1; }
.mailrow .rowactions form { display: inline; margin: 0; }
.mailrow .rowactions .mini { padding: 5px 11px; font-size: 12px; }
.tag-date { font-variant-numeric: tabular-nums; }
.empty { padding: 48px 18px; text-align: center; color: var(--ink-faint); font-style: italic; }

/* ---- message detail ------------------------------------------------------- */
.letter { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; max-width: 860px; }
.letter .lt-head { padding: 24px 28px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, var(--evergreen-tint), transparent); }
.letter .lt-subject { font-family: var(--display); font-weight: 560; font-size: 26px; letter-spacing: -.01em; margin: 0 0 14px; color: var(--ink); }
.letter .lt-meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13.5px; }
.letter .lt-meta dt { color: var(--ink-faint); text-transform: uppercase; letter-spacing: .08em; font-size: 11px; align-self: center; }
.letter .lt-meta dd { margin: 0; color: var(--ink); }
.letter .lt-meta .addr { font-family: var(--mono); font-size: 12.5px; }
.letter .lt-body { padding: 26px 28px; }
.letter .lt-body pre { white-space: pre-wrap; word-wrap: break-word; font-family: var(--sans); font-size: 15px; line-height: 1.65; margin: 0; color: var(--ink); }
.attachments { padding: 18px 28px; border-top: 1px dashed var(--line-strong); background: var(--paper); }
.attachments .at-label { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 10px; }
.attachments ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.attachments li { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line-strong); border-radius: 999px; padding: 7px 14px; font-size: 13px; }
.letter .lt-foot { display: flex; gap: 10px; padding: 16px 28px; border-top: 1px solid var(--line); }

/* ---- compose / reply form ------------------------------------------------- */
.composer { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); max-width: 820px; overflow: hidden; }
.composer .cp-head { font-family: var(--display); font-size: 22px; padding: 20px 26px 0; }
.composer form { padding: 14px 26px 24px; display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint); }
.field .static { font-family: var(--mono); font-size: 13px; color: var(--ink); padding: 6px 0; }
.composer .actions { display: flex; gap: 10px; align-items: center; }

/* ---- flashes -------------------------------------------------------------- */
.flashes { position: fixed; top: calc(var(--topbar-h) + 14px); left: 50%; transform: translateX(-50%); z-index: 80; width: min(560px, 92vw); display: flex; flex-direction: column; gap: 8px; }
.flash {
  padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px;
  background: var(--card); color: var(--ink); border: 1px solid var(--line-strong);
  border-left: 4px solid var(--ink-faint); box-shadow: var(--shadow-lg);
  animation: flashin .35s cubic-bezier(.2,.7,.2,1) both;
}
@keyframes flashin { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.flash-success { border-left-color: var(--ok); background: var(--ok-bg); }
.flash-error   { border-left-color: var(--err); background: var(--err-bg); }
.flash-info    { border-left-color: var(--info); background: var(--info-bg); }

/* ---- login ---------------------------------------------------------------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(420px, 100%); background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow-lg); padding: 40px 38px;
  animation: rise .5s cubic-bezier(.2,.7,.2,1) both;
}
.auth-card .brand { display: block; margin-bottom: 6px; }
.auth-card .mark { font-family: var(--display); font-size: 30px; }
.auth-card .mark em { color: var(--evergreen); font-style: italic; }
.auth-card .lede { color: var(--ink-soft); font-size: 14px; margin: 0 0 26px; }
.auth-card form { display: flex; flex-direction: column; gap: 16px; }
.auth-card .field > label { color: var(--ink-soft); }
.auth-card button { width: 100%; padding: 12px; font-size: 15px; }
.auth-card .error { margin-top: 14px; color: var(--err); background: var(--err-bg); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; }

/* ---- rich (HTML) composer ------------------------------------------------- */
.rt-toolbar { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.rt-btn {
  font: inherit; font-size: 13px; line-height: 1; cursor: pointer;
  padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--paper, #fff); color: var(--ink, #222);
}
.rt-btn:hover { background: var(--line); }
.rich-editor {
  min-height: 220px; max-height: 60vh; overflow-y: auto;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--paper, #fff); color: var(--ink, #222);
  font: inherit; line-height: 1.5;
}
.rich-editor:focus { outline: 2px solid var(--accent, #6b4); outline-offset: 1px; }
.rich-editor blockquote, .html-body blockquote {
  margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--line); color: var(--ink-faint, #666);
}

/* ---- rendered HTML message body ------------------------------------------- */
.html-body { line-height: 1.55; overflow-wrap: anywhere; }
.html-body img { max-width: 100%; height: auto; }
.html-body a { color: var(--accent, #36c); }
.html-body table { max-width: 100%; border-collapse: collapse; }
.html-body pre { white-space: pre-wrap; }

/* ---- sending overlay ------------------------------------------------------ */
#sending-overlay {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 18, 16, 0.45); backdrop-filter: blur(2px);
}
#sending-overlay .so-card {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 22px; border-radius: 12px;
  background: var(--paper, #fff); color: var(--ink, #222);
  box-shadow: 0 12px 40px rgba(0,0,0,0.25); font-weight: 500;
}
#sending-overlay .so-spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 3px solid var(--line, #ddd); border-top-color: var(--accent, #6b4);
  animation: so-spin 0.8s linear infinite;
}
@keyframes so-spin { to { transform: rotate(360deg); } }
button[disabled] { opacity: 0.6; cursor: progress; }

/* ---- responsive ----------------------------------------------------------- */
@media (max-width: 760px) {
  .sidebar { position: static; width: 100%; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .shell { flex-direction: column; }
  .main { margin-left: 0; padding: 22px 18px 56px; }
  .mailrow { grid-template-columns: 12px 1fr auto; }
  .mailrow .meta { display: none; }
}
