/* Status bar styles */
#status-bar {
  width: 100vw;
  height: 32px;
  background: rgba(34,34,34,0.6);
  color: #b0b0b0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  font-size: 1rem;
  letter-spacing: 1px;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,0.12);
  border-bottom: 1px solid rgba(80,80,80,0.18);
  backdrop-filter: blur(8px);
  padding: 6px 8px;
  gap: 8px;
  overflow: visible;
}

#status-indicator {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin: 0 8px;
  background: #888;
  box-shadow: 0 0 4px 0 rgba(0,0,0,0.18);
  vertical-align: middle;
  transition: background 0.3s;
  flex: 0 0 auto;
}
#status-indicator.connected {
  background: #3ec46d;
}
#status-indicator.disconnected {
  background: #c43e3e;
}

#status-text {
  font-weight: 500;
  font-size: 1rem;
  letter-spacing: 0.5px;
  margin-right: 16px;
  display: flex;
  align-items: center;
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Improved status bar button alignment */
.status-bar-buttons {
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  margin-left: auto;
  gap: 8px;
  flex-shrink: 0;
  overflow: visible;
  min-width: 0;
  padding-right: 30px;
  height: 100%;
}
#edit-toggle, #save-layout, #grid-settings-btn {
  height: 100%;
  margin-top: 0;
  margin-bottom: 0;
  padding-top: 0;
  padding-bottom: 0;
  display: flex;
  align-items: center;
}
#grid-settings-btn { order: 1; }
#save-layout { order: 2; }
#edit-toggle { order: 3; }

/* Responsive: stack buttons on very small screens */
@media (max-width: 500px) {
  .status-bar-buttons {
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    max-width: 90vw;
  }
}

#edit-toggle, #save-layout {
  background: rgba(60,60,60,0.7);
  color: #b0b0b0;
  border: none;
  border-radius: 14px;
  font-size: 0.92rem;
  padding: 2px 10px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  box-shadow: 0 1px 4px 0 rgba(0,0,0,0.10);
  height: 30px;
  display: flex;
  align-items: center;
  min-width: 0;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-left: 0;
  margin-right: 0;
  font-family: inherit;
}
#edit-toggle.edit-btn-floating, #save-layout.edit-btn-floating {
  margin-left: 32px;
}
#edit-toggle:hover, #save-layout:hover {
  background: rgba(80,80,80,0.95);
  color: #fff;
  box-shadow: 0 0 8px 2px #00ffff99, 0 2px 8px 0 rgba(0,0,0,0.10);
  z-index: 2;
}
#edit-toggle {
  margin-right: 0;
}

#grid-settings-btn {
  background: rgba(60,60,60,0.7);
  color: #b0b0b0;
  border: none;
  border-radius: 14px;
  font-size: 0.92rem;
  padding: 2px 10px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  box-shadow: 0 1px 4px 0 rgba(0,0,0,0.10);
  height: 30px;
  display: flex;
  align-items: center;
  min-width: 0;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-left: 0;
  margin-right: 0;
  font-family: inherit;
  visibility: hidden;
}
#grid-settings-btn.edit-visible {
  visibility: visible;
}
#grid-settings-btn:hover {
  background: rgba(80,80,80,0.95);
  color: #fff;
  box-shadow: 0 0 8px 2px #00ffff99, 0 2px 8px 0 rgba(0,0,0,0.10);
  z-index: 2;
}

body, html {
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #181a1b;
}

/* Animation disabling for noanim query param */
body.no-anim *, body.no-anim *:before, body.no-anim *:after {
  transition: none !important;
  animation: none !important;
  box-shadow: none !important;
}
body.no-anim #bg-mesh,
body.no-anim #grid-container,
body.no-anim .glass-panel {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
body.no-anim .grid-button,
body.no-anim #edit-toggle,
body.no-anim #save-layout,
body.no-anim #grid-settings-btn,
body.no-anim #debugImportBtn {
  transition: none !important;
  box-shadow: none !important;
}
/* Keep only press/click feedback */
body.no-anim .grid-button:active,
body.no-anim .grid-button:focus-visible,
body.no-anim #edit-toggle:active,
body.no-anim #save-layout:active,
body.no-anim #grid-settings-btn:active,
body.no-anim #debugImportBtn:active {
  filter: brightness(0.85);
  outline: 2px solid #00ffff;
}

