:root {
  --ink: #102039;
  --ink-deep: #0b1f3a;
  --paper: #f7fafd;
  --white: #ffffff;
  --muted: #4d5d73;
  --accent: #155eef;
  --accent-bright: #087cff;
  --turquoise: #12c8c7;
  --sky: #ddf3ff;
  --line: #c9d7e8;
  --font-display: "Plus Jakarta Sans", system-ui, sans-serif;
  --font-sans: "Source Sans 3", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --shadow: 0 10px 28px -16px rgb(11 31 58 / 0.18), 0 2px 6px rgb(11 31 58 / 0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; max-width: 100%; overflow-x: hidden; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1.02rem;
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, .primary, .ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: 0.85rem;
  border: 1px solid var(--line);
  background: var(--white);
  padding: 0.45rem 0.8rem;
  cursor: pointer;
}
.icon {
  width: 1.05rem;
  height: 1.05rem;
  flex: none;
  overflow: visible;
}
.field { position: relative; display: block; }
.field .icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.field input { padding-left: 2.25rem; }
.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
  box-shadow: 0 0 0 1px rgb(8 124 255 / 0.1), 0 16px 36px -18px rgb(21 94 239 / 0.4);
}
.primary:hover { background: var(--accent-bright); }
.ghost { background: transparent; }
.block { width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
code, .quote { font-family: var(--font-mono); }

.brand { display: flex; align-items: center; gap: 0.7rem; margin: 0; }
.mark {
  display: grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: 0.75rem;
  background: linear-gradient(120deg, #155eef 0%, #087cff 48%, #12c8c7 100%);
  color: white; font-family: var(--font-display); font-weight: 700;
  box-shadow: 0 0 0 1px rgb(8 124 255 / 0.1), 0 16px 36px -18px rgb(21 94 239 / 0.4);
}
.word { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.03em; font-size: 1.15rem; }
.ai { color: var(--accent); }
.i { color: var(--turquoise); }
.legal { display: block; font-size: 0.65rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.brand.on-ink .word { color: white; }
.brand.on-ink .ai { color: #7eb6ff; }
.product { margin-left: 0.35rem; color: var(--turquoise); font-family: var(--font-display); font-weight: 600; }

.login-body {
  min-height: 100%;
  background:
    radial-gradient(ellipse at 20% 0%, rgb(221 243 255 / 0.95), transparent 50%),
    radial-gradient(ellipse at 90% 80%, rgb(18 200 199 / 0.16), transparent 40%),
    var(--paper);
}
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 2rem 1rem; }
.login-card {
  width: min(52rem, 100%);
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 28rem;
}
.login-aside {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-start;
  padding: 2rem;
  background:
    radial-gradient(circle at 18% 78%, rgb(18 200 199 / 0.45), transparent 28%),
    linear-gradient(155deg, #155eef 0%, #087cff 52%, #0b3fbe 100%);
}
.login-aside .brand { position: relative; z-index: 1; }
.login-aside .legal { color: rgb(255 255 255 / 0.72); }
.orb {
  position: absolute;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.14);
}
.orb-a { width: 16rem; height: 16rem; right: -5.5rem; top: -6rem; background: rgb(8 60 180 / 0.35); }
.orb-b { width: 9.5rem; height: 9.5rem; left: -2.6rem; bottom: -3.2rem; background: rgb(255 255 255 / 0.16); }
.orb-c { width: 5.5rem; height: 5.5rem; right: 18%; bottom: 18%; background: #087cff; }
.login-pane {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 2.4rem 1.5rem;
}
.login-card h1 { font-family: var(--font-display); font-size: 2rem; margin: 0 0 1.1rem; letter-spacing: -0.03em; text-align: center; }
#login-form { width: min(18.5rem, 100%); }
.login-card form > button { width: 100%; position: relative; overflow: hidden; }
.login-card form > button > * { position: relative; z-index: 1; }
.spin {
  display: none;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  border: 2px solid rgb(255 255 255 / 0.35);
  border-top-color: white;
  animation: spin 0.7s linear infinite;
}
#login-form.is-busy .icon { display: none; }
#login-form.is-busy .spin { display: block; }
#login-form.is-busy input { opacity: 0.65; }
#login-form.is-busy button.primary::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, rgb(255 255 255 / 0.28) 50%, transparent 80%);
  animation: sheen 1.15s ease-in-out infinite;
}
#login-form.is-busy .login-aside,
.login-card:has(#login-form.is-busy) .orb { animation: drift 2.4s ease-in-out infinite alternate; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes sheen { from { transform: translateX(-120%); } to { transform: translateX(120%); } }
@keyframes drift { to { transform: translateY(-6px); } }
@media (prefers-reduced-motion: reduce) {
  .spin, #login-form.is-busy button.primary::after, .login-card:has(#login-form.is-busy) .orb { animation: none; }
}
form { display: grid; gap: 0.75rem; }
label { display: grid; gap: 0.25rem; font-size: 0.92rem; font-weight: 600; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 0.75rem; background: var(--paper); padding: 0.55rem 0.7rem; font-weight: 400;
}
.grid { display: grid; grid-template-columns: 1.4fr 0.5fr 0.9fr; gap: 0.6rem; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.error { color: #9f1239; background: #fff1f2; border-radius: 0.7rem; padding: 0.55rem 0.7rem; margin: 0; }
.check { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; }
.check input { width: auto; }

.top {
  height: 4rem; display: flex; align-items: center; justify-content: space-between;
  gap: 0.6rem; min-width: 0;
  padding: 0 0.8rem; background: var(--ink-deep); color: white;
}
.top-actions { display: flex; align-items: center; gap: 0.4rem; min-width: 0; flex: 1 1 auto; justify-content: flex-end; }
.ghost.on-ink { color: white; border-color: transparent; flex: none; }
#who { color: rgb(247 250 253 / 0.75); font-size: 0.92rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#show-folders { display: none; }

.shell {
  height: calc(100% - 4rem);
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 15rem minmax(18rem, 24rem) minmax(0, 1fr);
}
.folders, .list, .reader { min-height: 0; min-width: 0; overflow: auto; }
.folders { border-right: 1px solid var(--line); padding: 0.9rem; background: rgb(255 255 255 / 0.7); }
.folders ul { list-style: none; padding: 0; margin: 0.8rem 0 0; }
.folders li button {
  width: 100%; justify-content: flex-start; text-align: left; border: 0; background: transparent; border-radius: 0.7rem; padding: 0.45rem 0.6rem;
}
.folders li button .icon { color: var(--muted); }
.folders li button[aria-current="true"] { background: var(--sky); color: var(--accent); font-weight: 600; }
.folders li button[aria-current="true"] .icon { color: var(--accent); }
.list { border-right: 1px solid var(--line); background: var(--white); display: flex; flex-direction: column; overflow: hidden; }
#conv-list { flex: 1; min-height: 0; overflow: auto; }
.list-bar { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; min-width: 0; padding: 0.8rem 0.9rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--white); }
.list-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.35rem; min-width: 0; }
.mobile-compose { display: none; }
.list-bar h1 { font-family: var(--font-display); font-size: 1.15rem; margin: 0; display: flex; align-items: center; gap: 0.45rem; }
.conv { width: 100%; text-align: left; justify-content: stretch; border: 0; border-bottom: 1px solid var(--line); background: transparent; border-radius: 0; padding: 0.75rem 0.9rem; display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 0.7rem; row-gap: 0.12rem; align-items: center; color: #5e7086; }
.conv > .icon { grid-row: 1 / span 3; color: #73869b; }
.conv .from { font-weight: 500; color: #5e7086; }
.conv .subject { color: #5e7086; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .meta { color: #6d8094; font-size: 0.85rem; display: flex; justify-content: space-between; }
.conv.unread { color: var(--ink); box-shadow: inset 3px 0 0 var(--accent); }
.conv.unread > .icon { color: var(--accent); }
.conv.unread .from,
.conv.unread .subject { color: var(--ink); font-weight: 600; }
.conv.unread .meta { color: var(--muted); }
.pill { background: var(--sky); color: var(--accent); border-radius: 999px; padding: 0 0.45rem; font-size: 0.75rem; font-weight: 700; }

.reader { padding: 1rem 1.15rem 2rem; }
.empty { color: var(--muted); padding: 2rem 0; display: flex; align-items: center; gap: 0.55rem; }
#conv-list > .empty {
  min-height: 100%;
  margin: 0;
  padding: 2.5rem 1.5rem;
  box-sizing: border-box;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  gap: 0.75rem;
}
.empty .icon { width: 1.35rem; height: 1.35rem; color: var(--accent); }
#conv-list > .empty .icon { width: 1.85rem; height: 1.85rem; }
.atts { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0; }
.atts a { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--accent); }
.reader h2 { font-family: var(--font-display); letter-spacing: -0.03em; margin: 0.2rem 0 0.6rem; }
.tools { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.8rem; }
.letter { border: 1px solid var(--line); border-radius: 1rem; background: var(--white); box-shadow: var(--shadow); padding: 0.9rem 1rem; margin-bottom: 0.7rem; }
.letter header { display: flex; justify-content: space-between; gap: 1rem; }
.who { font-weight: 650; }
.when { color: var(--muted); font-size: 0.88rem; }
.mail-frame { width: 100%; height: 0; border: 0; display: block; overflow: hidden; background: white; border-radius: 0.6rem; }
.plain { white-space: pre-wrap; }
.headers { margin-top: 0.6rem; }
.headers pre, .quote { white-space: pre-wrap; background: var(--ink-deep); color: var(--paper); border-radius: 0.8rem; padding: 0.8rem; font-size: 0.82rem; }
dialog {
  width: min(40rem, calc(100% - 1.5rem));
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 0;
  box-shadow: var(--shadow);
}
dialog form { padding: 1rem; }
.to-line { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.35rem 0.6rem; align-items: end; }
.copy-toggles { display: flex; gap: 0.15rem; padding-bottom: 0.15rem; }
.copy-toggles button { border-color: transparent; background: transparent; color: var(--accent); font-size: 0.88rem; font-weight: 600; padding: 0.4rem 0.35rem; }
[hidden] { display: none !important; }
dialog header { display: flex; justify-content: space-between; align-items: center; }
dialog h2 { font-family: var(--font-display); margin: 0; }
.compose-actions { display: flex; justify-content: space-between; align-items: center; gap: 0.8rem; }
.kept-files { margin: 0; color: var(--muted); font-size: 0.88rem; }

@media (max-width: 900px) {
  .login-card { grid-template-columns: 1fr; min-height: 0; }
  .login-aside { min-height: 8.5rem; align-items: flex-start; }
  .orb-a { width: 10rem; height: 10rem; }
  .orb-b, .orb-c { display: none; }
  .login-pane { padding: 1.6rem 1.2rem 1.5rem; }
  .grid, .pair { grid-template-columns: 1fr; }
  #show-folders { display: inline-flex; }
  .mobile-compose { display: inline-flex; }
  .list-bar { flex-wrap: wrap; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .folders, .list, .reader { display: none; }
  .shell[data-pane="folders"] .folders,
  .shell[data-pane="reader"] .reader { display: block; height: calc(100vh - 4rem); }
  .shell[data-pane="list"] .list { display: flex; height: calc(100vh - 4rem); }
}
