:root {
  --bg: #0f1216;
  --panel: #161b22;
  --panel-2: #1c222b;
  --panel-3: #222a35;
  --text: #e6edf3;
  --muted: #9aa4b2;
  --accent: #4cc9f0;
  --accent-2: #f9a826;
  --danger: #f04747;
  --success: #2ecc71;
  --border: #2b3440;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --font-display: 'Sora', sans-serif;
  --font-body: 'Space Grotesk', sans-serif;
  --sidebar-width: 260px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background: radial-gradient(circle at 20% 20%, #19202b, var(--bg));
  color: var(--text);
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #141821, #0f1216 60%);
  border-right: 1px solid var(--border);
  padding: 24px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  transition: width 0.2s ease, left 0.2s ease;
  width: var(--sidebar-width);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: 0.5px;
  margin-bottom: 28px;
}

.brand i {
  color: var(--accent);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  justify-content: space-between;
  gap: 16px;
}

.user-panel {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 10px;
  align-items: center;
}

.user-panel .user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--panel-3);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: var(--muted);
}

.user-panel .user-avatar,
.user-panel .user-name {
  cursor: pointer;
}

.user-panel .user-avatar:hover {
  border: 1px solid var(--accent);
}

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

.user-panel .user-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.user-panel .user-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-panel .user-role {
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.user-panel .logout-mini {
  border: 1px solid var(--border);
  background: var(--panel-3);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.user-panel .logout-mini:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--muted);
  transition: all 0.2s ease;
}

.sidebar.collapsed,
.sidebar-collapsed .sidebar {
  padding: 20px 10px;
}

.sidebar.collapsed #brandName,
.sidebar-collapsed #brandName {
  display: none;
}

.sidebar.collapsed .brand,
.sidebar-collapsed .brand {
  justify-content: center;
}

.sidebar.collapsed .nav a,
.sidebar-collapsed .nav a {
  justify-content: center;
  font-size: 0;
  padding: 12px;
  gap: 0;
}

.sidebar.collapsed .nav a i,
.sidebar-collapsed .nav a i {
  font-size: 16px;
}

.sidebar.collapsed .user-panel,
.sidebar-collapsed .user-panel {
  grid-template-columns: 1fr;
  justify-items: center;
  gap: 8px;
  padding: 10px;
  width: 100%;
}

.sidebar.collapsed .user-panel .user-meta,
.sidebar-collapsed .user-panel .user-meta {
  display: none;
}

.sidebar.collapsed .user-panel .logout-mini,
.sidebar-collapsed .user-panel .logout-mini {
  justify-self: center;
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
}

.sidebar.collapsed .user-panel .user-avatar,
.sidebar-collapsed .user-panel .user-avatar {
  width: 36px;
  height: 36px;
  font-size: 12px;
}

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

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 12, 0.6);
  z-index: 900;
}

.sidebar-overlay.show {
  display: block;
}

.nav a.active,
.nav a:hover {
  background: var(--panel-2);
  color: var(--text);
}

.nav a i {
  width: 20px;
  text-align: center;
}

.content {
  padding: 28px 32px 60px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.page-title {
  font-family: var(--font-display);
  font-size: 28px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 22px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.stat-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: rgba(230, 237, 243, 0.85);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(120deg, rgba(45, 108, 223, 0.18), rgba(76, 201, 240, 0.08));
}

.stat-header i {
  font-size: 14px;
  opacity: 0.9;
}

.stat-header-action {
  height: 24px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 8px;
  gap: 6px;
}

.stat-card.has-header-action .stat-header {
  padding-top: 10px;
  padding-bottom: 10px;
}

.stat-card.has-header-action .stat-header > span {
  white-space: nowrap;
}

.stat-body {
  flex: 1;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 72px;
}

.stat-value {
  font-size: 22px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.ip-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--panel-3);
  font-weight: 600;
}

.copy-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.copy-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.status-running {
  color: var(--success);
}

.status-stopped {
  color: var(--danger);
}

.status-updating {
  color: #f2c14e;
}

.status-checking {
  color: #f2c14e;
}

.status-pill.status-running,
.status-pill.status-stopped,
.status-pill.status-updating,
.status-pill.status-checking {
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  animation: status-glow 1.8s ease-in-out infinite;
}

