/* =========================================================
   Comunicazioni Aziendali - Stile principale
   ========================================================= */

:root {
  --grigio-sfondo: #e9edf1;
  --grigio-sfondo-scuro: #dde3e9;
  --sidebar-bg: #2c3e50;
  --sidebar-bg-hover: #34495e;
  --sidebar-text: #ecf0f1;
  --azzurro: #2f80ed;
  --azzurro-scuro: #2166c9;
  --verde: #27ae60;
  --verde-scuro: #219150;
  --rosso: #e74c3c;
  --rosso-scuro: #c0392b;
  --card-bg: #ffffff;
  --card-border: #cfd8e3;
  --testo-scuro: #2c3e50;
  --radius-lg: 16px;
  --radius-md: 10px;
  --ombra: 0 2px 8px rgba(44, 62, 80, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--grigio-sfondo);
  color: var(--testo-scuro);
}

/* ---------- LOGIN ---------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--sidebar-bg) 0%, #486583 100%);
}
.login-box {
  background: var(--card-bg);
  padding: 40px 36px;
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 380px;
}
.login-logo {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  color: var(--sidebar-bg);
  margin-bottom: 4px;
}
.login-sub {
  text-align: center;
  color: #7f8c96;
  margin-top: 0;
  margin-bottom: 24px;
  font-size: 14px;
}
.login-box label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 14px 0 6px;
  color: var(--testo-scuro);
}
.login-box select,
.login-box input[type="text"],
.login-box input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--card-border);
  font-size: 15px;
  background: #f7f9fb;
}
.login-box select:focus,
.login-box input:focus {
  outline: none;
  border-color: var(--azzurro);
  background: #fff;
}
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  margin-bottom: 10px;
}
.alert-error {
  background: #fdecea;
  color: var(--rosso-scuro);
  border: 1px solid #f5c6c0;
}
.alert-ok {
  background: #eafaf1;
  color: var(--verde-scuro);
  border: 1px solid #b9e6cb;
}

/* ---------- BOTTONI GENERICI ---------- */
.btn {
  border: none;
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(0,0,0,0.2); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

.btn-primary { background: var(--azzurro); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--azzurro-scuro); }
.btn-block { width: 100%; margin-top: 22px; padding: 12px; font-size: 15px; }

.btn-logout { background: rgba(255,255,255,0.15); color: #fff; text-decoration: none; padding: 8px 16px; }
.btn-logout:hover { background: rgba(255,255,255,0.28); }

.btn-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--azzurro);
  color: #fff;
  text-decoration: none;
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  transition: transform 0.08s ease, background 0.15s ease;
  flex-shrink: 0;
}
.btn-help:hover { background: var(--azzurro-scuro); transform: translateY(-1px); }

.btn-edit  { background: var(--azzurro); color: #fff; }
.btn-edit:hover:not(:disabled)  { background: var(--azzurro-scuro); }
.btn-clear { background: #f2f4f7; color: var(--testo-scuro); border: 1px solid var(--card-border); }
.btn-clear:hover:not(:disabled) { background: #e3e7ec; }
.btn-save  { background: var(--verde); color: #fff; }
.btn-save:hover:not(:disabled)  { background: var(--verde-scuro); }

.btn-danger { background: var(--rosso); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--rosso-scuro); }

/* ---------- HEADER ---------- */
.app-header {
  height: 62px;
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 18px;
  gap: 16px;
  box-shadow: var(--ombra);
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-title {
  font-size: 20px;
  font-weight: 700;
  flex: 1;
  letter-spacing: 0.3px;
}
.menu-toggle {
  display: none;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
}
.header-user {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
}
.header-user em { color: #b9c5d0; font-style: normal; }

/* ---------- BODY / SIDEBAR ---------- */
.app-body {
  display: flex;
  min-height: calc(100vh - 62px);
}
.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.menu-item {
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 14.5px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.menu-item:hover, .menu-item.active {
  background: var(--sidebar-bg-hover);
}
.sidebar-overlay {
  display: none;
}

.content-area {
  flex: 1;
  padding: 24px 28px;
  overflow-y: auto;
}

.dashboard-toolbar-info {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 6px;
}
.dashboard-toolbar-info h2 { margin: 0; color: var(--sidebar-bg); }
.refresh-note { font-size: 12.5px; color: #7f8c96; }

/* ---------- CARD MESSAGGI (2 per riga) ---------- */
.msg-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}
.msg-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-left: 6px solid var(--azzurro);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--ombra);
}
.msg-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.msg-user-name {
  font-weight: 700;
  font-size: 16px;
  color: var(--sidebar-bg);
  flex: 1;
}
.role-tag {
  background: var(--azzurro);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 6px;
}
.edit-badge {
  font-size: 11px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.5px;
}
.badge-free { background: #eef1f4; color: #8a97a3; }
.badge-edit { background: #fdecea; color: var(--rosso-scuro); animation: pulse 1.4s infinite; }
@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.55; }
  100% { opacity: 1; }
}
.msg-actions { display: flex; gap: 6px; }
.msg-actions .btn { padding: 6px 12px; font-size: 12.5px; }

.msg-textarea {
  width: 100%;
  min-height: 110px;
  border-radius: var(--radius-md);
  border: 1px solid var(--card-border);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  background: #f7f9fb;
}
.msg-textarea:not([readonly]) {
  background: #fffef2;
  border-color: #f0c419;
}
.msg-textarea[readonly] { color: #4b5a68; }

.empty-state {
  padding: 30px;
  text-align: center;
  color: #7f8c96;
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px dashed var(--card-border);
}

/* ---------- FORM GENERICI (Crea Manager, Crea Dipendente, ecc.) ---------- */
.panel {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--card-border);
  padding: 24px;
  max-width: 480px;
  box-shadow: var(--ombra);
}
.panel h2 { margin-top: 0; color: var(--sidebar-bg); }
.panel label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 14px 0 6px;
}
.panel select, .panel input[type="text"], .panel input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--card-border);
  font-size: 14.5px;
  background: #f7f9fb;
}
.panel .btn { margin-top: 20px; }
.form-msg { margin-top: 14px; font-size: 14px; }
.form-msg.ok { color: var(--verde-scuro); }
.form-msg.err { color: var(--rosso-scuro); }

.loading { padding: 40px; text-align: center; color: #7f8c96; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 860px) {
  .msg-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .menu-toggle { display: block; }
  .app-title { font-size: 17px; }
  .header-user span { display: none; }

  .sidebar {
    position: fixed;
    top: 62px;
    left: 0;
    bottom: 0;
    width: 250px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 30;
    box-shadow: 4px 0 16px rgba(0,0,0,0.25);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 62px; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.35);
    z-index: 25;
  }
  .sidebar-overlay.open { display: block; }

  .content-area { padding: 16px; }
  .panel { max-width: 100%; }
}
