/* Loop Studio mail. Dark, same look as the AskMed dashboard. */
:root {
  color-scheme: dark;
  --page: #0a0a0a;
  --panel: #141414;
  --panel-2: #111111;
  --hover: #1a1a1a;
  --selected: #1b2433;
  --border: #262626;
  --divider: #222222;
  --ink: #ffffff;
  --ink-2: #d4d4d4;
  --muted: #8a8a8a;
  --faint: #6b6b6b;
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.14);
  --critical-ink: #f07070;
  --good-ink: #3ecf3e;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.mark { width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 15px; flex: none; }

/* Login */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { display: flex; flex-direction: column; align-items: center; }
.login-card .mark { width: 64px; height: 64px; border-radius: 16px; font-size: 26px; margin-bottom: 12px; }
.login-card h1 { font-size: 18px; font-weight: 600; margin: 0 0 24px; }
.pin { display: flex; gap: 12px; margin-bottom: 12px; }
.pin input {
  width: 48px; height: 56px; border-radius: 8px; border: 2px solid #333; background: var(--panel); color: var(--ink);
  text-align: center; font-size: 20px; font-weight: 700; outline: none; transition: border-color 0.15s; padding: 0;
}
.pin input:focus { border-color: #555; }
.pin input.filled { border-color: #22c55e; }
.login-hint { margin: 0; color: #666; font-size: 12px; min-height: 20px; text-align: center; }
.login-hint.error { color: #ef4444; font-size: 14px; }

/* App frame */
.app { height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto 1fr; }
.bar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--divider);
  padding-top: max(10px, env(safe-area-inset-top)); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right));
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-text { min-width: 0; }
.brand-text strong { display: block; font-size: 15px; }
.brand-text span { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search { flex: 1; max-width: 520px; margin-left: auto; }
.search input { width: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; outline: none; }
.search input:focus { border-color: #444; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--panel);
  border-radius: 8px; padding: 8px 14px; cursor: pointer; white-space: nowrap; min-height: 36px;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--hover); }
.btn:disabled { opacity: 0.55; cursor: default; }

.body { display: grid; grid-template-columns: 200px minmax(280px, 400px) minmax(0, 1fr); min-height: 0; }
.nav { border-right: 1px solid var(--divider); padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; text-align: left; background: none; border: 0;
  border-radius: 8px; padding: 9px 12px; cursor: pointer; color: var(--ink-2);
}
.nav button:hover { background: var(--hover); }
.nav button[aria-current="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.count { color: var(--accent); font-weight: 700; font-size: 12px; }

.list { border-right: 1px solid var(--divider); overflow-y: auto; min-height: 0; }
.list-head { position: sticky; top: 0; background: var(--page); padding: 12px 16px 8px; color: var(--muted); font-size: 11px; font-weight: 650; letter-spacing: 0.12em; text-transform: uppercase; border-bottom: 1px solid var(--divider); z-index: 1; }
.row { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--divider); background: none; padding: 12px 16px; cursor: pointer; }
.row:hover { background: var(--hover); }
.row[aria-current="true"] { background: var(--selected); }
.row-top { display: flex; align-items: baseline; gap: 8px; }
.row-from { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.row-time { color: var(--faint); font-size: 12px; flex: none; }
.row-subject { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); margin-top: 2px; }
.row-snippet { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--faint); font-size: 13px; margin-top: 2px; }
.row.unread .row-from, .row.unread .row-subject { color: var(--ink); font-weight: 700; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; align-self: center; }
.clip { color: var(--muted); font-size: 12px; }
.empty { padding: 40px 20px; color: var(--muted); text-align: center; }
.more { display: block; margin: 12px auto 20px; }

.reader { overflow-y: auto; min-height: 0; }
.reader-inner { padding: 20px 24px 40px; max-width: 980px; }
.reader-empty { height: 100%; display: grid; place-items: center; color: var(--faint); }
.back { display: none; }
.subject { font-size: 21px; font-weight: 700; margin: 0 0 14px; line-height: 1.3; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px; padding-bottom: 14px; border-bottom: 1px solid var(--divider); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: #2a3342; display: grid; place-items: center; font-weight: 700; flex: none; text-transform: uppercase; }
.who { flex: 1; min-width: 0; }
.who strong { overflow-wrap: anywhere; }
.who .addr, .who .to { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.when { color: var(--muted); font-size: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.mail-frame { width: 100%; border: 0; background: #fff; border-radius: 8px; min-height: 200px; display: block; }
.text-body { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink-2); line-height: 1.55; }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.file { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; text-decoration: none; color: var(--ink-2); max-width: 100%; }
.file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file small { color: var(--muted); flex: none; }
.sent-reply { margin-top: 18px; border-left: 3px solid var(--accent); padding: 4px 0 4px 14px; }
.sent-reply .when { margin-bottom: 6px; display: block; }

/* Writing */
.composer { margin-top: 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel-2); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.composer label { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--divider); padding-bottom: 8px; }
.composer label span { color: var(--muted); width: 56px; flex: none; font-size: 13px; }
.composer input { flex: 1; min-width: 0; background: none; border: 0; outline: none; padding: 4px 0; }
.composer textarea { width: 100%; min-height: 180px; resize: vertical; background: none; border: 0; outline: none; line-height: 1.55; }
.composer-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.composer-note { color: var(--muted); font-size: 12px; flex: 1; min-width: 160px; }
.composer-note.error { color: var(--critical-ink); }
.composer-note.ok { color: var(--good-ink); }
.compose-sheet { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: grid; place-items: center; padding: 16px; z-index: 20; }
.compose-sheet .composer { width: min(720px, 100%); margin: 0; max-height: calc(100dvh - 32px); overflow-y: auto; }
.compose-title { display: flex; align-items: center; justify-content: space-between; font-weight: 700; }
.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: #222; border: 1px solid var(--border); border-radius: 8px; padding: 10px 16px; z-index: 30; }

/* Tablet: folders become a row of tabs above the list */
@media (max-width: 1000px) {
  .body { grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .nav { grid-column: 1 / -1; flex-direction: row; border-right: 0; border-bottom: 1px solid var(--divider); padding: 8px; overflow-x: auto; }
  .nav button { width: auto; }
}

/* Phone: one pane at a time */
@media (max-width: 700px) {
  .bar { flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .brand { flex: 1; }
  .bar .btn { padding: 8px 10px; }
  .meta .when { flex-basis: 100%; padding-left: 48px; margin-top: -6px; }
  .body { grid-template-columns: minmax(0, 1fr); }
  .list { border-right: 0; }
  .app.reading .list, .app.reading .nav { display: none; }
  .app:not(.reading) .reader { display: none; }
  .back { display: inline-flex; }
  .reader-inner { padding: 16px 16px 40px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
}
