:root {
  color-scheme: light;
  --navy: #0a2540;
  --navy-2: #0e3054;
  --ink: #14273c;
  --body: #33475e;
  --muted: #68798d;
  --line: #dde5ee;
  --panel: #ffffff;
  --wash: #e9eef5;
  --azure: #1f6bff;
  --azure-dark: #1859d6;
  --azure-soft: #e7f0fe;
  --danger: #b42318;
  --success: #027a48;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--wash);
  color: var(--ink);
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
code { background: var(--azure-soft); padding: 0.12rem 0.3rem; border-radius: 0.3rem; }
h1, h2, h3 { color: var(--ink); }

/* ---------- Top bar ---------- */
.topbar {
  height: 60px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 18px;
  background: linear-gradient(90deg, var(--navy), var(--navy-2));
  color: white;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 0 rgba(10, 37, 64, 0.35);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 750;
  font-size: 1.12rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.brand-mark {
  width: 17px;
  height: 17px;
  background: linear-gradient(135deg, #57a8ff, #1f6bff);
  transform: rotate(45deg);
  border-radius: 4px;
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.25);
  flex: 0 0 auto;
}

.search-form {
  flex: 1 1 auto;
  max-width: 600px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.search-form input {
  border: 0;
  border-radius: 999px;
  padding: 9px 16px;
  background: #f2f5f9;
  color: var(--ink);
  box-shadow: none;
}
.search-form input:focus { outline: 3px solid rgba(87, 168, 255, 0.45); }
.button-search {
  background: rgba(255, 255, 255, 0.12);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 650;
}
.button-search:hover { background: rgba(255, 255, 255, 0.2); }

.topbar-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.account-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #eaf1f9;
  font-size: 0.9rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}
.account-label::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
  flex: 0 0 auto;
}
.badge {
  border: 1px solid #f2b544;
  background: rgba(242, 181, 68, 0.15);
  color: #ffd98a;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

/* ---------- Buttons & forms ---------- */
.button {
  border: 0;
  border-radius: 10px;
  padding: 9px 15px;
  font-weight: 650;
  transition: background 120ms ease, transform 120ms ease;
}
.button:active { transform: translateY(1px); }
.button:disabled { opacity: 0.55; cursor: default; }
.button-primary { background: var(--azure); color: white; }
.button-primary:hover { background: var(--azure-dark); }
.button-secondary { background: var(--azure-soft); color: #0f4d94; }
.button-secondary:hover { background: #d3e5fd; }
.button-quiet {
  background: transparent;
  color: #cfe0f2;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 8px 13px;
}
.button-quiet:hover { background: rgba(255, 255, 255, 0.1); color: white; }
.button-danger { background: #fff1f0; color: var(--danger); }
.button-danger:hover { background: #ffe0db; }
.button-wide { width: 100%; }
.text-button {
  border: 0;
  background: transparent;
  color: var(--azure-dark);
  font-weight: 700;
  padding: 4px;
}
.revoke-button {
  border: 0;
  background: #fff1f0;
  color: var(--danger);
  border-radius: 9px;
  padding: 8px 11px;
  font-weight: 700;
}

label {
  display: grid;
  gap: 7px;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--body);
}
input, textarea, select {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 10px 12px;
  background: white;
  color: var(--ink);
}
input:focus, textarea:focus, select:focus {
  outline: 3px solid rgba(31, 107, 255, 0.22);
  border-color: var(--azure);
}
.check-label { display: flex; align-items: center; gap: 8px; }
.check-label input { width: auto; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: calc(100vh - 60px);
  display: grid;
  place-items: center;
  padding: 24px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 14px 40px rgba(16, 35, 58, 0.08);
}
.login-card {
  width: min(440px, 100%);
  padding: 34px;
  display: grid;
  gap: 16px;
}
.login-card h1, .login-card p { margin: 0; }
.eyebrow {
  color: var(--azure-dark);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.76rem;
  font-weight: 800;
}

/* ---------- Workspace layout ---------- */
.workspace {
  display: grid;
  grid-template-columns: 252px minmax(320px, 400px) minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  height: calc(100vh - 60px);
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(16, 35, 58, 0.05);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  min-height: 0;
}
#composeButton { border-radius: 11px; padding: 11px; font-size: 0.98rem; }
#composeButton::before { content: "✎  "; }
.folder-list { display: grid; gap: 2px; align-content: start; }
.folder-tree-row { display: flex; align-items: center; gap: 2px; }
.folder-tree-row .folder-button { flex: 1 1 auto; width: auto; min-width: 0; }
.folder-button {
  width: 100%;
  border: 0;
  border-radius: 9px;
  padding: 8px 10px;
  background: transparent;
  color: var(--body);
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  font-weight: 550;
  gap: 8px;
}
.folder-button:hover { background: #eef3fa; }
.folder-button.active { background: var(--azure-soft); color: var(--azure-dark); font-weight: 700; }
.folder-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-count {
  min-width: 24px;
  text-align: center;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--muted);
  padding: 1px 7px;
  font-size: 0.78rem;
  font-weight: 650;
  flex: 0 0 auto;
}
.folder-button.active .folder-count { background: white; color: var(--azure-dark); }
.folder-toggle {
  flex: 0 0 20px;
  width: 20px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #9db0c6;
  cursor: pointer;
  font-size: 0.7rem;
  padding: 0;
}
.folder-toggle:hover { background: #eef3fa; color: var(--ink); }
.folder-toggle-spacer { flex: 0 0 20px; width: 20px; }
.folder-virtual { cursor: default; color: var(--muted); }
.sidebar-nav { display: grid; gap: 2px; border-top: 1px solid var(--line); padding-top: 10px; }
.sidebar-card {
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px 13px;
  background: #f7fafd;
}
.sidebar-card h2 { font-size: 0.82rem; margin: 0 0 5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.sidebar-card .muted { color: var(--muted); }

/* ---------- Message list ---------- */
.list-pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(16, 35, 58, 0.05);
  padding: 16px;
  min-width: 0;
  overflow-y: auto;
  min-height: 0;
}
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.list-header h1 { font-size: 1.3rem; margin: 0; letter-spacing: -0.02em; }
.message-list { display: grid; gap: 8px; margin-top: 12px; }
.message-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: white;
  border-radius: 13px;
  padding: 11px 12px;
  display: grid;
  gap: 4px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
.message-item:hover { border-color: #a9c6f5; }
.message-item.active { border-color: var(--azure); background: #f4f8ff; box-shadow: 0 0 0 3px rgba(31, 107, 255, 0.14); }
.message-open {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 11px;
  align-items: start;
}
.message-main { display: grid; gap: 3px; min-width: 0; }
.message-top, .message-bottom {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}
.message-from { font-weight: 650; font-size: 0.94rem; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-date { color: var(--muted); font-size: 0.78rem; white-space: nowrap; flex: 0 0 auto; }
.message-subject { font-weight: 550; font-size: 0.92rem; color: var(--body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-snippet { color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--azure); margin-right: 2px; }
.attachment-mark { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.attachment-mark::before { content: "📎 "; }
.message-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  margin-top: 4px;
}
.flag-select { width: auto; min-width: 108px; padding: 5px 7px; font-size: 0.82rem; border-radius: 8px; }
.flag-chip, .reminder-chip {
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.76rem;
  font-weight: 750;
  text-transform: capitalize;
  white-space: nowrap;
}
.flag-chip.red { background: #ffe4e0; color: #8f1d12; }
.flag-chip.orange { background: #ffead5; color: #8a3b00; }
.flag-chip.yellow { background: #fff3a3; color: #695800; }
.flag-chip.green { background: #d3f8df; color: #05603a; }
.flag-chip.blue { background: #dbeafe; color: #175cd3; }
.flag-chip.purple { background: #ebe9fe; color: #5925dc; }
.reminder-chip { background: var(--azure-soft); color: #0f4d94; text-transform: none; }

/* ---------- Avatars ---------- */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.01em;
  flex: 0 0 auto;
  user-select: none;
}
.avatar-lg { width: 46px; height: 46px; font-size: 1rem; }
.avatar-c0 { background: #2563eb; }
.avatar-c1 { background: #7c3aed; }
.avatar-c2 { background: #059669; }
.avatar-c3 { background: #d97706; }
.avatar-c4 { background: #dc2626; }
.avatar-c5 { background: #0891b2; }
.avatar-c6 { background: #db2777; }
.avatar-c7 { background: #4f46e5; }

/* ---------- Reader ---------- */
.reader-pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(16, 35, 58, 0.05);
  padding: 24px 28px;
  min-width: 0;
  overflow-y: auto;
  overflow-wrap: anywhere;
  min-height: 0;
}
.empty-state { text-align: center; padding: 12vh 20px; color: var(--muted); }
.empty-state h2 { color: var(--ink); }
.empty-icon { font-size: 3rem; color: var(--azure); }
.reader-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
#messageReader h2 { font-size: clamp(1.45rem, 2.6vw, 2.1rem); line-height: 1.15; letter-spacing: -0.03em; margin: 16px 0 18px; }
.reader-byline { display: flex; gap: 13px; align-items: flex-start; border-block: 1px solid var(--line); padding: 14px 0; }
.message-meta { display: grid; gap: 6px; margin: 0; }
.message-meta div { display: grid; grid-template-columns: 52px 1fr; gap: 10px; }
.message-meta dt { color: var(--muted); font-weight: 700; font-size: 0.85rem; padding-top: 1px; }
.message-meta dd { margin: 0; font-size: 0.94rem; }
.attachment-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.attachment-link {
  color: #0f4d94;
  background: var(--azure-soft);
  border-radius: 999px;
  padding: 7px 11px;
  text-decoration: none;
  font-weight: 650;
  font-size: 0.88rem;
}
.reader-body {
  white-space: pre-wrap;
  font: 0.99rem/1.7 ui-sans-serif, system-ui, sans-serif;
  color: var(--body);
  margin: 20px 0;
  max-width: 840px;
}
.followup-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fafd;
  padding: 14px 16px;
  margin-top: 16px;
  max-width: 850px;
}
.followup-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  text-align: left;
}
.followup-chevron { color: var(--muted); transition: transform 120ms ease; }
.followup-toggle[aria-expanded="true"] .followup-chevron { transform: rotate(90deg); }
#followupBody { margin-top: 14px; }
.followup-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.followup-actions, .calendar-controls { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Compose & settings ---------- */
.compose-form, .settings-panel { max-width: 850px; display: grid; gap: 15px; }
.compose-header { display: flex; justify-content: space-between; align-items: center; }
.compose-header h2, .settings-panel h3 { margin-bottom: 0; }
.form-actions { display: flex; justify-content: flex-end; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 20px; }
.settings-grid div { border: 1px solid var(--line); border-radius: 12px; padding: 11px; background: #fbfcfe; }
.settings-grid dt { color: var(--muted); font-size: 0.8rem; font-weight: 750; text-transform: uppercase; letter-spacing: 0.05em; }
.settings-grid dd { margin: 4px 0 0; overflow-wrap: anywhere; }
.token-form { display: grid; grid-template-columns: 1fr 190px auto; gap: 10px; align-items: end; }
.new-token { border: 1px solid #8ac2ff; background: var(--azure-soft); border-radius: 14px; padding: 14px; display: grid; gap: 10px; }
.token-list { display: grid; gap: 9px; }
.token-item { border: 1px solid var(--line); border-radius: 13px; padding: 13px; display: flex; justify-content: space-between; gap: 14px; align-items: center; background: white; }
.token-item h4 { margin: 0 0 4px; }
.token-item p { margin: 0; color: var(--muted); font-size: 0.88rem; }
.identity-form { display: grid; gap: 13px; max-width: 850px; }

/* ---------- Pages (reminders / calendar) ---------- */
.page-view { max-width: 1440px; margin: 0 auto; padding: 26px; }
.page-header { display: flex; justify-content: space-between; align-items: start; gap: 20px; margin-bottom: 20px; }
.page-header h1 { margin: 3px 0 6px; font-size: 1.9rem; letter-spacing: -0.03em; }
.reminder-list, .event-list { display: grid; gap: 10px; }
.reminder-item, .event-item {
  background: white;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 15px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
.reminder-item h3, .event-item h3 { margin: 0 0 5px; }
.reminder-item p, .event-item p { margin: 0; color: var(--muted); }
.reminder-item.due { border-color: #ffb4a8; background: #fff7f5; }
.calendar-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: white; }
.calendar-grid.week { min-height: 420px; }
.calendar-day { min-height: 118px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 8px; background: white; }
.calendar-day:nth-child(7n) { border-right: 0; }
.calendar-day.outside { background: #f7f9fb; color: var(--muted); }
.calendar-day.today { box-shadow: inset 0 0 0 2px var(--azure); }
.calendar-day-number { font-weight: 800; font-size: 0.88rem; margin-bottom: 7px; }
.calendar-event {
  width: 100%;
  border: 0;
  border-radius: 7px;
  background: var(--azure-soft);
  color: #0f4d94;
  text-align: left;
  padding: 5px 7px;
  margin-bottom: 5px;
  font-size: 0.8rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.event-form { padding: 20px; display: grid; gap: 13px; position: sticky; top: 84px; }
.event-form h2 { margin: 0; }
.event-actions { justify-content: space-between; }

/* ---------- Utilities ---------- */
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.error { color: var(--danger); font-weight: 650; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}
.sidebar::-webkit-scrollbar, .list-pane::-webkit-scrollbar, .reader-pane::-webkit-scrollbar { width: 9px; }
.sidebar::-webkit-scrollbar-thumb, .list-pane::-webkit-scrollbar-thumb, .reader-pane::-webkit-scrollbar-thumb { background: #c3cedd; border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }

@media (max-width: 1150px) {
  .workspace { grid-template-columns: 218px minmax(290px, 360px) minmax(0, 1fr); }
  .reader-pane { padding: 20px; }
  .account-label { display: none; }
}

@media (max-width: 860px) {
  .topbar { padding: 0 12px; gap: 10px; }
  .search-form { display: none; }
  .workspace { display: block; height: auto; padding: 10px; }
  .sidebar, .list-pane, .reader-pane { margin-bottom: 10px; overflow: visible; }
  .reader-pane { padding: 18px 15px 30px; }
  .token-form, .settings-grid, .calendar-layout { grid-template-columns: 1fr; }
  .event-form { position: static; }
  .page-view { padding: 18px 12px; }
  .page-header, .reminder-item, .event-item { display: grid; }
  .followup-grid { grid-template-columns: 1fr; }
  .calendar-day { min-height: 84px; padding: 5px; }
}

/* ---------- Bottom preview layout (Outlook-style) ---------- */
.list-header-actions { display: flex; gap: 6px; align-items: center; }
body.layout-bottom .workspace {
  grid-template-columns: 252px minmax(0, 1fr);
  grid-template-rows: minmax(170px, 42%) minmax(0, 1fr);
}
body.layout-bottom .sidebar { grid-row: 1 / span 2; }
body.layout-bottom .list-pane { grid-column: 2; grid-row: 1; }
body.layout-bottom .reader-pane { grid-column: 2; grid-row: 2; }
@media (max-width: 1150px) {
  body.layout-bottom .workspace { grid-template-columns: 218px minmax(0, 1fr); }
}
@media (max-width: 860px) {
  body.layout-bottom .workspace { display: block; }
}

/* ---------- Draggable preview splitter + overflow fixes ---------- */
body.layout-bottom .workspace {
  grid-template-rows: minmax(150px, var(--split, 42%)) 12px minmax(0, 1fr);
}
body.layout-bottom .sidebar { grid-row: 1 / span 3; }
body.layout-bottom .reader-pane { grid-row: 3; }
.splitter {
  grid-column: 2;
  grid-row: 2;
  cursor: row-resize;
  display: grid;
  place-items: center;
  touch-action: none;
  border-radius: 6px;
}
.splitter:hover, .splitter:active { background: rgba(31, 107, 255, 0.08); }
.splitter-grip {
  width: 56px;
  height: 5px;
  border-radius: 99px;
  background: #aebfd4;
  pointer-events: none;
}
.splitter:hover .splitter-grip, .splitter:active .splitter-grip { background: #5b82b8; }
.message-list, .message-item, .message-main, .message-snippet, .message-from, .message-subject { min-width: 0; }
.message-snippet, .message-from { flex: 1 1 auto; }
.sidebar { overflow-x: hidden; }

.danger-text { color: var(--danger); }
.row-delete-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
  font-size: 0.82rem;
  padding: 4px 6px;
  border-radius: 7px;
  margin-left: auto;
}
.row-delete-button:hover { background: #fff1f0; color: var(--danger); }

/* ---------- Draggable folder-pane splitter ---------- */
.workspace { grid-template-columns: var(--sidebar-w, 252px) 10px minmax(320px, 400px) minmax(0, 1fr); }
body.layout-bottom .workspace { grid-template-columns: var(--sidebar-w, 252px) 10px minmax(0, 1fr); }
body.layout-bottom .list-pane { grid-column: 3; }
body.layout-bottom .reader-pane { grid-column: 3; }
body.layout-bottom .splitter { grid-column: 3; }
.v-splitter {
  grid-column: 2;
  grid-row: 1;
  cursor: col-resize;
  display: grid;
  place-items: center;
  touch-action: none;
  border-radius: 6px;
}
body.layout-bottom .v-splitter { grid-row: 1 / span 3; }
.v-splitter:hover, .v-splitter:active { background: rgba(31, 107, 255, 0.08); }
.v-splitter-grip {
  width: 5px;
  height: 56px;
  border-radius: 99px;
  background: #aebfd4;
  pointer-events: none;
}
.v-splitter:hover .v-splitter-grip, .v-splitter:active .v-splitter-grip { background: #5b82b8; }
@media (max-width: 860px) {
  .v-splitter, .splitter { display: none; }
}
