:root {
  --bg: #0f1419;
  --bg-elevated: #1a222c;
  --bg-tile: #243040;
  --text: #eef2f6;
  --text-muted: #9aa8b8;
  --accent: #2d9f78;
  --accent-hover: #38b88c;
  --danger: #e85d5d;
  --border: #2e3a4a;
  --radius: 16px;
  --radius-sm: 10px;
  --touch: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.noscript {
  padding: 1.5rem;
  text-align: center;
}

/* Auth */
.app--auth {
  justify-content: center;
  padding: 1rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.auth-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  font-weight: 700;
}

.auth-card .subtitle {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.field {
  margin-bottom: 1rem;
}

.field label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.field input,
.field select {
  width: 100%;
  min-height: var(--touch);
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0.65rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn--primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
}

.btn--primary:active {
  background: var(--accent-hover);
}

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

.btn--danger {
  background: var(--danger);
  color: #fff;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert--error {
  background: rgba(232, 93, 93, 0.15);
  border: 1px solid var(--danger);
  color: #ffb4b4;
}

.alert--info {
  background: rgba(45, 159, 120, 0.15);
  border: 1px solid var(--accent);
}

/* Shell header */
.shell-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.shell-header h1 {
  margin: 0;
  font-size: 1.15rem;
  flex: 1;
  min-width: 0;
}

.lang-switch {
  display: flex;
  gap: 0.35rem;
}

.lang-switch button {
  min-height: 36px;
  min-width: 36px;
  padding: 0 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
}

.lang-switch button.is-active {
  border-color: var(--accent);
  color: var(--accent);
}

/* Tile grid */
.shell-main {
  flex: 1;
  padding: 1rem;
  padding-bottom: calc(4.5rem + var(--safe-bottom));
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.85rem;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 120px;
  padding: 1rem;
  background: var(--bg-tile);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  transition: transform 0.1s, border-color 0.15s;
}

.tile:active {
  transform: scale(0.97);
  border-color: var(--accent);
}

.tile__icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.tile__icon img {
  width: 32px;
  height: 32px;
}

.tile__title {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.2;
}

.tile--add {
  border-style: dashed;
  opacity: 0.5;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  padding: 0.5rem 0.5rem calc(0.5rem + var(--safe-bottom));
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  z-index: 20;
}

.bottom-nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  min-height: var(--touch);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.7rem;
  cursor: pointer;
}

.bottom-nav button.is-active {
  color: var(--accent);
}

.bottom-nav .nav-icon {
  font-size: 1.25rem;
}

/* Module view */
.module-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.module-view__bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.module-view__bar button {
  min-width: var(--touch);
  min-height: var(--touch);
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
}

.module-view__content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  -webkit-overflow-scrolling: touch;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.kv-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.kv-list li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

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

.kv-list .muted {
  color: var(--text-muted);
}

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

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

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

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

.data-table--users td {
  vertical-align: middle;
}

.data-table--users .btn-edit-user:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Dialog */
.utilix-dialog {
  border: none;
  padding: 0;
  margin: auto;
  max-width: calc(100vw - 2rem);
  width: 100%;
  max-height: calc(100dvh - 2rem);
  background: transparent;
}

.utilix-dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.utilix-dialog__panel {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  max-height: calc(100dvh - 2rem);
  overflow: hidden;
}

.utilix-dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.utilix-dialog__header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.utilix-dialog__close {
  min-width: var(--touch);
  min-height: var(--touch);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.utilix-dialog__subtitle {
  margin: 0;
  padding: 0.75rem 1rem 0;
  font-size: 0.85rem;
}

.utilix-dialog__panel .field {
  padding: 0 1rem;
  margin-bottom: 0.75rem;
}

.utilix-dialog__panel .field:first-of-type {
  margin-top: 0.75rem;
}

.utilix-dialog__panel .alert {
  margin: 0.75rem 1rem 0;
}

.field--checkbox {
  padding-bottom: 0.25rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: var(--touch);
  cursor: pointer;
}

.checkbox-label input {
  width: 1.15rem;
  height: 1.15rem;
}

.utilix-dialog__actions {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}

.utilix-dialog__actions .btn {
  flex: 1;
}

@media (min-width: 480px) {
  .utilix-dialog {
    width: 420px;
  }
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--bg);
}

.badge--ok { color: var(--accent); }
.badge--off { color: var(--danger); }

.offline-banner {
  background: #5c4a1a;
  color: #ffe9a8;
  text-align: center;
  padding: 0.5rem;
  font-size: 0.85rem;
}

.hidden { display: none !important; }

.profile-hero {
  text-align: center;
}

.profile-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}

.profile-avatar {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg);
  border: 3px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-avatar__initials {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

.profile-avatar__btn {
  min-height: 40px;
  cursor: pointer;
}

.profile-avatar__remove {
  min-height: 36px;
  font-size: 0.85rem;
  color: var(--danger) !important;
  border-color: transparent !important;
}

.profile-hero__name {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.profile-hero__username {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
}

.shell-header__user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 0.25rem 0;
}

.shell-header__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
  overflow: hidden;
}

.shell-header__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.shell-header__label {
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 96px;
  font-weight: 600;
}

.lang-switch--profile {
  justify-content: flex-start;
}

.lang-switch--profile button {
  min-height: var(--touch);
  min-width: 5.5rem;
  padding: 0 1rem;
  font-size: 0.9rem;
}

.card--danger {
  border-color: var(--danger);
}

.card--danger h2 {
  color: #ffb4b4;
}

.qr-wrap {
  display: flex;
  justify-content: center;
  padding: 0.75rem;
  background: #fff;
  border-radius: var(--radius);
  margin: 0 auto;
  max-width: 280px;
}

.segmented-nav {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1rem;
  padding: 0.25rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.segmented-nav__btn {
  flex: 1;
  min-height: var(--touch);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.segmented-nav__btn.is-active {
  background: var(--bg-tile);
  color: var(--text);
}

.qr-scanner-wrap {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: #000;
  aspect-ratio: 1;
  max-width: 320px;
  margin: 0 auto;
}

.qr-scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.contact-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.contact-list__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.contact-list__item:last-child {
  border-bottom: none;
}

.contact-list__meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.contact-list__meta strong {
  font-size: 0.95rem;
}

.contact-list__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
}

.btn--sm {
  min-height: 36px;
  padding: 0 0.65rem;
  font-size: 0.8rem;
}

.qr-image {
  display: block;
  width: 240px;
  height: 240px;
  image-rendering: pixelated;
}
