:root {
  --bg0: #0B1C2C;
  --bg1: #132A40;
  --bg2: #1A3854;
  --surface: #F4F7FA;
  --ink: #0E1A24;
  --muted: #5A6B7A;
  --line: #D5DEE7;
  --accent: #E8A317;
  --accent-ink: #1A1200;
  --ok: #1F7A4C;
  --danger: #B42318;
  --radius: 14px;
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
/* display:flex/grid sur .login/.app/.view écrase sinon l’attribut HTML hidden */
[hidden] { display: none !important; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 10% -10%, #1e4a6e 0%, transparent 55%),
    radial-gradient(90% 60% at 100% 0%, #0f2f4a 0%, transparent 50%),
    linear-gradient(165deg, var(--bg0), var(--bg1) 45%, #0a1622);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
.btn {
  appearance: none; border: 0; border-radius: 12px; padding: 0.85rem 1.1rem;
  font-weight: 600; cursor: pointer; transition: transform .15s ease, opacity .15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 10px;
  background: rgba(255,255,255,.08); color: #fff; font-size: 1.05rem; cursor: pointer;
  display: inline-grid; place-items: center;
}
.icon-btn svg { display: block; }

/* Login */
.login {
  min-height: 100%; display: grid; place-items: center; padding: 1.5rem;
  padding-top: calc(1.5rem + var(--safe-t));
}
.login-panel {
  width: min(100%, 380px); background: var(--surface); border-radius: 22px;
  padding: 1.75rem 1.4rem 1.5rem; display: grid; gap: .85rem;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
  animation: rise .45s ease;
}
.login-panel img { justify-self: center; border-radius: 12px; }
.brand {
  margin: 0; text-align: center; letter-spacing: .18em; text-transform: uppercase;
  font-size: .72rem; font-weight: 700; color: var(--muted);
}
.login-panel h1 {
  margin: -.4rem 0 0; text-align: center; font-family: var(--display);
  font-size: 2rem; font-weight: 700;
}
.login-sub { margin: 0; text-align: center; color: var(--muted); font-size: .92rem; line-height: 1.4; }
.login label, .reply-body label {
  display: grid; gap: .35rem; font-size: .82rem; font-weight: 600; color: var(--muted);
}
.login input, .reply-body input, .reply-body textarea {
  border: 1px solid var(--line); border-radius: 12px; padding: .75rem .85rem;
  background: #fff; color: var(--ink);
}
.login .check {
  display: flex; align-items: center; gap: .5rem; font-weight: 500; color: var(--ink);
}
.error { margin: 0; color: var(--danger); font-size: .9rem; }
.ok { margin: 0; color: var(--ok); font-size: .9rem; }

/* App shell */
.app {
  min-height: 100%; max-width: 520px; margin: 0 auto;
  display: flex; flex-direction: column;
  background: var(--surface);
  box-shadow: 0 0 0 1px rgba(255,255,255,.06);
}
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(.75rem + var(--safe-t)) 1rem .75rem;
  background: linear-gradient(180deg, var(--bg0), var(--bg1));
  color: #fff;
}
.top-brand { display: flex; align-items: center; gap: .65rem; }
.top-brand img { border-radius: 8px; }
.top-brand strong { display: block; font-size: .95rem; }
.top-brand small { color: rgba(255,255,255,.65); font-size: .75rem; }
.top-actions { display: flex; gap: .35rem; }
.hint {
  margin: 0; padding: .55rem 1rem; background: #fff7e6; color: #7a4e00;
  font-size: .85rem; border-bottom: 1px solid #f0dfb0;
}

.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.tabs {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: .35rem; padding: .75rem 1rem 0; background: var(--surface);
}
.tab {
  border: 0; background: transparent; padding: .7rem .4rem; border-radius: 10px;
  font-weight: 600; color: var(--muted); cursor: pointer;
}
.tab.is-active { background: #fff; color: var(--ink); box-shadow: 0 1px 0 var(--line); }
.badge {
  display: inline-block; min-width: 1.2rem; padding: 0 .3rem; margin-left: .15rem;
  border-radius: 999px; background: var(--accent); color: var(--accent-ink);
  font-size: .7rem; font-weight: 700;
}
.badge:empty { display: none; }
.panel { flex: 1; overflow: auto; padding: .75rem 1rem calc(1.25rem + var(--safe-b)); }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: .65rem; }
.list li {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem 1rem; cursor: pointer;
  animation: rise .35s ease both;
}
.list li:active { transform: scale(0.99); }
.list .title { font-weight: 650; margin: 0 0 .2rem; }
.list .meta { margin: 0; color: var(--muted); font-size: .82rem; }
.list .tag {
  display: inline-block; margin-top: .45rem; font-size: .72rem; font-weight: 600;
  color: #1a4d7a; background: #e8f1f8; padding: .15rem .45rem; border-radius: 6px;
}
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.soon {
  margin: 1.5rem 0; padding: 1.5rem; background: #fff; border-radius: var(--radius);
  border: 1px dashed var(--line); text-align: center;
}
.soon h2 { font-family: var(--display); margin: 0 0 .5rem; }
.soon p { color: var(--muted); line-height: 1.45; }
.soon .btn { display: inline-block; margin-top: .5rem; text-decoration: none; }

/* Reply */
.reply { background: var(--surface); }
.reply-head {
  display: flex; align-items: center; gap: .65rem;
  padding: calc(.65rem + var(--safe-t)) 1rem .65rem;
  background: #fff; border-bottom: 1px solid var(--line);
}
.reply-head .icon-btn { background: #eef2f6; color: var(--ink); }
.reply-head strong { display: block; }
.reply-head small { color: var(--muted); font-size: .8rem; }
.reply-body {
  flex: 1; overflow: auto; padding: 1rem;
  display: grid; gap: .75rem; align-content: start;
}
.reply-body .grow textarea { min-height: 220px; resize: vertical; line-height: 1.45; }
.reply-actions {
  display: grid; grid-template-columns: 1fr 1.4fr; gap: .65rem;
  padding: .85rem 1rem calc(.85rem + var(--safe-b));
  background: #fff; border-top: 1px solid var(--line);
}
.mail-preview {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: .85rem; font-size: .9rem; line-height: 1.45; white-space: pre-wrap;
  max-height: 180px; overflow: auto; color: var(--muted);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (min-width: 640px) {
  body { padding: 1.5rem 0; }
  .app { min-height: calc(100% - 3rem); border-radius: 20px; overflow: hidden; }
}
