*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: #1a1a1a;
  background: #f5f3ef;
  min-height: 100vh;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.header {
  margin-bottom: 2rem;
  text-align: center;
}

.header h1 {
  margin: 0 0 0.5rem;
  font-size: 1.75rem;
  font-weight: 700;
  color: #2c1810;
}

.subtitle {
  margin: 0;
  color: #5c534d;
  font-size: 0.95rem;
}

.form-section {
  background: #fff;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  margin-bottom: 2rem;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.field label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: #2c1810;
}

.field input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-size: 1rem;
  border: 1px solid #d4cfc9;
  border-radius: 8px;
  background: #fff;
  color: #1a1a1a;
  transition: border-color 0.2s;
}

.field input:focus {
  outline: none;
  border-color: #8b6914;
  box-shadow: 0 0 0 3px rgba(139, 105, 20, 0.15);
}

.field input::placeholder {
  color: #9a948c;
}

.btn {
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.05s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: #8b6914;
  color: #fff;
}

.btn-primary:hover {
  background: #7a5d12;
}

.btn-primary:disabled {
  background: #b8a86a;
  cursor: not-allowed;
  transform: none;
}

.error {
  margin: 0.75rem 0 0;
  padding: 0.6rem 0.85rem;
  background: #fef2f2;
  color: #b91c1c;
  border-radius: 8px;
  font-size: 0.9rem;
  display: none;
}

.error.visible {
  display: block;
}

.inbox-section {
  background: #fff;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.inbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.inbox-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #2c1810;
}

.count {
  font-size: 0.9rem;
  color: #5c534d;
}

.search-bar {
  margin-bottom: 1rem;
}

.search-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.search-form input[type="search"] {
  flex: 1;
  min-width: 200px;
  padding: 0.6rem 0.85rem;
  font-size: 1rem;
  border: 1px solid #d4cfc9;
  border-radius: 8px;
  background: #fff;
  color: #1a1a1a;
}

.search-form input[type="search"]:focus {
  outline: none;
  border-color: #8b6914;
  box-shadow: 0 0 0 3px rgba(139, 105, 20, 0.15);
}

.btn-search {
  flex-shrink: 0;
}

.search-info {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  color: #5c534d;
}

.btn-link {
  margin-top: 0.5rem;
  padding: 0.35rem 0;
  font-size: 0.9rem;
  font-weight: 500;
  border: none;
  background: transparent;
  color: #8b6914;
  cursor: pointer;
  text-decoration: underline;
  transition: color 0.15s;
}

.btn-link:hover {
  color: #7a5d12;
}

.pagination-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.pagination-info {
  font-size: 0.9rem;
  color: #5c534d;
}

.pagination-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.pagination-nav.pagination-loading {
  opacity: 0.7;
  pointer-events: none;
}

.pagination-btn {
  min-width: 2.25rem;
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid #d4cfc9;
  border-radius: 6px;
  background: #fff;
  color: #2c1810;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.pagination-btn:hover:not(:disabled) {
  background: #f5f3ef;
  border-color: #8b6914;
}

.pagination-btn.active {
  background: #8b6914;
  border-color: #8b6914;
  color: #fff;
}

.pagination-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination-ellipsis {
  padding: 0 0.25rem;
  font-size: 0.9rem;
  color: #8a8178;
}

.pagination-bottom {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #ebe8e4;
  justify-content: center;
}

.loading {
  text-align: center;
  padding: 2rem;
  color: #5c534d;
}

.email-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.email-list li {
  padding: 1rem;
  border-bottom: 1px solid #ebe8e4;
  transition: background 0.15s;
}

.email-list-item {
  cursor: pointer;
}

.email-list li:last-child {
  border-bottom: none;
}

.email-list li:hover {
  background: #faf9f7;
}

.email-subject-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.email-subject {
  font-weight: 600;
  color: #2c1810;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-attachment-icon {
  flex-shrink: 0;
  font-size: 1rem;
  opacity: 0.8;
}

