:root {
  --bg: #0f1419;
  --bg-elev: #1a222c;
  --bg-soft: #243040;
  --border: #2e3a48;
  --text: #e8eef4;
  --muted: #8b9aab;
  --primary: #3d9cf0;
  --primary-hover: #5aadf5;
  --danger: #e85d5d;
  --success: #3ecf8e;
  --info: #5b8def;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --sidebar-w: 220px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  gap: 1.5rem;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #3d9cf0, #7b5cff);
  display: grid; place-items: center; font-weight: 700; font-size: 1.1rem;
}
.brand-name { font-weight: 700; letter-spacing: 0.02em; }
.brand-sub { font-size: 0.75rem; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 0.35rem; flex: 1; }
.nav-item {
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}
.nav-item:hover { background: var(--bg-soft); text-decoration: none; }
.nav-item.active { background: var(--bg-soft); color: var(--primary); font-weight: 600; }
.nav-item.disabled { color: var(--muted); opacity: 0.45; cursor: not-allowed; }
.sidebar-footer { display: flex; flex-direction: column; gap: 0.5rem; }
.user-chip { font-size: 0.85rem; color: var(--muted); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.5rem; border-bottom: 1px solid var(--border);
  background: rgba(26, 34, 44, 0.7); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 { margin: 0; font-size: 1.15rem; font-weight: 600; }
.content { padding: 1.25rem 1.5rem 2rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  border: 1px solid var(--border); background: var(--bg-soft); color: var(--text);
  border-radius: 8px; padding: 0.5rem 0.9rem; cursor: pointer; font: inherit;
}
.btn:hover { filter: brightness(1.08); }
.btn-primary { background: var(--primary); border-color: transparent; color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.6rem; }

.badge {
  display: inline-block; font-size: 0.7rem; font-weight: 700;
  padding: 0.15rem 0.45rem; border-radius: 999px; letter-spacing: 0.04em;
}
.badge-demo { background: #5b3a00; color: #ffc857; }

.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.filters { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.select-wrap select, input, textarea {
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 0.5rem 0.7rem; font: inherit; width: 100%;
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9rem; }
label.stack > span, .stack > label > span, form.stack label > span {
  display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem;
}
.stack { display: flex; flex-direction: column; gap: 0.85rem; }
.muted { color: var(--muted); font-size: 0.9rem; }
.nowrap { white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}
.inline { display: inline; }

.msg-table-wrap {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: auto; background: var(--bg-elev);
}
.msg-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.msg-table th {
  text-align: left; padding: 0.65rem 0.85rem; color: var(--muted);
  font-weight: 500; border-bottom: 1px solid var(--border); font-size: 0.8rem;
}
.msg-table td { padding: 0.7rem 0.85rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.msg-table tr { cursor: pointer; }
.msg-table tbody tr:hover { background: var(--bg-soft); }
.msg-table tr.unseen .subject, .msg-table tr.unseen .from { font-weight: 650; }
.dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--primary);
}
.subject { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.from { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tag {
  display: inline-block; font-size: 0.7rem; padding: 0.12rem 0.45rem;
  border-radius: 999px; background: var(--bg-soft); margin: 0 0.15rem 0.15rem 0;
  text-transform: lowercase;
}
.tag-cif { background: #1e3a5f; color: #8ec5ff; }
.tag-amazon { background: #3d2e00; color: #ffc14a; }
.tag-alibaba { background: #3d1a00; color: #ff8a4a; }
.tag-fournisseur { background: #1a3d2e; color: #6ddea8; }
.tag-compta { background: #2a1a3d; color: #c5a0ff; }
.tag-action { background: #3d1a1a; color: #ff8a8a; }
.tag-spam { background: #333; color: #aaa; }

.message-view, .draft-view {
  max-width: 860px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1.4rem;
}
.message-header h2 { margin: 0 0 0.75rem; font-size: 1.25rem; }
.meta { display: grid; gap: 0.35rem; margin: 0 0 1rem; }
.meta > div { display: grid; grid-template-columns: 70px 1fr; gap: 0.5rem; }
.meta dt { color: var(--muted); margin: 0; }
.meta dd { margin: 0; word-break: break-word; }

.tag-editor { margin: 1rem 0; }
.tag-editor fieldset {
  border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem 1rem;
}
.chip-group { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.6rem; }
.chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  background: var(--bg-soft); padding: 0.3rem 0.55rem; border-radius: 999px;
  font-size: 0.85rem; cursor: pointer;
}

.attachments ul { padding-left: 1.1rem; }
.body-panel { margin: 1.25rem 0; }
.text-body {
  white-space: pre-wrap; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 1rem; overflow: auto; max-height: 520px;
}
.html-body {
  width: 100%; min-height: 320px; border: 1px solid var(--border);
  border-radius: 10px; background: #fff;
}
.message-actions { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }

.send-confirm {
  background: #2a1f14; border: 1px solid #6b4a20; border-radius: 10px;
  padding: 0.75rem 1rem;
}
.confirm-check { display: flex; align-items: flex-start; gap: 0.6rem; font-size: 0.92rem; }
.confirm-check input { width: auto; margin-top: 0.2rem; }

.alert {
  padding: 0.75rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-size: 0.95rem;
}
.alert-error { background: #3a1a1a; border: 1px solid var(--danger); color: #ffb4b4; }
.alert-success { background: #143028; border: 1px solid var(--success); color: #a8f0cc; }
.alert-info { background: #152238; border: 1px solid var(--info); color: #b8d4ff; }

.empty-state {
  text-align: center; padding: 3rem 1rem; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius);
}

/* Login */
.login-body {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(ellipse at top, #1a2a3d 0%, var(--bg) 55%);
}
.login-card {
  width: min(400px, 92vw); background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: 16px; padding: 1.75rem;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.login-brand { margin-bottom: 1.25rem; }

@media (max-width: 800px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { flex-direction: row; align-items: center; margin-left: auto; }
  .subject, .from { max-width: 140px; }
}


/* Parc / Serveurs */
.parc-table tr { cursor: default; }
.parc-table .host-ip { max-width: 280px; word-break: break-word; }
.badge-stub { background: #3d2e00; color: #ffc857; }
.badge-live { background: #143028; color: #6ddea8; }
.badge-ok { background: #143028; color: #6ddea8; }
.badge-down { background: #3a1a1a; color: #ff8a8a; }
.badge-unknown { background: #2a2a2a; color: #aaa; }


/* Inbox pro — priority + quick filters */
.quick-chips {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
  margin: -0.35rem 0 1rem;
}
.quick-chip {
  display: inline-flex; align-items: center;
  padding: 0.28rem 0.7rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-elev);
  color: var(--muted); font-size: 0.82rem; text-decoration: none;
}
.quick-chip:hover { color: var(--text); border-color: var(--primary); text-decoration: none; }
.quick-chip.active {
  background: var(--bg-soft); color: var(--primary);
  border-color: var(--primary); font-weight: 600;
}

.prio-badge {
  display: inline-block; font-size: 0.68rem; font-weight: 700;
  padding: 0.14rem 0.45rem; border-radius: 999px;
  letter-spacing: 0.02em; text-transform: uppercase; white-space: nowrap;
}
.prio-urgent { background: #4a1010; color: #ff8a8a; }
.prio-high { background: #4a2e10; color: #ffb86b; }
.prio-normal { background: #1a2e3d; color: #8ec5ff; }
.prio-low { background: #2a2a2a; color: #9aa3ad; }

.prio-reasons {
  display: flex; flex-wrap: wrap; gap: 0.35rem;
  margin: 0 0 0.85rem;
}
.prio-reason {
  font-size: 0.75rem; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 999px; padding: 0.12rem 0.5rem;
}

.message-title-row {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 0.65rem; margin-bottom: 0.5rem;
}
.message-title-row h2 { margin: 0; flex: 1 1 auto; }

.msg-table-dense td { padding: 0.48rem 0.7rem; }
.msg-table-dense th { padding: 0.45rem 0.7rem; }
.date-cell { font-size: 0.8rem; }

@media (max-width: 800px) {
  .msg-table-dense .tags { display: none; }
  .msg-table-dense .date-cell { font-size: 0.72rem; }
  .content { padding: 0.85rem 0.85rem 1.5rem; }
  .subject { max-width: 160px; }
}
