/* ============================================================
   dotPixel Mail — Stylesheet
   ============================================================ */

:root {
  --accent:        #1a56db;
  --accent-light:  #e8f0fe;
  --accent-dark:   #1141a8;
  --bg:            #f3f4f6;
  --surface:       #ffffff;
  --surface-2:     #f9fafb;
  --border:        #e5e7eb;
  --border-2:      #d1d5db;
  --text-1:        #111827;
  --text-2:        #374151;
  --text-3:        #6b7280;
  --text-4:        #9ca3af;
  --danger:        #dc2626;
  --danger-light:  #fee2e2;
  --success:       #059669;
  --warn:          #d97706;
  --sidebar-w:     240px;
  --list-w:        340px;
  --radius:        10px;
  --radius-sm:     6px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:     0 4px 12px rgba(0,0,0,.10);
  --font:          'DM Sans', system-ui, sans-serif;
  --font-mono:     'DM Mono', monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:         #111827;
    --surface:    #1f2937;
    --surface-2:  #111827;
    --border:     #374151;
    --border-2:   #4b5563;
    --text-1:     #f9fafb;
    --text-2:     #e5e7eb;
    --text-3:     #9ca3af;
    --text-4:     #6b7280;
    --accent-light: #1e3a5f;
  }
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-1);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Login pagina ─────────────────────────────────────── */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-bg {
  position: fixed; inset: 0; z-index: 0;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 50%, #1a56db 100%);
  opacity: .06;
  pointer-events: none;
}

.login-grid-lines {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: .5;
}

.login-container {
  position: relative; z-index: 1;
  width: 100%;
  max-width: 420px;
  padding: 24px 16px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 1.5);
  padding: 40px;
  box-shadow: var(--shadow-md);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
  font-size: 17px;
  font-weight: 400;
  color: var(--text-1);
}
.login-logo strong { font-weight: 600; }
.login-logo-text { letter-spacing: -.3px; }

.login-card h1 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-1);
  margin-bottom: 6px;
}

.login-subtitle {
  color: var(--text-3);
  margin-bottom: 28px;
  font-size: 14px;
}

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-1);
  font-family: var(--font);
  font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26,86,219,.15);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 100px;
  gap: 12px;
}

.advanced-toggle {
  margin-bottom: 16px;
}
.advanced-toggle summary {
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.advanced-toggle summary::before {
  content: '▸';
  transition: transform .2s;
}
.advanced-toggle[open] summary::before { transform: rotate(90deg); }
.advanced-fields {
  padding: 14px 0 0;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn-primary:hover  { background: var(--accent-dark); }
.btn-primary:active { transform: scale(.98); }
.btn-full { width: 100%; justify-content: center; padding: 12px; }

.btn-secondary {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  background: transparent;
  color: var(--text-2);
  border: 1.5px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border-2); }

.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 18px;
}
.alert-error {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid #fca5a5;
}

.login-footer {
  text-align: center;
  margin-top: 28px;
  font-size: 12px;
  color: var(--text-4);
}
.login-footer a { color: var(--accent); text-decoration: none; }

/* ── App layout ───────────────────────────────────────── */
body.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) var(--list-w) 1fr;
  grid-template-rows: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar {
  grid-column: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  height: 100vh;
  overflow-y: auto;
}

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

.logo {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 400; color: var(--text-1);
}
.logo strong { font-weight: 600; }

.sidebar-close {
  display: none;
  background: none; border: none;
  color: var(--text-3); cursor: pointer;
  font-size: 16px; padding: 4px;
}

.compose-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 12px;
  padding: 10px 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
  width: calc(100% - 24px);
}
.compose-btn:hover { background: var(--accent-dark); }

.folder-nav {
  flex: 1;
  padding: 8px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  cursor: pointer;
  border-radius: 0;
  color: var(--text-2);
  font-size: 14px;
  transition: background .1s, color .1s;
  user-select: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 500;
}
.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.nav-section {
  padding: 10px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-4);
}

