﻿/* Gate Control — stile condiviso area riservata (da template gate-control) */
:root {
  --bg: #f2f5f9;
  --surface: #ffffff;
  --accent: #135eab;
  --accent-light: rgba(19,94,171,0.08);
  --accent-mid: rgba(19,94,171,0.15);
  --accent-border: rgba(19,94,171,0.25);
  --text-primary: #1a2536;
  --text-secondary: #536580;
  --text-muted: #8d9db5;
  --text-faint: #b0bdd0;
  --border: rgba(0,0,0,0.06);
  --closed: #8d9db5;
  --closed-light: rgba(141,157,181,0.08);
  --closed-border: rgba(141,157,181,0.18);
  --emergency: #e54d4d;
  --emergency-light: rgba(229,77,77,0.08);
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.03);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.04);
  --shadow-accent: 0 2px 12px rgba(19,94,171,0.12), 0 4px 20px rgba(19,94,171,0.06);
}

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

html, body {
  width: 100%; min-height: 100vh; min-height: 100dvh;
  background: var(--bg);
  font-family: 'Outfit', 'SF Pro Display', -apple-system, sans-serif;
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(-16px) scale(0.95); } to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); } }
@keyframes login-out { 0% { opacity: 1; } 50% { opacity: 0.5; transform: scale(1.01); } 100% { opacity: 0; transform: scale(1.03); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse-send {
  0% { transform: scale(1); }
  30% { transform: scale(0.93); }
  60% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

.bg-dots {
  position: fixed; inset: 0; opacity: 0.4; pointer-events: none; z-index: 0;
  background-image: radial-gradient(circle, rgba(0,0,0,0.04) 1px, transparent 1px);
  background-size: 28px 28px;
}

.screen { display: none; }
.screen.active { display: flex; }

/* ===== LOGIN ===== */
.login-screen {
  min-height: 100vh; min-height: 100dvh;
  flex-direction: column; align-items: center; justify-content: center;
  padding: 20px; position: relative; z-index: 1;
  animation: fadeIn 0.5s ease;
}
.login-screen.exiting { animation: login-out 0.8s ease forwards; }

.login-logo { margin-bottom: 8px; animation: fadeInUp 0.6s ease; }
.login-title {
  font-size: 22px; font-weight: 700; letter-spacing: -0.3px;
  color: var(--text-primary); animation: fadeInUp 0.6s ease 0.1s both;
}
.login-subtitle {
  font-size: 12px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--text-muted); font-weight: 500; margin-bottom: 36px;
  animation: fadeInUp 0.6s ease 0.15s both;
}

.login-card {
  width: 100%; max-width: 320px;
  display: flex; flex-direction: column; gap: 12px;
  animation: fadeInUp 0.6s ease 0.2s both;
}
.login-card.error { animation: shake 0.4s ease; }

.text-input {
  width: 100%; padding: 15px 18px; border-radius: 14px;
  border: 1.5px solid var(--border); background: var(--surface);
  font-family: 'Outfit', sans-serif; font-size: 15px; color: var(--text-primary);
  box-shadow: var(--shadow); outline: none; transition: all 0.15s ease;
}
.text-input:focus { border-color: var(--accent-border); box-shadow: var(--shadow-accent); }
.text-input::placeholder { color: var(--text-faint); }

.error-msg {
  min-height: 28px; display: flex; align-items: center; justify-content: center;
  color: var(--emergency); font-size: 13px; font-weight: 500;
}

.login-hint {
  color: var(--text-faint); font-size: 11px; margin-top: 36px;
  text-align: center; line-height: 1.6; animation: fadeInUp 0.6s ease 0.5s both;
}

.back-home {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 16px; padding: 8px 18px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); font-size: 12px; font-weight: 600;
  text-decoration: none; box-shadow: var(--shadow);
  transition: all 0.15s ease; animation: fadeInUp 0.6s ease 0.6s both;
}
.back-home:active { transform: scale(0.95); }
.back-home:hover { color: var(--accent); border-color: var(--accent-border); }

/* ===== DASHBOARD ===== */
.dashboard-screen {
  min-height: 100vh; min-height: 100dvh;
  flex-direction: column; max-width: 480px; margin: 0 auto;
  position: relative; z-index: 1; animation: fadeIn 0.5s ease; width: 100%;
}

.dash-header {
  padding: 16px 20px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: rgba(242,245,249,0.85); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  position: sticky; top: 0; z-index: 10;
}
.user-info { display: flex; align-items: center; gap: 12px; }
.user-avatar {
  width: 38px; height: 38px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-light), var(--accent-mid));
  border: 1px solid var(--accent-border);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); font-size: 13px; font-weight: 700; letter-spacing: 0.5px;
  text-transform: uppercase;
}
.user-name { font-size: 14px; font-weight: 600; color: var(--text-primary); text-transform: capitalize; }
.user-role { font-size: 11px; font-weight: 500; color: var(--text-muted); }
.header-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); box-shadow: var(--shadow); transition: all 0.15s ease;
}
.icon-btn:active { transform: scale(0.93); }
.icon-btn.active { background: var(--accent-light); color: var(--accent); border-color: var(--accent-border); }
.icon-btn svg { pointer-events: none; }

