:root {
  /* Pikali brand palette (charte pikali.fr) — warm terracotta / peach */
  --bg: #fff8f3;            /* warm cream surface */
  --panel: #ffffff;
  --border: #f0e0d6;
  --border-light: #f5ebe4;
  --text: #3d2c29;          /* warm dark brown */
  --muted: #7d6b66;
  --muted-light: #a69490;
  --accent: #e07b39;        /* primary terracotta */
  --accent-dark: #c56a2d;   /* darker terracotta (links / hover) */
  --accent-light: #f4a574;
  --accent-soft: #ffeee4;   /* soft peach tint */
  --accent-peach: #fff5ef;  /* very light peach surface */
  --danger: #c0392b;
  --success: #166534;
  /* Warm dark sidebar (charte gradient-dark) */
  --sidebar: #3d2c29;
  --sidebar-2: #5c4742;
  --sidebar-hover: #513c37;
  --sidebar-line: #4a3733;
  --sidebar-text: #f5ebe4;
  --sidebar-muted: #b9a69f;
  --shadow: 0 2px 8px -2px rgba(224,123,57,.10), 0 1px 2px rgba(61,44,41,.05);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; border-radius: 8px; }

/* ---------- Login ---------- */
.login-overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(165deg, #3d2c29 0%, #5c4742 50%, #7d6b66 100%);
}
.login-card {
  background: var(--panel); padding: 40px 36px; border-radius: 16px; width: 340px;
  display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo, .brand { font-family: "Syne", "Inter", sans-serif; font-weight: 800; font-size: 26px; letter-spacing: -.5px; }
.login-logo span, .brand span { color: var(--accent-light); }
.login-sub { margin: -6px 0 8px; color: var(--muted); font-size: 13px; }
.login-card input {
  padding: 11px 12px; border: 1px solid var(--border); border-radius: 9px; font-size: 14px; width: 100%;
}
.login-card button {
  background: var(--accent); color: #fff; padding: 12px; font-weight: 600; font-size: 15px;
}
.login-err { color: var(--danger); font-size: 13px; text-align: center; }

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--col1, 240px) 6px var(--col2, 360px) 6px 1fr;
  height: 100vh;
}