.email-meta {
  font-size: 0.85rem;
  color: #5c534d;
}

.email-meta span + span::before {
  content: " · ";
  margin: 0 0.25rem;
}

.email-from {
  color: #6b5b4f;
}

.email-date {
  color: #8a8178;
}

/* Modal lecture mail — masquée par défaut, display: flex uniquement quand ouverte */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal:not([hidden]) {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  cursor: pointer;
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: min(1100px, 95vw);
  height: 92vh;
  max-height: 92vh;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #ebe8e4;
  flex-shrink: 0;
}

.modal-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: #2c1810;
  line-height: 1.35;
  flex: 1;
  min-width: 0;
}

.modal-close {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: #5c534d;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.modal-close:hover {
  background: #f5f3ef;
  color: #2c1810;
}

.modal-meta {
  padding: 1rem 1.5rem;
  font-size: 0.9rem;
  color: #5c534d;
  border-bottom: 1px solid #ebe8e4;
  flex-shrink: 0;
}

.modal-meta-row {
  margin-bottom: 0.35rem;
}

.modal-meta-row:last-child {
  margin-bottom: 0;
}

.modal-attachments {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #ebe8e4;
  background: #faf9f7;
  flex-shrink: 0;
}

.modal-attachments-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #2c1810;
  margin-bottom: 0.5rem;
}

.modal-attachments-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.modal-attachment-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid #ebe8e4;
}

.modal-attachment-item:last-child {
  border-bottom: none;
}

.modal-attachment-name {
  font-size: 0.9rem;
  color: #2c1810;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-attachment-size {
  font-size: 0.85rem;
  color: #5c534d;
}

.btn-download-attachment {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid #8b6914;
  border-radius: 6px;
  background: transparent;
  color: #8b6914;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-download-attachment:hover {
  background: #8b6914;
  color: #fff;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid #ebe8e4;
  flex-shrink: 0;
}

.btn-reply {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid #8b6914;
  border-radius: 8px;
  background: transparent;
  color: #8b6914;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-reply:hover {
  background: #8b6914;
  color: #fff;
}

.btn-open-window {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid #d4cfc9;
  border-radius: 8px;
  background: #fff;
  color: #2c1810;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-open-window:hover {
  background: #f5f3ef;
  border-color: #8b6914;
  color: #8b6914;
}

.btn-secondary {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid #d4cfc9;
  border-radius: 8px;
  background: #fff;
  color: #2c1810;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-secondary:hover {
  background: #f5f3ef;
  border-color: #8b6914;
}

.reply-form-container {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #ebe8e4;
  background: #faf9f7;
  flex-shrink: 0;
}

.reply-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.reply-form .field label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: #2c1810;
  font-size: 0.9rem;
}

.reply-form .field input,
.reply-form .field textarea {
  width: 100%;
  padding: 0.6rem 0.8rem;
  font-size: 0.95rem;
  border: 1px solid #d4cfc9;
  border-radius: 8px;
  background: #fff;
  color: #1a1a1a;
  font-family: inherit;
}

.reply-form .field textarea {
  resize: vertical;
  min-height: 100px;
}

.reply-form-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.reply-message {
  margin: 0.75rem 0 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  border-radius: 8px;
}

.reply-message-success {
  background: #dcfce7;
  color: #166534;
}

.reply-message-error {
  background: #fef2f2;
  color: #b91c1c;
}

.modal-loading {
  padding: 2rem;
  text-align: center;
  color: #5c534d;
}

.modal-body {
  flex: 1;
  overflow: auto;
  padding: 1.5rem;
  min-height: 200px;
}

.modal-body-iframe {
  width: 100%;
  min-height: 400px;
  height: 100%;
  border: none;
  display: block;
}

.modal-body-text {
  margin: 0;
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: #2c1810;
}

.modal-error,
.modal-empty {
  margin: 0;
  color: #b91c1c;
}

.modal-empty {
  color: #5c534d;
}