.nav-loading { padding: 12px 16px; color: var(--text-4); font-size: 13px; }

.sidebar-footer {
  padding: 14px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 13px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.user-name  { font-size: 13px; font-weight: 500; color: var(--text-1); }
.user-email { font-size: 12px; color: var(--text-4); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.user-info  { flex: 1; min-width: 0; }

.logout-btn {
  background: none; border: none;
  color: var(--text-4); cursor: pointer;
  padding: 6px; border-radius: var(--radius-sm);
  transition: color .15s, background .15s;
  display: flex; align-items: center;
}
.logout-btn:hover { color: var(--danger); background: var(--danger-light); }

/* ── Berichtenlijst ───────────────────────────────────── */
.message-list {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  height: 100vh;
  background: var(--surface);
}

.list-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  height: 56px;
}

.list-header h2 {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-1);
}

.menu-toggle {
  display: none;
  background: none; border: none;
  color: var(--text-3); cursor: pointer;
  padding: 4px; border-radius: var(--radius-sm);
}

.refresh-btn {
  background: none; border: none;
  color: var(--text-4); cursor: pointer;
  padding: 5px; border-radius: var(--radius-sm);
  transition: color .15s, background .15s;
}
.refresh-btn:hover { color: var(--accent); background: var(--accent-light); }
.refresh-btn.spinning svg { animation: spin .6s linear infinite; }

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

.list-body { flex: 1; overflow-y: auto; }
.list-loading { padding: 24px 16px; color: var(--text-4); font-size: 13px; text-align: center; }

.msg-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 2px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
  align-items: start;
}
.msg-item:hover   { background: var(--surface-2); }
.msg-item.active  { background: var(--accent-light); }
.msg-item.unread .msg-from,
.msg-item.unread .msg-subject { font-weight: 600; }

.msg-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  grid-row: 1 / 3;
  align-self: center;
  flex-shrink: 0;
  transition: background .15s;
}
.msg-item:not(.unread) .msg-dot { background: transparent; }

.msg-from    { font-size: 13px; font-weight: 500; color: var(--text-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-date    { font-size: 11px; color: var(--text-4); white-space: nowrap; }
.msg-subject { grid-column: 2; font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-flagged { color: var(--warn); font-size: 13px; grid-row: 2; grid-column: 3; }

.list-pagination {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-4);
}
.list-pagination button {
  background: none; border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); padding: 4px 12px;
  font-size: 12px; cursor: pointer; color: var(--text-2);
  transition: background .1s;
}
.list-pagination button:hover { background: var(--surface-2); }
.list-pagination button:disabled { opacity: .4; cursor: default; }

/* ── Berichtweergave ──────────────────────────────────── */
.message-view {
  grid-column: 3;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  overflow: hidden;
}

.view-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 100%;
  color: var(--text-4);
  font-size: 14px;
}

.view-header {
  padding: 20px 28px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.view-subject {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-1);
  margin-bottom: 12px;
  line-height: 1.3;
}

.view-meta {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.view-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 14px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.view-from  { font-size: 14px; font-weight: 500; color: var(--text-1); }
.view-email { font-size: 12px; color: var(--text-3); }
.view-date  { margin-left: auto; font-size: 12px; color: var(--text-4); white-space: nowrap; }

.view-actions {
  display: flex;
  gap: 8px;
  padding: 10px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.view-action-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-family: var(--font); font-size: 13px;
  cursor: pointer;
  transition: background .1s, border-color .1s;
}
.view-action-btn:hover { background: var(--border); border-color: var(--border-2); }
.view-action-btn.danger:hover { background: var(--danger-light); color: var(--danger); border-color: #fca5a5; }

.view-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
}

.view-body-html {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  max-width: 720px;
  line-height: 1.7;
  color: var(--text-1);
  word-break: break-word;
}

.view-body-html img { max-width: 100%; height: auto; }
.view-body-html a   { color: var(--accent); }
.view-body-html blockquote {
  border-left: 3px solid var(--border-2);
  margin: 12px 0;
  padding: 6px 16px;
  color: var(--text-3);
}

.view-attachments {
  margin-top: 16px;
  max-width: 720px;
}
.view-attachments h4 {
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-4);
  margin-bottom: 8px;
}
.attachment-list { display: flex; flex-wrap: wrap; gap: 8px; }
.attachment-item {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
  transition: background .1s;
}
.attachment-item:hover { background: var(--accent-light); }

