/* ============ Capo Mail — papel, espresso & latão ============ */
:root {
  --ink: #231c14;
  --ink-soft: #5d5343;
  --ink-faint: #93876f;
  --paper: #f6f1e7;
  --paper-deep: #efe7d6;
  --card: #fffdf8;
  --line: #e4dac4;
  --line-strong: #d3c5a6;
  --espresso: #1c1610;
  --espresso-2: #2a221a;
  --cream: #f1e8d8;
  --cream-dim: #b3a78e;
  --brass: #a87b2e;
  --brass-bright: #c89a45;
  --brass-soft: #f0e3c5;
  --seal: #b3402e;
  --seal-soft: #f4ddd5;
  --leaf: #3e6b4f;
  --leaf-soft: #dde8dc;
  --shadow: 0 1px 2px rgba(40, 30, 12, 0.06), 0 8px 24px -12px rgba(40, 30, 12, 0.18);
  --shadow-lift: 0 2px 4px rgba(40, 30, 12, 0.08), 0 16px 40px -16px rgba(40, 30, 12, 0.28);
  --display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --ui: 'Archivo', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--ui);
  font-size: 14px;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(168, 123, 46, 0.07), transparent 60%),
    repeating-linear-gradient(0deg, transparent 0 2px, rgba(120, 96, 50, 0.013) 2px 4px),
    var(--paper);
}
::selection { background: var(--brass-soft); }

button { font-family: var(--ui); cursor: pointer; }
input, select, textarea {
  font-family: var(--ui); font-size: 14px; color: var(--ink);
  background: var(--card); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 9px 11px; outline: none; width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brass); box-shadow: 0 0 0 3px rgba(168, 123, 46, 0.15);
}
textarea { resize: vertical; line-height: 1.55; }
label { display: block; font-size: 11.5px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-soft); margin: 0 0 5px; }
a { color: var(--brass); }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line-strong); background: var(--card); color: var(--ink);
  border-radius: 8px; padding: 8px 14px; font-size: 13.5px; font-weight: 500;
  transition: transform 0.12s, box-shadow 0.15s, background 0.15s, border-color 0.15s;
}
.btn:hover { border-color: var(--brass); box-shadow: var(--shadow); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn.gold { background: linear-gradient(160deg, var(--brass-bright), var(--brass)); border-color: #8f6722; color: #fff8ea; }
.btn.gold:hover { filter: brightness(1.06); }
.btn.danger { color: var(--seal); }
.btn.danger:hover { border-color: var(--seal); }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--paper-deep); box-shadow: none; transform: none; }

/* ============ login ============ */
.login-stage {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 500px at 20% 110%, rgba(168, 123, 46, 0.12), transparent 55%),
    radial-gradient(800px 400px at 90% -10%, rgba(62, 107, 79, 0.08), transparent 60%),
    var(--espresso);
}
.login-card {
  width: 360px; background: var(--card); border-radius: 14px; padding: 38px 34px 30px;
  border: 1px solid rgba(168, 123, 46, 0.35); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.55);
  animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.25, 1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(0.985); } to { opacity: 1; transform: none; } }
.login-card .sig { text-align: center; margin-bottom: 22px; }
.login-card h1 { font-family: var(--display); font-weight: 600; font-size: 30px; margin: 8px 0 2px; text-align: center; letter-spacing: 0.01em; }
.login-card h1 em { font-style: italic; color: var(--brass); }
.login-card p.sub { margin: 0 0 24px; text-align: center; color: var(--ink-faint); font-size: 12.5px; letter-spacing: 0.14em; text-transform: uppercase; }
.login-card .err { color: var(--seal); font-size: 13px; min-height: 18px; margin: 10px 0 2px; text-align: center; }
.login-card button { width: 100%; justify-content: center; margin-top: 8px; padding: 11px; font-size: 14.5px; }

/* ============ layout ============ */
.shell { display: grid; grid-template-columns: 252px 1fr; height: 100vh; }

