@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap');

/* Fluidna osnovna veličina - sve što je u rem/em jedinicama raste proporcionalno
   sa veličinom ekrana (mali laptop -> 2K -> 4K), tako da app ne izgleda sitno
   razvučen na velikim monitorima. */
html {
  font-size: clamp(15px, 0.55vw + 12px, 21px);
}

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --border: #e4e9f2;
  --text: #0b1930;
  --text-dim: #64748b;
  --primary: #087bff;
  --primary-hover: #0668d9;
  --primary-tint: #eaf3ff;
  --navy: #0a3866;
  --navy-2: #0f4a86;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(11, 25, 48, 0.04), 0 8px 24px rgba(11, 25, 48, 0.06);
  --sidebar-w: clamp(220px, 15vw, 280px);
  --bottom-nav-h: 64px;
  /* Kompaktni "klasični webmail" tokeni - koriste se svugdje OSIM login ekrana */
  --app-radius: 4px;
  --app-radius-sm: 3px;
  --app-border: var(--border);
  --toolbar-bg: var(--surface-2);
}

body.dark {
  --bg: #0b1730;
  --surface: #131f3a;
  --surface-2: #182548;
  --border: #223055;
  --text: #eef2fb;
  --text-dim: #93a2c2;
  --primary-tint: #16294f;
  --navy: #0a2f57;
  --navy-2: #0f3d6e;
  --shadow: 0 1px 2px rgba(0,0,0,0.2), 0 8px 24px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 0.8125rem;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

.hidden { display: none !important; }

/* Ikonice prate veličinu teksta elementa u kojem se nalaze (em), pa rastu
   proporcionalno sa fluidnom veličinom fonta na velikim ekranima. */
button svg,
.folder-item-label svg,
.message-item .star svg,
.attachment-chip svg,
.rail-btn svg,
.bn-btn span svg {
  width: 1em;
  height: 1em;
}
.empty-state-icon, .detail-empty-icon svg { width: 2.6em; height: 2.6em; }

button {
  font: inherit;
  font-size: 0.8125rem;
  border: 1px solid transparent;
  border-radius: var(--app-radius-sm);
  padding: 0.4375rem 0.8125rem;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease, opacity 0.12s ease, transform 0.08s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
}
button:hover { background: var(--primary-hover); }
button:active { opacity: 0.85; transform: scale(0.96); }
button:disabled { opacity: 0.6; cursor: default; transform: none; }
button.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { background: var(--surface-2); border-color: var(--text-dim); }
button.secondary:active { background: var(--border); }
button.danger { background: var(--surface); color: var(--danger); border: 1px solid var(--border); }
button.danger:hover { background: #fef2f2; border-color: var(--danger); }
button.danger:active { background: #fee2e2; }
body.dark button.danger:hover { background: #2a1414; }
body.dark button.danger:active { background: #3a1a1a; }

/* Login zadržava svoj puniji/zaobljeniji izgled dugmadi */
#view-login button, #view-lock button {
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 14px;
  transition: background 0.15s ease, transform 0.12s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.15s ease;
}
#view-login button:hover, #view-lock button:hover { transform: translateY(-1px); }
#view-login button:active, #view-lock button:active { transform: scale(0.97) translateY(0); opacity: 1; }

.icon-btn {
  background: transparent;
  color: #fff;
  padding: 8px;
  border-radius: var(--app-radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); }
.icon-btn:active { opacity: 0.8; }

button.icon-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  width: 34px;
}

button svg { display: block; }
button span svg { display: block; }

/* ---------------- HEADER ---------------- */

header {
  display: none !important;
}

.header-left, .header-right { display: flex; align-items: center; gap: 4px; }

header h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-mark { width: 24px; height: 24px; border-radius: 6px; }

.only-mobile { display: none; }

.account-switcher { position: relative; }

.dropdown {
  position: absolute;
  right: 0;
  top: 44px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  min-width: 220px;
  padding: 6px;
  z-index: 40;
}

.dropdown {
  animation: authIn 0.18s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.dropdown-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.12s ease;
  gap: 8px;
}
.dropdown-item:hover { background: var(--surface-2); }
.dropdown-item:active { background: var(--border); }
.dropdown-item.active { color: var(--primary); }
.dropdown-divider { height: 1px; background: var(--border); margin: 6px 2px; }

/* ---------------- SEARCH ---------------- */

.search-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: var(--navy-2);
}
.search-bar input {
  flex: 1;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
}
.search-bar input::placeholder { color: rgba(255,255,255,0.5); }
.search-bar select#search-scope {
  flex: 0 0 auto;
  width: auto;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  font-size: 12px;
}
.search-bar select#search-scope option { color: var(--text); }
.search-bar .icon-only-sm { color: rgba(255,255,255,0.75); }
.search-bar .icon-only-sm:hover { background: rgba(255,255,255,0.12); color: #fff; }

.search-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  padding: 0.625rem 1rem;
  background: var(--navy-2);
  border-top: 1px solid rgba(255,255,255,0.12);
}
.search-filters label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 700;
  color: rgba(255,255,255,0.75);
}
.search-filters input[type="date"] {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  font-size: 0.75rem;
  padding: 0.375rem 0.5rem;
}
.search-filters .filter-checkbox { flex-direction: row; align-items: center; gap: 0.375rem; }
.search-filters .filter-checkbox input { width: 16px; height: 16px; }
.search-filters .link-btn { color: #bcd9ff; }
.search-filters .link-btn:hover { color: #fff; }

/* ---------------- PAGINACIJA ---------------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-top: none;
  background: var(--surface);
}
.pg-pages { display: flex; gap: 3px; }
.pg-page {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  min-width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: var(--app-radius-sm);
}
.pg-page:hover { background: var(--surface-2); }
.pg-page:active { background: var(--border); }
.pg-page.active { background: var(--primary); color: #fff; }
.pg-range {
  text-align: center;
  font-size: 0.6875rem;
  color: var(--text-dim);
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--border);
  border-top: none;
  background: var(--toolbar-bg);
}

/* ---------------- QUOTA ---------------- */

.quota-bar { padding: 0.5rem 0.625rem; display: flex; flex-direction: column; gap: 0.25rem; }
.quota-bar-track {
  height: 5px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}
.quota-bar-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width 0.3s ease; }
.quota-bar-fill.quota-bar-warn { background: var(--danger); }
.quota-bar span { font-size: 0.625rem; color: var(--text-dim); font-weight: 600; }

/* ---------------- RICH TEXT EDITOR ---------------- */

.rte-toolbar { display: flex; gap: 3px; padding: 4px; border: 1px solid var(--border); border-bottom: none; border-radius: var(--app-radius-sm) var(--app-radius-sm) 0 0; background: var(--surface-2); }
.rte-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  font-size: 0.75rem;
  border-radius: var(--app-radius-sm);
}
.rte-btn:hover { background: var(--surface); border-color: var(--border); }
.rte-btn:active { background: var(--border); }
.rte-editor {
  min-height: 160px;
  max-height: 360px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--app-radius-sm) var(--app-radius-sm);
  padding: 0.75rem 0.875rem;
  font-size: 0.8125rem;
  line-height: 1.55;
}
.rte-editor:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.rte-editor:empty::before { content: attr(data-placeholder); color: var(--text-dim); }