.time-bar {
  padding: 12px 20px; display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border);
}
.time-date { color: var(--text-muted); font-size: 11px; font-weight: 500; letter-spacing: 1px; text-transform: uppercase; }
.time-clock { color: var(--accent); font-size: 13px; font-weight: 600; font-family: 'JetBrains Mono', monospace; letter-spacing: 1px; }

/* Log panel */
.log-panel {
  margin: 12px 16px 0; padding: 16px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border);
  max-height: 200px; overflow-y: auto; box-shadow: var(--shadow);
  animation: slideUp 0.3s ease; display: none;
}
.log-panel.visible { display: block; }
.log-title { color: var(--text-muted); font-size: 11px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 10px; }
.log-empty { color: var(--text-faint); font-size: 12px; }
.log-entry { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.log-entry:last-child { border-bottom: none; }
.log-action { font-size: 12px; font-weight: 600; color: var(--accent); }
.log-gate { color: var(--text-secondary); font-size: 12px; }
.log-time { color: var(--text-faint); font-size: 11px; font-family: 'JetBrains Mono', monospace; }

/* Section */
.section-title {
  padding: 14px 20px 10px;
  color: var(--text-muted); font-size: 11px; font-weight: 600;
  letter-spacing: 1.5px; text-transform: uppercase;
}

/* Gate grid */
.gate-grid {
  padding: 0 16px 20px; display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: min-content; align-content: start; gap: 12px;
}
.gate-empty { grid-column: 1 / -1; color: var(--text-faint); font-size: 13px; padding: 20px 4px; }

/* Gate card */
.gate-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 16px; cursor: pointer;
  transition: all 0.25s ease; user-select: none;
  position: relative; overflow: hidden; box-shadow: var(--shadow);
}
.gate-card:active { transform: scale(0.97); }
.gate-card.expanded {
  border-color: var(--accent-border);
  box-shadow: var(--shadow-accent);
}

.gate-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.gate-icon svg { display: block; }
.gate-type-label {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 20px; font-size: 10px; font-weight: 600;
  letter-spacing: 0.5px; text-transform: uppercase;
  background: var(--closed-light); color: var(--closed);
  border: 1px solid var(--closed-border);
}
.gate-type-label.emergency {
  background: var(--emergency-light); color: var(--emergency);
  border-color: rgba(229,77,77,0.2);
}
.gate-name { color: var(--text-primary); font-size: 13px; font-weight: 600; margin-bottom: 3px; line-height: 1.3; }
.gate-location { color: var(--text-muted); font-size: 11px; font-weight: 400; margin-bottom: 4px; }

/* Modalità riordino (drag & drop) */
@keyframes wiggle {
  0% { transform: rotate(-0.8deg); }
  50% { transform: rotate(0.8deg); }
  100% { transform: rotate(-0.8deg); }
}
.gate-grid.edit-mode .gate-card {
  cursor: grab; touch-action: none; user-select: none;
  border-style: dashed; border-color: var(--accent-border);
  background: var(--accent-light);
  animation: wiggle 0.35s ease-in-out infinite;
}
.gate-grid.edit-mode .gate-card .gate-name { color: var(--accent); }
.gate-card.dragging {
  animation: none !important;
  transition: none !important;
  opacity: 0.9;
  border-style: solid; border-color: var(--accent);
  background: var(--surface);
  box-shadow: var(--shadow-md), var(--shadow-accent);
  cursor: grabbing; position: relative; z-index: 10;
}