.sidebar {
  background: linear-gradient(180deg, var(--espresso-2), var(--espresso) 30%);
  color: var(--cream); display: flex; flex-direction: column; padding: 18px 14px 14px;
  border-right: 1px solid #00000033;
}
.brand { display: flex; align-items: baseline; gap: 8px; padding: 2px 8px 16px; }
.brand .mark { color: var(--brass-bright); font-size: 15px; transform: translateY(-1px); }
.brand h1 { font-family: var(--display); font-size: 21px; font-weight: 600; margin: 0; letter-spacing: 0.02em; }
.brand h1 em { font-style: italic; color: var(--brass-bright); font-weight: 500; }

.compose-btn {
  margin: 2px 4px 14px; justify-content: center; padding: 10.5px; font-size: 14px; border-radius: 9px;
  box-shadow: 0 6px 18px -6px rgba(200, 154, 69, 0.5);
}

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8.5px 10px; border-radius: 8px;
  color: var(--cream-dim); text-decoration: none; font-size: 13.5px; font-weight: 500;
  border: 1px solid transparent; transition: background 0.15s, color 0.15s;
  animation: navIn 0.4s cubic-bezier(0.2, 0.8, 0.25, 1) both;
}
.nav-item:nth-child(1) { animation-delay: 0.03s; } .nav-item:nth-child(2) { animation-delay: 0.06s; }
.nav-item:nth-child(3) { animation-delay: 0.09s; } .nav-item:nth-child(4) { animation-delay: 0.12s; }
.nav-item:nth-child(5) { animation-delay: 0.15s; } .nav-item:nth-child(6) { animation-delay: 0.18s; }
@keyframes navIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
.nav-item:hover { background: #ffffff10; color: var(--cream); }
.nav-item.active { background: #ffffff14; color: #fff; border-color: #ffffff1c; }
.nav-item .ico { width: 18px; text-align: center; opacity: 0.9; }
.nav-item .count {
  margin-left: auto; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px;
  background: var(--brass); color: #fff7e6;
}
.nav-item .count.muted { background: #ffffff1f; color: var(--cream-dim); }
.nav-item .count:empty { display: none; }

.side-sec { margin: 18px 8px 6px; font-size: 10.5px; letter-spacing: 0.18em; color: #8b7d62; text-transform: uppercase; }
.accounts { display: flex; flex-direction: column; gap: 1px; overflow-y: auto; min-height: 40px; }
.acct {
  display: flex; align-items: center; gap: 9px; padding: 6.5px 10px; border-radius: 7px;
  color: var(--cream-dim); font-size: 13px; cursor: pointer; border: 1px solid transparent;
}
.acct:hover { background: #ffffff0d; color: var(--cream); }
.acct.active { background: #ffffff12; color: #fff; border-color: #ffffff1a; }
.acct .dot { width: 9px; height: 9px; border-radius: 99px; flex: none; box-shadow: 0 0 0 2px #00000040; }
.acct .em { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct.err .em::after { content: ' ⚠'; color: #e8a23c; }

.side-bottom { margin-top: auto; padding-top: 12px; }
.sync-line { display: flex; align-items: center; gap: 8px; padding: 8px 10px; color: #8b7d62; font-size: 11.5px; }
.sync-line .pulse { width: 7px; height: 7px; border-radius: 99px; background: var(--leaf); }
.sync-line.busy .pulse { background: var(--brass-bright); animation: blink 0.9s infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

/* ============ main ============ */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 13px 20px;
  border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--card) 70%, transparent);
  backdrop-filter: blur(6px);
}
.topbar h2 { font-family: var(--display); font-size: 21px; font-weight: 600; margin: 0; }
.topbar h2 em { font-style: italic; color: var(--brass); }
.searchbox { position: relative; margin-left: auto; width: min(340px, 36vw); }
.searchbox input { padding-left: 34px; border-radius: 99px; background: var(--paper-deep); border-color: transparent; }
.searchbox input:focus { background: var(--card); border-color: var(--brass); }
.searchbox .lens { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-faint); }

.content { display: grid; grid-template-columns: minmax(330px, 410px) 1fr; flex: 1; min-height: 0; }

/* lista */
.list-pane { border-right: 1px solid var(--line); overflow-y: auto; background: color-mix(in srgb, var(--paper) 55%, var(--card)); }
.row {
  position: relative; display: flex; flex-direction: column; gap: 3px;
  padding: 11px 16px 11px 18px; border-bottom: 1px solid var(--line); cursor: pointer;
  transition: background 0.12s, transform 0.12s;
}
.row::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: transparent; transition: background 0.15s;
}
.row.unread::before { background: var(--brass); }
.row:hover { background: var(--card); }
.row.sel { background: var(--card); box-shadow: inset -3px 0 0 var(--brass); }
.row .l1 { display: flex; align-items: center; gap: 8px; }
.row .dot { width: 8px; height: 8px; border-radius: 99px; flex: none; }
.row .from { font-weight: 500; font-size: 13.5px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread .from { font-weight: 700; color: var(--ink); }
.row .when { margin-left: auto; font-size: 11.5px; color: var(--ink-faint); flex: none; }
.row .subj { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread .subj { font-weight: 600; }
.row .snip { font-size: 12.5px; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .badges { display: flex; gap: 5px; margin-top: 2px; }
.list-empty { padding: 60px 24px; text-align: center; color: var(--ink-faint); }
.list-empty .big { font-family: var(--display); font-size: 19px; font-style: italic; color: var(--ink-soft); margin-bottom: 6px; }
.list-more { display: block; width: calc(100% - 32px); margin: 12px 16px 20px; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.05em; text-transform: uppercase; padding: 2px 8px; border-radius: 99px;
}
.chip.importante { background: var(--seal-soft); color: var(--seal); }
.chip.normal { background: var(--paper-deep); color: var(--ink-soft); }
.chip.spam { background: #efe3ce; color: #8a6a1f; }
.chip.pendente { background: var(--paper-deep); color: var(--ink-faint); }
.chip.salvo { background: var(--leaf-soft); color: var(--leaf); }
.chip.anexo { background: var(--paper-deep); color: var(--ink-soft); text-transform: none; letter-spacing: 0; }

/* leitura */
.read-pane { overflow-y: auto; min-width: 0; display: flex; flex-direction: column; }
.read-empty { flex: 1; display: grid; place-items: center; color: var(--ink-faint); }
.read-empty .sig { text-align: center; opacity: 0.85; }
.read-empty .sig .d { font-size: 26px; color: var(--brass); }
.read-empty .sig p { font-family: var(--display); font-style: italic; font-size: 17px; color: var(--ink-soft); margin: 8px 0 0; }

.msg { padding: 22px 28px 34px; animation: msgIn 0.25s ease both; }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg h3 { font-family: var(--display); font-size: 23px; font-weight: 600; margin: 0 0 14px; line-height: 1.25; }
.msg-head {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.avatar {
  width: 40px; height: 40px; border-radius: 99px; flex: none; display: grid; place-items: center;
  font-family: var(--display); font-weight: 600; font-size: 17px; color: #fff8ea;
}
.msg-head .who { min-width: 0; }
.msg-head .who .n { font-weight: 600; font-size: 14.5px; }
.msg-head .who .a { color: var(--ink-faint); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; }
.msg-head .who .t { color: var(--ink-faint); font-size: 12px; margin-top: 3px; }
.msg-head .meta { margin-left: auto; text-align: right; flex: none; }
.msg-head .meta .when { color: var(--ink-faint); font-size: 12px; margin-bottom: 6px; }
.ai-note {
  margin: 12px 0 0; padding: 9px 13px; border-left: 3px solid var(--brass);
  background: var(--brass-soft); border-radius: 0 9px 9px 0; font-size: 12.5px; color: #6d5118;
}
.msg-actions { display: flex; flex-wrap: wrap; gap: 7px; margin: 14px 0; }
.msg-body-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.msg-body-card iframe { width: 100%; border: 0; display: block; background: #fff; }
.msg-body-card pre {
  margin: 0; padding: 20px 22px; white-space: pre-wrap; word-break: break-word;
  font-family: var(--ui); font-size: 14px; line-height: 1.6;
}
.atts { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }

/* ============ configurações ============ */
.settings { padding: 24px 30px 60px; overflow-y: auto; max-width: 980px; }
.settings h3 { font-family: var(--display); font-size: 19px; font-weight: 600; margin: 26px 0 12px; }
.settings h3:first-child { margin-top: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.frow { margin-bottom: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink); }
.check input { width: auto; }
.acct-table { width: 100%; border-collapse: collapse; }
.acct-table td, .acct-table th { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; }
.acct-table th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); }
.preset-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.preset-chip {
  border: 1px solid var(--line-strong); background: var(--paper-deep); border-radius: 99px;
  padding: 6px 13px; font-size: 12.5px; font-weight: 600;
}
.preset-chip.on { background: var(--espresso); color: var(--cream); border-color: var(--espresso); }
.hint { font-size: 12px; color: var(--ink-faint); margin-top: 5px; line-height: 1.45; }
.logbox { font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; background: var(--espresso); color: var(--cream-dim); border-radius: 10px; padding: 12px 14px; max-height: 260px; overflow: auto; white-space: pre-wrap; }
.logbox .warn { color: #e0b45c; } .logbox .error { color: #e07a5f; }

/* ============ modais & toasts ============ */
.overlay {
  position: fixed; inset: 0; background: rgba(24, 17, 9, 0.45); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px; z-index: 50; animation: fade 0.15s ease both;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(680px, 96vw); max-height: 92vh; overflow-y: auto; background: var(--card);
  border-radius: 14px; border: 1px solid var(--line-strong); box-shadow: var(--shadow-lift);
  padding: 22px 24px; animation: pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}
@keyframes pop { from { opacity: 0; transform: scale(0.96) translateY(8px); } to { opacity: 1; transform: none; } }
.modal h3 { font-family: var(--display); font-size: 20px; font-weight: 600; margin: 0 0 16px; }
.modal .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.modal .foot .left { margin-right: auto; display: flex; gap: 8px; }

#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 99; }
.toast {
  background: var(--espresso); color: var(--cream); border-radius: 10px; padding: 11px 16px;
  font-size: 13px; box-shadow: var(--shadow-lift); border-left: 3px solid var(--brass-bright);
  animation: toastIn 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2) both; max-width: 360px;
}
.toast.err { border-left-color: var(--seal); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

.ai-bar { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; margin-top: 8px; }

.acct-error {
  margin: 12px 16px; padding: 12px 14px; text-align: left;
  background: #fdf0ee; border: 1px solid #e8c4ba; border-radius: 10px;
  color: #8c3325; font-size: 12.5px; line-height: 1.55; word-break: break-word;
}
.acct-error a { color: #8c3325; font-weight: 600; }

.acct { position: relative; }
.acct .acct-edit {
  margin-left: auto; padding: 0 4px; border-radius: 6px;
  color: var(--cream-dim, #b8ab93); opacity: 0; font-size: 13px; transition: opacity 0.15s;
}
.acct:hover .acct-edit { opacity: 0.85; }
.acct .acct-edit:hover { opacity: 1; color: #e9c878; }
.ai-bar .undo { font-size: 12.5px; }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 99px; animation: rot 0.7s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ============ responsivo ============ */
@media (max-width: 1080px) {
  .content { grid-template-columns: 1fr; }
  .read-pane { display: none; }
  .content.reading .list-pane { display: none; }
  .content.reading .read-pane { display: flex; }
  .back-btn { display: inline-flex !important; }
}
.back-btn { display: none; }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px; }
  .brand { padding: 0 6px; } .side-sec, .accounts, .sync-line { display: none; }
  .compose-btn { margin: 0; padding: 8px 12px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .side-bottom { margin: 0; padding: 0; }
}
