/* assets/css/components/pages/email.css
 * Webmail Dattago (admin only). Layout cheio: pastas | lista | leitura/compositor.
 */

.email-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 64px);
  width: 100%;
  padding: 20px 24px 0;
  box-sizing: border-box;
}

.email-header {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 16px;
  margin-bottom: 14px; flex: 0 0 auto;
}
.email-header h1 { font-size: 22px; font-weight: 700; color: var(--text); margin: 0; }
.email-subtitle { font-size: 13px; color: var(--text-muted); margin: 3px 0 0; }
.email-header-actions { display: flex; gap: 8px; }

.email-btn-primary {
  padding: 9px 16px; font-size: 14px; font-weight: 600; font-family: inherit;
  background: var(--text); color: var(--surface); border: none; border-radius: 10px;
  cursor: pointer; transition: opacity 0.15s;
}
.email-btn-primary:hover { opacity: 0.9; }
.email-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.email-btn-ghost {
  padding: 9px 16px; font-size: 14px; font-weight: 500; font-family: inherit;
  background: transparent; color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer;
}
.email-btn-ghost:hover { background: var(--hover-bg); }

.email-error {
  padding: 12px 16px; background: var(--accent-soft, rgba(91, 91, 240, 0.08));
  color: var(--accent, #4338ca); border-left: 3px solid var(--accent, #4338ca);
  border-radius: 8px; margin-bottom: 12px; font-size: 13px; flex: 0 0 auto;
}

/* ── 3 colunas ── */
.email-body {
  display: grid;
  grid-template-columns: 190px 340px 1fr;
  gap: 14px;
  flex: 1 1 auto;
  min-height: 0;
  padding-bottom: 20px;
}

/* Pastas */
.email-folders {
  display: flex; flex-direction: column; gap: 4px; min-height: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px;
}
.email-folder {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 9px 12px; font-size: 13px; font-weight: 500; font-family: inherit;
  background: transparent; color: var(--text); border: none; border-radius: 8px; cursor: pointer;
}
.email-folder:hover { background: var(--hover-bg); }
.email-folder.is-active { background: var(--bg-soft); font-weight: 600; }
.email-folder-ic { font-size: 14px; }
.email-folder-count {
  margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px; box-sizing: border-box;
  background: var(--danger, #dc2626); color: #fff; font-size: 11px; font-weight: 700;
  line-height: 18px; text-align: center; border-radius: 9px;
}

/* Avatar */
.email-avatar {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 13px; font-weight: 700; overflow: hidden;
}
.email-avatar--logo { background: #fff; border: 1px solid var(--border); }
.email-avatar--logo img { width: 100%; height: 100%; object-fit: cover; }

/* Lista */
.email-list-pane {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
}
.email-list-toolbar { padding: 10px; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.email-search {
  width: 100%; box-sizing: border-box; height: 34px; padding: 0 10px; font-size: 13px; font-family: inherit;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
}
.email-search:focus { outline: none; border-color: var(--accent); }
.email-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.email-list-empty { padding: 32px 20px; text-align: center; color: var(--text-muted); font-style: italic; font-size: 13px; }

.email-item {
  display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border-subtle);
  cursor: pointer; border-left: 3px solid transparent;
}
.email-item:hover { background: var(--hover-bg); }
.email-item.is-selected { background: var(--bg-soft); border-left-color: var(--accent, #4338ca); }
.email-item.is-unread .email-item-from { font-weight: 700; }
.email-item.is-unread .email-item-subject { font-weight: 600; color: var(--text); }
.email-item-main { min-width: 0; flex: 1 1 auto; }
.email-item-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.email-item-from { font-size: 13px; color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.email-item-date { font-size: 11px; color: var(--text-muted); flex: 0 0 auto; }
.email-item-subject { font-size: 13px; color: var(--text); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-item-clip { margin-right: 4px; }
.email-item-snippet { font-size: 12px; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Leitura / Compositor */
.email-reader {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
}
.email-reader-placeholder { margin: auto; color: var(--text-muted); font-size: 14px; text-align: center; }
.email-reader-head { padding: 16px 22px; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.email-reader-head-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.email-reader-subject { font-size: 18px; font-weight: 700; color: var(--text); margin: 0 0 10px; flex: 1 1 auto; }
.email-reader-acts { flex: 0 0 auto; display: flex; gap: 6px; }
.email-act-btn {
  padding: 6px 12px; font-size: 12px; font-weight: 500; font-family: inherit; cursor: pointer;
  background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: 8px;
}
.email-act-btn:hover { background: var(--hover-bg); }
.email-del-btn {
  padding: 6px 12px; font-size: 12px; font-weight: 500; font-family: inherit; cursor: pointer;
  background: transparent; color: var(--danger, #dc2626); border: 1px solid var(--border); border-radius: 8px;
}
.email-del-btn:hover { background: var(--hover-bg-danger, rgba(220,38,38,0.08)); border-color: var(--danger, #dc2626); }
.email-del-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.email-reader-meta { display: flex; align-items: center; gap: 10px; }
.email-reader-meta-txt { display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: var(--text-muted); min-width: 0; }
.email-reader-meta-txt strong { color: var(--text); font-weight: 600; }
.email-reader-date { font-size: 12px; }
.email-reader-body { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
.email-html-frame { width: 100%; height: 100%; min-height: 320px; border: 0; background: #fff; }
.email-text-body { margin: 0; padding: 22px; white-space: pre-wrap; word-break: break-word; font-family: inherit; font-size: 14px; color: var(--text); line-height: 1.55; }

/* Anexos */
.email-attachments { flex: 0 0 auto; padding: 12px 22px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.email-att-title { width: 100%; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 2px; }
.email-att-loading { font-size: 12px; color: var(--text-muted); font-style: italic; }
.email-att-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 240px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); text-decoration: none; font-size: 12px; }
.email-att-chip:hover { background: var(--hover-bg); border-color: var(--accent); }
.email-att-chip svg { flex: 0 0 auto; color: var(--text-muted); }
.email-att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.email-att-size { flex: 0 0 auto; color: var(--text-muted); }

/* ── Compositor inline ── */
.email-composer { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.email-composer-bar { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.email-attach-btn { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 4px; padding: 8px 12px; font-size: 13px; font-family: inherit; cursor: pointer; background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: 8px; }
.email-attach-btn:hover { background: var(--hover-bg); }
.cf-drop-hint { flex: 1 1 auto; min-width: 0; font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Chips de anexo (estilo Gmail) */
.cf-attachments { flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px; }
.cf-attachments:not(:empty) { padding: 12px 20px; border-top: 1px solid var(--border-subtle); }
.cf-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 280px;
  padding: 6px 8px 6px 10px; font-size: 12px;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 8px; color: var(--text);
}
.cf-chip svg { flex: 0 0 auto; color: var(--text-muted); }
.cf-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.cf-chip-size { flex: 0 0 auto; color: var(--text-muted); }
.cf-chip-err { flex: 0 0 auto; color: var(--danger, #dc2626); font-weight: 600; }
.cf-chip--error { border-color: var(--danger, #dc2626); }
.cf-chip-x {
  flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; padding: 0; margin-left: 2px; cursor: pointer;
  background: transparent; border: none; border-radius: 4px; color: var(--text-muted);
}
.cf-chip-x:hover { background: var(--hover-bg); color: var(--text); }
.cf-spin {
  flex: 0 0 auto; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent, #4338ca);
  animation: cf-spin 0.7s linear infinite;
}
@keyframes cf-spin { to { transform: rotate(360deg); } }
/* Realce ao arrastar arquivo sobre o compositor */
.email-composer.is-dragover { outline: 2px dashed var(--accent, #4338ca); outline-offset: -6px; }
.email-composer-fields { flex: 0 0 auto; padding: 6px 18px; }
.cf-row { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border-subtle); }
.cf-row > span { flex: 0 0 56px; font-size: 13px; color: var(--text-muted); font-weight: 500; }
.cf-row input, .cf-row select { flex: 1 1 auto; border: none; background: transparent; color: var(--text); font-size: 14px; font-family: inherit; padding: 9px 0; min-width: 0; }
.cf-row input:focus, .cf-row select:focus { outline: none; }
.cf-from { cursor: pointer; }

/* Editor rich text */
.email-rt-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 1px; padding: 7px 14px; border-bottom: 1px solid var(--border); background: var(--bg-soft); flex: 0 0 auto; }
.rt-btn {
  min-width: 30px; height: 30px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; font-family: inherit; cursor: pointer; color: var(--text);
  background: transparent; border: 1px solid transparent; border-radius: 6px;
}
.rt-btn:hover { background: var(--hover-bg); border-color: var(--border); }
.rt-btn svg { display: block; }
.rt-size { height: 30px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); font-size: 13px; font-family: inherit; padding: 0 6px; cursor: pointer; }
.rt-sep { width: 1px; height: 20px; background: var(--border); margin: 0 5px; }

/* Botão de cor (A) com barra + caret + paleta popover */
.rt-color { position: relative; display: inline-flex; }
.rt-color-trigger { gap: 1px; }
.rt-A { font-weight: 800; font-size: 14px; line-height: 1; }
.rt-A-hl { background: #fef08a; padding: 0 2px; border-radius: 2px; color: #111827; }
.rt-cbar { display: block; width: 14px; height: 3px; border-radius: 2px; margin-top: 1px; }
.rt-color-trigger .rt-cbar { position: absolute; bottom: 4px; left: 6px; }
.rt-palette {
  position: absolute; top: 34px; left: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(8, 18px); gap: 3px; padding: 8px;
  background: var(--surface-card, var(--surface)); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow-modal, 0 8px 24px rgba(0,0,0,0.18));
}
.rt-palette[hidden] { display: none; }
.rt-pal-sw { width: 18px; height: 18px; padding: 0; border: 1px solid rgba(0,0,0,0.12); border-radius: 3px; cursor: pointer; }
.rt-pal-sw:hover { outline: 2px solid var(--accent, #4338ca); outline-offset: 1px; }
.rt-pal-none { grid-column: 1 / -1; margin-top: 4px; padding: 5px; font-size: 12px; font-family: inherit; cursor: pointer; background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: 6px; }
.rt-pal-none:hover { background: var(--hover-bg); }

/* Split-button de lista (botão + caret + menu de estilos) */
.rt-split { position: relative; display: inline-flex; align-items: center; }
.rt-split-caret { min-width: 18px; padding: 0 2px; }
.rt-listmenu {
  position: absolute; top: 34px; left: 0; z-index: 40; min-width: 210px;
  display: flex; flex-direction: column; padding: 5px;
  background: var(--surface-card, var(--surface)); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow-modal, 0 8px 24px rgba(0,0,0,0.18));
}
.rt-listmenu[hidden] { display: none; }
.rt-listmenu button {
  text-align: left; padding: 8px 12px; font-size: 13px; font-family: inherit; cursor: pointer;
  background: transparent; color: var(--text); border: none; border-radius: 6px; white-space: nowrap;
}
.rt-listmenu button:hover { background: var(--hover-bg); }

/* Ícones dentro de botões com texto */
.email-btn-primary, .email-btn-ghost { display: inline-flex; align-items: center; gap: 6px; }
.email-act-btn, .email-del-btn { display: inline-flex; align-items: center; gap: 5px; }
.email-attach-btn svg, .email-btn-primary svg, .email-btn-ghost svg, .email-act-btn svg, .email-del-btn svg { display: block; }
.email-folder-ic { display: inline-flex; }
.email-folder-ic svg { display: block; }
.email-item-clip { display: inline-flex; vertical-align: -2px; margin-right: 4px; color: var(--text-muted); }
.email-editor {
  flex: 1 1 auto; overflow-y: auto; min-height: 180px; padding: 16px 20px;
  font-family: system-ui, sans-serif; font-size: 14px; color: var(--text); line-height: 1.55;
  background: var(--surface); outline: none;
}
.email-editor:empty::before { content: 'Escreva sua mensagem…'; color: var(--text-muted); }
.email-composer-error { flex: 0 0 auto; padding: 10px 18px; color: #b91c1c; font-size: 13px; background: rgba(220,38,38,0.08); }
.email-composer-error[hidden] { display: none; }

/* ── Modal Comunicado (broadcast) ── */
.email-modal { position: fixed; inset: 0; z-index: var(--z-modal); display: flex; align-items: center; justify-content: center; }
.email-modal[hidden] { display: none; }
.email-modal-backdrop { position: absolute; inset: 0; background: var(--surface-overlay); backdrop-filter: blur(2px); }
.email-modal-content { position: relative; width: 100%; max-width: 480px; max-height: calc(100vh - 48px); overflow-y: auto; margin: var(--space-6); padding: var(--space-7); background: var(--surface-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-modal); z-index: 1; }
.email-modal-content h2 { font-size: var(--text-xl); font-weight: 700; margin: 0 0 8px; color: var(--text); }
.email-modal-hint { font-size: 12px; color: var(--text-muted); margin: 0 0 18px; }
.email-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.email-field label { font-size: 13px; font-weight: 500; color: var(--text); }
.email-filter { height: 40px; padding: 0 10px; font-size: 14px; font-family: inherit; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.email-field input[type="text"] { height: 40px; padding: 0 12px; font-size: 14px; font-family: inherit; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.email-field textarea { width: 100%; box-sizing: border-box; padding: 10px 12px; font-size: 14px; font-family: inherit; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); resize: vertical; }
.email-field input:focus, .email-field textarea:focus, .email-filter:focus { outline: none; border-color: var(--accent); }
.email-form-error { padding: 10px 12px; background: rgba(220, 38, 38, 0.08); color: #b91c1c; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }
.email-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* Modal Configurações de E-mail (abas) */
.email-cfg-content { max-width: 640px; }
.email-cfg-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 4px 0 16px; }
.email-cfg-tab {
  padding: 9px 14px; font-size: 13px; font-weight: 600; font-family: inherit; cursor: pointer;
  background: transparent; color: var(--text-muted); border: none; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.email-cfg-tab:hover { color: var(--text); }
.email-cfg-tab.is-active { color: var(--text); border-bottom-color: var(--accent, #4338ca); }
.email-cfg-pane[hidden] { display: none; }
.cfg-identities { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.cfg-identity-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center; }
.cfg-identity-del {
  padding: 8px 12px; font-size: 13px; font-family: inherit; cursor: pointer;
  background: transparent; color: var(--danger, #dc2626); border: 1px solid var(--border); border-radius: 8px;
}
.cfg-identity-del:hover { background: var(--hover-bg-danger, rgba(220,38,38,0.08)); border-color: var(--danger, #dc2626); }
.email-cfg-sig { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.email-cfg-sig-ta {
  width: 100%; box-sizing: border-box; padding: 10px 12px; font-size: 12px; font-family: ui-monospace, monospace;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); resize: vertical;
}
.email-cfg-sig-ta:focus { outline: none; border-color: var(--accent); }
.email-cfg-sig-preview {
  padding: 12px; border: 1px dashed var(--border); border-radius: 8px; background: #fff; overflow: auto;
  font-size: 13px;
}
@media (max-width: 620px) { .email-cfg-sig { grid-template-columns: 1fr; } }

/* Dark mode */
[data-theme="dark"] .email-folders,
[data-theme="dark"] .email-list-pane,
[data-theme="dark"] .email-reader,
[data-theme="dark"] .email-modal-content { background: var(--surface); border-color: var(--border); }
[data-theme="dark"] .email-search,
[data-theme="dark"] .email-filter,
[data-theme="dark"] .email-field input,
[data-theme="dark"] .email-field textarea { background: var(--bg); border-color: var(--border); color: var(--text); }
[data-theme="dark"] .email-rt-toolbar { background: var(--bg); }
[data-theme="dark"] .email-btn-primary { background: var(--text); color: var(--bg); }

/* Responsivo: telas estreitas escondem a coluna de pastas (lista + leitura/compositor seguem) */
@media (max-width: 1000px) {
  .email-body { grid-template-columns: 300px 1fr; }
  .email-folders { display: none; }
}