.status-pill.status-running {
  box-shadow: 0 0 12px rgba(46, 204, 113, 0.35), 0 0 24px rgba(46, 204, 113, 0.15);
}

.status-pill.status-stopped {
  box-shadow: 0 0 12px rgba(240, 71, 71, 0.35), 0 0 24px rgba(240, 71, 71, 0.15);
}

.status-pill.status-updating {
  box-shadow: 0 0 12px rgba(242, 193, 78, 0.35), 0 0 24px rgba(242, 193, 78, 0.15);
}

.status-pill.status-checking {
  box-shadow: 0 0 12px rgba(242, 193, 78, 0.35), 0 0 24px rgba(242, 193, 78, 0.15);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--panel-3);
  font-size: 18px;
  font-weight: 700;
}

.status-pill i {
  font-size: 18px;
}

.status-anim {
  animation: pulse 1.6s ease-in-out infinite;
}

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

@keyframes status-glow {
  0% { transform: translateY(0); filter: brightness(1); }
  50% { transform: translateY(-1px); filter: brightness(1.15); }
  100% { transform: translateY(0); filter: brightness(1); }
}

.motd-card .motd-body {
  padding: 16px;
  color: var(--text);
  line-height: 1.5;
  min-height: 64px;
}

.motd-card.collapsed .motd-body {
  display: none;
}

.dashboard-motd-collapsed .motd-card .motd-body {
  display: none;
}

.motd-toggle {
  min-width: 30px;
  justify-content: center;
}

.motd-card .motd-body p {
  margin: 0 0 10px;
}

.motd-card .motd-body ul {
  margin: 8px 0 0 18px;
}

.motd-card .motd-icon {
  color: var(--accent);
  margin-right: 6px;
}

.motd-preview {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 10px;
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.icon-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 13px;
}

.icon-chip i {
  color: var(--accent);
}

.card h3 {
  margin: 0 0 6px;
  font-size: 16px;
  color: var(--muted);
}

.card .value {
  font-size: 22px;
  font-weight: 600;
}

.section {
  margin-top: 28px;
}

.motd-section {
  margin-top: 28px;
  margin-bottom: 18px;
}

.section h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table th,
.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.table th {
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 500;
}

.table th.checkbox-col,
.table td.checkbox-col {
  text-align: center;
}

.table td.checkbox-col input {
  margin: 0;
}

.table tr:last-child td {
  border-bottom: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  justify-content: center;
}

.action-bar {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.action-bar .btn {
  padding: 12px 18px;
  font-size: 15px;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn.primary {
  background: linear-gradient(120deg, #2d6cdf, #4cc9f0);
  border-color: transparent;
}

.btn.success {
  background: linear-gradient(120deg, #1f8f4e, #2ecc71);
  border-color: transparent;
}

.btn.info {
  background: linear-gradient(120deg, #1f4bd6, #2f7bd9);
  border-color: transparent;
}

.btn.warning {
  background: linear-gradient(120deg, #c78307, #f2c14e);
  border-color: transparent;
  color: #0f1216;
}

.btn.schedule-stop-btn {
  background: linear-gradient(120deg, #3e1c77, #5b2f8f);
  border-color: transparent;
  color: #f4edff;
}

.btn.danger {
  background: linear-gradient(120deg, #b31237, #f04747);
}

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

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-family: var(--font-body);
}

label {
  display: inline-block;
  margin-bottom: 8px;
}

textarea {
  min-height: 240px;
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--panel-3);
  color: var(--muted);
}

.badge.success {
  color: var(--success);
}

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

.role-user {
  color: var(--text);
}

.role-vip {
  color: #f9a826;
}

.role-mod {
  color: #4cc9f0;
}

.role-admin {
  color: #f04747;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-3);
  font-size: 12px;
}

.role-badge i {
  font-size: 12px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--panel-3);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: 12px;
  font-weight: 600;
}

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

.avatar-click {
  cursor: pointer;
  border: 1px solid transparent;
}

.avatar-click:hover {
  border-color: var(--accent);
}

.actor-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

#logsTable td {
  vertical-align: top;
}

#logsTable td:not(.details-cell) {
  white-space: nowrap;
}

#logsTable .details-cell {
  white-space: normal;
  word-break: break-word;
  min-width: 280px;
}

.toast-container {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: linear-gradient(145deg, rgba(28,34,43,0.95), rgba(22,27,34,0.95));
  border: 1px solid var(--border);
  padding: 12px 16px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  max-width: 520px;
  pointer-events: auto;
  animation: toast-in 0.22s ease-out, toast-fade 0.35s ease-in forwards;
  animation-delay: 0s, 3.6s;
}

.toast.success {
  border-color: rgba(46, 204, 113, 0.5);
}

.toast.error {
  border-color: rgba(240, 71, 71, 0.6);
}

.toast.info {
  border-color: rgba(76, 201, 240, 0.6);
}

.toast .toast-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-3);
}