/* Vertical drag handles between columns */
.col-splitter {
  background: transparent; cursor: col-resize; position: relative; z-index: 5;
  display: flex; align-items: center; justify-content: center;
}
.col-splitter:hover { background: var(--accent-soft); }
.col-splitter .cs-grip { width: 4px; height: 42px; border-radius: 3px; background: #d8c4b8; transition: background .12s; }
.col-splitter:hover .cs-grip { background: var(--accent); }
body.col-splitting { cursor: col-resize; user-select: none; }
body.col-splitting .reply-editor { pointer-events: none; }
.col-accounts { background: linear-gradient(180deg, #3d2c29 0%, #33231f 100%); color: var(--sidebar-text); display: flex; flex-direction: column; }
.brand { padding: 20px 18px 10px; color: #fff; }
.accounts-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 18px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--sidebar-muted);
}
.accounts-head button {
  background: var(--sidebar-2); color: #fff; width: 26px; height: 26px; font-size: 18px; line-height: 1; border-radius: 7px;
}
.accounts-head button:hover { background: var(--accent); }
.accounts { list-style: none; margin: 0; padding: 6px 10px; overflow-y: auto; flex: 1; min-height: 0; }
.account-item { margin-bottom: 3px; }
.account {
  display: flex; align-items: center; gap: 8px; padding: 10px 8px; border-radius: 10px;
  cursor: pointer; position: relative;
}
.account:hover { background: var(--sidebar-hover); }
.account.active { background: var(--sidebar-2); }
.account .a-caret {
  background: transparent; line-height: 1;
  width: 18px; height: 22px; padding: 0; flex-shrink: 0; border-radius: 4px;
  display: flex; align-items: center; justify-content: center; transition: transform .15s;
}
/* Explicit filled triangle (points right; rotates down when expanded) */
.account .a-caret::before {
  content: ""; display: block; width: 0; height: 0;
  border-style: solid; border-width: 5px 0 5px 7px;
  border-color: transparent transparent transparent var(--sidebar-muted);
  transition: border-color .12s;
}
.account .a-caret:hover::before { border-left-color: #fff; }
.account-item.expanded .account .a-caret { transform: rotate(90deg); }

/* Group headers separating mailboxes from back-office SAV */
.accounts-group-title {
  list-style: none; padding: 12px 12px 5px; margin-top: 4px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .9px; text-transform: uppercase;
  color: var(--accent-light);
}
.accounts-group-title:first-child { margin-top: 0; }

/* Folder drop-down under the active account */
.acc-folders { margin: 2px 0 6px 14px; padding-left: 14px; border-left: 1px solid var(--sidebar-line); display: flex; flex-direction: column; gap: 1px; }
.acc-folder {
  display: flex; align-items: center; text-align: left; background: transparent; color: var(--sidebar-muted);
  padding: 7px 10px; border-radius: 7px; font-size: 12.5px; width: 100%;
}
.acc-folder:hover { background: var(--sidebar-hover); color: #fff; }
.acc-folder.active { background: var(--accent); color: #fff; font-weight: 600; }
.acc-folder .af-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-folder-loading { color: var(--sidebar-muted); font-size: 12px; padding: 6px 10px; }
.account .badge {
  width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.account .a-name { flex: 1; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account .a-count {
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; display: flex; align-items: center; justify-content: center;
}
.account .a-count.zero { background: var(--sidebar-2); color: var(--sidebar-muted); }
.account .a-err { color: var(--accent-light); font-size: 14px; }
.sidebar-foot { padding: 12px; display: flex; gap: 8px; border-top: 1px solid var(--sidebar-line); }
.sidebar-foot button { flex: 1; background: var(--sidebar-2); color: var(--sidebar-text); padding: 9px; font-size: 12.5px; }
.sidebar-foot button:hover { background: var(--sidebar-hover); }

/* ---------- Threads ---------- */
.col-threads { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.threads-head { padding: 16px 18px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.th-title { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.th-dot { width: 10px; height: 10px; border-radius: 50%; }
.th-folder { margin-top: 4px; color: var(--muted); font-size: 12.5px; font-weight: 500; }
.th-folder:empty { display: none; }
.threads { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.thread { padding: 13px 18px; border-bottom: 1px solid var(--border-light); cursor: pointer; }
/* Unread threads: subtle blue tint + inset accent bar. Placed before :hover and
   .active so those states still win visually. Read threads stay plain white. */
.thread.unread { background: var(--accent-peach); box-shadow: inset 3px 0 0 var(--accent); }
.thread.unread:hover { background: var(--accent-soft); }
.thread:hover { background: #fdf6f1; }
.thread.active { background: var(--accent-soft); border-left: 3px solid var(--accent); padding-left: 15px; }
.thread.unread.active { box-shadow: none; }
.thread .t-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.thread .t-from { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread.unread .t-from { font-weight: 800; }
.thread.unread .t-subject { font-weight: 700; }
/* Read threads: correspondent and subject recede slightly (Apple Mail style). */
.thread:not(.unread) .t-from { font-weight: 500; }
.thread:not(.unread) .t-subject { color: var(--muted); }
.thread .t-date { color: var(--muted); font-size: 11.5px; flex-shrink: 0; }
.thread .t-subject { font-size: 13px; margin: 3px 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .t-preview { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .t-tags { display: flex; gap: 6px; margin-top: 6px; align-items: center; }
.tag-todo { background: #fef3c7; color: #92400e; font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 5px; }
.tag-count { color: var(--muted); font-size: 11px; }
.dot-unread { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

/* ---------- Conversation ---------- */
.col-message { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.msg-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.conversation { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.conv-head {
  padding: 16px 22px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; position: relative;
}
.conv-info { flex: 1; min-width: 0; }
.conv-subject { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-from { color: var(--muted); font-size: 13px; margin-top: 2px; }
.conv-actions { display: flex; gap: 8px; }
.conv-actions button { background: var(--border-light); color: var(--text); padding: 8px 12px; font-size: 12.5px; font-weight: 500; }
.conv-actions button:hover { background: #ecdccf; }
.conv-actions button.danger { color: var(--danger); }
.conv-actions button.danger:hover { background: #fbe4e0; }
.move-menu {
  position: absolute; right: 22px; top: 58px; background: #fff; border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); z-index: 10; overflow: hidden;
}
.move-menu button { display: block; width: 100%; text-align: left; background: #fff; padding: 10px 16px; border-radius: 0; font-size: 13px; }
.move-menu button:hover { background: var(--accent-peach); }

.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 16px; }

/* Draggable divider between the conversation (top) and the reply editor (bottom) */
.reply-splitter {
  flex-shrink: 0; height: 11px; cursor: ns-resize; background: var(--panel);
  border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
}
.reply-splitter:hover { background: var(--accent-soft); }
.reply-splitter .rs-grip { width: 42px; height: 4px; border-radius: 3px; background: #d8c4b8; transition: background .12s; }
.reply-splitter:hover .rs-grip { background: var(--accent); }
body.splitting { cursor: ns-resize; user-select: none; }
body.splitting .reply-editor { pointer-events: none; }
.bubble { max-width: 78%; border-radius: 14px; padding: 13px 16px; box-shadow: var(--shadow); }
.bubble .b-head { font-size: 12px; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; gap: 12px; }
.bubble .b-body { font-size: 14px; line-height: 1.5; word-wrap: break-word; overflow-wrap: anywhere; }
.bubble .b-body img { max-width: 100%; height: auto; }
.bubble .b-body a { color: var(--accent-dark); }
.bubble.in { background: var(--panel); align-self: flex-start; border-top-left-radius: 4px; }
.bubble.out { background: var(--accent-soft); align-self: flex-end; border-top-right-radius: 4px; }

.reply {
  background: var(--panel); padding: 10px 18px 14px; flex-shrink: 0;
  height: 260px; min-height: 140px; display: flex; flex-direction: column; overflow: hidden;
}
.reply-toolbar {
  display: flex; align-items: center; gap: 2px; padding: 4px; margin-bottom: 8px;
  background: var(--accent-peach); border: 1px solid var(--border); border-radius: 9px 9px 0 0; border-bottom: none;
}
.rt-btn {
  background: transparent; color: #5c4742; width: 30px; height: 30px; border-radius: 6px;
  font-size: 14px; display: flex; align-items: center; justify-content: center; line-height: 1;
}
.rt-btn:hover { background: var(--accent-soft); }
.rt-btn:active { background: #f7ddcb; }
.rt-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.reply-toolbar { flex-shrink: 0; }
.reply-toolbar + .reply-editor { border-radius: 0 0 10px 10px; margin-top: -8px; }
.reply-editor {
  width: 100%; flex: 1; min-height: 54px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 10px; padding: 12px; font-family: inherit;
  font-size: 14px; line-height: 1.5; background: #fff; outline: none;
}
.reply-editor:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(224,123,57,.15); }
.reply-editor:empty:before { content: attr(data-placeholder); color: var(--muted); }
.reply-editor a { color: var(--accent-dark); }
.reply-editor ul { margin: 6px 0; padding-left: 22px; }
.reply-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; flex-shrink: 0; max-height: 64px; overflow-y: auto; }
.att-chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent-dark);
  border: 1px solid #f6d3ba; border-radius: 8px; padding: 4px 8px; font-size: 12px; max-width: 260px;
}
.att-chip .att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.att-chip .att-size { color: var(--accent); font-size: 11px; }
.att-chip .att-x { background: transparent; color: var(--accent); font-size: 12px; padding: 0 2px; line-height: 1; }
.att-chip .att-x:hover { color: var(--danger); }
.reply-bar { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; flex-shrink: 0; }
.reply-status { color: var(--muted); font-size: 12.5px; }
.reply-status.ok { color: var(--success); }
.reply-status.err { color: var(--danger); }
#btn-send { background: var(--accent); color: #fff; padding: 10px 20px; font-weight: 600; font-size: 14px; }
#btn-send:disabled { opacity: .5; cursor: default; }

.empty, .loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Segmented control (filter + reply mode) ---------- */
.seg { display: inline-flex; background: var(--border-light); border-radius: 8px; padding: 2px; gap: 2px; }
.seg button { background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; padding: 5px 11px; border-radius: 6px; }
.seg button:hover { color: var(--text); }
.seg button.active { background: #fff; color: var(--accent-dark); box-shadow: var(--shadow); }

/* ---------- Search ---------- */
.th-search { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.search-box { position: relative; display: flex; align-items: center; }
.search-box .search-ico {
  position: absolute; left: 10px; font-size: 12px; opacity: .55; pointer-events: none;
}
.search-box input {
  width: 100%; padding: 8px 30px 8px 30px; border: 1px solid var(--border);
  border-radius: 9px; font-size: 13px; font-family: inherit; background: #fff; outline: none;
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(224,123,57,.15); }
/* Hide the native search clear cross; we render our own. */
.search-box input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.search-clear {
  position: absolute; right: 6px; background: var(--border-light); color: var(--muted);
  width: 20px; height: 20px; border-radius: 50%; font-size: 11px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.search-clear:hover { background: #ecdccf; color: var(--text); }
.search-scope { align-self: flex-start; }
/* While searching, the filter/select tools are irrelevant. */
.threads-head.searching .threads-tools,
.threads-head.searching .batch-bar { display: none !important; }

/* Search result rows: account badge + originating folder */
.thread.search-result .t-from { display: flex; align-items: center; gap: 6px; }
.sr-badge {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  min-width: 26px; height: 17px; padding: 0 5px; border-radius: 5px;
  color: #fff; font-size: 9.5px; font-weight: 800; letter-spacing: .3px;
}
.sr-folder {
  background: var(--accent-soft); color: var(--accent-dark); border: 1px solid #f6d3ba;
  font-size: 10px; font-weight: 600; padding: 1px 7px; border-radius: 5px;
}

/* ---------- Threads toolbar (filter + select) ---------- */
.threads-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; }
.th-select-btn { background: var(--border-light); color: var(--text); font-size: 12px; font-weight: 600; padding: 6px 12px; }
.th-select-btn:hover { background: #ecdccf; }
.th-select-btn.active { background: var(--accent); color: #fff; }

/* ---------- Bulk action bar ---------- */
.batch-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; }
.batch-all { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.batch-all input { width: 16px; height: 16px; cursor: pointer; }
.batch-actions { display: flex; gap: 6px; }
.batch-actions button { background: var(--border-light); color: var(--text); font-size: 12px; font-weight: 600; padding: 6px 10px; }
.batch-actions button:hover { background: #ecdccf; }
.batch-actions button.danger { color: var(--danger); }
.batch-actions button.danger:hover { background: #fbe4e0; }
.batch-actions button:disabled { opacity: .45; cursor: default; }
.batch-actions button:disabled:hover { background: var(--border-light); }
.ghost2 { background: transparent; color: var(--muted); }
.ghost2:hover { background: var(--border-light) !important; }

/* ---------- Selectable thread rows ---------- */
.thread { display: flex; align-items: flex-start; gap: 10px; }
.thread .t-main { flex: 1; min-width: 0; }
.thread.selectable { cursor: default; }
.thread .t-check { display: flex; align-items: center; padding-top: 2px; }
.thread .t-check input { width: 16px; height: 16px; cursor: pointer; }
.thread.checked { background: var(--accent-peach); }

/* ---------- Reply: mode + recipients ---------- */
.reply { height: 300px; min-height: 200px; }
.reply-addr { flex-shrink: 0; display: flex; flex-direction: column; gap: 6px; margin-bottom: 9px; }
.reply-mode { align-self: flex-start; }
.addr-row { display: flex; align-items: center; gap: 8px; }
.addr-row label { width: 24px; font-size: 12px; color: var(--muted); font-weight: 700; text-align: right; }
.addr-row input {
  flex: 1; min-width: 0; padding: 7px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; font-family: inherit; background: #fff;
}
.addr-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(224,123,57,.15); }
.addr-row input.locked { background: var(--accent-peach); color: var(--muted); cursor: default; }

/* ---------- Related conversations (same person, by email) ---------- */
.related { flex-shrink: 0; background: var(--panel); border-bottom: 1px solid var(--border); }
.related.hidden { display: none; }
.related.loading .rel-head.static { color: var(--muted); }
.rel-head {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 9px 22px; background: var(--accent-peach); border: none; border-bottom: 1px solid transparent;
  font-size: 12.5px; font-weight: 600; color: #5c4742; cursor: pointer; text-align: left;
}
.rel-head.static { cursor: default; }
button.rel-head:hover { background: var(--accent-soft); }
.rel-ico { font-size: 13px; flex-shrink: 0; }
.rel-label { flex: 1; min-width: 0; }
.rel-caret { color: var(--muted); font-size: 11px; transition: transform .15s ease; }
.related.open .rel-caret { transform: rotate(180deg); }
.related.open .rel-head { border-bottom-color: var(--border); }
.rel-list { list-style: none; margin: 0; padding: 0; max-height: 34vh; overflow-y: auto; }
.rel-item { padding: 9px 22px; border-bottom: 1px solid var(--border-light); cursor: pointer; }
.rel-item:last-child { border-bottom: none; }
.rel-item:hover { background: var(--accent-peach); }
.rel-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rel-from { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 600; font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rel-date { flex-shrink: 0; color: var(--muted); font-size: 11px; }
.rel-subject { font-size: 12.5px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rel-tags { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