/* ---------------- LAYOUT / SIDEBAR ---------------- */

.layout { display: flex; align-items: flex-start; max-width: 1100px; margin: 0 auto; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
}

.fab-inline {
  width: 100%;
  padding: 8px;
  border-radius: var(--app-radius-sm);
  font-weight: 700;
  font-size: 13px;
}

.folder-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
.icon-only-sm:active { background: var(--border); transform: scale(0.92); }
.icon-only-sm {
  background: transparent;
  color: var(--text-dim);
  padding: 4px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
}
.icon-only-sm:hover { background: var(--surface-2); color: var(--primary); }
.icon-only-sm:disabled { opacity: 0.35; cursor: default; background: transparent; color: var(--text-dim); transform: none; }
.icon-only-sm.danger:hover:not(:disabled) { background: rgba(239,68,68,0.12); color: var(--danger); }

/* ---------------- TOOLBAR IZNAD LISTE (višestruki izbor) ---------------- */

.list-toolbar {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--app-radius) var(--app-radius) 0 0;
  background: var(--surface-2);
  flex-wrap: wrap;
}
.lt-col {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding: 0.3rem 0.625rem;
}
.lt-col-list {
  width: clamp(360px, 24vw, 460px);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
}
.lt-col-detail { flex: 1; min-width: 0; }
.sidebar-topbar {
  position: relative;
  margin: -10px -8px 6px -8px;
  padding: 0.3rem 0.75rem;
  min-height: 2.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
#account-dropdown-sidebar { top: calc(100% + 4px); right: 8px; left: auto; }
.sidebar-topbar-email {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lt-group { display: flex; flex-wrap: wrap; align-items: stretch; gap: 1px; }
.lt-btn-wrap { position: relative; display: flex; }
.lt-btn-wrap .dropdown { min-width: 160px; top: calc(100% + 2px); left: 0; right: auto; }

.lt-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0.3rem 0.4rem;
  border-radius: var(--app-radius-sm);
  min-width: 2.4rem;
  min-height: 2.375rem;
}
.lt-btn small { font-size: 0.5625rem; font-weight: 700; line-height: 1; white-space: nowrap; }
.lt-btn:hover { background: var(--surface) !important; }
.lt-btn:active:not(:disabled) { background: var(--border) !important; }
.lt-btn.active { color: var(--primary); background: var(--primary-tint); }
.lt-btn:disabled { opacity: 0.5; cursor: default; pointer-events: none; }
#lt-delete:hover:not(:disabled) { background: rgba(239,68,68,0.12) !important; color: var(--danger); }

.list-toolbar .dropdown-item {
  width: 100%;
  background: transparent;
  color: var(--text);
  border: none;
  justify-content: flex-start;
  font-size: 0.75rem;
  text-align: left;
}
.list-toolbar .dropdown-item:hover { background: var(--surface-2); }
.list-toolbar .dropdown-item:active { background: var(--border); }

.lt-count { font-size: 0.6875rem; font-weight: 700; color: var(--text-dim); padding: 0 0.375rem; }

.msg-checkbox-wrap { display: flex; align-items: center; padding-top: 2px; }
.msg-checkbox { width: 15px; height: 15px; cursor: pointer; }
.message-item.selected { background: var(--primary-tint); border-left-color: var(--primary); }

.thread-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-size: 0.625rem;
  font-weight: 800;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  cursor: pointer;
}
.thread-count:hover { background: var(--primary-tint); color: var(--primary); border-color: var(--primary); }
.thread-child .message-item { padding-left: 2.25rem; background: var(--surface-2); }

