:root {
  --bg: #0a1020;
  --surface: #101827;
  --surface-2: #141f33;
  --surface-3: #0d1524;
  --border: #1f2b3d;
  --border-strong: #2d3e57;
  --text: #e5edf8;
  --text-muted: #94a3b8;
  --accent: #6fbf2a;
  --accent-dark: #4f9a1f;
  --accent-soft: rgba(111, 191, 42, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --radius: 16px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: radial-gradient(800px 520px at 0% 0%, rgba(111, 191, 42, 0.2), transparent 68%) no-repeat fixed, var(--bg);
  color-scheme: dark;
}

.hidden {
  display: none !important;
}

/* Center screen (boot / login) */
.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.boot-loader {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Login Card */
.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 32px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.48);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 20px;
  color: #fff;
  background: linear-gradient(180deg, #78c52f 0%, #4f9a1f 100%);
  box-shadow: 0 8px 20px rgba(95, 168, 38, 0.35);
  flex-shrink: 0;
}

.brand-mark.small {
  width: 34px;
  height: 34px;
  font-size: 16px;
  border-radius: 10px;
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.subtitle {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.login-form, .composer-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="search"],
textarea {
  width: 100%;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(111, 191, 42, 0.22);
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrap input {
  padding-right: 84px;
}

.password-wrap .icon-btn {
  position: absolute;
  right: 8px;
  font-size: 12px;
  padding: 6px 10px;
}

/* Buttons */
button {
  font-family: inherit;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(180deg, #78c52f 0%, #4f9a1f 100%);
  color: #fff;
  border: 1px solid #8fd14f;
  border-radius: 999px;
  padding: 11px 18px;
  font-weight: 700;
  font-size: 13.5px;
  box-shadow: 0 6px 18px rgba(95, 168, 38, 0.3);
  transition: filter 0.15s, opacity 0.15s;
}

.btn-primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 9px 15px;
  font-weight: 600;
  font-size: 13px;
  transition: background 0.15s, border-color 0.15s;
}

.btn-secondary:hover:not(:disabled) {
  background: #1c2a42;
  border-color: #3d5270;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 13px;
}

.btn-ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.icon-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 8px;
  padding: 6px 8px;
  font-weight: 600;
}

.icon-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.small {
  padding: 7px 13px !important;
  font-size: 12.5px !important;
}

.full-width {
  width: 100%;
}

.alert-error {
  background: var(--danger-soft);
  border: 1px solid rgba(248, 113, 113, 0.4);
  color: #fecaca;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
}

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

.topbar {
  height: 62px;
  padding: 0 18px;
  background: rgba(16, 24, 39, 0.92);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.mailbox-pill {
  font-size: 12px;
  color: #bfe896;
  background: var(--accent-soft);
  border: 1px solid rgba(111, 191, 42, 0.35);
  border-radius: 999px;
  padding: 3px 10px;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  max-width: 480px;
}

.search-bar input {
  border-radius: 999px;
  padding: 8px 15px;
  font-size: 13px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sync-status {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.user-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
}

/* 3-pane Workspace */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 230px 360px 1fr;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  background: rgba(16, 24, 39, 0.72);
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}

.folder-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.folder-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 13px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13.5px;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}

.folder-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.folder-item.active {
  background: var(--accent-soft);
  border-color: rgba(111, 191, 42, 0.35);
  color: #ffffff;
}

.folder-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: #081204;
}

.folder-badge.muted {
  background: var(--surface-2);
  color: var(--text-muted);
}

.sidebar-note {
  margin-top: auto;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
}

.sidebar-note strong {
  display: block;
  color: var(--text);
  margin-bottom: 4px;
}

.sidebar-note p {
  margin: 0;
}

.sidebar-note code {
  font-size: 11px;
  color: #bfe896;
  word-break: break-all;
}

/* Message List Pane */
.list-pane {
  background: rgba(13, 21, 36, 0.85);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.pane-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pane-header h2 {
  margin: 0;
  font-size: 15px;
}

.muted-text {
  font-size: 12px;
  color: var(--text-muted);
}

.message-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.message-item {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 13px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background 0.12s;
}

.message-item:hover {
  background: rgba(255, 255, 255, 0.035);
}

.message-item.selected {
  background: rgba(111, 191, 42, 0.12);
  border-left: 3px solid var(--accent);
  padding-left: 13px;
}

.msg-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.msg-sender {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}

.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.msg-time {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.msg-subject {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-item.unread .msg-subject {
  font-weight: 700;
  color: #ffffff;
}

.msg-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-flags {
  font-size: 11px;
  color: #bfe896;
}

.list-state {
  padding: 28px 18px;
  text-align: center;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.load-more-wrap {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

/* Reader Pane */
.reader-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}

.reader-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  gap: 8px;
}

.empty-icon {
  font-size: 36px;
  opacity: 0.5;
}

.reader-empty h3 {
  margin: 4px 0 0;
  color: var(--text);
}

.reader-empty p {
  max-width: 380px;
  margin: 0;
  line-height: 1.5;
}

.reader-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.reader-toolbar {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.reader-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mail-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(16, 24, 39, 0.55);
}

.mail-subject {
  margin: 0 0 12px;
  font-size: 19px;
  line-height: 1.3;
}

.mail-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 6px 18px;
  font-size: 13px;
}

.meta-label {
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 4px;
}

.attachments-bar {
  padding: 10px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-3);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.attachments-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  text-decoration: none;
  font-size: 12.5px;
  transition: border-color 0.15s, background 0.15s;
}

.attachment-link:hover {
  border-color: var(--accent);
  background: #1a2942;
}

.mail-body-wrap {
  flex: 1;
  min-height: 0;
  padding: 16px 20px;
  overflow: auto;
  display: flex;
}

.mail-iframe {
  width: 100%;
  min-height: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #ffffff;
}

.mail-text-fallback {
  width: 100%;
  margin: 0;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  line-height: 1.6;
  overflow: auto;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 9, 18, 0.76);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-card {
  width: 100%;
  max-width: 680px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.from-banner {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 14px;
  font-size: 13px;
}

.attachments-upload-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.file-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  font-size: 12px;
}

.file-chip button {
  background: none;
  border: none;
  color: var(--danger);
  font-weight: 700;
  padding: 0 2px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
}

.modal-footer-actions {
  display: flex;
  gap: 10px;
}

/* Toasts */
.toast-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  font-size: 13.5px;
  max-width: 360px;
}

.toast.success {
  border-color: var(--accent);
}

.toast.error {
  border-color: var(--danger);
  color: #fecaca;
}

.mobile-only {
  display: none;
}

@media (max-width: 1024px) {
  .workspace {
    grid-template-columns: 200px 300px 1fr;
  }
  .sync-status {
    display: none;
  }
}

@media (max-width: 820px) {
  .topbar {
    height: auto;
    padding: 10px 12px;
    flex-wrap: wrap;
  }
  .search-bar {
    order: 3;
    max-width: none;
    width: 100%;
  }
  .workspace {
    grid-template-columns: 1fr;
  }
  .sidebar {
    flex-direction: row;
    align-items: center;
    padding: 10px 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    gap: 10px;
  }
  .sidebar .full-width {
    width: auto;
    white-space: nowrap;
  }
  .folder-nav {
    flex-direction: row;
    overflow-x: auto;
  }
  .sidebar-note {
    display: none;
  }
  .reader-pane {
    display: none;
  }
  .app-shell.mobile-reading .list-pane {
    display: none;
  }
  .app-shell.mobile-reading .reader-pane {
    display: flex;
  }
  .mobile-only {
    display: inline-flex;
  }
}
