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

:root {
  --bg: #0a0a0f;
  --header-bg: #0a0a0f;
  --glass: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.09);
  --text: #f0f0f5;
  --text-muted: #7a7a8c;
  --accent: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.3);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "Outfit", -apple-system, sans-serif;
  --mono: "JetBrains Mono", monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  color-scheme: dark;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior: none;
}

/* Ekrany bez nagłówka — jednolite tło pod paskiem statusu */
#screen-login.active,
#screen-denied.active,
#screen-loading.active {
  background: linear-gradient(
    to bottom,
    var(--header-bg) 0,
    var(--header-bg) var(--safe-top),
    var(--bg) var(--safe-top),
    var(--bg) 100%
  );
}

.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.45;
}

.orb-1 {
  width: 500px;
  height: 500px;
  background: #6366f1;
  top: -180px;
  left: -80px;
}

.orb-2 {
  width: 400px;
  height: 400px;
  background: #8b5cf6;
  bottom: -120px;
  right: -60px;
}

.noise {
  position: absolute;
  inset: 0;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.screen {
  display: none;
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.loader-ring {
  width: 36px;
  height: 36px;
  border: 2px solid var(--glass-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Auth */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 1.5rem calc(1.25rem + var(--safe-right)) calc(1.5rem + var(--safe-bottom)) calc(1.25rem + var(--safe-left));
  padding-top: calc(1.5rem + var(--safe-top));
}

.auth-card {
  width: 100%;
  max-width: 380px;
  padding: 2.25rem;
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
}

.auth-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border-radius: 14px;
  color: white;
  margin-bottom: 0.875rem;
}

.logo-mark.small {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  margin-bottom: 0;
}

.auth-header h1,
.page-title h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.auth-form label span {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.auth-form input {
  padding: 0.7rem 0.9rem;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  transition: border-color 0.2s;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.1rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: white;
  margin-top: 0.25rem;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--accent-glow);
}

.btn-secondary {
  background: var(--glass);
  color: var(--text);
  border: 1px solid var(--glass-border);
  width: 100%;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 0.45rem;
  border-radius: 8px;
}

.btn-ghost:hover {
  background: var(--glass);
  color: var(--text);
}

.btn.loading {
  position: relative;
  color: transparent;
}

.btn.loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.denied-card {
  text-align: center;
}

.denied-card h1 {
  font-size: 1.35rem;
  margin-bottom: 0.5rem;
}

.denied-card p {
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

/* Page header — łączy się z paskiem statusu iOS */
.page-header {
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
  flex-shrink: 0;
  background: var(--header-bg);
  border-bottom: 1px solid var(--glass-border);
  padding-top: var(--safe-top);
}

.page-header-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 0.8rem calc(1.25rem + var(--safe-right)) 0.8rem calc(1.25rem + var(--safe-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 52px;
}

.page-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.user-email {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Main */
.main {
  flex: 1;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem calc(1.25rem + var(--safe-right)) calc(2rem + var(--safe-bottom)) calc(1.25rem + var(--safe-left));
}

.services-grid {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.category-section {
  animation: fadeUp 0.4s ease both;
}

.category-title {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
  padding-left: 0.15rem;
}

.services-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.service-card {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1rem;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  animation: fadeUp 0.35s ease both;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 64px;
}

.service-card:hover {
  border-color: color-mix(in srgb, var(--brand, var(--accent)) 50%, transparent);
  transform: translateY(-1px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
}

.service-card:hover .service-arrow {
  color: var(--brand, var(--accent));
  transform: translateX(3px);
}

.service-logo {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  background: color-mix(in srgb, var(--brand, var(--accent)) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--brand, var(--accent)) 22%, transparent);
}

.service-logo img {
  display: block;
  object-fit: contain;
  filter: brightness(0) saturate(100%) invert(1);
  opacity: 0.92;
}

.service-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.service-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.service-category {
  display: none;
}

.service-host {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.service-arrow {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: all 0.2s;
}

.services-skeleton {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.skeleton-card {
  height: 68px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--glass) 25%, rgba(255,255,255,0.08) 50%, var(--glass) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.empty-state,
.error-state {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
}

.error-state {
  color: #f87171;
}

.toast {
  position: fixed;
  bottom: calc(1.5rem + var(--safe-bottom));
  left: calc(50% + (var(--safe-left) - var(--safe-right)) / 2);
  transform: translateX(-50%) translateY(80px);
  padding: 0.75rem 1.25rem;
  background: rgba(25, 25, 35, 0.95);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  z-index: 100;
  opacity: 0;
  transition: all 0.3s;
  max-width: calc(100vw - 2rem - var(--safe-left) - var(--safe-right));
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (min-width: 768px) {
  .page-header-inner,
  .main {
    max-width: 1100px;
  }

  .main {
    padding-top: 2rem;
    padding-bottom: 2rem;
  }

  .category-title {
    display: none;
  }

  .category-section,
  .services-list {
    display: contents;
  }

  .services-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.875rem;
  }

  .service-category {
    display: block;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
  }

  .service-card {
    position: relative;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.875rem;
    padding: 1.125rem;
    min-height: 140px;
  }

  .service-card .service-arrow {
    position: absolute;
    top: 1rem;
    right: 1rem;
  }

  .services-skeleton {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.875rem;
  }

  .skeleton-card {
    height: 140px;
  }
}

@media (min-width: 1100px) {
  .page-header-inner,
  .main {
    max-width: 1280px;
  }

  .services-grid,
  .services-skeleton {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .service-card:hover {
    transform: translateY(-2px);
  }
}

@media (max-width: 600px) {
  .user-email {
    display: none;
  }
}

@media (display-mode: standalone) {
  .page-header-inner {
    padding-top: 0.7rem;
    padding-bottom: 0.7rem;
  }

  .page-title h1 {
    font-size: 1.5rem;
  }
}
