/* ============================================================
   Design Tokens
   ============================================================ */
:root {
  --bg-app:        #F7F8FA;
  --bg-panel:      #FFFFFF;
  --bg-sidebar:    #12172B;
  --bg-sidebar-hover: #1C2340;
  --accent:        #5B5FEF;
  --accent-hover:  #4A4EDB;
  --accent-soft:   #EEEEFD;
  --text-primary:  #1A1D29;
  --text-muted:    #6B7280;
  --text-inverse:  #E7E9F5;
  --border:        #E5E7EB;
  --border-strong: #D1D5DB;
  --unread-dot:    #5B5FEF;
  --danger:        #E5484D;

  --font-ui:     'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-read:   'Newsreader', Georgia, serif;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: var(--font-ui);
  color: var(--text-primary);
  background: var(--bg-app);
  font-size: 14px;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ============================================================
   Auth Screen
   ============================================================ */
.auth-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 15% 20%, rgba(91,95,239,0.12), transparent 40%),
    var(--bg-sidebar);
}
.auth-card {
  width: 380px;
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  padding: 36px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.auth-brand-mark {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: var(--accent); color: white;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-read); font-style: italic; font-size: 20px;
}
.auth-brand-name { font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }

.auth-tabs { display: flex; gap: 4px; margin-bottom: 24px; background: var(--bg-app); padding: 4px; border-radius: var(--radius-sm); }
.auth-tab {
  flex: 1; padding: 8px; border: none; background: transparent;
  border-radius: var(--radius-sm); font-weight: 500; color: var(--text-muted);
}
.auth-tab.active { background: var(--bg-panel); color: var(--text-primary); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 13px; color: var(--text-muted); }
.auth-form input {
  padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 14px; color: var(--text-primary);
}
.auth-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.auth-error { color: var(--danger); font-size: 13px; min-height: 0; margin: 0; }

.btn-primary {
  background: var(--accent); color: white; border: none;
  padding: 11px; border-radius: var(--radius-sm); font-weight: 600; font-size: 14px;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: transparent; color: var(--text-muted); border: 1px solid var(--border-strong);
  padding: 10px 16px; border-radius: var(--radius-sm); font-weight: 500;
}

/* ============================================================
   App Shell
   ============================================================ */
.app { height: 100vh; display: flex; flex-direction: column; }

/* Top Bar */
.top-bar {
  display: flex; align-items: center; gap: 16px;
  background: var(--bg-sidebar); padding: 10px 16px;
  border-bottom: 1px solid #0A0E1C;
}
.top-bar-brand { display: flex; align-items: center; gap: 8px; color: var(--text-inverse); font-weight: 700; font-size: 14px; flex-shrink: 0; }
.top-bar-brand .auth-brand-mark { width: 26px; height: 26px; font-size: 14px; }
.search-input-top { width: 320px; max-width: 40vw; }
.top-bar-spacer { flex: 1; }
.btn-compose {
  background: var(--accent); color: white; border: none; width: 100%;
  padding: 10px 16px; border-radius: var(--radius-sm); font-weight: 600; font-size: 13px;
  margin-bottom: 14px;
}
.btn-logout {
  background: transparent; border: none; color: var(--text-inverse); font-size: 16px;
  padding: 6px 10px; border-radius: var(--radius-sm); opacity: 0.7;
}
.btn-logout:hover { opacity: 1; }

.app-body { flex: 1; display: grid; grid-template-columns: 240px 340px 1fr; overflow: hidden; }

/* Signature element: sidebar with accounts stacked, each with its own nested folder tree */
.sidebar {
  background: var(--bg-panel); border-right: 1px solid var(--border);
  padding: 16px 12px; overflow-y: auto; display: flex; flex-direction: column;
}
.sidebar-accounts { flex: 1; display: flex; flex-direction: column; gap: 4px; }

.account-block { border-radius: var(--radius-sm); }
.account-header {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 8px; border: none; background: transparent; border-radius: var(--radius-sm);
  text-align: left; font-weight: 700; font-size: 13px; color: var(--text-primary);
}
.account-header:hover { background: var(--bg-app); }
.account-header-avatar {
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--accent); color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.account-header-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-header-chevron { font-size: 10px; color: var(--text-muted); transition: transform 0.15s; }
.account-block.expanded .account-header-chevron { transform: rotate(90deg); }