#folder-list { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }

.folder-item-right { display: flex; align-items: center; gap: 6px; }
.folder-item-manage {
  opacity: 0;
  font-weight: 900;
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--text-dim);
  transition: opacity 0.12s ease, background 0.12s ease;
}
.folder-item:hover .folder-item-manage { opacity: 1; }
.folder-item-manage:hover { background: var(--border); }
.folder-item-manage:active { background: var(--text-dim); color: #fff; transform: scale(0.92); }

.folder-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.375rem 0.5rem;
  border-radius: var(--app-radius-sm);
  border-left: 2px solid transparent;
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}
.folder-item:hover { background: var(--primary-tint); }
.folder-item:active { background: var(--border); transform: scale(0.98); }
.folder-item.active { background: var(--surface); color: var(--primary); border-left-color: var(--primary); }
.folder-item.active:hover { background: var(--primary-tint); }
.folder-item.drop-target { background: var(--primary-tint); border-left-color: var(--primary); outline: 2px dashed var(--primary); outline-offset: -2px; }
.message-item.dragging { opacity: 0.5; }
.folder-item-label { display: inline-flex; align-items: center; gap: 0.5em; line-height: 1.2; }
.folder-item-right { display: inline-flex; align-items: center; gap: 0.375rem; }
.folder-item .count {
  font-size: 0.625rem;
  font-weight: 800;
  background: var(--text-dim);
  color: #fff;
  border-radius: var(--app-radius-sm);
  padding: 1px 6px;
  min-width: 16px;
  text-align: center;
}
.folder-item.active .count { background: var(--primary); }

