@import url("styles.css");

body.auth-locked .portal-shell {
  display: none;
}

body:not(.auth-locked) .login-gate {
  display: none;
}

/* Portale — schermata login */
.portal-login-gate {
  background: linear-gradient(135deg, #f0f4f8 0%, #c3cfe2 50%, #e8eef5 100%);
}

.portal-login-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: min(100%, 440px);
}

.portal-login-card {
  width: 100%;
  padding: 36px 34px 28px;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.14);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.portal-login-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 24px 72px rgba(15, 23, 42, 0.16);
}

.portal-login-header {
  text-align: center;
  margin-bottom: 24px;
}

.portal-login-logo {
  display: block;
  max-height: 44px;
  width: auto;
  margin: 0 auto 16px;
}

.portal-login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 1.65rem;
  font-weight: 700;
  color: #2d3748;
  margin-bottom: 6px;
}

.portal-login-brand-icon {
  font-size: 1.75rem;
}

.portal-login-highlight {
  color: #2563eb;
}

.portal-login-subtitle {
  margin: 0;
  color: #718096;
  font-size: 0.92rem;
}

.portal-login-alert {
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
  margin-bottom: 16px;
  line-height: 1.45;
}

.portal-login-alert--error {
  background: #fff5f5;
  border: 1px solid #feb2b2;
  color: #c53030;
}

.portal-login-alert--success {
  background: #f0fff4;
  border: 1px solid #9ae6b4;
  color: #276749;
}

.portal-login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.portal-form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.portal-form-group label {
  font-size: 0.88rem;
  font-weight: 600;
  color: #2d3748;
}

.portal-form-group input {
  padding: 12px 14px;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.95rem;
  background: #f7fafc;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.portal-form-group input:focus {
  outline: none;
  border-color: #2563eb;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.portal-form-group input::placeholder {
  color: #a0aec0;
}

.portal-password-wrapper {
  position: relative;
}

.portal-password-wrapper input {
  width: 100%;
  padding-right: 44px;
}

.portal-password-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.portal-form-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
  flex-wrap: wrap;
}

.portal-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #4a5568;
  cursor: pointer;
  user-select: none;
}

.portal-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #2563eb;
  cursor: pointer;
}

.portal-forgot-link {
  background: none;
  border: none;
  padding: 0;
  color: #2563eb;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}

.portal-forgot-link:hover {
  text-decoration: underline;
  color: #1a56db;
}

.portal-btn-login {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 16px;
  margin-top: 4px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
}

.portal-btn-login:hover:not(:disabled) {
  background: #1a56db;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.portal-btn-login:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.portal-btn-login-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: portal-login-spin 0.75s linear infinite;
}

@keyframes portal-login-spin {
  to { transform: rotate(360deg); }
}

.portal-login-card-footer {
  text-align: center;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid #e2e8f0;
}

.portal-login-card-footer p {
  margin: 0 0 6px;
  font-size: 0.88rem;
  color: #4a5568;
}

.portal-contact-link {
  color: #2563eb;
  font-weight: 600;
  text-decoration: none;
}

.portal-contact-link:hover {
  text-decoration: underline;
}

.portal-login-help {
  font-size: 0.82rem !important;
  color: #a0aec0 !important;
  margin-top: 8px !important;
}

.portal-login-dashboard-link {
  margin-top: 10px !important;
  font-size: 0.82rem !important;
}

.portal-login-dashboard-link a {
  color: #718096;
  text-decoration: none;
}

.portal-login-dashboard-link a:hover {
  color: #2563eb;
  text-decoration: underline;
}

.portal-login-page-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 12px;
  font-size: 0.82rem;
  color: #718096;
}

.portal-login-footer-divider {
  color: #cbd5e0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 480px) {
  .portal-login-card {
    padding: 28px 20px 22px;
  }

  .portal-login-brand {
    font-size: 1.4rem;
  }

  .portal-form-options {
    flex-direction: column;
    align-items: flex-start;
  }
}

.portal-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.portal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 40;
}

.portal-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.portal-sidebar-toggle {
  display: none;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 0.35rem 0.55rem;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}

.portal-header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.portal-header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.portal-user-menu {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
}

.portal-user-name {
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
}

.portal-link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
}

.portal-link-button:hover {
  color: var(--text);
}

.portal-layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.portal-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 45;
}

.portal-sidebar {
  width: 240px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--panel);
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.portal-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.portal-nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.portal-nav-item:hover {
  background: var(--accent-soft);
}

.portal-nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.portal-nav-icon {
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

.portal-nav-badge {
  margin-left: auto;
  min-width: 1.25rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
}

.portal-nav-badge.warn {
  background: #fef3c7;
  color: #b45309;
}

.portal-token-preview {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.9rem;
  word-break: break-all;
  padding: 0.75rem;
  border-radius: 8px;
  background: var(--bg, #f1f5f9);
  border: 1px solid var(--border);
}

.portal-token-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.portal-sidebar-foot {
  margin: auto 0 0;
  padding: 0.75rem;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
}

.portal-content {
  flex: 1;
  min-width: 0;
  padding: 1.25rem 1.5rem 2rem;
  overflow: auto;
}

.portal-section {
  display: none;
  animation: portalFadeIn 0.2s ease;
}

.portal-section.active {
  display: block;
}

@keyframes portalFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.portal-section-head {
  margin-bottom: 1rem;
}

.portal-section-head h1 {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
}

.portal-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.portal-kpi {
  padding: 1rem 1.1rem;
  background: #2563eb;
  border: 1px solid #1d4ed8;
  color: #fff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.25);
}

button.portal-kpi-link {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

button.portal-kpi-link:hover,
button.portal-kpi-link:focus-visible {
  background: #1d4ed8;
  border-color: #1e40af;
  box-shadow: 0 6px 18px rgba(29, 78, 216, 0.35);
  outline: none;
  transform: translateY(-1px);
}

.portal-kpi h3 {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.88);
}

.portal-kpi-value {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
}

.portal-kpi-meta {
  margin: 0.35rem 0 0;
  font-size: 0.88rem;
  color: rgba(255, 255, 255, 0.9);
}

.portal-alerts {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.portal-alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fffbeb;
  color: #92400e;
  font-size: 0.92rem;
}

.portal-alert.error {
  background: #fef2f2;
  color: #b91c1c;
}

.portal-alert button {
  margin-left: 0.5rem;
}

.portal-panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

.portal-dl {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem 1.5rem;
  margin: 0;
}

.portal-dl > div {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.portal-dl dt {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.portal-dl dd {
  margin: 0;
  font-weight: 600;
}

.status-pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.status-pill.online { background: #dcfce7; color: #166534; }
.status-pill.offline { background: #fee2e2; color: #b91c1c; }
.status-pill.pending { background: #fef3c7; color: #b45309; }

.portal-dialog {
  border: none;
  padding: 0;
  background: transparent;
  max-width: min(420px, 92vw);
}

.portal-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.portal-dialog-card {
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.portal-dialog-card h2 {
  margin: 0;
  font-size: 1.1rem;
}

.portal-dialog-card label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.portal-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.login-forgot-wrap {
  margin-top: 0.5rem;
  text-align: center;
}

@media (max-width: 900px) {
  .portal-sidebar-toggle {
    display: inline-block;
  }

  .portal-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 8px 30px rgba(15, 23, 42, 0.15);
  }

  body.portal-sidebar-open .portal-sidebar {
    transform: translateX(0);
  }

  body.portal-sidebar-open .portal-sidebar-backdrop {
    display: block;
  }

  .portal-content {
    padding: 1rem;
  }
}