.folder-list { list-style: none; margin: 2px 0 8px; padding: 0 0 0 14px; display: none; flex-direction: column; gap: 1px; border-left: 1px solid var(--border); }
.account-block.expanded .folder-list { display: flex; }
.folder-item {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 6px 10px; border-radius: var(--radius-sm); color: var(--text-muted);
  font-weight: 500; font-size: 13px;
}
.folder-item:hover { background: var(--bg-app); color: var(--text-primary); }
.folder-item.active { background: var(--accent-soft); color: var(--accent); }
.folder-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-item-count { font-size: 11px; color: var(--text-muted); }
.folder-item-add {
  opacity: 0; width: 16px; height: 16px; line-height: 16px; text-align: center;
  border-radius: 4px; font-size: 12px; flex-shrink: 0; color: var(--text-muted);
}
.folder-item:hover .folder-item-add { opacity: 1; }
.folder-item-add:hover { background: var(--accent); color: white; }

.account-add-row {
  border: 1px dashed var(--border-strong); background: transparent; color: var(--text-muted);
  padding: 10px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; margin-top: 10px;
}
.account-add-row:hover { background: var(--bg-app); color: var(--text-primary); }
.folder-add-row {
  border: none; background: transparent; color: var(--text-muted); text-align: left;
  padding: 5px 10px 8px; font-size: 12px; font-weight: 500;
}
.folder-add-row:hover { color: var(--accent); }