.sidebar-settings { width: 100%; }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 20;
}

main { flex: 1; min-width: 0; padding: 10px 10px 90px; }

/* ---------------- LOGIN / LOCK ---------------- */

#view-login {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--surface);
}

#view-lock {
  max-width: 460px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  z-index: 1;
}

#view-lock::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--navy);
}

.lock-screen {
  text-align: center;
  padding: 80px 20px;
  animation: authIn 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.lock-logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 20px; }
.lock-screen h2 { font-size: 20px; margin: 0 0 8px; color: #fff; }
.lock-screen p { color: rgba(255,255,255,0.7); margin: 0 0 20px; }

@keyframes authIn {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.login-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: clamp(2.5rem, 12vh, 6rem) 1rem 2.5rem;
  animation: authIn 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.login-logo-wrap { margin-bottom: 1.75rem; }
.login-logo-img { width: auto; max-width: clamp(220px, 18vw, 320px); height: auto; max-height: clamp(80px, 7vw, 118px); display: block; }

.login-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  box-shadow: var(--shadow);
  margin-top: 1rem;
}

.compose-form, .settings-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--app-radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: none;
  margin-top: 0;
}

.login-form-simple {
  width: 100%;
  max-width: clamp(360px, 26vw, 460px);
  margin-top: 0;
  border: none;
  box-shadow: none;
  padding: 0;
}

.login-form label, .compose-form label, .settings-form label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.input-icon-wrap { position: relative; }
.input-icon-wrap .input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  display: flex;
  pointer-events: none;
}
.input-icon-wrap input { padding-left: 40px; width: 100%; }

.login-advanced {
  border: none;
  padding: 0;
}
.login-advanced summary {
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--primary);
  list-style: none;
  background: var(--surface-2, rgba(10,56,102,0.06));
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.login-advanced summary:hover { background: rgba(10,56,102,0.1); }
.login-advanced summary::after {
  content: '';
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.login-advanced[open] summary::after { transform: rotate(-135deg); }
.login-advanced summary::-webkit-details-marker { display: none; }
.login-advanced[open] summary { margin-bottom: 0.625rem; }
.login-advanced .row { margin-top: 0.5rem; }
.login-advanced .row:first-of-type { margin-top: 0; }
body.dark .login-advanced summary { background: rgba(255,255,255,0.05); }
body.dark .login-advanced summary:hover { background: rgba(255,255,255,0.09); }

.link-btn {
  background: transparent;
  color: var(--primary);
  font-weight: 700;
  font-size: 0.8125rem;
  padding: 0.375rem;
}
.link-btn:hover { background: transparent; color: var(--primary-hover); text-decoration: underline; }

.login-footer {
  text-align: center;
  padding: 1.25rem 1rem 1.75rem;
  color: var(--text-dim);
  font-size: 0.75rem;
}
.login-footer-logo { width: auto; height: clamp(22px, 2vw, 30px); margin-bottom: 0.375rem; }
.login-footer p { margin: 0; }

input, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 0.875rem;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 500;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 4px var(--primary-tint);
}
textarea { min-height: 140px; resize: vertical; }

