:root {
  --rj-bg: #0f1419;
  --rj-bg-elev: #171d25;
  --rj-bg-soft: #1e2630;
  --rj-border: rgba(148, 163, 184, 0.14);
  --rj-text: #e8eef6;
  --rj-muted: #93a4b8;
  --rj-accent: #14b8a6;
  --rj-accent-2: #0d9488;
  --rj-accent-soft: rgba(20, 184, 166, 0.14);
  --rj-danger: #f87171;
  --rj-warn: #fbbf24;
  --rj-ok: #34d399;
  --rj-radius: 14px;
  --rj-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --rj-sidebar: 260px;
  --font-sans: "IBM Plex Sans", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--rj-text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(20, 184, 166, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(56, 189, 248, 0.08), transparent 50%),
    linear-gradient(180deg, #10161d 0%, #0b1015 100%);
  background-attachment: fixed;
}

a { color: var(--rj-accent); text-decoration: none; }
a:hover { color: #5eead4; }

code, .font-monospace {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

/* App bar + Android-style navigation drawer */
.app-root {
  min-height: 100vh;
  padding-top: calc(56px + env(safe-area-inset-top, 0px));
}

.app-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: calc(56px + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 0.5rem 0 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(15, 20, 25, 0.92);
  border-bottom: 1px solid var(--rj-border);
  backdrop-filter: blur(14px);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

.app-bar-title {
  flex: 1;
  min-width: 0;
  line-height: 1.15;
  padding-left: 0.15rem;
}

.app-bar-title strong {
  display: block;
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-bar-title span {
  display: block;
  font-size: 0.72rem;
  color: var(--rj-muted);
}

.app-bar-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding-right: 0.35rem;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--rj-text);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  background: rgba(255, 255, 255, 0.06);
  outline: none;
}

.hamburger {
  width: 18px;
  height: 14px;
  display: grid;
  gap: 4px;
  align-content: center;
}

.hamburger span {
  display: block;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.drawer-scrim.show {
  opacity: 1;
  pointer-events: auto;
}

.nav-drawer {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 70;
  width: min(300px, 86vw);
  height: 100vh;
  height: 100dvh;
  padding:
    calc(0.85rem + env(safe-area-inset-top, 0px))
    0.75rem
    calc(0.85rem + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, #171d25 0%, #10161d 100%);
  border-right: 1px solid var(--rj-border);
  box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transform: translateX(-105%);
  transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform;
}

.nav-drawer.open {
  transform: translateX(0);
}

body.drawer-open {
  overflow: hidden;
}

.drawer-header {
  display: grid;
  grid-template-columns: 44px 1fr 40px;
  gap: 0.65rem;
  align-items: center;
  padding: 0.55rem 0.35rem 0.85rem;
  border-bottom: 1px solid var(--rj-border);
}

.drawer-user {
  min-width: 0;
  line-height: 1.2;
}

.drawer-user strong {
  display: block;
  font-size: 1.05rem;
}

.drawer-user span {
  display: block;
  color: var(--rj-muted);
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drawer-close {
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  color: var(--rj-muted);
}

.drawer-nav {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: 2px;
  padding: 0.5rem 0.15rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.drawer-section {
  margin: 0.15rem 0.75rem 0.35rem;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b7c90;
}

.drawer-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-height: 44px;
  height: 44px;
  padding: 0 0.85rem;
  border-radius: 12px;
  color: var(--rj-muted);
  transition: background 0.15s ease, color 0.15s ease;
  flex: 0 0 auto;
}

.drawer-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--rj-text);
}

.drawer-item.active {
  background: var(--rj-accent-soft);
  color: #5eead4;
}

.drawer-ico {
  width: 24px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.drawer-footer {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--rj-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.35rem 0.5rem;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--rj-accent), #0891b2);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #042f2e;
  box-shadow: 0 10px 30px rgba(20, 184, 166, 0.35);
}

.brand-text {
  line-height: 1.15;
}

.brand-text strong {
  display: block;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.brand-text span {
  color: var(--rj-muted);
  font-size: 0.8rem;
}

.app-content {
  padding: 1.25rem 1.25rem 2.5rem;
  max-width: 1280px;
  margin: 0 auto;
}

/* Desktop wide: permanent rail + hamburger still opens overlay drawer like Android */
@media (min-width: 1100px) {
  .app-root:not(.is-pwa) .app-content {
    padding-left: 1.75rem;
    padding-right: 1.75rem;
  }
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-title h1 {
  margin: 0;
  font-size: clamp(1.5rem, 2vw, 1.9rem);
  letter-spacing: -0.03em;
  font-weight: 600;
}

.page-title p {
  margin: 0.35rem 0 0;
  color: var(--rj-muted);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* Cards / panels */
.rj-card {
  background: rgba(23, 29, 37, 0.88);
  border: 1px solid var(--rj-border);
  border-radius: var(--rj-radius);
  box-shadow: var(--rj-shadow);
  overflow: hidden;
  backdrop-filter: blur(10px);
}

.rj-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.95rem 1.15rem;
  border-bottom: 1px solid var(--rj-border);
  background: rgba(255, 255, 255, 0.02);
  font-weight: 600;
}

.rj-card-body { padding: 1.15rem; }

/* Entity cards (users, devices) — mobile-first */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
  padding: 1rem;
}

@media (min-width: 700px) {
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1100px) {
  .card-grid.card-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.entity-card {
  border: 1px solid var(--rj-border);
  border-radius: 14px;
  background: linear-gradient(165deg, rgba(30, 38, 48, 0.95), rgba(18, 24, 31, 0.95));
  padding: 1rem 1.05rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-width: 0;
}

.entity-card-link {
  position: relative;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.entity-card-link:hover {
  border-color: rgba(96, 165, 250, 0.45);
  transform: translateY(-1px);
}

.entity-card-hit {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
}

.entity-actions-over {
  position: relative;
  z-index: 2;
}

.crumb-back {
  display: inline-block;
  margin-bottom: 0.35rem;
  color: var(--rj-muted);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
}

.crumb-back:hover {
  color: var(--rj-text);
}

.entity-card.is-inactive {
  opacity: 0.72;
}

.entity-card.is-danger {
  border-color: rgba(248, 113, 113, 0.45);
  background: linear-gradient(165deg, rgba(60, 28, 28, 0.55), rgba(18, 24, 31, 0.95));
}

.entity-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.entity-card-title {
  min-width: 0;
}

.entity-card-title strong {
  display: block;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  word-break: break-word;
}

.entity-card-title span {
  display: block;
  color: var(--rj-muted);
  font-size: 0.82rem;
  margin-top: 0.15rem;
}

.entity-meta {
  display: grid;
  gap: 0.45rem;
}

.entity-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.88rem;
}

.entity-meta-row .k {
  color: var(--rj-muted);
  flex-shrink: 0;
}

.entity-meta-row .v {
  text-align: right;
  min-width: 0;
  word-break: break-word;
}

.entity-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-top: 0.15rem;
  border-top: 1px solid var(--rj-border);
}

.entity-actions .form-select,
.entity-actions .form-control {
  min-width: 0;
  flex: 1 1 140px;
}

.entity-actions .btn {
  flex: 0 0 auto;
}

.pwd-row {
  display: flex;
  gap: 0.45rem;
  width: 100%;
}

.pwd-row .form-control { flex: 1; }

.folder-access-empty {
  margin: 0;
  font-size: 0.82rem;
  color: var(--rj-muted);
}

.folder-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.folder-check {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.55rem;
  border: 1px solid var(--rj-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.02);
  font-size: 0.82rem;
  cursor: pointer;
  user-select: none;
}

.folder-check:has(input:checked) {
  border-color: rgba(20, 184, 166, 0.45);
  background: rgba(20, 184, 166, 0.1);
}

.folder-check input { accent-color: var(--rj-accent); }

.folder-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.folder-tag {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--rj-border);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.8rem;
  color: var(--rj-muted);
}

.float-scrim {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.16s ease;
}

.float-scrim.show { opacity: 1; }

.float-card {
  position: fixed;
  z-index: 90;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -46%) scale(0.98);
  width: min(420px, calc(100vw - 1.5rem));
  max-height: min(80vh, 560px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--rj-border);
  border-radius: 16px;
  background: linear-gradient(165deg, rgba(30, 38, 48, 0.98), rgba(15, 20, 25, 0.98));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: opacity 0.16s ease, transform 0.16s ease;
  overflow: hidden;
}

.float-card.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.float-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--rj-border);
}

.float-card-head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.float-card-head p {
  margin: 0.2rem 0 0;
  color: var(--rj-muted);
  font-size: 0.82rem;
}

.float-card-toolbar {
  display: flex;
  gap: 0.4rem;
  padding: 0.75rem 1rem 0;
}

.float-checks {
  padding: 0.75rem 1rem;
  overflow: auto;
  flex: 1;
  min-height: 80px;
}

.float-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1rem 1rem;
  border-top: 1px solid var(--rj-border);
}

