/* App shell, header (brand + servers + logout), tab bar, footer */
.app-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

/* Row 1: brand | server status | logout */
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding: 0.65rem 1.5rem;
  flex-wrap: wrap;
}

.navbar-brand {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.navbar-version {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

a.navbar-brand-link {
  text-decoration: none;
  transition: color 0.2s;
}
a.navbar-brand-link:hover {
  color: var(--accent);
}
a.navbar-brand-link:hover .navbar-version {
  color: var(--text-muted);
}

.header-server-status {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.45rem 0.65rem;
  flex: 1 1 180px;
  min-width: 0;
}

.server-status-label {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  white-space: nowrap;
}

.tunnel-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.32rem 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.tunnel-pill.connected {
  color: #4ade80;
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.06);
}
.tunnel-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.tunnel-pill.disconnected .dot { opacity: 0.45; }

/* Access-gated chrome stays hidden until /api/auth/me resolves, so tabs the
   account cannot use never flash on screen. */
.app-header[data-access='pending'] .tab-bar,
.app-header[data-access='pending'] .header-user {
  visibility: hidden;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.header-user-name {
  padding: 0.28rem 0.55rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.header-user-name:hover {
  background: var(--surface-hover);
  border-color: var(--border);
}

.header-user-role {
  padding: 0.16rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.header-user-role.is-super {
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.08);
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.9rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  font-size: 0.8125rem;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.2s, border-color 0.2s;
  flex-shrink: 0;
  margin-left: auto;
}
.logout-btn:hover { color: var(--text); border-color: var(--text-muted); }
.logout-btn svg { width: 16px; height: 16px; }

/* Row 2: tabs only — compact height */
.header-tab-row {
  padding: 0.25rem 1.5rem 0.5rem;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
}

.tab-bar {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding: 0.1rem 0;
}
.tab-bar::-webkit-scrollbar { height: 4px; }
.tab-bar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.nav-tab {
  flex-shrink: 0;
  padding: 0.32rem 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 7px;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: color 0.2s, background 0.2s, box-shadow 0.2s;
  border: 1px solid transparent;
  line-height: 1.35;
}
.nav-tab:hover {
  color: var(--text);
  background: var(--surface-hover);
}
.nav-tab.active {
  color: var(--text);
  background: var(--bg);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.2);
}

@media (max-width: 760px) {
  .header-top {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand logout"
      "user user"
      "servers servers";
    align-items: center;
    gap: 0.6rem 0.75rem;
    padding: 0.6rem 1rem;
  }
  .header-user {
    grid-area: user;
    justify-content: flex-start;
    margin-left: -0.55rem;
  }
  .navbar-brand {
    grid-area: brand;
    font-size: 1rem;
    line-height: 1.2;
  }
  .navbar-version {
    font-size: 0.62rem;
  }
  .header-server-status {
    grid-area: servers;
    justify-content: flex-start;
    align-items: center;
    gap: 0.4rem 0.45rem;
    flex: none;
    width: 100%;
    min-width: 0;
  }
  .server-status-label {
    font-size: 0.58rem;
    margin-right: 0.15rem;
  }
  .tunnel-pill {
    font-size: 0.7rem;
    padding: 0.26rem 0.5rem;
    border-radius: 6px;
  }
  .tunnel-pill .dot {
    width: 5px;
    height: 5px;
  }
  .logout-btn {
    grid-area: logout;
    margin-left: 0;
    align-self: start;
    padding: 0.38rem 0.65rem;
    font-size: 0.76rem;
    border-radius: 7px;
  }
  .logout-btn svg {
    width: 14px;
    height: 14px;
  }
  .header-tab-row {
    padding: 0.2rem 1rem 0.42rem;
  }
  .tab-bar {
    gap: 0.2rem;
  }
  .nav-tab {
    font-size: 0.76rem;
    padding: 0.28rem 0.65rem;
    border-radius: 6px;
  }
}

.footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ========== Shared modal (change password, account editor) ========== */
/* Self-contained so it works on every page regardless of page CSS. */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}

.modal-card {
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 2.5rem);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.modal-head h2 {
  font-size: 1.05rem;
  font-weight: 600;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.25rem;
}
.modal-close:hover { color: var(--text); }

.modal-field { margin-bottom: 1rem; }
.modal-field label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

.modal-input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}
.modal-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.modal-hint {
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.modal-error,
.modal-success {
  padding: 0.7rem 0.85rem;
  border-radius: 9px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
.modal-error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}
.modal-success {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #86efac;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 1.35rem;
}

.modal-btn {
  padding: 0.55rem 1rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.modal-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-muted);
}
.modal-btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.modal-btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}
.modal-btn--danger {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
}
.modal-btn--danger:hover:not(:disabled) {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}

/* Body copy inside a modal (as opposed to a field's helper text) */
.modal-hint--body {
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text);
}
.modal-hint--body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
  padding: 0.08rem 0.3rem;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.modal-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ========== Game server reload progress (every page, top left) ========== */
.reload-activity {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 80;
  width: min(300px, calc(100vw - 1.5rem));
  padding: 0.7rem 0.8rem 0.75rem;
  border: 1px solid rgba(59, 130, 246, 0.45);
  border-radius: 12px;
  background: rgba(24, 24, 28, 0.97);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  font-size: 0.78rem;
  animation: reload-activity-in 0.18s ease-out;
}
.reload-activity--done { border-color: rgba(34, 197, 94, 0.45); }
.reload-activity--failed { border-color: rgba(239, 68, 68, 0.5); }

.reload-activity-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.reload-activity-head strong {
  flex: 1;
  font-size: 0.82rem;
  font-weight: 600;
}
.reload-activity-time {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.reload-activity-icon {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
}
.reload-activity--running .reload-activity-icon {
  border: 2px solid rgba(59, 130, 246, 0.3);
  border-top-color: #60a5fa;
  animation: reload-activity-spin 0.8s linear infinite;
}
.reload-activity--done .reload-activity-icon { background: var(--success); }
.reload-activity--failed .reload-activity-icon { background: var(--error); }

.reload-activity-source {
  margin-top: 0.2rem;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reload-activity-bar {
  position: relative;
  height: 4px;
  margin: 0.5rem 0 0.45rem;
  overflow: hidden;
  border-radius: 99px;
  background: var(--bg);
}
.reload-activity-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #60a5fa;
  transition: width 0.3s;
}
.reload-activity--done .reload-activity-bar span { background: var(--success); }
.reload-activity--failed .reload-activity-bar span { background: var(--error); }
.reload-activity-bar.is-running::after {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  content: '';
  animation: reload-activity-shimmer 1.2s linear infinite;
}

.reload-activity-servers {
  display: grid;
  gap: 0.2rem;
  list-style: none;
}
.reload-activity-servers li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--text-muted);
}
.reload-activity-servers li.is-reloading span:last-child { color: #93c5fd; }
.reload-activity-servers li.is-done span:last-child { color: #86efac; }
.reload-activity-servers li.is-failed span:last-child { color: #fca5a5; }
.reload-activity-more {
  margin-top: 0.35rem;
  color: var(--text-muted);
  font-size: 0.7rem;
}

@keyframes reload-activity-spin { to { transform: rotate(360deg); } }
@keyframes reload-activity-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
@keyframes reload-activity-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .reload-activity,
  .reload-activity-icon,
  .reload-activity-bar.is-running::after { animation: none !important; }
}
