* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: #f5f5f5;
  color: #333;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Header --- */
.header {
  background: linear-gradient(135deg, #1E2761 0%, #2a3580 100%);
  color: #fff;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  position: relative;
  z-index: 10;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 0;
}
.header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.header-sep {
  margin: 0 14px;
  opacity: 0.3;
  font-size: 20px;
  font-weight: 300;
}
.header-role {
  font-size: 14px;
  font-weight: 400;
  opacity: 0.7;
  white-space: nowrap;
}
.header .area-badge {
  background: #F9A825;
  color: #1E2761;
  padding: 4px 14px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  white-space: nowrap;
}
.header-mailbox {
  font-size: 13px;
  opacity: 0.5;
  margin-left: 14px;
  font-family: 'Consolas', 'Courier New', monospace;
  white-space: nowrap;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.header-logo {
  height: 28px;
  width: auto;
  background: #fff;
  padding: 3px 8px;
  border-radius: 4px;
}
.header button {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  padding: 6px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
}
.header button:hover {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.4);
}

/* --- Login --- */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}
.login-box {
  background: #fff;
  border-radius: 8px;
  padding: 40px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
  width: 360px;
  text-align: center;
}
.login-box h2 {
  color: #1E2761;
  margin-bottom: 8px;
  font-size: 22px;
}
.login-box .subtitle {
  color: #888;
  font-size: 14px;
  margin-bottom: 24px;
}
.login-box input[type="password"] {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}
.login-box input:focus { border-color: #1E2761; }
.login-box button {
  width: 100%;
  padding: 12px;
  background: #1E2761;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  margin-top: 16px;
  font-weight: 600;
}
.login-box button:hover { background: #2a3580; }
.login-error {
  color: #c62828;
  font-size: 14px;
  margin-top: 12px;
  display: none;
}

/* --- Main Layout --- */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* --- Lista messaggi (pannello sinistro) --- */
.message-list {
  width: 380px;
  min-width: 320px;
  background: #fff;
  border-right: 1px solid #e0e0e0;
  overflow-y: auto;
  flex-shrink: 0;
}
.message-list .toolbar {
  padding: 12px 16px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafafa;
}
.message-list .toolbar span {
  font-size: 13px;
  color: #888;
}
.message-list .toolbar button {
  background: none;
  border: none;
  color: #1E2761;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.message-item {
  padding: 14px 16px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition: background 0.15s;
}
.message-item:hover { background: #f5f8ff; }
.message-item.active { background: #e8eef8; border-left: 3px solid #1E2761; }
.message-item.unread { font-weight: 600; }
.message-item .from {
  font-size: 14px;
  color: #1E2761;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.message-item .subject {
  font-size: 13px;
  color: #333;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.message-item .preview {
  font-size: 12px;
  color: #999;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.message-item .date {
  font-size: 11px;
  color: #aaa;
  float: right;
  margin-top: -2px;
}

/* --- Dettaglio messaggio (pannello destro) --- */
.message-detail {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.detail-header {
  padding: 16px 24px;
  border-bottom: 1px solid #e0e0e0;
  background: #fff;
  flex-shrink: 0;
}
.detail-header h2 {
  font-size: 18px;
  color: #1E2761;
  margin-bottom: 6px;
}
.detail-header .meta {
  font-size: 13px;
  color: #888;
}
.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  background: #fff;
}
.detail-body iframe {
  width: 100%;
  border: none;
  min-height: 300px;
}
.detail-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: #ccc;
  font-size: 18px;
  background: #fff;
}

/* --- Reply box --- */
.reply-box {
  border-top: 2px solid #e0e0e0;
  padding: 16px 24px;
  background: #fafafa;
  flex-shrink: 0;
}
.reply-box textarea {
  width: 100%;
  min-height: 80px;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  outline: none;
}
.reply-box textarea:focus { border-color: #1E2761; }
.reply-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}
.reply-actions .quick-btns button {
  background: #e8eef8;
  border: 1px solid #c0d0e8;
  color: #1E2761;
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  margin-right: 8px;
}
.reply-actions .quick-btns button:hover { background: #d0dff0; }
.reply-actions .send-btn {
  background: #2e7d32;
  color: #fff;
  border: none;
  padding: 10px 24px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.reply-actions .send-btn:hover { background: #1b5e20; }
.reply-actions .send-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}
.reply-status {
  font-size: 13px;
  margin-top: 8px;
  min-height: 20px;
}
.reply-status.success { color: #2e7d32; }
.reply-status.error { color: #c62828; }

/* --- Loading / Error --- */
.loading {
  text-align: center;
  padding: 40px;
  color: #888;
}
.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid #e0e0e0;
  border-top-color: #1E2761;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Responsive --- */
@media (max-width: 768px) {
  .main { flex-direction: column; }
  .message-list { width: 100%; max-height: 40vh; border-right: none; border-bottom: 1px solid #e0e0e0; }
}