#view-login button[type="submit"] {
  padding: 0.8125rem 1rem;
  font-size: 0.9375rem;
  margin-top: 4px;
  background: var(--primary);
  box-shadow: 0 8px 20px rgba(8, 123, 255, 0.35);
}
#view-login button[type="submit"]:hover {
  box-shadow: 0 10px 26px rgba(8, 123, 255, 0.45);
  transform: translateY(-1px);
}

.row { display: flex; gap: 10px; min-width: 0; }
.row > * { flex: 1; min-width: 0; }
.row input { width: 100%; box-sizing: border-box; }

/* ---------------- MESSAGE LIST ---------------- */

.status-bar {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--text-dim);
  text-align: left;
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--border);
  border-bottom: none;
  background: var(--toolbar-bg);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  position: relative;
}

.list-options-menu {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--app-radius-sm);
  box-shadow: var(--shadow);
  padding: 0.625rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  text-transform: none;
  letter-spacing: normal;
}
.list-options-menu label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--text-dim);
}
.list-options-menu select { font-size: 0.75rem; padding: 0.3rem 0.4rem; }

.more-menu-wrap { position: relative; display: inline-flex; }
.more-menu-wrap .dropdown { top: calc(100% + 4px); right: 0; left: auto; min-width: 200px; }
.more-menu-wrap .dropdown-item {
  width: 100%;
  background: transparent;
  color: var(--text);
  border: none;
  justify-content: flex-start;
  font-size: 0.75rem;
  text-align: left;
}
.more-menu-wrap .dropdown-item:hover { background: var(--surface-2); }
.more-menu-wrap .dropdown-item:active { background: var(--border); }

.pull-indicator {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  padding: 8px;
}

#message-list {
  border: 1px solid var(--border);
  border-top: none;
  background: var(--surface);
}

.message-item-wrap {
  position: relative;
  overflow: hidden;
}

.swipe-actions {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  overflow: hidden;
}
.swipe-actions .swipe-archive, .swipe-actions .swipe-delete {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
}
.swipe-actions .swipe-archive { background: var(--primary); justify-content: flex-start; padding-left: 20px; }
.swipe-actions .swipe-delete { background: var(--navy); justify-content: flex-end; padding-right: 20px; }

.message-item {
  background: var(--surface);
  border: none;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  border-radius: 0;
  padding: 0.5rem 0.625rem;
  cursor: pointer;
  display: flex;
  gap: 0.625rem;
  align-items: flex-start;
  position: relative;
  transition: background 0.1s ease, border-color 0.1s ease;
  touch-action: pan-y;
}
.message-item:hover { background: var(--surface-2); }
.message-item:active { background: var(--primary-tint); }

.message-item.unread { border-left-color: var(--primary); font-weight: 700; }
.message-item.unread:hover { background: var(--surface-2); }
.message-item.unread:active { background: var(--primary-tint); }

.message-item.open { background: var(--primary-tint); border-left-color: var(--primary); }
.message-item.open:hover { background: var(--primary-tint); }

