/* =============================================
   GESTIONE PRESENZE — style.css
   ============================================= */

:root {
  --blue:        #1a56a0;
  --blue-dark:   #133d77;
  --blue-light:  #e8f0fb;
  --green:       #1a6b3a;
  --green-light: #e6f4ec;
  --red:         #b91c1c;
  --red-light:   #fef2f2;
  --orange:      #c2740a;
  --orange-light:#fff7ed;
  --gray-50:     #f8fafc;
  --gray-100:    #f1f5f9;
  --gray-200:    #e2e8f0;
  --gray-400:    #94a3b8;
  --gray-600:    #475569;
  --gray-800:    #1e293b;
  --white:       #ffffff;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 4px 24px rgba(0,0,0,.10);
  --shadow-sm:   0 2px 8px rgba(0,0,0,.07);
  --transition:  .18s ease;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--gray-800);
  background: var(--gray-50);
  min-height: 100vh;
  line-height: 1.6;
}

/* ---- UTILITY ---- */
.hidden { display: none !important; }

/* ---- ALERTS ---- */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
}
.alert-error   { background: var(--red-light);    color: var(--red);    border: 1px solid #fecaca; }
.alert-success { background: var(--green-light);  color: var(--green);  border: 1px solid #bbf7d0; }
.alert-info    { background: var(--blue-light);   color: var(--blue);   border: 1px solid #bfdbfe; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .65rem 1.4rem;
  border: none; border-radius: var(--radius-sm);
  font-size: .95rem; font-weight: 600; cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn-primary   { background: var(--blue);  color: var(--white); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { background: var(--gray-200); color: var(--gray-800); }
.btn-secondary:hover { background: var(--gray-400); color: var(--white); }
.btn-full { width: 100%; justify-content: center; }
.btn-sm   { padding: .4rem .9rem; font-size: .85rem; }

.btn-icon {
  background: none; border: none; cursor: pointer;
  color: var(--gray-600); padding: .4rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
  display: flex; align-items: center;
}
.btn-icon:hover { color: var(--blue); background: var(--blue-light); }
.btn-icon svg { width: 20px; height: 20px; }

/* ---- FORMS ---- */
.form-group { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1.1rem; }
.form-group label { font-size: .85rem; font-weight: 600; color: var(--gray-600); text-transform: uppercase; letter-spacing: .04em; }
.form-group input,
.form-group select {
  padding: .75rem 1rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  color: var(--gray-800);
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26,86,160,.12);
}

.input-eye { position: relative; }
.input-eye input { padding-right: 3rem; }
.eye-btn {
  position: absolute; right: .75rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer;
  color: var(--gray-400); padding: .2rem;
}
.eye-btn svg { width: 18px; height: 18px; }

/* ---- HEADER ---- */
.app-header {
  background: var(--blue);
  color: var(--white);
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,.15);
}
.header-inner {
  max-width: 680px; margin: 0 auto;
  padding: .85rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between;
}
.header-logo {
  display: flex; align-items: center; gap: .6rem;
  font-weight: 700; font-size: 1.05rem;
}
.header-user {
  display: flex; align-items: center; gap: .75rem;
  font-size: .9rem; opacity: .9;
}
.header-user .btn-icon { color: rgba(255,255,255,.8); }
.header-user .btn-icon:hover { color: var(--white); background: rgba(255,255,255,.15); }

/* ---- LOGO ICON ---- */
.logo-icon {
  width: 42px; height: 42px;
  background: var(--white);
  color: var(--blue);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 1.2rem;
  box-shadow: var(--shadow-sm);
}
.logo-icon.small { width: 32px; height: 32px; font-size: .95rem; border-radius: 7px; }

/* =============================================
   LOGIN PAGE
   ============================================= */
.page-login {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1a3a6b 0%, #1a56a0 60%, #2271c7 100%);
  padding: 1.5rem;
}
.login-wrapper { width: 100%; max-width: 420px; }

.login-card {
  background: var(--white);
  border-radius: 20px;
  padding: 2.5rem 2rem;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo .logo-icon {
  width: 64px; height: 64px; font-size: 1.8rem; border-radius: 16px;
  background: var(--blue); color: var(--white);
  margin: 0 auto 1rem;
  box-shadow: 0 8px 24px rgba(26,86,160,.35);
}
.login-logo h1 { font-size: 1.35rem; color: var(--gray-800); margin-bottom: .3rem; }
.login-subtitle { font-size: .9rem; color: var(--gray-400); }

.login-footer { text-align: center; margin-top: 1.5rem; color: rgba(255,255,255,.5); font-size: .8rem; }

/* Spinner sul bottone */
.btn-spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =============================================
   APP PAGE
   ============================================= */
.page-app { background: var(--gray-50); }
.app-main { max-width: 480px; margin: 0 auto; padding: 1.25rem; }

/* Status card */
.status-card {
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
  color: var(--white);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  margin-bottom: 1.25rem;
  box-shadow: 0 8px 28px rgba(26,86,160,.30);
}
.status-date { font-size: .9rem; opacity: .8; margin-bottom: .2rem; text-transform: capitalize; }
.status-time { font-size: 2.8rem; font-weight: 800; letter-spacing: -.02em; line-height: 1; margin-bottom: .75rem; }
.status-badge {
  display: inline-block;
  padding: .3rem .9rem;
  border-radius: 20px;
  font-size: .85rem; font-weight: 700;
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.3);
}
.status-badge.in  { background: rgba(34,197,94,.25); border-color: rgba(34,197,94,.5); }
.status-badge.out { background: rgba(249,115,22,.25); border-color: rgba(249,115,22,.5); }

/* Check-in buttons */
.checkin-section {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
  margin-bottom: 1rem;
}
.btn-checkin {
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  padding: 1.5rem 1rem;
  border: none; border-radius: var(--radius);
  font-size: 1.1rem; font-weight: 700; cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
  box-shadow: var(--shadow-sm);
}
.btn-checkin svg { width: 32px; height: 32px; }
.btn-checkin:active { transform: scale(.95); }
.btn-checkin:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-entrata { background: var(--green-light); color: var(--green); }
.btn-entrata:hover:not(:disabled) { background: #c7eed8; box-shadow: 0 6px 20px rgba(26,107,58,.18); }
.btn-uscita  { background: var(--orange-light); color: var(--orange); }
.btn-uscita:hover:not(:disabled)  { background: #ffe9c7; box-shadow: 0 6px 20px rgba(194,116,10,.18); }

/* GPS status */
.gps-status {
  display: flex; align-items: center; gap: .5rem;
  font-size: .82rem; color: var(--gray-400);
  margin-bottom: 1rem; padding: .4rem .2rem;
}
.gps-status svg { width: 14px; height: 14px; flex-shrink: 0; }
.gps-status.ok    { color: var(--green); }
.gps-status.error { color: var(--red); }

/* Feedback message */
.feedback-msg {
  padding: .85rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 600; font-size: .95rem;
  margin-bottom: 1rem;
  animation: fadeIn .3s ease;
}
.feedback-msg.success { background: var(--green-light); color: var(--green); border: 1px solid #86efac; }
.feedback-msg.error   { background: var(--red-light);   color: var(--red);   border: 1px solid #fca5a5; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* Storico */
.storico-section { margin-top: 1.5rem; }
.section-title { font-size: 1rem; font-weight: 700; color: var(--gray-600); margin-bottom: .75rem; text-transform: uppercase; letter-spacing: .05em; }
.storico-list { display: flex; flex-direction: column; gap: .5rem; }
.storico-loading { text-align: center; color: var(--gray-400); font-size: .9rem; padding: 1.5rem; }

.storico-item {
  background: var(--white);
  border-radius: var(--radius-sm);
  padding: .85rem 1rem;
  display: flex; align-items: center; gap: .85rem;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid transparent;
}
.storico-item.entrata { border-left-color: var(--green); }
.storico-item.uscita  { border-left-color: var(--orange); }

.storico-icon {
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.storico-item.entrata .storico-icon { background: var(--green-light); color: var(--green); }
.storico-item.uscita  .storico-icon { background: var(--orange-light); color: var(--orange); }
.storico-icon svg { width: 18px; height: 18px; }

.storico-info { flex: 1; min-width: 0; }
.storico-tipo { font-weight: 700; font-size: .95rem; text-transform: capitalize; }
.storico-meta { font-size: .8rem; color: var(--gray-400); margin-top: .1rem; }

.storico-coords {
  font-size: .75rem; color: var(--gray-400);
  text-align: right; line-height: 1.3;
}

/* =============================================
   MESSAGGI / CHAT
   ============================================= */

/* Bottone messaggio sullo storico */
.msg-btn {
  position: relative;
  background: none; border: none; cursor: pointer;
  color: var(--gray-400); padding: .35rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
  display: flex; align-items: center;
  flex-shrink: 0;
}
.msg-btn:hover { color: var(--blue); background: var(--blue-light); }
.msg-btn svg { width: 20px; height: 20px; }

/* Bottone messaggio nella tabella admin */
.iv-msg-btn {
  position: relative;
  background: none; border: none; cursor: pointer;
  color: var(--gray-400); padding: .3rem;
  border-radius: 6px;
  transition: color var(--transition), background var(--transition);
  display: inline-flex; align-items: center;
}
.iv-msg-btn:hover { color: var(--blue); background: var(--blue-light); }

/* Badge non letti */
.msg-badge, .iv-msg-badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 16px; height: 16px;
  background: var(--red); color: var(--white);
  border-radius: 10px; font-size: .65rem; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px;
  border: 2px solid var(--white);
}

/* Modal chat */
.chat-modal {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
@media (min-width: 520px) {
  .chat-modal { align-items: center; padding: 1rem; }
}
.chat-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
}
.chat-box {
  position: relative; z-index: 1;
  background: var(--white);
  border-radius: 16px 16px 0 0;
  width: 100%; max-width: 480px;
  max-height: 85vh;
  display: flex; flex-direction: column;
  box-shadow: 0 -8px 40px rgba(0,0,0,.20);
  animation: slideUp .22s ease;
}
@media (min-width: 520px) {
  .chat-box { border-radius: 16px; animation: modalIn .2s ease; max-height: 75vh; }
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}
.chat-title {
  display: flex; align-items: center; gap: .5rem;
  font-weight: 700; font-size: .95rem; color: var(--blue);
}
.chat-close {
  background: none; border: none; font-size: 1.5rem;
  cursor: pointer; color: var(--gray-400); line-height: 1; padding: .1rem .3rem;
}
.chat-close:hover { color: var(--gray-800); }

.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex; flex-direction: column; gap: .6rem;
}
.chat-loading, .chat-empty {
  text-align: center; color: var(--gray-400);
  font-size: .88rem; padding: 1.5rem 0;
}

/* Bolle */
.chat-msg { display: flex; flex-direction: column; max-width: 82%; }
.chat-msg.msg-out { align-self: flex-end; align-items: flex-end; }
.chat-msg.msg-in  { align-self: flex-start; align-items: flex-start; }

.msg-from { font-size: .72rem; font-weight: 700; color: var(--gray-400); margin-bottom: .15rem; text-transform: uppercase; letter-spacing: .04em; }

.msg-bubble {
  padding: .6rem .9rem;
  border-radius: 16px;
  font-size: .9rem; line-height: 1.5;
  word-break: break-word;
}
.msg-out .msg-bubble { background: var(--blue); color: var(--white); border-bottom-right-radius: 4px; }
.msg-in  .msg-bubble { background: var(--gray-100); color: var(--gray-800); border-bottom-left-radius: 4px; }

.msg-time { font-size: .72rem; color: var(--gray-400); margin-top: .2rem; }

/* Input area */
.chat-input-area {
  display: flex; gap: .6rem; align-items: flex-end;
  padding: .85rem 1.25rem;
  border-top: 1px solid var(--gray-200);
  flex-shrink: 0;
}
.chat-input-area textarea {
  flex: 1; resize: none;
  padding: .6rem .85rem;
  border: 2px solid var(--gray-200);
  border-radius: 12px; font-size: .9rem;
  font-family: inherit; line-height: 1.4;
  transition: border-color var(--transition);
}
.chat-input-area textarea:focus { outline: none; border-color: var(--blue); }

.storico-luogo {
  font-size: .8rem; color: var(--blue);
  margin-top: .1rem; font-weight: 600;
}

/* =============================================
   MEDIA IN CHAT (video/foto)
   ============================================= */
.msg-media {
  display: block;
  max-width: 100%; width: 100%;
  border-radius: 10px; margin-bottom: .4rem;
  background: #000;
}
video.msg-media { max-height: 280px; }
img.msg-media   { max-height: 220px; object-fit: cover; cursor: pointer; }

.chat-media-btn {
  color: var(--blue); flex-shrink: 0;
}
.chat-media-btn:hover { background: var(--blue-light); }

/* Barra progresso upload */
.chat-upload-progress {
  padding: .5rem 1.25rem;
  display: flex; align-items: center; gap: .75rem;
  border-top: 1px solid var(--gray-100);
  background: var(--gray-50);
  font-size: .82rem; color: var(--gray-600);
}
.upload-bar {
  flex: 1; height: 6px; background: var(--gray-200);
  border-radius: 3px; overflow: hidden;
}
.upload-bar-fill {
  height: 100%; width: 0%;
  background: var(--blue);
  border-radius: 3px;
  transition: width .2s ease;
}
