:root {
  --green: #1f7a4c;
  --green-dark: #155a38;
  --green-light: #e6f2ea;
  --green-soft: #d4e9dc;
  --bg: #f4f7f5;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #5f6b76;
  --border: #dbe5df;
  --shadow: 0 18px 50px rgba(21, 90, 56, 0.12);
  --radius: 16px;
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
}

@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

a {
  color: inherit;
  text-decoration: none;
}

.page-login {
  background:
    radial-gradient(circle at top right, rgba(31, 122, 76, 0.18), transparent 42%),
    linear-gradient(160deg, #eef6f1 0%, #f8faf9 45%, #edf3ef 100%);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login-card {
  width: min(100%, 26rem);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: 2.25rem 2rem 1.75rem;
}

.brand-mark {
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  margin-bottom: 1.25rem;
}

.brand-mark.sm {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 10px;
  font-size: 0.85rem;
  margin-bottom: 0;
}

.login-card h1,
.hero h1 {
  margin: 0;
  font-size: 1.75rem;
  color: var(--green-dark);
}

.lead {
  margin: 0.5rem 0 1.75rem;
  color: var(--muted);
  line-height: 1.5;
}

.login-form {
  display: grid;
  gap: 0.65rem;
}

.login-form label {
  font-size: 0.9rem;
  font-weight: 600;
  color: #334155;
}

.login-form input[type="text"],
.login-form input[type="password"] {
  width: 100%;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.login-form input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 122, 76, 0.15);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0.35rem 0 0.75rem;
  font-size: 0.92rem;
  color: var(--muted);
  font-weight: 500;
}

.checkbox-row input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--green);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  padding: 0.78rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  width: 100%;
  color: #fff;
  background: linear-gradient(135deg, var(--green), var(--green-dark));
}

.btn-primary.btn-auto {
  width: auto;
}

.btn-primary:hover {
  filter: brightness(1.03);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 0.55rem 0.9rem;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.18);
}

.alert {
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.92rem;
}

.alert-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-success {
  background: #ecfdf3;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.footnote {
  margin: 1.25rem 0 0;
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
}

.pwa-hint {
  margin-top: 0.5rem;
  font-size: 0.78rem;
}

.page-portal {
  background: linear-gradient(180deg, #f7faf8 0%, #f1f5f2 100%);
}

.topbar {
  background: linear-gradient(135deg, var(--green-dark), var(--green));
  color: #fff;
  box-shadow: 0 8px 24px rgba(21, 90, 56, 0.18);
  padding-top: env(safe-area-inset-top, 0);
}

.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

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

.brand-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: inherit;
}

.brand-name {
  font-size: 1.15rem;
  font-weight: 700;
}

.userbar {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.user-greeting {
  font-size: 0.95rem;
  opacity: 0.95;
}

.portal-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.hero {
  margin-bottom: 1.5rem;
}

.hero p {
  margin: 0.45rem 0 0;
  color: var(--muted);
  max-width: 38rem;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.app-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.2rem 1.1rem;
  min-height: 190px;
  display: flex;
  flex-direction: column;
  position: relative;
}

.app-card-active {
  box-shadow: 0 10px 28px rgba(31, 122, 76, 0.08);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.app-card-active:hover {
  transform: translateY(-2px);
  border-color: #b9dcc8;
  box-shadow: 0 16px 34px rgba(31, 122, 76, 0.14);
}

.app-card-soon {
  opacity: 0.72;
  background: #fafcfb;
}

.app-icon {
  font-size: 1.75rem;
  line-height: 1;
  margin-bottom: 0.75rem;
}

.app-card h2 {
  margin: 0 0 0.45rem;
  font-size: 1.15rem;
  color: var(--green-dark);
}

.app-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  flex: 1;
}

.app-cta {
  margin-top: 1rem;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--green);
}

.badge {
  margin-top: 1rem;
  align-self: flex-start;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #64748b;
  background: #eef2f7;
  border-radius: 999px;
  padding: 0.28rem 0.65rem;
}

.portal-footer {
  text-align: center;
  padding: 0 1rem calc(2rem + env(safe-area-inset-bottom, 0px));
  color: var(--muted);
  font-size: 0.82rem;
}

.pwa-install-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9998;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
  background: #fff;
  border-top: 1px solid var(--border);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.08);
}

.pwa-install-banner[hidden] {
  display: none;
}

.pwa-install-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.pwa-install-inner p {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text);
}

.pwa-install-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-ghost-dark {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.55rem 0.9rem;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

@media (display-mode: standalone) {
  .pwa-install-banner {
    display: none !important;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.page-admin .admin-main {
  max-width: 1100px;
}

.admin-hero-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.25rem;
}

.admin-stats {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  min-width: 5.5rem;
  text-align: center;
  box-shadow: 0 4px 16px rgba(21, 90, 56, 0.06);
}

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--green-dark);
  line-height: 1.2;
}

.stat-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 0.15rem;
}

.admin-roles-info {
  margin-bottom: 1.25rem;
}

.roles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}

.role-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.role-card p {
  margin: 0.5rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.45;
}

.role-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}

.role-pill-admin {
  background: #e8f0ff;
  color: #1e40af;
}

.role-pill-voksen {
  background: var(--green-light);
  color: var(--green-dark);
}

.role-pill-barn {
  background: #fff4e6;
  color: #9a5b13;
}

.role-pill-member,
.role-pill-viewer {
  background: var(--green-light);
  color: var(--green-dark);
}