.glass-panel {
  position: relative;
  z-index: 1;
  margin: 0 auto;
  border-radius: 32px;
  background: rgba(30, 32, 40, 0.35);
  box-shadow: 0 8px 32px 0 rgba(0,0,0,0.25);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  padding: 32px 24px;
  max-width: 98vw;
  max-height: 98vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
#bg-mesh {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
  display: block;
}
#main-viewport {
  position: fixed;
  top: 32px;
  left: 0;
  width: 100vw;
  height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  background: none;
  z-index: 1;
}
#grid-container {
  box-sizing: border-box;
  display: grid;
  flex: 1 1 auto;
  width: 100vw;
  height: 100%;
  margin-top: 0;
  padding: 40px;
  align-items: center;
  justify-items: center;
  justify-content: center;
  align-content: center;
  background: rgba(30, 32, 40, 0.025);
  backdrop-filter: blur(42px) saturate(1.38);
  -webkit-backdrop-filter: blur(42px) saturate(1.38);
  border: 1.5px solid rgba(255,255,255,0.22);
  box-shadow: 0 8px 32px 0 rgba(0,0,0,0.18), 0 0 32px 0 rgba(255,255,255,0.10) inset;
  position: relative;
  border-radius: 0;
  gap: 24px;
  grid-template-rows: repeat(var(--grid-rows, 8), 1fr);
  grid-template-columns: repeat(var(--grid-cols, 10), 1fr);
}

.grid-button {
  width: 100%;
  height: 100%;
  min-width: 72px;
  min-height: 72px;
  margin: 0;
  font-size: clamp(0.7vw, 2.5vw, 1.2em);
  background: #23272fbb;
  color: #b0b0b0;
  border: none;
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s, box-shadow 0.2s, transform 0.1s, outline 0.2s;
  box-shadow: 6px 8px 16px 0 rgba(0,0,0,0.48), 1px 2px 8px 0 rgba(0,255,255,0.10) inset;
  border: 1.5px solid rgba(255,255,255,0.18);
  touch-action: manipulation;
  font-family: inherit;
  font-weight: 600;
  outline: none;
  padding: 18px 12px; /* More padding for touch */
  overflow: hidden;
}
.grid-button:hover, .grid-button:focus-visible {
  box-shadow: 0 0 12px 3px #00ffff99, 0 2px 8px 0 rgba(0,0,0,0.10);
  background: #23272fff;
  z-index: 2;
  outline: none;
}
.grid-button:active {
  background: #3a3f4b;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  transform: scale(0.97);
}
.grid-button:disabled {
  background: #23272f;
  opacity: 0.2;
}
.grid-button.drag-over {
  outline: 2px dashed #888;
}
.button-icon {
  font-size: 2.2em;
  margin-bottom: 0.15em;
  display: block;
  line-height: 1;
  pointer-events: none;
}
.grid-button .button-title {
  font-size: 1em;
  line-height: 1.2;
  word-break: break-word;
  overflow-wrap: anywhere;
  text-align: center;
  max-width: 90%;
  margin: 0 auto;
}

