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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --border: #2a2a4a;
  --text: #e0e0e0;
  --text-muted: #888;
  --accent: #4fc3f7;
  --accent-hover: #29b6f6;
  --danger: #ef5350;
  --danger-hover: #c62828;
  --unread-bg: #1e2a45;
  --header-h: 56px;
  --sidebar-w: 220px;
  --list-w: 320px;
}

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

/* Header */
.header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

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

.logout-link {
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: color 0.2s, border-color 0.2s;
}
.logout-link:hover { color: var(--text); border-color: var(--text-muted); }

/* App layout */
.app-layout {
  display: flex;
  height: calc(100vh - var(--header-h));
  margin-top: var(--header-h);
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  overflow-y: auto;
}

.compose-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  margin-bottom: 20px;
}
.compose-btn:hover { background: var(--accent-hover); }

.account-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 0 8px;
  margin-bottom: 8px;
}

.account-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
  margin-bottom: 2px;
}
.account-item:hover { background: var(--border); }
.account-item.active { background: var(--surface2); color: var(--accent); }

.account-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #000;
  flex-shrink: 0;
}

.account-name { flex: 1; font-size: 13px; }

.account-badge {
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
}

/* Email list panel */
.email-list-panel {
  width: var(--list-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
  background: var(--surface);
  flex-shrink: 0;
}

.refresh-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color 0.2s;
}
.refresh-btn:hover { color: var(--text); }

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

.email-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.email-item:hover { background: var(--border); }
.email-item.active { background: var(--surface2); }
.email-item.unread { background: var(--unread-bg); }
.email-item.unread .item-from { font-weight: 700; color: var(--text); }
.email-item.unread .item-subject { font-weight: 600; }

.item-row1 { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 3px; }
.item-from { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.item-date { font-size: 11px; color: var(--text-muted); flex-shrink: 0; margin-left: 8px; }
.item-subject { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-muted);
  font-size: 13px;
  gap: 8px;
}

/* Email view panel */
.email-view-panel {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.view-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 12px;
}
.view-empty p { font-size: 14px; }

/* Email detail */
.email-detail {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-header {
  padding: 20px 24px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

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

.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s, border-color 0.15s;
}
.action-btn:hover { background: var(--border); border-color: var(--text-muted); }
.action-btn.danger { color: var(--danger); border-color: var(--danger); }
.action-btn.danger:hover { background: rgba(239,83,80,0.1); }

.detail-meta {
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.detail-meta strong { color: var(--text); }

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.detail-body iframe {
  width: 100%;
  border: none;
  background: white;
  border-radius: 6px;
}

.detail-attachments {
  padding: 12px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.attachments-title { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.attachment-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-right: 8px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
.attachment-item:hover { background: var(--border); }

/* Compose form */
.compose-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}
.close-btn:hover { color: var(--text); }

.compose-fields {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.field-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  flex-shrink: 0;
}
.field-row label {
  width: 50px;
  font-size: 13px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.field-row input, .field-row select {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  padding: 12px 0;
  font-size: 14px;
  outline: none;
}
.field-row select option { background: var(--surface); }

.compose-body-area {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 16px 24px;
}

.compose-body {
  flex: 1;
  outline: none;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  overflow-y: auto;
  min-height: 200px;
}
.compose-body:empty::before {
  content: 'Текст листа...';
  color: var(--text-muted);
}
.compose-body blockquote {
  border-left: 3px solid var(--border);
  margin: 8px 0;
  padding: 4px 12px;
  color: var(--text-muted);
}

.compose-error {
  color: var(--danger);
  font-size: 13px;
  padding: 8px 24px;
  flex-shrink: 0;
}

.compose-actions {
  padding: 12px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.send-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.6; cursor: not-allowed; }

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

/* Toast notification */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 10000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.toast-success {
  background: #2e7d32;
  color: #fff;
}
.toast-error {
  background: var(--danger);
  color: #fff;
}
