:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f242e;
  --border: #2a303c;
  --text: #e6e9ef;
  --muted: #8b94a6;
  --accent: #5b8cff;
  --accent-hover: #4678f5;
  --danger: #e5534b;
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; margin-bottom: 12px; }
.error-text { color: var(--danger); font-size: 13px; margin-top: 10px; }

/* Buttons & Inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius); border: 1px solid transparent;
  font: inherit; font-weight: 500; cursor: pointer; transition: background 0.15s;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-full { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: var(--border); }
.btn-danger-ghost:hover:not(:disabled) { background: rgba(229, 83, 75, 0.12); }
.btn-danger-sm { padding: 5px 10px; font-size: 12px; background: var(--danger); color: #fff; }
.btn-icon { background: none; border: none; color: var(--muted); font-size: 16px; cursor: pointer; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field input, .field textarea {
  width: 100%; padding: 9px 11px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.input-group { display: flex; align-items: center; }
.input-group input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-suffix {
  padding: 9px 10px; background: var(--surface-2); border: 1px solid var(--border);
  border-left: none; border-radius: 0 var(--radius) var(--radius) 0; color: var(--muted); font-size: 13px; white-space: nowrap;
}

/* Auth Screen */
.auth-shell { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 26px; }
.brand { margin-bottom: 20px; }
.brand h1 { font-size: 22px; margin-bottom: 4px; }

/* Main Layout */
.app-shell { display: grid; grid-template-columns: 210px 320px 1fr; height: 100vh; overflow: hidden; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px; gap: 14px;
}
.account-pill { font-size: 12px; color: var(--muted); margin-bottom: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.folder-btn {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border: none; border-radius: var(--radius);
  background: transparent; color: var(--text); font: inherit; cursor: pointer; text-align: left;
}
.folder-btn:hover { background: var(--surface-2); }
.folder-btn.active { background: var(--surface-2); color: var(--accent); font-weight: 600; }
.badge { font-size: 11px; color: var(--muted); }
.sidebar-bottom { display: flex; flex-direction: column; gap: 6px; }

/* Message List */
.list-pane { border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.pane-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.pane-header h2 { font-size: 16px; }
.message-list { flex: 1; overflow-y: auto; }
.msg-item {
  padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer;
  display: flex; flex-direction: column; gap: 3px;
}
.msg-item:hover { background: var(--surface); }
.msg-item.active { background: var(--surface-2); border-left: 3px solid var(--accent); padding-left: 13px; }
.msg-item.unread .msg-from, .msg-item.unread .msg-subject { font-weight: 700; color: #fff; }
.msg-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.msg-from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-date { color: var(--muted); font-size: 11px; white-space: nowrap; }
.msg-subject { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-snippet { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Reader Pane */
.reader-pane { display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
.reader-empty { margin: auto; font-size: 14px; }
.reader-content { display: flex; flex-direction: column; height: 100%; }
.reader-header { padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--surface); }
.reader-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.reader-subject { font-size: 18px; margin-bottom: 8px; }
.reader-meta { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.attachments { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.att-chip { font-size: 11px; padding: 3px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); }
.img-banner {
  margin-top: 10px; padding: 7px 10px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted);
}
.reader-frame { flex: 1; width: 100%; border: none; background: var(--bg); }

/* Modals & Toast */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.65); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card { width: 100%; max-width: 560px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.modal-sm { max-width: 400px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

.toast {
  position: fixed; bottom: 18px; right: 18px; z-index: 100;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  padding: 10px 14px; border-radius: var(--radius); font-size: 13px;
}

.mobile-only { display: none; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; border-right: none; border-bottom: 1px solid var(--border); padding: 10px; }
  .sidebar-top, .sidebar-bottom { flex-direction: row; width: 100%; gap: 6px; }
  .folder-nav { flex-direction: row; overflow-x: auto; }
  .reader-pane { display: none; }
  .app-shell.reading .list-pane, .app-shell.reading .sidebar { display: none; }
  .app-shell.reading .reader-pane { display: flex; height: 100vh; }
  .mobile-only { display: inline-flex; }
}