:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --surface: #1a1d24;
  --surface-2: #23262f;
  --surface-3: #2c303a;
  --border: #2c303a;
  --text: #f2f3f5;
  --text-muted: #9a9ea8;
  --accent: #3b82f6;
  --accent-strong: #5b9bff;
  --danger: #ef4444;
  --success: #22c55e;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --nav-height: 76px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent-strong);
}

button {
  font-family: inherit;
}

/* Centered auth pages (login) */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
}

.auth-card h1 {
  margin: 0 0 1.5rem;
  font-size: 1.5rem;
  text-align: center;
}

.language-select {
  display: block;
  margin: 0 0 1rem auto;
  width: auto;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
}

form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

input,
select {
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
}

.phone-field {
  display: flex;
  gap: 0.5rem;
}

.phone-field select {
  flex: none;
  width: 6.5rem;
}

.phone-field input {
  flex: 1;
  min-width: 0;
}

input:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button.primary {
  padding: 0.8rem 1rem;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}

button.primary:active {
  background: var(--accent-strong);
}

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

button.secondary {
  width: 100%;
  padding: 0.8rem 1rem;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--text);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}

button.secondary:active {
  background: var(--border);
}

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

.error {
  color: var(--danger);
  font-size: 0.875rem;
  margin: 0;
}

/* App shell (dashboard / profile / admin) */
.app-page {
  min-height: 100vh;
  padding: 1.5rem 1.25rem calc(var(--nav-height) + 1.5rem);
  max-width: 480px;
  margin: 0 auto;
}

.greeting {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0.5rem 0 1.5rem;
}

.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 1.5rem 0 0.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

#users-row {
  margin-top: 1rem;
}

.banner {
  background: linear-gradient(135deg, #1e3a8a33, #1a1d24);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Feature tile (dashboard action, e.g. "Öppna grinden") */
.tile {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  padding: 1.1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.tile:active {
  background: var(--surface-2);
}

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

.tile-icon {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile-icon svg {
  width: 24px;
  height: 24px;
  stroke: white;
}

.tile-text {
  flex: 1;
  min-width: 0;
}

.tile-subtitle {
  display: block;
  font-weight: 400;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.app-page-top {
  padding-top: 3rem;
}

.gate-hero[hidden] {
  display: none;
}

.gate-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 3rem 1.5rem;
  text-align: center;
}

.barrier-stage {
  width: 220px;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.barrier-icon {
  width: 100%;
  height: 100%;
  color: white;
}

.gate-button {
  width: 100%;
}

#gate-message {
  color: var(--text-muted);
  font-size: 0.9rem;
  min-height: 1.2em;
  margin: 0;
}

.empty-state {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 1.5rem;
  text-align: center;
}

/* List rows (profile, admin) */
.list-item[hidden] {
  display: none;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.list-item:last-child {
  border-bottom: none;
}

.list-item-icon {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.list-item-icon svg {
  stroke: currentColor;
  color: var(--text-muted);
}

.list-item-body {
  flex: 1;
  min-width: 0;
}

.list-item-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.list-item-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

button.list-action {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.5rem;
}

.avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  flex: none;
}

.avatar-sm {
  width: 40px;
  height: 40px;
  font-size: 1.05rem;
}

.list-item-link {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.list-item-link:active {
  background: var(--surface-2);
}

.chevron {
  flex: none;
  color: var(--text-muted);
  stroke: currentColor;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

.bottom-nav-inner {
  display: flex;
  gap: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 0.4rem;
  width: 100%;
  max-width: 400px;
}

.nav-item[hidden] {
  display: none;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.5rem 0.25rem;
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 600;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
}

.nav-item.active {
  color: white;
  background: var(--accent);
}

/* Sub-page header (back button + title, no bottom nav) */
.subpage-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.subpage-header h1 {
  margin: 0;
  font-size: 1.3rem;
  flex: 1;
}

.subpage-header .add-button {
  margin-left: auto;
}

.back-button {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

.back-button svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
}

.password-field {
  position: relative;
}

.password-field input {
  width: 100%;
  padding-right: 2.75rem;
}

.password-toggle {
  position: absolute;
  right: 0.4rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.4rem;
  display: flex;
}

.password-toggle svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
}

.password-toggle .eye-icon {
  display: none;
}

#account-success {
  color: var(--success);
  font-size: 0.9rem;
  margin: 0;
}

/* Confirm modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 100;
}

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

.modal {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.modal p {
  margin: 0 0 1.25rem;
  font-size: 0.95rem;
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
}

.modal-btn {
  flex: 1;
  padding: 0.7rem;
  border: none;
  border-radius: var(--radius-pill);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.modal-btn.primary {
  background: var(--accent);
  color: white;
}

.modal-btn.secondary {
  background: var(--surface-3);
  color: var(--text);
}

/* Admin: table -> card list of users */
.user-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
}

.user-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.75rem;
}

.user-card-header .phone {
  font-weight: 600;
}

.user-card-header .name {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.6rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.checkbox-row input {
  width: auto;
}