.edit-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #23272f;
  color: #b0b0b0;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
  padding: 36px 32px 28px 32px;
  z-index: 1001;
  min-width: 340px;
  max-width: 96vw;
  display: flex;
  flex-direction: column;
  gap: 20px;
  font-size: 1rem;
}
.edit-modal label {
  font-size: 1rem;
  margin-bottom: 4px;
}
.edit-modal input, .edit-modal select {
  width: 100%;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid #444;
  background: #181818;
  color: #b0b0b0;
  font-size: 1rem;
  margin-bottom: 12px;
  font-family: inherit;
}
.edit-modal .modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}
.edit-modal button {
  background: #3a3f4b;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 20px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}
.edit-modal button:hover {
  background: #4e5670;
}
.edit-modal .modal-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: #fff;
}
.edit-modal .modal-close {
  position: absolute;
  top: 10px;
  right: 16px;
  background: none;
  border: none;
  color: #b0b0b0;
  font-size: 1.5rem;
  cursor: pointer;
}
.edit-modal .modal-close:hover {
  color: #fff;
}
.edit-modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
}
.edit-modal .row {
  display: flex;
  gap: 12px;
  align-items: center;
}
.edit-modal .row label {
  margin-bottom: 0;
}
.edit-modal .add-remove-btns {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.edit-modal .add-btn, .edit-modal .remove-btn {
  background: #2e8b57;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 0.98rem;
  cursor: pointer;
  transition: background 0.2s;
}
.edit-modal .remove-btn {
  background: #b03a3a;
}
.edit-modal .add-btn:hover {
  background: #3ebd7d;
}
.edit-modal .remove-btn:hover {
  background: #d44a4a;
}

/* StreamerBot Discovery Overlay */
#sb-discovery-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(10, 10, 20, 0.92);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.25rem;
  font-family: inherit;
  transition: opacity 0.3s;
}
#sb-discovery-overlay .sb-discovery-box {
  background: #23272f;
  border-radius: 18px;
  box-shadow: 0 8px 32px rgba(0,255,255,0.18);
  padding: 36px 32px 28px 32px;
  min-width: 340px;
  max-width: 96vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  border: 2px solid #00ffff88;
}
#sb-discovery-overlay .sb-discovery-progress {
  width: 100%;
  background: #181a1b;
  border-radius: 8px;
  margin: 12px 0 0 0;
  height: 18px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,255,255,0.10) inset;
}
#sb-discovery-overlay .sb-discovery-bar {
  height: 100%;
  background: linear-gradient(90deg, #00ffff 0%, #3ec46d 100%);
  transition: width 0.2s;
}
#sb-discovery-overlay .sb-discovery-btns {
  display: flex;
  gap: 18px;
  margin-top: 18px;
}
#sb-discovery-overlay button {
  background: #00ffff;
  color: #23272f;
  border: none;
  border-radius: 8px;
  padding: 10px 28px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
#sb-discovery-overlay button:hover {
  background: #3ec46d;
  color: #fff;
}

/* Debug Import Button Styling */
#debugImportBtn {
  background: linear-gradient(135deg, #23272f 80%, #00ffff44 100%);
  color: #00ffff;
  border: none;
  border-radius: 12px;
  box-shadow: 0 4px 16px 0 rgba(0,0,0,0.25);
  font-size: 1.1rem;
  font-weight: 600;
  padding: 10px 22px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
  outline: none;
  letter-spacing: 0.03em;
}
#debugImportBtn:hover {
  background: linear-gradient(135deg, #23272f 60%, #00ffff88 100%);
  color: #fff;
  box-shadow: 0 6px 24px 0 rgba(0,255,255,0.18);
}

.empty-cell {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  /* Invisible in normal mode */
  background: none;
  border: none;
  pointer-events: auto;
}
body.edit-mode .empty-cell {
  border: 2px dashed #00ffff44;
  border-radius: 24px;
  background: rgba(0,255,255,0.03);
  transition: border 0.2s, background 0.2s;
  min-width: 24px;
  min-height: 24px;
}
body.edit-mode .empty-cell:hover {
  border-color: #00ffff99;
  background: rgba(0,255,255,0.08);
  cursor: pointer;
}
.hidden-cell {
  visibility: hidden;
  pointer-events: none;
}

/* Remove extra margin from top row buttons */
.grid-button[data-row="0"] {
  margin-top: 0;
}

#save-layout.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
