/* ==========================================================================
   Gear Grow Mail — design tokens
   Palette pulled from the brand mark: true black + signal green on white.
   ========================================================================== */
:root {
  --gg-black: #121214;
  --gg-black-soft: #1c1d20;
  --gg-green: #14c76b;
  --gg-green-dark: #0fa659;
  --gg-green-tint: #e7faf0;
  --gg-bg: #f5f6f7;
  --gg-surface: #ffffff;
  --gg-border: #e4e6e9;
  --gg-text: #17181a;
  --gg-text-muted: #6b7280;
  --gg-text-faint: #9aa0a6;
  --gg-danger: #e0483f;
  --gg-radius-sm: 8px;
  --gg-radius-md: 12px;
  --font-display: 'Archivo', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --gg-shadow: 0 8px 28px rgba(18, 18, 20, 0.14);
  --topbar-h: 60px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--gg-text);
  background: var(--gg-bg);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
input, textarea { font-family: inherit; font-size: 15px; }
svg { width: 20px; height: 20px; display: block; }
a { color: var(--gg-green-dark); }

.g-green { color: var(--gg-green); }
.g-black { color: var(--gg-black); }

/* Signature angled-corner shape — echoes the flag/tail on the logo's G.
   Used sparingly: primary CTA + brand chips only. */
.cut-corner {
  clip-path: polygon(0 0, 100% 0, 100% 68%, 90% 100%, 0 100%);
}

.btn {
  border: none;
  border-radius: var(--gg-radius-sm);
  padding: 11px 20px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--gg-green);
  color: #06210f;
}
.btn-primary:hover { background: var(--gg-green-dark); color: #fff; }
.btn-block { width: 100%; }

.icon-btn {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; border-radius: 50%;
  color: currentColor; cursor: pointer;
  transition: background .12s ease;
}
.icon-btn:hover { background: rgba(0,0,0,.06); }
.icon-btn.danger:hover { background: rgba(224,72,63,.12); color: var(--gg-danger); }

/* ==========================================================================
   Auth screen
   ========================================================================== */
.auth-body {
  min-height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: var(--gg-black);
  background-image: radial-gradient(circle at 20% 20%, #1d1e21 0%, var(--gg-black) 55%);
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--gg-surface);
  border-radius: var(--gg-radius-md);
  padding: 36px 30px 28px;
  box-shadow: var(--gg-shadow);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-logo { width: 46px; height: 46px; }
.auth-brand-text {
  font-family: var(--font-display); font-weight: 800; font-size: 18px; letter-spacing: .2px;
  display: flex; align-items: baseline; gap: 6px;
}
.auth-sub { font-family: var(--font-body); font-weight: 500; font-size: 12px; color: var(--gg-text-muted); margin-left: 2px; }
.auth-card h1 { font-family: var(--font-display); font-size: 21px; margin: 0 0 4px; }
.auth-hint { color: var(--gg-text-muted); font-size: 14px; margin: 0 0 20px; }
.auth-error {
  background: #fdeceb; color: #a8271f; border: 1px solid #f6c8c4;
  border-radius: var(--gg-radius-sm); padding: 10px 12px; font-size: 13.5px; margin-bottom: 16px;
}
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--gg-text-muted); }
.field input {
  border: 1.5px solid var(--gg-border); border-radius: var(--gg-radius-sm);
  padding: 11px 12px; font-size: 15px; color: var(--gg-text); background: var(--gg-surface);
}
.field input:focus { outline: none; border-color: var(--gg-green); box-shadow: 0 0 0 3px var(--gg-green-tint); }
.auth-footnote { text-align: center; font-size: 12.5px; color: var(--gg-text-faint); margin: 20px 0 0; }

/* ==========================================================================
   App shell
   ========================================================================== */