.float-card .icon-btn {
  border: 0;
  background: transparent;
  color: var(--rj-muted);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
}

.float-card .icon-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--rj-text);
}

.empty-state {
  text-align: center;
  color: var(--rj-muted);
  padding: 2rem 1rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat {
  padding: 1rem 1.1rem;
  border-radius: var(--rj-radius);
  border: 1px solid var(--rj-border);
  background: linear-gradient(180deg, rgba(30, 38, 48, 0.9), rgba(23, 29, 37, 0.9));
}

.stat .label {
  color: var(--rj-muted);
  font-size: 0.82rem;
  margin-bottom: 0.35rem;
}

.stat .value {
  font-size: 1.7rem;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.stat.ok .value { color: var(--rj-ok); }
.stat.warn .value { color: var(--rj-warn); }
.stat.danger .value { color: var(--rj-danger); }
.stat.accent .value { color: var(--rj-accent); }

/* Tables */
.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--rj-text);
  --bs-table-border-color: var(--rj-border);
  --bs-table-hover-bg: rgba(20, 184, 166, 0.06);
  margin-bottom: 0;
}

.table thead th {
  color: var(--rj-muted);
  font-weight: 550;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom-color: var(--rj-border) !important;
}

.table td, .table th {
  border-color: var(--rj-border);
  vertical-align: middle;
}

