/* ===================================================================
   AS Automation - Login screen
   Palette istituzionale: rosso #ED1C24 / blu navy #003F80
   =================================================================== */

:root {
  --as-red:        #ED1C24;
  --as-red-dark:   #C41019;
  --as-blue:       #003F80;
  --as-blue-dark:  #002A56;
  --as-blue-light: #4372A1;
  --bg:            #f0f2f7;
  --surface:       #ffffff;
  --border:        #cdd3e0;
  --text:          #1e293b;
  --text-2:        #475569;
  --text-3:        #94a3b8;
  --red-bg:        #fef2f2;
  --shadow-lg:     0 25px 50px -12px rgba(0, 0, 0, 0.35);
}

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

html, body {
  height: 100%;
  font-family: 'Barlow', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
}

/* ===== Sfondo gradiente istituzionale ===== */
.bg-gradient {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #003F80 0%, #002A56 60%, #1a0810 100%);
  z-index: -1;
}
.bg-gradient::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 15% 20%, rgba(67, 114, 161, 0.4) 0%, transparent 50%),
    radial-gradient(circle at 85% 85%, rgba(237, 28, 36, 0.25) 0%, transparent 55%),
    radial-gradient(circle at 50% 50%, rgba(237, 28, 36, 0.08) 0%, transparent 70%);
}

/* ===== Card centrale ===== */
.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border-radius: 20px;
  padding: 28px 32px 24px;
  box-shadow: var(--shadow-lg);
  position: relative;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  border-top: 4px solid var(--as-red);
}

/* ===== Header card ===== */
.login-header {
  text-align: center;
  margin-bottom: 24px;
}
.logo-img {
  max-width: 220px;
  width: 70%;
  height: auto;
  margin: 0 auto 6px;
  display: block;
}
.subtitle {
  font-size: 14px;
  color: var(--text-2);
  margin-top: 0;
  font-weight: 500;
  letter-spacing: 0.3px;
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 24px;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s;
}
.tab:hover:not(.active) {
  color: var(--text);
}
.tab.active {
  background: var(--surface);
  color: var(--as-blue);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ===== Panel switching ===== */
.panel { display: none; }
.panel.active { display: block; }

/* ===== Form fields (Admin) ===== */
.field {
  display: block;
  margin-bottom: 16px;
}
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus {
  outline: none;
  border-color: var(--as-blue);
  box-shadow: 0 0 0 3px rgba(0, 63, 128, 0.15);
}

.input-with-toggle {
  position: relative;
}
.input-with-toggle input {
  padding-right: 44px;
}
.toggle-pwd {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--text-3);
  display: flex;
  border-radius: 6px;
}
.toggle-pwd:hover { color: var(--as-blue); background: var(--bg); }

/* ===== Bottone primario ===== */
.btn-primary {
  width: 100%;
  padding: 14px;
  margin-top: 8px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--as-blue) 0%, var(--as-blue-dark) 100%);
  color: #fff;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform 0.05s, box-shadow 0.15s, opacity 0.15s;
  box-shadow: 0 4px 12px rgba(0, 63, 128, 0.35);
}
.btn-primary:hover:not(:disabled) {
  box-shadow: 0 6px 18px rgba(0, 63, 128, 0.45);
}
.btn-primary:active:not(:disabled) {
  transform: translateY(1px);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}
.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Pannello tecnico ===== */
.pin-instruction {
  text-align: center;
  font-size: 15px;
  color: var(--text-2);
  margin-bottom: 16px;
}

.pin-display {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
  height: 24px;
  align-items: center;
}
.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  transition: all 0.15s;
}
.pin-dot.filled {
  background: var(--as-blue);
  border-color: var(--as-blue);
  transform: scale(1.1);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.key {
  height: 60px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-family: inherit;
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.08s;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.key:hover {
  background: var(--bg);
  border-color: var(--as-blue);
}
.key:active {
  background: var(--as-blue);
  color: #fff;
  transform: scale(0.96);
}
.key-action {
  background: var(--bg);
  color: var(--text-2);
  font-size: 18px;
}

/* ===== Error box ===== */
.error-box {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--red-bg);
  border: 1px solid #fecaca;
  color: var(--as-red-dark);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
}

/* ===== Footer ===== */
.login-footer {
  margin-top: 20px;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
}

/* ===================================================================
   RESPONSIVE — iPad orizzontale (tecnici sul campo)
   =================================================================== */
@media (min-width: 768px) and (max-width: 1366px) and (orientation: landscape) {
  .login-card { max-width: 480px; }
  .key { height: 64px; font-size: 26px; }
}

/* iPad verticale / tablet piccoli */
@media (max-width: 767px) {
  .login-card {
    padding: 24px 20px 20px;
    border-radius: 16px;
  }
  .key { height: 56px; font-size: 22px; }
  .logo-img { max-width: 180px; }
}

/* Schermo molto piccolo / orizzontale corto */
@media (max-height: 700px) {
  .login-card { padding: 20px 24px; }
  .login-header { margin-bottom: 14px; }
  .logo-img { max-width: 170px; margin-bottom: 2px; }
  .subtitle { font-size: 13px; }
  .key { height: 50px; font-size: 20px; }
  .tabs { margin-bottom: 16px; }
}
