:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e8eaed;
  --text-dim: #9aa1ac;
  --accent: #5b8cff;
  --accent-2: #7c5cff;
  --online: #37d67a;
  --offline: #ff5c6c;
  --error: #ffb454;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: radial-gradient(circle at top left, #1a1e29, var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 40px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar__logo {
  height: 34px;
  width: auto;
  display: block;
}

.topbar__title {
  font-size: 18px;
  color: var(--text-dim);
  padding-left: 12px;
  border-left: 1px solid var(--border);
  font-weight: 600;
  letter-spacing: 0.2px;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.search {
  width: 260px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease;
}

.search:focus {
  border-color: var(--accent);
}

.hub-body {
  display: flex;
  align-items: stretch;
}

.sidebar {
  flex-shrink: 0;
  width: 240px;
  padding: 20px 12px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 75px;
  height: calc(100vh - 75px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar__home,
.sidebar__app {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--text-dim);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sidebar__home:hover,
.sidebar__app:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar__home.active,
.sidebar__app.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
}

.sidebar__section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  padding: 16px 12px 6px;
}

.sidebar__apps {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar__app span:first-child {
  flex-shrink: 0;
}

.hub-main {
  flex: 1;
  min-width: 0;
}

#home-view {
  max-width: 1180px;
  margin: 0 auto;
  padding: 36px 40px 80px;
}

#app-view {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 75px);
}

#app-view[hidden] {
  display: none;
}

.app-view__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.app-view__title {
  font-weight: 600;
  font-size: 15px;
}

.app-view__external {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
}

.app-view__external:hover {
  text-decoration: underline;
}

.app-frame-container {
  flex: 1;
  position: relative;
}

.app-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: white;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
  max-width: 480px;
}

.summary__card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary__value {
  font-size: 26px;
  font-weight: 700;
}

.summary__value--online { color: var(--online); }
.summary__value--offline { color: var(--offline); }

.summary__label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.category-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.category-tab {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.category-tab:hover {
  color: var(--text);
  border-color: var(--accent);
}

.category-tab.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  border-color: transparent;
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  overflow: hidden;
}

.card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 12px 30px rgba(91, 140, 255, 0.15);
}

.card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.card__name {
  font-size: 16px;
  font-weight: 600;
}