.table-danger {
  --bs-table-bg: rgba(248, 113, 113, 0.08);
  --bs-table-color: var(--rj-text);
}

.table-secondary {
  --bs-table-bg: rgba(148, 163, 184, 0.06);
  --bs-table-color: var(--rj-text);
}

/* Forms */
.form-control, .form-select {
  background: var(--rj-bg);
  border: 1px solid var(--rj-border);
  color: var(--rj-text);
  border-radius: 10px;
}

.form-control:focus, .form-select:focus {
  background: var(--rj-bg);
  color: var(--rj-text);
  border-color: var(--rj-accent);
  box-shadow: 0 0 0 0.2rem rgba(20, 184, 166, 0.2);
}

.form-control::placeholder { color: #6b7c90; }
.form-label { color: var(--rj-muted); font-weight: 500; }
.form-text { color: #7f91a6; }
.form-check-label { color: var(--rj-muted); }

.btn {
  border-radius: 10px;
  font-weight: 560;
}

.btn-primary {
  --bs-btn-bg: var(--rj-accent-2);
  --bs-btn-border-color: var(--rj-accent-2);
  --bs-btn-hover-bg: var(--rj-accent);
  --bs-btn-hover-border-color: var(--rj-accent);
  --bs-btn-active-bg: #0f766e;
  --bs-btn-active-border-color: #0f766e;
  color: #042f2e;
}

.btn-outline-secondary,
.btn-outline-danger {
  --bs-btn-color: var(--rj-muted);
  --bs-btn-border-color: var(--rj-border);
  --bs-btn-hover-bg: var(--rj-bg-soft);
  --bs-btn-hover-border-color: #64748b;
  --bs-btn-hover-color: var(--rj-text);
}

.btn-outline-danger {
  --bs-btn-color: #fca5a5;
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: rgba(248, 113, 113, 0.2);
  --bs-btn-hover-border-color: var(--rj-danger);
}

.btn-warning {
  --bs-btn-color: #422006;
  --bs-btn-bg: var(--rj-warn);
  --bs-btn-border-color: var(--rj-warn);
}

.badge {
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.alert {
  border-radius: 12px;
  border: 1px solid transparent;
}

.alert-danger {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.35);
  color: #fecaca;
}

.alert-success, .alert-info, .alert-warning {
  background: rgba(20, 184, 166, 0.1);
  border-color: rgba(20, 184, 166, 0.3);
  color: #ccfbf1;
}

.alert-warning {
  background: rgba(251, 191, 36, 0.12);
  border-color: rgba(251, 191, 36, 0.35);
  color: #fde68a;
}

.list-group-item {
  background: transparent;
  border-color: var(--rj-border);
  color: var(--rj-text);
}

.text-muted { color: var(--rj-muted) !important; }
.text-danger { color: #fca5a5 !important; }

/* Auth pages */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.auth-panel {
  width: min(440px, 100%);
  padding: 1.75rem;
  border-radius: 20px;
  border: 1px solid var(--rj-border);
  background: rgba(23, 29, 37, 0.92);
  box-shadow: var(--rj-shadow);
  backdrop-filter: blur(12px);
}

.auth-panel .brand {
  margin-bottom: 1.25rem;
}

.auth-panel h1 {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}

.install-btn {
  display: none;
}

.install-btn.show { display: inline-flex; }

@media (max-width: 992px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .app-content { padding: 1rem; }
}

@media (max-width: 560px) {
  .stat-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
}
