/* === FOUC prevention === */
[x-cloak] { display: none !important; }

/* === Lightbox === */
.lightbox-overlay {
  display: flex !important;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.9);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.lightbox-overlay[style*="display: none"] {
  display: none !important;
}
.lightbox-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  width: auto;
  object-fit: contain;
  cursor: default;
  margin: auto;
}

/* === Override pico.css responsive font-size === */

:root {
  font-size: 100% !important;
  --pico-box-shadow: none;
  --pico-button-box-shadow: none;
  --pico-button-hover-box-shadow: none;
  --pico-card-box-shadow: none;
  --pico-dropdown-box-shadow: none;
  --pico-group-box-shadow: none;
  --pico-group-box-shadow-focus-with-button: none;
  --pico-group-box-shadow-focus-with-input: none;
  --pico-switch-thumb-box-shadow: none;
}

/* === Disconnect banner === */

.disconnect-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: #c62828;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 500;
}

/* === Layout === */

.admin-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

.mobile-header {
  display: none;
}

/* === Sidebar === */

.admin-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--pico-muted-border-color);
  background: var(--pico-background-color);
  overflow-y: auto;
}

.sidebar-header {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--pico-muted-border-color);
  font-size: 1.1rem;
}

.sidebar-nav {
  flex: 1;
  padding: 0.5rem;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--pico-border-radius);
  color: var(--pico-color);
  text-decoration: none;
  font-size: 0.95rem;
  margin-bottom: 0.125rem;
}

.sidebar-nav a:hover {
  background: var(--pico-secondary-hover-background);
  color: #fff;
}

.sidebar-nav a.active {
  background: var(--pico-primary-background);
  color: var(--pico-primary-inverse);
}

.sidebar-nav a.active svg {
  stroke: var(--pico-primary-inverse);
}

.sidebar-nav a.game-link {
  margin-top: 0.5rem;
  border: 1px solid var(--pico-muted-border-color);
}

.sidebar-nav a.game-link:hover {
  border-color: var(--pico-primary);
  color: var(--pico-primary);
}

/* Sidebar section header */
.sidebar-section-header {
  padding: 0.75rem 0.75rem 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--pico-muted-color);
  margin-top: 0.5rem;
  border-top: 1px solid var(--pico-muted-border-color);
}

.sidebar-section-header:first-child {
  margin-top: 0;
  border-top: none;
}

.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--pico-muted-border-color);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.sidebar-logout {
  font-size: 0.85rem;
}

/* === Main content === */

.admin-main {
  padding: 2rem;
  overflow-y: auto;
}

/* === Login === */

.login-card {
  max-width: 400px;
  margin: 10vh auto;
}

.error-text {
  color: var(--pico-del-color);
  font-size: 0.875rem;
}

