*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f1726;
  --bg-card: #1e2a45;
  --accent: #d4a843;
  --accent-dim: #a07830;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --success: #4caf50;
  --warning: #ff9800;
  --error: #f44336;
  --border: #2a3a5e;
  --hover: #243354;
  --sidebar-width: 220px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }

/* ── Login screen ─────────────────────────────────────────────────────────── */

#login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 24px;
}

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.login-card .logo {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.login-card .tagline {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 28px;
}

.login-card .form-group { margin-bottom: 14px; text-align: left; }
.login-card .form-label { color: var(--text-secondary); }
.login-card .form-control { background: var(--bg-tertiary); }

.login-card .error-msg {
  background: rgba(244, 67, 54, 0.12);
  border: 1px solid var(--error);
  color: var(--error);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 20px;
  display: none;
}

.login-card .error-msg.visible { display: block; }
.login-card .btn { display: flex; gap: 10px; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #1a1a2e;
  width: 100%;
  padding: 13px;
  font-size: 15px;
}

.btn-primary:hover:not(:disabled) { background: #e0b54f; }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) { background: var(--hover); }

.btn-danger {
  background: transparent;
  border: 1px solid var(--error);
  color: var(--error);
}

.btn-danger:hover:not(:disabled) { background: rgba(244,67,54,0.1); }

.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ── App shell ────────────────────────────────────────────────────────────── */

#app { display: none; flex-direction: column; height: 100vh; }
#app.visible { display: flex; }

/* ── Header ───────────────────────────────────────────────────────────────── */

header {
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 10;
}

.header-brand {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.03em;
}

.header-brand span {
  color: var(--text-secondary);
  font-weight: 400;
  font-size: 13px;
  margin-left: 10px;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--text-secondary);
  font-size: 13px;
}

/* ── Main layout ──────────────────────────────────────────────────────────── */

.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-section { padding: 16px 12px 8px; }

.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 4px;
  margin-bottom: 6px;
}

.inbox-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.1s, color 0.1s;
  font-size: 13px;
  margin-bottom: 2px;
}

.inbox-item:hover { background: var(--hover); color: var(--text-primary); }

.inbox-item.active {
  background: rgba(212, 168, 67, 0.15);
  color: var(--accent);
  font-weight: 500;
}

.inbox-item .inbox-icon { margin-right: 8px; font-size: 15px; }

.inbox-item .inbox-name { flex: 1; }

.badge {
  background: var(--accent);
  color: #1a1a2e;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
}

.badge.zero { display: none; }

.sidebar-stats {
  margin-top: auto;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}

.stat-val { color: var(--accent); font-weight: 600; }

/* ── Content area ─────────────────────────────────────────────────────────── */

.content-area {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Email list ───────────────────────────────────────────────────────────── */

.email-list-pane {
  width: 380px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.pane-title {
  font-size: 15px;
  font-weight: 600;
}

.search-bar {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}

.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }

.email-list {
  flex: 1;
  overflow-y: auto;
}

.email-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}

.email-item:hover { background: var(--hover); }
.email-item.active { background: rgba(212, 168, 67, 0.08); border-left: 3px solid var(--accent); }
.email-item.unread { background: rgba(255,255,255,0.03); }
.email-item.unread .email-subject { font-weight: 600; color: var(--text-primary); }

.email-item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 3px;
}

.email-sender {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.email-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: 8px;
}

.email-subject {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

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

.email-badges {
  display: flex;
  gap: 5px;
  margin-top: 5px;
  flex-wrap: wrap;
}

.priority-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.priority-badge.high { background: rgba(244,67,54,0.2); color: var(--error); }
.priority-badge.normal { background: rgba(76,175,80,0.15); color: var(--success); }
.priority-badge.client { background: rgba(212,168,67,0.2); color: var(--accent); border: 1px solid rgba(212,168,67,0.4); }
.priority-badge.attachment { background: rgba(160,160,176,0.15); color: var(--text-secondary); }

/* ── Email detail ─────────────────────────────────────────────────────────── */

.email-detail-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

.detail-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 14px;
}

.detail-content {
  display: none;
  flex-direction: column;
  height: 100%;
}

.detail-content.visible { display: flex; }

.detail-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.detail-subject {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 10px;
  line-height: 1.3;
}

.detail-meta {
  display: flex;
  gap: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  flex-wrap: wrap;
}

.detail-meta span { display: flex; gap: 5px; }
.detail-meta strong { color: var(--text-primary); }

.detail-actions {
  padding: 10px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary);
}

.detail-body-html {
  background: #fff;
  color: #1a1a2e;
  border-radius: 8px;
  padding: 20px;
}

/* ── Compose modal ────────────────────────────────────────────────────────── */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.visible { display: flex; }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 640px;
  max-width: 96vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
  font-weight: 600;
}

.modal-body { padding: 18px 20px; flex: 1; overflow-y: auto; }

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.form-group { margin-bottom: 14px; }

.form-label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.form-control {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  font-family: inherit;
}

.form-control:focus { border-color: var(--accent); }

textarea.form-control { resize: vertical; min-height: 180px; }

/* ── Skeleton loaders ─────────────────────────────────────────────────────── */

.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 4px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-row {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.skel-line { height: 12px; margin-bottom: 8px; }
.skel-line.w60 { width: 60%; }
.skel-line.w80 { width: 80%; }
.skel-line.w40 { width: 40%; }

/* ── Toast notifications ──────────────────────────────────────────────────── */

#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 13px;
  color: var(--text-primary);
  animation: slideIn 0.2s ease;
  max-width: 320px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--error); }

@keyframes slideIn {
  from { transform: translateX(40px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Scrollbars ───────────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .email-detail-pane { display: none; }
  .email-detail-pane.mobile-visible { display: flex; position: absolute; inset: 56px 0 0 0; z-index: 20; }
  .email-list-pane { width: 100%; border-right: none; }
}

@media (max-width: 640px) {
  .sidebar { display: none; }
  .sidebar.mobile-open { display: flex; position: absolute; inset: 56px 0 0 0; z-index: 30; width: 240px; }
}