.toast.success .toast-icon {
  color: var(--success);
}

.toast.error .toast-icon {
  color: var(--danger);
}

.toast.info .toast-icon {
  color: var(--accent);
}

.toast .toast-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toast-fade {
  to {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
}
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 12, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1100;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(460px, 92vw);
  max-width: 100%;
  padding: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal h3 {
  margin-top: 0;
}

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

.modal input,
.modal select,
.modal textarea {
  max-width: 100%;
  min-width: 0;
}

#shutdownModal input[type="datetime-local"] {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
}

#shutdownModal .modal-actions {
  margin-top: 14px;
}

#playersTableWrap {
  overflow-x: auto;
}

.players-modal-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.players-modal-top p {
  margin: 0;
}

.players-refresh-badge {
  margin-left: auto;
  white-space: nowrap;
}

#playersModal .modal-actions {
  margin-top: 20px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 600px at 20% 15%, rgba(76, 201, 240, 0.18), transparent 60%),
    radial-gradient(900px 500px at 80% 70%, rgba(249, 168, 38, 0.16), transparent 60%),
    radial-gradient(700px 400px at 50% 90%, rgba(46, 204, 113, 0.12), transparent 60%),
    linear-gradient(180deg, #0f141c, #0b0f14);
  position: relative;
  overflow: hidden;
}

.login-shell::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(600px 300px at 15% 10%, rgba(76, 201, 240, 0.12), transparent 60%),
    radial-gradient(600px 300px at 85% 85%, rgba(249, 168, 38, 0.12), transparent 60%);
  filter: blur(2px);
  opacity: 0.7;
}

.login-shell::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 80px 80px;
  opacity: 0.4;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px 20px;
  width: min(460px, 92vw);
  box-shadow: var(--shadow);
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
}

.login-card h1 {
  font-family: var(--font-display);
  margin-top: 0;
}

.login-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  margin: 12px auto 0;
  justify-content: center;
  text-align: center;
  align-self: center;
}

.login-title {
  font-size: 26px;
  margin: 0 0 6px;
}

.login-subtitle {
  color: var(--muted);
  margin: 0 0 10px;
}

.input-icon {
  position: relative;
}

.input-icon i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.input-icon input {
  padding-left: 36px;
}

.login-actions .btn {
  padding: 12px 18px;
  font-size: 15px;
  min-width: 120px;
}

.login-actions {
  display: grid;
  gap: 10px;
}

.login-actions #loginBtn {
  width: 100%;
  justify-content: center;
}

.login-actions .btn.ghost {
  width: 100%;
  justify-content: center;
}

.notfound-card {
  text-align: center;
}

.notfound-code {
  font-family: var(--font-display);
  font-size: 72px;
  line-height: 1;
  margin-bottom: 8px;
  color: var(--accent);
  text-shadow: 0 0 22px rgba(76, 201, 240, 0.35);
}

.notfound-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.notfound-actions .btn {
  min-width: 160px;
  justify-content: center;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    height: 100vh;
    left: -280px;
    z-index: 1001;
  }
  .sidebar.open {
    left: 0;
  }

  .modal {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
    padding: 16px;
    overflow-y: auto;
  }

  .modal-actions {
    flex-wrap: wrap;
    justify-content: stretch;
  }

  .modal-actions .btn {
    flex: 1 1 100%;
    justify-content: center;
  }

  /* iOS Safari can zoom small inputs and cause visual overflow in modals. */
  .modal input,
  .modal select,
  .modal textarea {
    font-size: 16px;
  }

  #shutdownModal .section {
    overflow: hidden;
  }

  .players-modal-top {
    flex-wrap: wrap;
  }

  .players-refresh-badge {
    margin-left: 0;
  }
}
