/* ============================================================================
 * BASE.CSS — ROB BRAIN 360° MOBILE CANONS
 * - SafeArea Top (Dynamic Island/Notch) & Bottom (Home Bar / 3 Tasti Android)
 * - ZERO text-overflow: ellipsis (...) e ZERO box overflow (320px -> 440px+)
 * - color-scheme: dark (disattiva Xiaomi MIUI Force Dark Mode)
 * - Input min 16px (zero auto-zoom iOS Safari)
 * ============================================================================ */

:root {
  color-scheme: dark;
  --bg-deep: #090D14;
  --bg-surface: #121926;
  --bg-elevated: #1A2436;
  --border-subtle: rgba(255, 255, 255, 0.10);
  --border-accent: rgba(229, 169, 60, 0.45);
  --text-main: #F8FAFC;
  --text-muted: #CBD5E1;
  --text-subtle: #94A3B8;
  --accent-gold: #E5A93C;
  --accent-gold-light: #F6D07A;
  --accent-green: #10B981;
  --accent-red: #EF4444;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --vvh: 100dvh;
  --kb-offset: 0px;
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100dvh;
  min-height: -webkit-fill-available;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: absolute;
  top: -120px;
  left: 12px;
  z-index: 9999;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--accent-gold);
  color: #080D14;
  font-weight: 700;
  text-decoration: none;
}
.skip-link:focus-visible {
  top: max(12px, var(--safe-top));
}

:focus-visible {
  outline: 2px solid var(--accent-gold-light);
  outline-offset: 2px;
}

.app-shell {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-deep);
}

/* ---- LOGIN SCREEN ---- */
.login-screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: calc(max(16px, var(--safe-top)) + 8px) 16px calc(max(20px, var(--safe-bottom)) + var(--kb-offset, 0px) + 12px);
}

.login-card {
  width: 100%;
  max-width: 420px;
  margin: auto 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.login-brand {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.login-logo {
  width: 68px;
  height: 68px;
  object-fit: contain;
}

.login-title {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.25;
  color: var(--text-main);
}

.login-sub {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--text-muted);
}

/* ---- FORM & BUTTONS (Min 16px input -> zero auto-zoom iOS) ---- */
.stack-sm { display: flex; flex-direction: column; gap: 10px; }
.stack-md { display: flex; flex-direction: column; gap: 14px; }

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: normal;
  overflow-wrap: anywhere;
}

.field-input,
.field-select,
.field-textarea {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-main);
  font-family: inherit;
  font-size: 16px; /* Obbligatorio >= 16px per bloccare auto-zoom iOS Safari */
  line-height: 1.35;
}

.field-textarea {
  min-height: 84px;
  resize: vertical;
}

.otp-input {
  text-align: center;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.3em;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  height: auto;
  padding: 11px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.94rem;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: transform 0.14s ease, opacity 0.14s ease;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.52; cursor: not-allowed; }
.btn-block { width: 100%; }

.btn-primary {
  background: var(--accent-gold);
  color: #080D14;
}

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border-subtle);
  color: var(--text-main);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.45);
  color: #FCA5A5;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.helper-text {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.inline-alert {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.86rem;
  line-height: 1.4;
  white-space: normal;
  overflow-wrap: anywhere;
}

.inline-alert.is-error {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #FCA5A5;
}

.inline-alert.is-info {
  background: rgba(229, 169, 60, 0.14);
  border: 1px solid var(--border-accent);
  color: var(--accent-gold-light);
}

.toast-bar {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: calc(max(12px, var(--safe-bottom)) + var(--kb-offset, 0px) + 74px);
  z-index: 6000;
  margin: 0 auto;
  max-width: 440px;
  padding: 12px 16px;
  border-radius: 14px;
  background: #172133;
  border: 1px solid var(--border-accent);
  color: var(--text-main);
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55);
}

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover:not(:disabled) { opacity: 0.92; }
  .btn-secondary:hover:not(:disabled) { border-color: var(--border-accent); }
}