.avatar {
  width: 1.875rem;
  height: 1.875rem;
  border-radius: var(--app-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.message-item-body { flex: 1; min-width: 0; display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }
.message-item .from { font-weight: 700; font-size: 0.8125rem; letter-spacing: -0.01em; display: flex; align-items: center; gap: 5px; flex: 1 1 auto; min-width: 0; }
.message-item .star { color: #f59e0b; display: inline-flex; align-items: center; flex-shrink: 0; }
.message-item .star svg { fill: currentColor; }
.message-item .subject { font-size: 0.75rem; margin-top: 1px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; flex-basis: 100%; }
.message-item .date { font-size: 0.6875rem; color: var(--text-dim); font-weight: 600; flex-shrink: 0; }
.message-item .attach-indicator { font-size: 0.6875rem; color: var(--text-dim); display: inline-flex; align-items: center; gap: 3px; }

/* Skeleton loading */
.skeleton-item {
  background: var(--surface);
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 8px 10px;
  margin-bottom: 0;
  display: flex;
  gap: 10px;
}
.skeleton-avatar, .skeleton-line {
  background: var(--surface-2);
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: 8px;
}
.skeleton-avatar { width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0; }
.skeleton-body { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.skeleton-line { height: 12px; }
.skeleton-line.w60 { width: 60%; }
.skeleton-line.w40 { width: 40%; }
.skeleton-line.w30 { width: 30%; }
@keyframes skeleton-loading { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-dim); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-state-icon { color: var(--text-dim); opacity: 0.6; }
.empty-state p { margin: 0; }

/* ---------------- MESSAGE DETAIL ---------------- */

#view-message:not(.hidden), #view-compose:not(.hidden), #view-settings:not(.hidden), #view-add-account:not(.hidden) {
  animation: authIn 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.message-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0;
  padding: 0.875rem 1rem;
  box-shadow: none;
}
.message-detail h2 { margin-top: 0; font-size: 1rem; font-weight: 700; letter-spacing: -0.01em; }
.message-detail .meta { color: var(--text-dim); font-size: 0.75rem; margin-bottom: 0.75rem; font-weight: 500; line-height: 1.6; padding-bottom: 0.625rem; border-bottom: 1px solid var(--border); }
.message-detail .body { white-space: pre-wrap; line-height: 1.55; font-size: 0.8125rem; }

.attachments-list { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.attachment-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--app-radius-sm);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
}
.attachment-chip span { display: inline-flex; align-items: center; gap: 8px; }
.detail-empty .detail-empty-icon { display: flex; }
.attachment-chip a { color: var(--primary); text-decoration: none; font-weight: 700; }

.attachments-list { display: flex; flex-direction: column; gap: 6px; }
.attachments-list .attachment-chip { padding: 6px 8px; font-size: 12px; }
.attachment-remove {
  background: transparent;
  color: var(--danger);
  padding: 4px;
  width: 22px;
  height: 22px;
  border-radius: var(--app-radius-sm);
}
.attachment-remove:hover { background: rgba(239,68,68,0.12); }

.cc-bcc-toggle { align-self: flex-start; padding: 2px 4px; margin-top: -6px; }
#cc-bcc-fields { display: flex; flex-direction: column; gap: 12px; }

.detail-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.625rem;
  margin: 0 0 0 0;
  padding: 0.375rem 0.625rem;
  background: var(--toolbar-bg);
  border: 1px solid var(--border);
  border-bottom: none;
  flex-wrap: wrap;
}
.detail-toolbar-actions { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.detail-toolbar-actions button { font-size: 0.75rem; padding: 0.375rem 0.625rem; }

.reply-bar { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ---------------- COMPOSE / SETTINGS ---------------- */

.error-msg {
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
body.dark .error-msg { background: #2a1414; border-color: #5c2323; }

.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }

.settings-form { max-width: 560px; margin: 0 auto; }
.settings-form h2 { margin: 0 0 4px; font-size: 16px; }
.settings-block { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 4px; display: flex; flex-direction: column; gap: 8px; }
.settings-block h3 { margin: 0; font-size: 13px; }
.hint { font-size: 12px; color: var(--text-dim); margin: 0; }
.save-ok { color: var(--success); font-weight: 700; font-size: 13px; }

.switch-row { flex-direction: row !important; align-items: center; justify-content: space-between; gap: 12px; }
.switch-row input[type="checkbox"] { width: 20px; height: 20px; }

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.625rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--app-radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 6px;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.account-row:hover { border-color: rgba(8,123,255,0.3); background: var(--primary-tint); }
.account-row:active { background: var(--border); }
.account-row .remove-account { background: transparent; color: var(--danger); padding: 4px 8px; }
.account-row .remove-account:hover { background: rgba(239,68,68,0.12); }
.account-row .remove-account:active { background: rgba(239,68,68,0.22); }
.account-row .switch-account { padding: 4px 10px; font-size: 0.75rem; }

/* ---------------- FAB ---------------- */

.fab {
  display: none !important;
}

/* ---------------- BOTTOM NAV (mobile) ---------------- */

.bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  align-items: flex-end;
  justify-content: space-between;
  gap: 4px;
}

.bn-btn {
  background: transparent;
  color: var(--text-dim);
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 2px;
  border-radius: 12px;
  font-weight: 600;
  text-align: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.bn-btn:hover { background: var(--surface-2); }
.bn-btn:active span { transform: scale(0.88); }
.bn-btn small { font-size: clamp(10px, 2.6vw, 12px); font-weight: 700; line-height: 1; }
.bn-btn.active { color: var(--primary); }
.bn-btn.active span { animation: bnPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes bnPop {
  0% { transform: scale(0.7); }
  100% { transform: scale(1); }
}
.bn-btn span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  transition: transform 0.12s ease;
}
.bn-btn span svg { width: clamp(20px, 5.5vw, 24px); height: clamp(20px, 5.5vw, 24px); }

.bn-compose {
  background: var(--primary);
  color: #fff;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  flex: 0 0 auto;
  margin-top: -22px;
  box-shadow: 0 8px 20px rgba(8, 123, 255, 0.4);
  border: 3px solid var(--bg);
}
.bn-compose:hover { background: var(--primary-hover); }
.bn-compose span svg { width: 24px; height: 24px; }

/* ---------------- FOLDER BOTTOM SHEET ---------------- */

.folder-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 45;
}

.folder-sheet-backdrop {
  transition: opacity 0.25s ease;
  opacity: 0;
}
.folder-sheet-backdrop:not(.hidden) { opacity: 1; }

.folder-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 46;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,0.25);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.25, 1);
  max-height: 70vh;
  overflow-y: auto;
}
.folder-sheet.open { transform: translateY(0); }