/* === Components === */

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.toolbar h3 {
  margin: 0;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toolbar-search {
  margin-bottom: 0 !important;
  padding: 0.4rem 0.75rem;
  max-width: 200px;
  height: auto;
}

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

.card-item {
  margin: 0;
}

.card-item header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-preview {
  aspect-ratio: 3/4;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--pico-card-background-color);
  border-radius: var(--pico-border-radius);
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-placeholder {
  color: var(--pico-muted-color);
  font-size: 0.875rem;
}

.card-stats {
  font-size: 0.75rem;
  max-height: 80px;
  overflow: auto;
  margin-bottom: 0.5rem;
}

.card-item footer {
  padding-top: 0;
}

.card-item footer [role="group"] {
  margin-bottom: 0;
}

.card-item footer button {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
}

.role-badge {
  font-size: 0.75rem;
  padding: 0.125rem 0.5rem;
  border-radius: 1rem;
  background: var(--pico-primary-background);
  color: var(--pico-primary-inverse);
}

.role-badge[data-role="admin"] {
  background: var(--pico-del-color);
}

.floating-notification {
  position: fixed;
  top: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  padding: 0.75rem 1.5rem;
  border-radius: var(--pico-border-radius);
  background: #2e7d32;
  color: #fff;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.floating-notification.error {
  background: #c62828;
}

.empty-state {
  text-align: center;
  color: var(--pico-muted-color);
  padding: 2rem;
}

/* === Delete Confirmation Modal === */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.modal-content {
  background: var(--pico-background-color);
  border-radius: var(--pico-border-radius);
  padding: 2rem;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
}

.modal-content h4 {
  margin-top: 0;
}

.modal-content [role="group"] {
  margin-bottom: 0;
}

/* === Game Data Tables === */

.game-data-table {
  font-size: 0.9rem;
}

.game-data-table th {
  white-space: nowrap;
  font-size: 0.85rem;
}

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

.game-data-table code {
  font-size: 0.8rem;
  background: var(--pico-code-background-color);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
}

.action-cell {
  white-space: nowrap;
}

/* Sortable table headers */
.sortable {
  cursor: pointer;
  user-select: none;
}

.sortable:hover {
  color: var(--pico-primary);
}

.sort-indicator {
  font-size: 0.7em;
  margin-left: 0.25em;
  opacity: 0.7;
}

.small-btn {
  font-size: 0.75rem !important;
  padding: 0.25rem 0.5rem !important;
  margin: 0 0.125rem;
}

/* JSON display areas */
.json-display {
  font-size: 0.75rem;
  max-height: 120px;
  overflow: auto;
  background: #f5f7fa;
  padding: 0.5rem;
  border-radius: var(--pico-border-radius);
  white-space: pre-wrap;
  word-break: break-all;
}

.static-field-value {
  min-height: 1.5rem;
  padding: 0.35rem 0.6rem;
  border: none;
  border-radius: 0;
  background: #f5f7fa;
  color: var(--pico-color);
  display: flex;
  align-items: center;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.static-field-value code {
  font-size: 0.8rem;
  word-break: break-all;
  background: transparent;
  padding: 0;
  color: inherit;
}

/* === User Avatars === */

.user-avatar-small {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.user-avatar-large {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.user-avatar-initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--pico-primary-background);
  color: var(--pico-primary-inverse);
  font-weight: 600;
  font-size: 0.75rem;
}

.user-avatar-initials.user-avatar-large {
  font-size: 1.5rem;
}

/* === Profile Modal === */

.profile-modal {
  max-width: 500px;
}

.avatar-section {
  margin-bottom: 0.5rem;
}

.avatar-dropzone {
  border: 2px dashed var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  padding: 1rem;
  text-align: center;
  transition: border-color 0.2s;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-dropzone.dragover {
  border-color: var(--pico-primary);
  background: rgba(0, 0, 0, 0.02);
}

.avatar-dropzone-text p {
  margin-bottom: 0.5rem;
  color: var(--pico-muted-color);
  font-size: 0.85rem;
}

.avatar-crop-container {
  max-width: 100%;
}

.avatar-crop-container img {
  max-height: 300px;
}

/* === Presence Warning === */

.presence-warning {
  background: #fff3cd;
  border: 1px solid #ffc107;
  color: #856404;
  padding: 0.75rem 1rem;
  border-radius: var(--pico-border-radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.presence-warning span {
  display: block;
}

.presence-warning span + span {
  margin-top: 0.25rem;
}

.read-only-notice {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid #90caf9;
  border-radius: var(--pico-border-radius);
  background: #e3f2fd;
  color: #0d47a1;
  font-size: 0.95rem;
}

/* === Responsive: mobile sidebar === */

.sidebar-backdrop {
  display: none;
}

@media (max-width: 768px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .mobile-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--pico-muted-border-color);
    background: var(--pico-background-color);
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .hamburger {
    background: none;
    border: none;
    padding: 0.25rem;
    margin: 0;
    cursor: pointer;
    color: var(--pico-color);
    width: auto;
  }

  .admin-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .admin-sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .admin-main {
    padding: 1rem;
  }

  .game-data-table {
    font-size: 0.8rem;
  }

  .toolbar-search {
    max-width: 140px;
  }
}

/* JSON Form Editor */
.json-form-editor {
  margin-bottom: 1rem;
}

.json-form-item {
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  background: #fafafa;
}

.json-form-item .json-form-item {
  background: #f5f5f5;
  border-color: #ccc;
}

.json-form-nested {
  background: #f0f0f0 !important;
  border-color: #bbb !important;
  padding: 0.5rem;
  margin-bottom: 0.25rem;
}

.string-array-editor {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.string-array-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  background: #e8e8e8;
  border-radius: 4px;
  padding: 0.15rem 0.3rem;
}

.string-array-tag select,
.string-array-tag input {
  border: 1px solid #ccc;
  border-radius: 3px;
  background: #fff;
}

.pill {
  display: inline-block;
  background: #e8e8e8;
  border-radius: 12px;
  padding: 0.15rem 0.5rem;
  font-size: 0.8rem;
  line-height: 1.4;
}

/* === Note Cards === */

.note-card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.note-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1rem;
  margin: 0;
  border: 1px solid #e0e0e0;
}

.note-card-body {
  flex: 1;
  min-width: 0;
}

.note-card-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-left: 1rem;
}

.note-image-delete-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* === Revision Diff === */

.revision-diff { font-size: 0.85rem; line-height: 1.6; }
.diff-info { color: #888; font-style: italic; }
.diff-change { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem; padding: 0.15rem 0; }
.diff-label { font-weight: 600; color: #333; white-space: nowrap; }
.diff-old { color: #c62828; text-decoration: line-through; word-break: break-all; }
.diff-arrow { color: #888; flex-shrink: 0; }
.diff-new { color: #2e7d32; font-weight: 500; word-break: break-all; }