.tilgang-list {
  display: grid;
  gap: 1rem;
}

.tilgang-card .app-access-form {
  margin-top: 0.5rem;
}

.app-checkboxes {
  border: none;
  margin: 0 0 1rem;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.app-check {
  font-weight: 500;
}

.barn-apps-field {
  margin: 0.25rem 0 0.5rem;
  padding: 0.85rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
  display: grid;
  gap: 0.35rem;
}

.barn-apps-field .field-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: #334155;
}

.app-access-block {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.app-access-title {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

.app-access-lead {
  margin: 0 0 0.85rem;
  font-size: 0.85rem;
}

.app-access-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid #eef2ef;
}

.app-access-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.app-access-user {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  min-width: 8rem;
  flex: 0 0 9.5rem;
}

.app-access-user strong {
  font-size: 0.92rem;
}

.app-access-user .muted {
  font-size: 0.8rem;
}

.app-access-row .app-toggle-grid {
  flex: 1 1 12rem;
}

.app-toggle-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.app-toggle {
  cursor: pointer;
  margin: 0;
}

.app-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.app-toggle-label {
  display: inline-block;
  padding: 0.38rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  background: #fff;
  color: var(--text);
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  user-select: none;
}

.app-toggle input:focus-visible + .app-toggle-label {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.app-toggle input:checked + .app-toggle-label {
  background: var(--green-light);
  border-color: var(--green);
  color: var(--green-dark);
  font-weight: 600;
}

.field-hint {
  margin: 0.35rem 0 0.75rem;
  padding: 0.65rem 0.75rem;
  font-size: 0.85rem;
  color: var(--green-dark);
  background: var(--green-light);
  border-radius: 8px;
  border: 1px solid var(--green-soft);
}

@media (max-width: 640px) {
  .app-access-row {
    flex-direction: column;
    align-items: stretch;
  }

  .app-access-user {
    flex: none;
  }

  .app-access-row .btn {
    align-self: flex-start;
  }
}

.admin-layout {
  display: grid;
  grid-template-columns: 1fr min(22rem, 100%);
  gap: 1rem;
  align-items: start;
}

@media (max-width: 900px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }
}

.panel-head h2 {
  margin: 0;
}

.panel-head .muted {
  margin: 0.35rem 0 0;
  font-size: 0.88rem;
}

.user-cell-name {
  display: block;
  font-weight: 600;
}

.user-cell-meta {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
}

.row-inactive {
  opacity: 0.65;
}

.status-badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
}

.status-active {
  background: var(--green-light);
  color: var(--green-dark);
}

.status-inactive {
  background: #fee2e2;
  color: #991b1b;
}

.cell-date {
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.88rem;
}

.cell-actions {
  text-align: right;
  white-space: nowrap;
}

.user-action-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
}

.btn-danger {
  background: #991b1b;
  color: #fff;
  border: 1px solid #7f1d1d;
}

.btn-danger:hover {
  background: #7f1d1d;
}

.inline-form {
  display: inline;
  margin: 0;
}

.role-select {
  font: inherit;
  font-size: 0.88rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  max-width: 11rem;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
}

.page-admin .user-action-group .btn-ghost-dark {
  background: #fff;
  color: var(--green-dark);
  border-color: var(--green-soft);
}

.page-admin .user-action-group .btn-ghost-dark:hover {
  background: var(--green-light);
  border-color: var(--green);
}

.text-sm {
  font-size: 0.82rem;
}

.admin-form select {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  background: #fff;
}

.admin-denied {
  display: grid;
  place-items: center;
  min-height: 40vh;
  padding: 2rem 0;
}

.admin-denied-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.75rem;
  max-width: 26rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.admin-denied-card h1 {
  margin: 0 0 0.75rem;
  color: var(--green-dark);
}

.admin-denied-card p {
  margin: 0 0 0.75rem;
  line-height: 1.5;
}

.admin-denied-card .btn-primary {
  margin-top: 1rem;
  display: inline-block;
}

.breadcrumb {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
}

.breadcrumb a {
  color: var(--green);
  font-weight: 600;
}

.admin-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.2rem 1.35rem;
  margin-bottom: 1rem;
}

.admin-panel h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  color: var(--green-dark);
}

.muted {
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  background: #f8fbf9;
}

.admin-form {
  display: grid;
  gap: 0.65rem;
  max-width: 28rem;
}

.admin-form label {
  font-size: 0.9rem;
  font-weight: 600;
  color: #334155;
}

.admin-form input {
  width: 100%;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
}

.admin-form input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 122, 76, 0.15);
}

.admin-form .btn-primary {
  width: auto;
  margin-top: 0.35rem;
}

.app-launch-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.34);
  backdrop-filter: blur(3px);
  padding: 1rem;
}

.app-launch-overlay[hidden] {
  display: none;
}

.app-launch-card {
  width: min(100%, 22rem);
  background: #fff;
  border-radius: 16px;
  padding: 1.5rem 1.35rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.app-launch-spinner {
  width: 2.4rem;
  height: 2.4rem;
  margin: 0 auto 1rem;
  border: 3px solid var(--green-soft);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: fp-spin 0.8s linear infinite;
}

.app-launch-title {
  margin: 0;
  font-weight: 700;
  color: var(--green-dark);
}

.app-launch-sub {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

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

@media (max-width: 640px) {
  .topbar-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .userbar {
    width: 100%;
    justify-content: space-between;
  }

  .login-card {
    padding: 1.75rem 1.25rem 1.5rem;
  }
}