.folder-sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  margin: 6px auto 12px;
}

.folder-sheet-title {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 800;
  text-align: center;
}

.folder-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px 8px;
}

.folder-grid-item {
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 4px;
  border-radius: 14px;
  color: var(--text);
  position: relative;
  transition: background 0.15s ease, transform 0.12s ease;
}
.folder-grid-item:hover { background: var(--surface-2); }
.folder-grid-item:active { transform: scale(0.94); }
.folder-grid-item.active { color: var(--primary); }
.folder-grid-icon {
  width: 50px;
  height: 50px;
  border-radius: 16px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.folder-grid-item:hover .folder-grid-icon { transform: scale(1.08); }
.folder-grid-item.active .folder-grid-icon { background: var(--primary-tint); color: var(--primary); }
.folder-grid-item span.label {
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folder-grid-count {
  position: absolute;
  top: 2px;
  right: 10px;
  font-size: 10px;
  font-weight: 800;
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  padding: 1px 6px;
  min-width: 16px;
  text-align: center;
}

/* ---------------- ICON RAIL (desktop) ---------------- */

.icon-rail {
  display: none;
  width: 3.25rem;
  flex-shrink: 0;
  background: var(--navy);
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0.75rem 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.icon-rail-logo { width: 1.75rem; height: 1.75rem; border-radius: var(--app-radius-sm); margin-bottom: 0.5rem; }

.rail-btn {
  background: transparent;
  color: rgba(255,255,255,0.75);
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: var(--app-radius-sm);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.12s ease, color 0.12s ease, transform 0.08s ease;
}
.rail-btn:hover { background: rgba(255,255,255,0.12); color: #fff; }
.rail-btn:active { background: rgba(255,255,255,0.22); color: #fff; transform: scale(0.92); }
.rail-btn.active { background: var(--primary); color: #fff; }
.rail-btn.danger { background: transparent; color: rgba(239,68,68,0.85); }
.rail-btn.danger:hover { background: rgba(239,68,68,0.15); color: #ef4444; }
.rail-btn.danger:active { background: rgba(239,68,68,0.28); color: #ef4444; }
.rail-spacer { flex: 1; }

/* ---------------- SPLIT VIEW (desktop: list + detail side by side) ---------------- */

.detail-pane { position: relative; }
.detail-empty {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-dim);
  padding: 20px;
}
.detail-empty .emoji { font-size: 40px; margin-bottom: 10px; }
.detail-empty-watermark {
  width: clamp(220px, 20vw, 420px);
  height: auto;
  opacity: 0.16;
  filter: grayscale(1);
  margin-bottom: 1.5rem;
  user-select: none;
  pointer-events: none;
}
body.dark .detail-empty-watermark { opacity: 0.22; }

/* ---------------- RESPONSIVE ---------------- */

@media (max-width: 860px) {
  .only-mobile { display: inline-flex; }
  .only-mobile-flex { display: block; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100%;
    background: var(--bg);
    z-index: 35;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: 78vw;
    max-width: 300px;
    padding-top: calc(16px + env(safe-area-inset-top));
  }
  .sidebar.open { transform: translateX(0); }
  main { padding: calc(12px + env(safe-area-inset-top)) 12px calc(84px + env(safe-area-inset-bottom)); }
  .bottom-nav { display: flex; }
  #btn-compose-sidebar { display: block; }

  header { display: none; }
  #search-bar {
    padding-top: calc(10px + env(safe-area-inset-top));
  }

  body { font-size: clamp(15px, 3.6vw, 17px); }
  h1, h2 { font-size: clamp(18px, 5vw, 22px); }
  .message-item .subject { font-size: clamp(14px, 3.8vw, 16px); }
  .message-item .snippet, .message-item .from { font-size: clamp(13px, 3.4vw, 15px); }
  .avatar { width: clamp(38px, 10vw, 46px); height: clamp(38px, 10vw, 46px); font-size: clamp(14px, 3.6vw, 16px); }
  .logo-mark, .lock-logo, .login-logo { width: clamp(48px, 14vw, 64px); height: clamp(48px, 14vw, 64px); }
  button { font-size: clamp(14px, 3.6vw, 16px); padding: clamp(10px, 2.8vw, 13px) clamp(14px, 4vw, 18px); }
  input, textarea { font-size: clamp(15px, 3.8vw, 17px) !important; }

  /* ---- List toolbar: stack the two icon groups full-width, divider becomes horizontal ---- */
  .list-toolbar { flex-direction: column; }
  .lt-col-list {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .lt-col-detail { width: 100%; }
  .lt-col { padding: 0.3rem 0.375rem; gap: 0.125rem; }
  .lt-btn { min-width: 2.15rem; padding: 0.3rem 0.3rem; }
  .lt-btn small { font-size: 0.5rem; }
  #lt-count { padding: 0 0.25rem; }
  .sidebar-topbar { margin-top: calc(-16px - env(safe-area-inset-top)); }
}

@media (min-width: 861px) {
  .fab { display: none !important; }
  .only-desktop { display: flex; }
  .only-mobile-flex { display: none; }

  .layout { max-width: 100vw; }
  main { padding: 0; max-width: none; }

  .split-view {
    display: flex;
    align-items: flex-start;
    gap: 0;
  }

  #view-inbox.list-pane {
    width: clamp(360px, 24vw, 460px);
    flex-shrink: 0;
    max-height: calc(100vh - 20px);
    overflow-y: auto;
    padding-right: 0;
  }

  .detail-pane {
    flex: 1;
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0;
    box-shadow: none;
    min-height: calc(100vh - 20px);
    padding: 0;
  }
  .detail-pane .message-detail,
  .detail-pane .settings-form,
  .detail-pane .login-form {
    border: none;
    box-shadow: none;
    margin: 0;
    background: transparent;
  }
  .detail-pane .compose-form {
    border: none;
    box-shadow: none;
    margin: 0;
    background: transparent;
    padding: 14px 16px;
  }
  .detail-pane .settings-form { padding: 14px 16px; }
  .detail-pane #btn-back { display: none; }
  .detail-pane.showing-empty .detail-empty { display: flex; }
  .detail-pane .detail-toolbar { border-top: none; }
}