.gate-expand { display: none; animation: scaleIn 0.2s ease; }
.gate-expand.visible { display: block; }
.gate-desc { color: var(--text-secondary); font-size: 11px; margin-bottom: 12px; line-height: 1.4; }

.open-btn {
  padding: 14px 0; border-radius: 14px; border: none;
  font-size: 15px; font-weight: 600; font-family: 'Outfit', sans-serif;
  cursor: pointer; width: 100%; transition: all 0.2s ease; letter-spacing: 0.3px;
  background: linear-gradient(135deg, #135eab, #1b78d4);
  color: #fff; box-shadow: 0 4px 14px rgba(19,94,171,0.3);
}
.open-btn:active { transform: scale(0.97); filter: brightness(0.95); }
.open-btn.sending { animation: pulse-send 0.5s ease; }

/* ===== TABS ===== */
.tab-bar {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 14px 16px 2px;
}
.tab-btn {
  padding: 8px 18px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); font-size: 12px; font-weight: 600;
  font-family: 'Outfit', sans-serif; cursor: pointer;
  box-shadow: var(--shadow); transition: all 0.15s ease; user-select: none;
}
.tab-btn:active { transform: scale(0.95); }
.tab-btn.active { background: var(--accent-light); border-color: var(--accent-border); color: var(--accent); box-shadow: var(--shadow-accent); }

/* Selettore gruppi nella dashboard utente */
#tabs-varchi { margin-bottom: 12px; }

/* ===== ADMIN ===== */
.group-manage { display: flex; gap: 8px; padding: 4px 16px 12px; align-items: stretch; }
.group-manage .text-input { flex: 1; padding: 12px 16px; }
.group-manage .open-btn { width: auto; padding: 0 22px; }
.group-list { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 16px 12px; }
.group-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 10px 7px 16px; border-radius: 20px;
  border: 1px solid var(--accent-border); background: var(--accent-light);
  color: var(--accent); font-size: 12px; font-weight: 600;
}
.group-pill .pill-del {
  width: 18px; height: 18px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--emergency);
  font-size: 12px; font-weight: 700; cursor: pointer; line-height: 1;
  border: 1px solid var(--border);
}
.admin-list { padding: 0 16px 120px; display: flex; flex-direction: column; gap: 12px; }
.admin-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 16px; box-shadow: var(--shadow);
}
.admin-card-top { display: flex; align-items: center; gap: 12px; }
.admin-note { padding: 4px 20px 10px; color: var(--text-faint); font-size: 11px; line-height: 1.5; }
.group-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.chip {
  padding: 7px 16px; border-radius: 20px;
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  cursor: pointer; transition: all 0.15s ease; user-select: none; text-transform: capitalize;
}
.chip.on { background: var(--accent-light); border-color: var(--accent-border); color: var(--accent); box-shadow: var(--shadow-accent); }
.chip:active { transform: scale(0.94); }

.save-bar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; z-index: 20;
  padding: 14px 16px; padding-bottom: calc(14px + env(safe-area-inset-bottom));
  background: rgba(242,245,249,0.9); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
}

/* Toast */
.toast {
  position: fixed; top: 20px; left: 50%;
  transform: translateX(-50%); z-index: 100;
  padding: 10px 24px; border-radius: 12px;
  background: var(--surface); font-size: 13px; font-weight: 600;
  letter-spacing: 0.3px; box-shadow: var(--shadow-md);
  animation: toast-in 0.3s ease;
  display: none; white-space: nowrap;
  border: 1px solid var(--accent-border); color: var(--accent);
}
.toast.visible { display: block; }
.toast.error { border-color: rgba(229,77,77,0.35); color: var(--emergency); }

/* Footer */
.dash-footer {
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: center; align-items: center; gap: 6px; margin-top: auto;
}
.footer-text { color: var(--text-faint); font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; font-weight: 500; }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 2px; }

@supports (padding: env(safe-area-inset-top)) {
  .dash-header { padding-top: calc(16px + env(safe-area-inset-top)); }
  .login-screen { padding-top: calc(20px + env(safe-area-inset-top)); }
}