.card__category {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.status__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status--online .status__dot { background: var(--online); box-shadow: 0 0 8px var(--online); }
.status--online { color: var(--online); }

.status--offline .status__dot { background: var(--offline); }
.status--offline { color: var(--offline); }

.status--error .status__dot { background: var(--error); }
.status--error { color: var(--error); }

.status--checking .status__dot {
  background: var(--text-dim);
  animation: pulse 1.2s infinite ease-in-out;
}
.status--checking { color: var(--text-dim); }

.status__dot--online { background: var(--online); box-shadow: 0 0 8px var(--online); }
.status__dot--offline { background: var(--offline); }
.status__dot--error { background: var(--error); }
.status__dot--checking { background: var(--text-dim); animation: pulse 1.2s infinite ease-in-out; }

@keyframes pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

.card__description {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
  flex: 1;
}

.card__url {
  font-size: 12px;
  color: var(--accent);
  font-family: 'SF Mono', Monaco, monospace;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.login-card__logo {
  height: 40px;
  width: auto;
  align-self: center;
  margin-bottom: 4px;
}

.login-card__subtitle {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  margin: 0 0 8px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}

.login-field input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease;
}

.login-field input:focus {
  border-color: var(--accent);
}

.login-submit {
  margin-top: 8px;
  padding: 11px 16px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.login-submit:hover {
  opacity: 0.9;
}

.login-error {
  color: var(--offline);
  font-size: 13px;
  text-align: center;
  margin: 0;
  min-height: 16px;
}

.login-success {
  color: var(--online);
  font-size: 13px;
  text-align: center;
  margin: 0;
}

.login-link {
  align-self: center;
  color: var(--text-dim);
  font-size: 13px;
  text-decoration: none;
}

.login-link:hover {
  color: var(--accent);
}

.login-submit:disabled {
  opacity: 0.6;
  cursor: default;
}

.logout-btn {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.logout-btn:hover {
  color: var(--text);
  border-color: var(--offline);
}

.users-link {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 13px;
  text-decoration: none;
  transition: all 0.15s ease;
}

.users-link:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* ── Users page ────────────────────────────────────────────────── */
.users-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.users-title { font-size: 22px; font-weight: 700; margin: 0; }
.users-subtitle { color: var(--text-dim); font-size: 13px; margin: 6px 0 0; }

.add-user-btn {
  flex-shrink: 0;
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.add-user-btn:hover { opacity: 0.9; }

.users-error {
  background: rgba(255, 92, 108, 0.12);
  border: 1px solid var(--offline);
  color: var(--offline);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

.users-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.users-table { width: 100%; border-collapse: collapse; }
.users-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  background: var(--surface-2);
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.users-table td {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--text);
}
.users-table tr:last-child td { border-bottom: none; }

.users-group-row td {
  padding: 10px 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  background: var(--surface-2);
}
.users-col-actions {
  width: auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.groups-manage-btn {
  padding: 6px 12px;
  font-size: 12px;
}

.users-level-select {
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s ease;
}
.users-level-select:focus { border-color: var(--accent); }

.users-delete-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--offline);
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s ease;
}
.users-delete-btn:hover { background: rgba(255, 92, 108, 0.12); }

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

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

.modal-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.modal-title { font-size: 18px; font-weight: 700; margin: 0; }
.modal-sub { color: var(--text-dim); font-size: 13px; margin: 6px 0 20px; }

.modal-card .login-field { margin-bottom: 14px; }

.apps-checklist {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
}

.apps-checklist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

.apps-checklist-item:hover { background: var(--surface-2); }

.apps-checklist-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.modal-actions {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-btn-secondary,
.modal-btn-primary {
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
}

.modal-btn-secondary {
  background: var(--surface-2);
  color: var(--text-dim);
}
.modal-btn-secondary:hover { color: var(--text); border-color: var(--accent); }

.modal-btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  border-color: transparent;
}
.modal-btn-primary:hover { opacity: 0.9; }
.modal-btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

/* Sign in with Google */
.login-google { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 4px; }
.login-google[hidden] { display: none; }
.login-google__divider { display: flex; align-items: center; gap: 10px; width: 100%; opacity: 0.6; font-size: 13px; }
.login-google__divider::before,
.login-google__divider::after { content: ""; flex: 1; border-top: 1px solid currentColor; opacity: 0.4; }

/* Invitations */
.users-notice {
  background: rgba(91, 140, 255, 0.10);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
  overflow-wrap: anywhere;
}
.users-notice code { user-select: all; }
.users-status-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--text-dim);
  color: var(--text-dim);
  font-size: 11px;
  vertical-align: middle;
}
.users-resend-btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 10px;
  margin-right: 6px;
}
.users-resend-btn:hover { border-color: var(--accent); }
.users-resend-btn:disabled { opacity: 0.5; cursor: default; }
.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
}
.link-btn:disabled { opacity: 0.5; cursor: default; }
.reset-or { margin-top: 14px; }

/* Two-step sign-in */
.login-hint { color: var(--text-dim); font-size: 13px; text-align: center; margin: 4px 0; }
.twofa-steps { color: var(--text-dim); font-size: 13px; padding-left: 20px; margin: 4px 0; align-self: stretch; }
.twofa-qr { display: block; margin: 8px auto; width: 200px; height: 200px; background: #fff; border-radius: 8px; }
.twofa-key { user-select: all; letter-spacing: 1px; word-break: break-all; }
.twofa-recovery { list-style: none; padding: 0; margin: 8px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; font-family: monospace; font-size: 15px; text-align: center; user-select: all; }
.login-card[hidden] { display: none; }
.users-status-badge--ok { border-color: #3ecf8e; color: #3ecf8e; }

/* Up but slow to answer right now (e.g. mid-sync) — not down */
.status--busy .status__dot { background: var(--error); }
.status--busy { color: var(--error); }
.status__dot--busy { background: var(--error); }
.twofa-trust { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--text-dim); margin: 6px 0 10px; cursor: pointer; text-align: left; }
.twofa-trust input { margin-top: 2px; }