/* ── Compose modal ────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: flex-end;
  padding: 0 24px 24px 0;
}
.modal-overlay[hidden] { display: none !important; }

.compose-modal {
  width: 580px;
  max-height: 80vh;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slide-up .2s ease;
}

@keyframes slide-up {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.modal-header h3 { font-size: 14px; font-weight: 600; color: var(--text-1); }
.modal-close {
  background: none; border: none;
  font-size: 20px; color: var(--text-4);
  cursor: pointer; line-height: 1;
  padding: 0 4px;
}

.modal-body { flex: 1; overflow-y: auto; }

.compose-field {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding: 0 18px;
}
.compose-field label {
  font-size: 12px; font-weight: 600;
  color: var(--text-4); width: 56px;
  flex-shrink: 0; padding: 12px 0;
}
.compose-field input {
  flex: 1; border: none; outline: none;
  padding: 12px 0; background: transparent;
  font-family: var(--font); font-size: 14px;
  color: var(--text-1);
}
.compose-subject { }

.compose-body-wrap {
  display: flex; flex-direction: column;
  min-height: 220px;
}

.compose-toolbar {
  display: flex; gap: 4px; align-items: center;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
}
.compose-toolbar button {
  background: none; border: none;
  padding: 4px 8px; border-radius: 4px;
  cursor: pointer; font-size: 14px;
  color: var(--text-3); transition: background .1s, color .1s;
}
.compose-toolbar button:hover { background: var(--surface-2); color: var(--text-1); }
.compose-toolbar .sep {
  width: 1px; height: 16px;
  background: var(--border-2); margin: 0 4px;
}

.compose-body {
  flex: 1; padding: 14px 18px;
  min-height: 180px;
  font-size: 14px; line-height: 1.7;
  color: var(--text-1); outline: none;
  font-family: var(--font);
}
.compose-body:empty::before {
  content: 'Schrijf je bericht hier…';
  color: var(--text-4);
  pointer-events: none;
}

.modal-footer {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.compose-status { flex: 1; font-size: 12px; color: var(--text-4); }

/* ── Mobiel ───────────────────────────────────────────── */
.mobile-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.4);
}

@media (max-width: 900px) {
  body.app {
    grid-template-columns: 1fr;
    grid-template-rows: 100vh;
  }

  .sidebar {
    position: fixed; left: 0; top: 0;
    width: var(--sidebar-w);
    height: 100%;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-md);
  }
  .sidebar-close { display: block; }
  .mobile-overlay.active { display: block; }

  .message-list {
    grid-column: 1;
    position: absolute; top: 0; left: 0; right: 0;
    width: 100%;
    z-index: 2;
  }
  .message-list.hidden { display: none; }
  .menu-toggle { display: block; }

  .message-view {
    grid-column: 1;
    position: absolute; top: 0; left: 0; right: 0;
    width: 100%;
    z-index: 3;
    display: none;
  }
  .message-view.open { display: flex; }

  .compose-modal {
    width: 100vw; max-height: 90vh;
    border-radius: var(--radius) var(--radius) 0 0;
  }
  .modal-overlay { padding: 0; align-items: flex-end; }
}

@media (max-width: 640px) {
  .view-header   { padding: 16px 16px 12px; }
  .view-actions  { padding: 8px 16px; }
  .view-body     { padding: 16px; }
  .view-body-html { padding: 16px; }
}

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