.app-body { overflow: hidden; }
.app-shell { height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h); flex: 0 0 auto;
  display: flex; align-items: center; gap: 12px;
  background: var(--gg-black); color: #fff;
  padding: 0 14px;
}
.topbar-brand { display: flex; align-items: center; gap: 9px; }
.topbar-logo { width: 28px; height: 28px; }
.topbar-title { font-family: var(--font-display); font-weight: 700; font-size: 15px; display: none; }
.topbar .icon-btn { color: #fff; }
.topbar-search {
  flex: 1; display: flex; align-items: center; gap: 8px;
  background: var(--gg-black-soft); border: 1px solid #2a2b2f;
  border-radius: 20px; padding: 0 14px; height: 38px; max-width: 520px;
}
.search-icon { color: #8b8d92; flex: 0 0 auto; }
.topbar-search input {
  background: transparent; border: none; color: #fff; width: 100%; font-size: 14px;
}
.topbar-search input::placeholder { color: #8b8d92; }
.topbar-search input:focus { outline: none; }
.topbar-user { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.user-email { font-size: 13px; color: #c8cace; }

.app-body-row { flex: 1; display: flex; min-height: 0; position: relative; }

/* ---- Sidebar (folder rail) ---- */
.sidebar {
  width: 220px; flex: 0 0 auto;
  background: var(--gg-black); color: #d7d8db;
  display: flex; flex-direction: column;
  padding: 16px 12px;
}
.compose-btn {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--gg-green); color: #06210f; border: none;
  font-weight: 700; font-size: 14.5px; padding: 12px 14px; margin-bottom: 18px;
  cursor: pointer; transition: background .15s ease;
}
.compose-btn:hover { background: var(--gg-green-dark); color: #fff; }
.compose-btn { border-radius: var(--gg-radius-sm); clip-path: polygon(0 0, 100% 0, 100% 68%, 90% 100%, 0 100%); }

.folder-list { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.folder-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--gg-radius-sm);
  font-size: 14px; cursor: pointer; color: #c8cace;
  border: none; background: transparent; width: 100%; text-align: left;
}
.folder-item svg { width: 17px; height: 17px; flex: 0 0 auto; color: #8b8d92; }
.folder-item:hover { background: var(--gg-black-soft); }
.folder-item.active { background: var(--gg-black-soft); color: #fff; }
.folder-item.active svg { color: var(--gg-green); }
.folder-item .f-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-item .f-badge {
  background: var(--gg-green); color: #06210f; font-size: 11px; font-weight: 700;
  border-radius: 10px; padding: 1px 7px; min-width: 18px; text-align: center;
}
.sidebar-footer { margin-top: auto; padding-top: 14px; }
.mini-tag { font-family: var(--font-display); font-size: 11px; letter-spacing: 1px; color: #55575c; }

.sidebar-scrim { display: none; }

/* ---- Message list pane ---- */
.msg-list-pane {
  width: 360px; flex: 0 0 auto;
  background: var(--gg-surface); border-right: 1px solid var(--gg-border);
  display: flex; flex-direction: column; min-height: 0;
}
.msg-list-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 10px;
}
.msg-list-head h2 { font-family: var(--font-display); font-size: 18px; margin: 0; }
.msg-list { flex: 1; overflow-y: auto; }
.msg-row {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 16px; border-bottom: 1px solid var(--gg-border);
  cursor: pointer; position: relative;
}
.msg-row:hover { background: var(--gg-bg); }
.msg-row.active { background: var(--gg-green-tint); }
.msg-row .dot {
  width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: 0 0 auto;
  background: var(--gg-green);
}
.msg-row.read .dot { background: transparent; }
.msg-row-main { flex: 1; min-width: 0; }
.msg-row-top { display: flex; justify-content: space-between; gap: 8px; }
.msg-from { font-size: 14px; font-weight: 600; color: var(--gg-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-row.read .msg-from { font-weight: 500; color: var(--gg-text-muted); }
.msg-date { font-size: 12px; color: var(--gg-text-faint); flex: 0 0 auto; }
.msg-subject { font-size: 13.5px; color: var(--gg-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.msg-row.read .msg-subject { color: var(--gg-text-faint); }
.msg-star { color: #d7d9dc; flex: 0 0 auto; margin-top: 4px; }
.msg-star.on { color: #f0a92a; }
.msg-list-empty, .list-loading { padding: 40px 20px; text-align: center; color: var(--gg-text-faint); font-size: 14px; }
.msg-list-pager { display: flex; justify-content: center; gap: 8px; padding: 10px; border-top: 1px solid var(--gg-border); }
.msg-list-pager button {
  border: 1px solid var(--gg-border); background: #fff; border-radius: 7px;
  padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.msg-list-pager button:disabled { opacity: .4; cursor: default; }
.msg-list-pager span { font-size: 13px; color: var(--gg-text-muted); align-self: center; }

/* ---- Reading pane ---- */
.reading-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--gg-surface); }
.reading-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--gg-text-faint); gap: 12px;
}
.empty-logo { width: 56px; height: 56px; opacity: .18; }
.reading-content { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.reading-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--gg-border);
}
.reading-toolbar-actions { display: flex; gap: 2px; margin-left: auto; }
.reading-body { flex: 1; overflow-y: auto; padding: 20px 24px 40px; }
.reading-subject { font-family: var(--font-display); font-size: 21px; font-weight: 700; margin: 0 0 14px; }
.reading-meta { display: flex; gap: 12px; margin-bottom: 18px; }
.reading-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--gg-green);
  color: #06210f; font-weight: 700; display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto; font-size: 15px;
}
.reading-meta-text { flex: 1; min-width: 0; }
.reading-from { font-weight: 600; font-size: 14.5px; }
.reading-to, .reading-cc { font-size: 12.5px; color: var(--gg-text-muted); }
.reading-date { font-size: 12.5px; color: var(--gg-text-faint); margin-left: auto; white-space: nowrap; }
.reading-iframe { width: 100%; border: none; min-height: 200px; }
.reading-attachments { margin-top: 20px; display: flex; flex-wrap: wrap; gap: 8px; }
.attachment-chip {
  display: flex; align-items: center; gap: 7px;
  border: 1px solid var(--gg-border); border-radius: var(--gg-radius-sm);
  padding: 8px 12px; font-size: 13px; text-decoration: none; color: var(--gg-text);
  background: var(--gg-bg);
}
.attachment-chip svg { width: 15px; height: 15px; color: var(--gg-text-muted); }
.attachment-chip .a-size { color: var(--gg-text-faint); font-size: 11.5px; }

/* ==========================================================================
   Compose modal
   ========================================================================== */
.compose-overlay {
  position: fixed; inset: 0; background: rgba(18,18,20,.35);
  display: flex; align-items: flex-end; justify-content: flex-end;
  z-index: 50; padding: 0;
}
.compose-modal {
  width: 480px; max-width: 100vw; height: 560px; max-height: 92vh;
  background: var(--gg-surface); border-radius: var(--gg-radius-md) var(--gg-radius-md) 0 0;
  box-shadow: var(--gg-shadow); display: flex; flex-direction: column; overflow: hidden;
  margin: 0 20px 0 0;
}
.compose-head {
  background: var(--gg-black); color: #fff; padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between; font-size: 14px; font-weight: 600;
}
.compose-head-actions { display: flex; gap: 2px; }
.compose-head .icon-btn { color: #fff; width: 30px; height: 30px; }
.compose-form { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.compose-field { border-bottom: 1px solid var(--gg-border); padding: 0 14px; }
.compose-field input { width: 100%; border: none; padding: 11px 0; font-size: 14px; }
.compose-field input:focus { outline: none; }
.compose-ccbcc-toggle { border-bottom: none; padding: 4px 14px; }
.compose-ccbcc-toggle button { border: none; background: none; color: var(--gg-text-muted); font-size: 12.5px; cursor: pointer; padding: 0; }
.cc-bcc-row { display: flex; flex-direction: column; }
.cc-bcc-row input { border-bottom: 1px solid var(--gg-border); }
.cc-bcc-row input:last-child { border-bottom: none; }
.compose-body-field { flex: 1; padding: 0; border-bottom: none; min-height: 0; }
.compose-body-field textarea {
  width: 100%; height: 100%; border: none; resize: none; padding: 14px; font-size: 14.5px; line-height: 1.5;
}
.compose-body-field textarea:focus { outline: none; }
.compose-attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px; }
.compose-attachments .a-chip { display:flex; align-items:center; gap:6px; background: var(--gg-bg); border:1px solid var(--gg-border); border-radius: 6px; padding: 4px 8px; font-size: 12px; }
.compose-attachments .a-chip button { border:none; background:none; cursor:pointer; color: var(--gg-text-faint); font-size: 14px; line-height: 1; }
.compose-footer { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-top: 1px solid var(--gg-border); }
.attach-btn { cursor: pointer; color: var(--gg-text-muted); width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 50%; }
.attach-btn:hover { background: var(--gg-bg); }
.compose-error { margin: 0 14px 12px; background: #fdeceb; color: #a8271f; border-radius: 7px; padding: 8px 10px; font-size: 13px; }

/* ==========================================================================
   Toast
   ========================================================================== */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--gg-black); color: #fff; padding: 11px 18px; border-radius: 8px;
  font-size: 13.5px; z-index: 100; box-shadow: var(--gg-shadow);
}

/* ==========================================================================
   Responsive behaviour
   ========================================================================== */
.only-mobile { display: none; }

@media (min-width: 641px) {
  .topbar-title { display: block; }
}

/* Tablet/desktop: three panes side by side, always both list+reading visible */
@media (min-width: 900px) {
  .msg-list-pane { display: flex !important; }
  .reading-pane { display: flex !important; }
}

/* Mobile: single-column navigation between list <-> reading, off-canvas folders */
@media (max-width: 899px) {
  .only-desktop { display: none; }
  .only-mobile { display: inline-flex; }

  .sidebar {
    position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: 260px; z-index: 40;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .app-shell.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-scrim {
    display: none; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(0,0,0,.4); z-index: 39;
  }
  .app-shell.sidebar-open .sidebar-scrim { display: block; }

  .msg-list-pane { width: 100%; border-right: none; }
  .reading-pane { display: none; position: fixed; top: var(--topbar-h); left: 0; right: 0; bottom: 0; z-index: 20; }
  .app-shell.show-reading .msg-list-pane { display: none; }
  .app-shell.show-reading .reading-pane { display: flex; }

  .reading-body { padding: 16px; }
  .reading-subject { font-size: 18px; }

  .compose-overlay { align-items: stretch; justify-content: stretch; }
  .compose-modal { width: 100%; height: 100%; max-height: 100%; border-radius: 0; margin: 0; }

  .topbar-search { max-width: none; }
}

@media (max-width: 420px) {
  .reading-meta { flex-wrap: wrap; }
  .reading-date { width: 100%; margin-left: 52px; }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
}

/* Focus visibility */
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--gg-green); outline-offset: 2px;
}