/* Message Pane */
.message-pane { background: var(--bg-app); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.message-pane-header { padding: 16px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--border); }
.message-pane-header h2 { margin: 0; font-size: 16px; font-weight: 700; }
.search-input {
  padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg-panel);
}
.message-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.message-item {
  padding: 12px; border-radius: var(--radius-md); margin-bottom: 4px;
  display: flex; flex-direction: column; gap: 4px; border: 1px solid transparent; position: relative;
}
.message-item:hover { background: var(--bg-panel); border-color: var(--border); }
.message-item.active { background: var(--bg-panel); border-color: var(--accent); }
.message-item.unread .message-item-subject { font-weight: 700; }
.message-item-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.message-item-from { font-weight: 600; font-size: 13px; }
.message-item-date { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.message-item-subject { font-size: 13px; color: var(--text-primary); }
.message-item-folder {
  font-size: 10px; font-weight: 600; color: var(--accent); background: var(--accent-soft);
  padding: 1px 6px; border-radius: 999px; margin-left: 4px;
}
.message-item-preview { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-item-unread-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--unread-dot); flex-shrink: 0; }
.message-item-actions {
  position: absolute; top: 8px; right: 10px; display: flex; gap: 4px; opacity: 0;
}
.message-item:hover .message-item-actions { opacity: 1; }
.message-item-star, .message-item-trash {
  border: none; background: var(--bg-panel); width: 22px; height: 22px; border-radius: 6px;
  font-size: 12px; color: var(--text-muted); box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.message-item-star:hover, .message-item-trash:hover { color: var(--text-primary); }
.message-item-star.active { color: #E8A93B; }

/* Reading Pane */
.reading-pane { background: var(--bg-panel); overflow-y: auto; padding: 32px; }
.reading-empty {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-muted); gap: 8px;
}
.reading-empty-mark { font-size: 32px; opacity: 0.4; }
.reading-header { border-bottom: 1px solid var(--border); padding-bottom: 20px; margin-bottom: 24px; }
.reading-subject { font-family: var(--font-read); font-size: 24px; font-weight: 500; margin: 0 0 12px; }
.reading-meta { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }
.reading-meta strong { color: var(--text-primary); }
.reading-actions { display: flex; gap: 8px; margin-top: 16px; }
.reading-actions button {
  padding: 7px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: transparent; font-size: 13px; font-weight: 500; color: var(--text-muted);
}
.reading-actions button:hover { background: var(--bg-app); color: var(--text-primary); }
.reading-actions .message-item-star { width: auto; height: auto; padding: 7px 10px; box-shadow: none; }
.reading-actions .message-item-star.active { color: #E8A93B; border-color: #E8A93B; }
.reading-body { font-family: var(--font-read); font-size: 16px; line-height: 1.65; }
.reading-body img { max-width: 100%; }

.settings-account-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.settings-account-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px;
}
.settings-account-meta { display: block; font-size: 11px; color: var(--text-muted); font-weight: 400; }

/* ============================================================
   Modals
   ============================================================ */
.modal {
  position: fixed; inset: 0; background: rgba(18,23,43,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-card {
  width: 420px; background: var(--bg-panel); border-radius: var(--radius-lg);
  padding: 28px; box-shadow: 0 24px 70px rgba(0,0,0,0.25);
}
.modal-card-wide { width: 560px; }
.modal-card h3 { margin: 0 0 18px; font-size: 18px; }
.modal-tabs { display: flex; gap: 4px; margin-bottom: 18px; background: var(--bg-app); padding: 4px; border-radius: var(--radius-sm); }
.modal-tab { flex: 1; padding: 7px; border: none; background: transparent; border-radius: var(--radius-sm); font-size: 12px; font-weight: 500; color: var(--text-muted); }
.modal-tab.active { background: var(--bg-panel); color: var(--text-primary); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.modal-form { display: flex; flex-direction: column; gap: 12px; }
.modal-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 500; color: var(--text-muted); }
.modal-form input, .modal-form select, .modal-form textarea {
  padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
.modal-form textarea { resize: vertical; font-family: var(--font-read); font-size: 15px; }
.form-row { display: flex; gap: 10px; }
.form-row label { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.modal-notice { padding: 12px; background: var(--accent-soft); color: var(--accent); border-radius: var(--radius-sm); font-size: 13px; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
  .app-body { grid-template-columns: 1fr; }
  .folder-pane, .message-pane { display: none; }
}

/* ============================================================
   Mehrfachauswahl / Bulk-Bar
   ============================================================ */
.bulk-bar {
  display: flex; align-items: center; gap: 12px;
  background: var(--accent-soft); border-radius: var(--radius-sm);
  padding: 8px 10px; font-size: 12px; color: var(--accent);
}
.bulk-select-all { display: flex; align-items: center; gap: 6px; font-weight: 600; cursor: pointer; }
.bulk-count { flex: 1; }
.bulk-actions { display: flex; gap: 6px; align-items: center; }
.bulk-actions button, .bulk-actions select {
  border: 1px solid var(--accent); background: var(--bg-panel); color: var(--accent);
  padding: 5px 9px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 600;
}
.bulk-actions .bulk-delete { border-color: var(--danger); color: var(--danger); }

.message-item-checkbox {
  margin-right: 4px; align-self: flex-start; margin-top: 2px;
}
.message-item { flex-direction: row; align-items: flex-start; gap: 8px; }
.message-item-content { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.message-item[draggable="true"] { cursor: grab; }
.message-item.dragging { opacity: 0.5; }

.folder-item.drag-over { background: var(--accent-soft); outline: 1px dashed var(--accent); }

/* ============================================================
   Rich-Text-Editor (Compose & Signatur)
   ============================================================ */
.rte-toolbar { display: flex; gap: 4px; margin-bottom: -4px; }
.rte-toolbar button {
  border: 1px solid var(--border-strong); background: var(--bg-panel); color: var(--text-muted);
  width: 30px; height: 28px; border-radius: var(--radius-sm); font-size: 13px;
}
.rte-toolbar button:hover { background: var(--bg-app); color: var(--text-primary); }
.rte-editor {
  min-height: 160px; max-height: 340px; overflow-y: auto;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 10px 12px; font-family: var(--font-read); font-size: 15px; line-height: 1.5;
}
.rte-editor:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.rte-editor:empty::before { content: attr(data-placeholder); color: var(--text-muted); }
#signature-body.rte-editor { min-height: 100px; max-height: 220px; }
