@font-face {
  font-family: 'Prompt';
  src: url('/fonts/Prompt-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
}
@font-face {
  font-family: 'Prompt';
  src: url('/fonts/Prompt-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
}
html {
  font-size: 13px;
}

body {
  max-width: 1000px;
  background-color: #111;
  color: #e1e7ec;
  font-weight: 300;
  font-family: 'Prompt', sans-serif;
  margin: 0 auto;
}

main {
  display: grid;
  grid-template-columns: 1fr 280px;
  /* gap: 12px; */
  align-items: start;
}

.main-left {
  min-width: 0;
}
main .main-right{
  padding:0;
  background-color: var(--main-color);
  margin-top: 5px;
}

h3 {
  font-weight: 500;
  color: #00d2ff;
  font-family: 'Prompt', 'Sarabun', sans-serif;
  font-size: 1.15rem;
  letter-spacing: 0.5px;
}

.container {
  max-width: 100%;
  margin: auto;
  margin-top: 5px;
}

/* Header Connection Bar */
.header-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1a1e29;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid #2d3748;
  margin-bottom: 12px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.header-panel .status-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: #252a38;
  color: #8892b0;
  border: 1px solid #363d52;
}

.status-badge.connected {
  background: rgba(76, 175, 80, 0.15);
  color: #4CAF50;
  border-color: #4CAF50;
}

.status-badge.wifi-connected {
  background: rgba(0, 210, 255, 0.15);
  color: #00d2ff;
  border-color: #00d2ff;
}

.status-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f44336;
}

.status-badge.connected .dot {
  background: #4CAF50;
  box-shadow: 0 0 6px #4CAF50;
}

.status-badge.wifi-connected .dot {
  background: #00d2ff;
  box-shadow: 0 0 6px #00d2ff;
}

.btn-ble-connect {
  background: linear-gradient(135deg, #0072ff, #00c6ff);
  color: white;
  border: none;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(0, 114, 255, 0.3);
}

.btn-ble-connect:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 114, 255, 0.5);
}

.btn-ble-connect.connected {
  background: #333;
  color: #ff5252;
  border: 1px solid #555;
  box-shadow: none;
}

/* Layer & OS Selector Bar */
.layer-selector {
  margin-bottom: 12px;
  background: #1a1e29;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid #2d3748;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.selector-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.selector-group.flex-grow {
  flex-grow: 1;
}

.layer-selector label {
  color: #8892b0;
  font-size: 12px;
  font-weight: 500;
}

.layer-btn-group {
  display: flex;
  gap: 6px;
}

.layer-tab-btn {
  background: #252a38;
  color: #ccd6f6;
  border: 1px solid #363d52;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: 0.2s;
}

.layer-tab-btn:hover {
  background: #2e3547;
  border-color: #00d2ff;
}

.layer-tab-btn.active {
  background: #00d2ff;
  color: #0b101b;
  border-color: #00d2ff;
  box-shadow: 0 0 10px rgba(0, 210, 255, 0.4);
}

.layer-selector input[type="text"],
.layer-selector select {
  background: #12151e;
  color: #fff;
  border: 1px solid #363d52;
  padding: 8px 12px;
  border-radius: 6px;
  font-family: 'Prompt', sans-serif;
  font-size: 13px;
}

.layer-selector input[type="text"]:focus,
.layer-selector select:focus {
  outline: none;
  border-color: #00d2ff;
}

/* Pad Layout & 3x5 Grid */
.pad-layout {
  background: #141721;
  padding: 16px;
  border-radius: 10px;
  border: 1px solid #2d3748;
  margin-bottom: 12px;
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
}

.grid-header-note {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 11px;
  color: #718096;
}

.matrix-grid-3x5 {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

/* Stream Deck Button Card */
.deck-btn {
  position: relative;
  background: #1e2230;
  border: 2px solid #2d3748;
  border-radius: 8px;
  min-height: 82px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.deck-btn:hover {
  background: #252b3d;
  border-color: #4a5568;
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0,0,0,0.4);
}

.deck-btn.active {
  border-color: #00d2ff;
  background: #1c2e42;
  box-shadow: 0 0 12px rgba(0, 210, 255, 0.5);
}

.deck-btn .key-index-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  background: rgba(15, 23, 42, 0.9);
  border: 1.5px solid #00d2ff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9.5px;
  font-weight: 700;
  color: #00d2ff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace;
  box-shadow: 0 0 6px rgba(0, 210, 255, 0.35);
  pointer-events: none;
  z-index: 2;
  transition: all 0.2s ease;
}

.deck-btn:hover .key-index-badge {
  border-color: #38bdf8;
  color: #ffffff;
  background: rgba(0, 210, 255, 0.25);
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.6);
}

.deck-btn.active .key-index-badge {
  background: #00d2ff;
  color: #0b1329;
  border-color: #ffffff;
  box-shadow: 0 0 10px rgba(0, 210, 255, 0.8);
}

.deck-btn .deck-icon-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  margin-bottom: 3px;
  color: #00d2ff;
}

.deck-btn .deck-icon-preview svg {
  width: 24px;
  height: 24px;
}

.deck-btn .deck-label {
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  text-align: center;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 95%;
}

.deck-btn .deck-sublabel {
  font-size: 10px;
  color: #8892b0;
  text-align: center;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 95%;
}

/* Sortable Drag Ghost */
.sortable-ghost {
  opacity: 0.4;
  background: #00d2ff !important;
  border: 2px dashed #fff !important;
}

.sortable-chosen {
  background: #2a344a !important;
}

/* Dual Encoders Section */
.encoders-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #262c3d;
}

.encoder-box {
  background: #181d29;
  border: 1px solid #2d3748;
  border-radius: 8px;
  padding: 8px 12px;
}

.encoder-box-header {
  font-size: 12px;
  font-weight: 600;
  color: #00d2ff;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.encoder-subgrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.encoder-btn {
  background: #212636;
  border: 1px solid #363d52;
  border-radius: 6px;
  padding: 6px 4px;
  text-align: center;
  cursor: pointer;
  transition: 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.encoder-btn:hover {
  background: #293044;
  border-color: #00d2ff;
}

.encoder-btn.active {
  border-color: #00d2ff;
  background: #17324d;
  box-shadow: 0 0 10px rgba(0, 210, 255, 0.4);
}

.encoder-btn strong {
  font-size: 10px;
  color: #ccd6f6;
  margin-bottom: 2px;
}

.encoder-btn .enc-val {
  font-size: 9px;
  color: #00ff87;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Edit Panel */
.edit-panel {
  background: #1a1e29;
  border: 1px solid #2d3748;
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.edit-panel h4 {
  font-size: 14px;
  margin-top: 0;
  margin-bottom: 12px;
  font-weight: 600;
}

.form-group {
  margin-bottom: 10px;
}

.form-group label {
  display: block;
  margin-bottom: 4px;
  color: #8892b0;
  font-size: 12px;
  font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group select {
  width: 100%;
  padding: 8px 12px;
  background: #12151e;
  border: 1px solid #363d52;
  color: #00ff87;
  border-radius: 6px;
  font-family: 'Prompt', monospace;
  font-size: 13px;
  box-sizing: border-box;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: #00d2ff;
}

.icon-selector-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
  background: #12151e;
  border: 1px solid #363d52;
  border-radius: 6px;
  padding: 8px;
  margin-top: 5px;
}

.icon-choice-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 2px;
  border-radius: 4px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: 0.15s;
}

.icon-choice-item:hover {
  background: #252b3d;
  border-color: #4a5568;
}

.icon-choice-item.selected {
  background: rgba(0, 210, 255, 0.2);
  border-color: #00d2ff;
  color: #00d2ff;
}

.icon-choice-item svg {
  width: 20px;
  height: 20px;
  margin-bottom: 2px;
}

.icon-choice-item span {
  font-size: 9px;
  color: #8892b0;
}

/* Shortcut Catcher */
.shortcut-catcher {
  display: flex;
  gap: 8px;
}

.shortcut-catcher input {
  flex-grow: 1;
  cursor: pointer;
}

/* Buttons & Action Bar */
button {
  font-family: 'Prompt', sans-serif;
  transition: 0.2s;
}

.btn-primary {
  background: linear-gradient(135deg, #00d2ff, #0072ff);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-success {
  background: #4CAF50;
  color: white;
  border: none;
  padding: 9px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

.btn-success:hover {
  background: #43a047;
}

.btn-secondary {
  background: #2d3748;
  color: #ccd6f6;
  border: 1px solid #4a5568;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
}

.btn-secondary:hover {
  background: #3a455f;
}

.footer-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1a1e29;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid #2d3748;
}

/* Modals */
.deck-modal {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.8);
  z-index: 10000;
  align-items: center;
  justify-content: center;
}

.deck-modal-box {
  background: #1a1e29;
  border: 1px solid #2d3748;
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 440px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.7);
}

.deck-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.deck-modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.deck-modal-close {
  background: transparent;
  border: none;
  color: #8892b0;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}

.deck-modal-close:hover {
  color: #fff;
}

/* Success Overlay */
.save-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  z-index: 10001;
  align-items: center;
  justify-content: center;
}

.save-box {
  background: #1a1e29;
  border: 1px solid #4CAF50;
  padding: 24px 36px;
  border-radius: 12px;
  text-align: center;
  color: white;
  box-shadow: 0 10px 30px rgba(0,0,0,0.8);
}

.save-box i {
  font-size: 44px;
  color: #4CAF50;
  margin-bottom: 12px;
}

/* =========================================
   Icon Library Sidebar (.icon-library-sidebar)
   ========================================= */
.icon-library-sidebar {
  background: transparent;
  /* border: 1px solid #2d3748; */
  /* border-radius: 8px; */
  /* padding: 10px; */
  position: sticky;
  top: 15px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  /* box-shadow: none; */
  box-sizing: border-box;
  overflow-x: hidden;
  width: 100%;
}

.icon-palette-header {
  margin-bottom: 8px;
}

.palette-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 13px;
  color: #fff;
  margin-bottom: 8px;
}

.icon-count-badge {
  background: rgba(0, 210, 255, 0.15);
  color: #00d2ff;
  border: 1px solid #00d2ff;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
}

.icon-search-wrap input {
  width: 100%;
  padding: 8px 12px;
  background: #10131c;
  border: 1px solid #363d52;
  border-radius: 6px;
  color: #00ff87;
  font-family: 'Prompt', sans-serif;
  font-size: 12px;
  box-sizing: border-box;
}

.icon-search-wrap input:focus {
  outline: none;
  border-color: #00d2ff;
}

.icon-category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.cat-chip {
  background: #232838;
  color: #8892b0;
  border: 1px solid #363d52;
  padding: 3px 8px;
  border-radius: 14px;
  font-size: 10px;
  cursor: pointer;
  transition: 0.15s;
}

.cat-chip:hover {
  background: #2c3347;
  color: #fff;
}

.cat-chip.active {
  background: #00d2ff;
  color: #0b101b;
  border-color: #00d2ff;
  font-weight: 600;
}

.drag-hint {
  font-size: 10px;
  color: #718096;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.icon-library-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
  flex: 1;
  margin-top: 8px;
  max-height: calc(100vh - 230px);
  box-sizing: border-box;
}

.icon-palette-item {
  background: #202534;
  border: 1px solid #2f374a;
  border-radius: 5px;
  padding: 5px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: grab;
  user-select: none;
  transition: all 0.15s ease;
  position: relative;
  min-width: 0;
  box-sizing: border-box;
}

.icon-palette-item:active {
  cursor: grabbing;
}

.icon-palette-item:hover {
  background: #293043;
  border-color: #00d2ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 210, 255, 0.25);
}

.icon-palette-item i,
.icon-palette-item svg {
  font-size: 14px;
  width: 16px;
  height: 16px;
  color: #00d2ff;
  margin-bottom: 2px;
}

.icon-palette-item span {
  font-size: 8px;
  color: #a0aec0;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  display: block;
  box-sizing: border-box;
  padding: 0 1px;
}

/* Drag over highlight on 3x5 button */
.deck-btn.drag-over {
  border-color: #00ff87 !important;
  background: rgba(0, 255, 135, 0.15) !important;
  transform: scale(1.04);
  box-shadow: 0 0 15px rgba(0, 255, 135, 0.6) !important;
}

/* Responsive */
@media screen and (max-width: 1024px) {
  main {
    grid-template-columns: 1fr;
  }
  .icon-library-sidebar {
    position: static;
    max-height: 480px;
  }
  .icon-library-grid {
    grid-template-columns: repeat(6, 1fr);
    max-height: 300px;
  }
}

@media screen and (max-width: 768px) {
  .matrix-grid-3x5 {
    grid-template-columns: repeat(3, 1fr);
  }
  .encoders-panel {
    grid-template-columns: 1fr;
  }
  .icon-selector-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .icon-library-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Ensure SweetAlert2 is always on top of modals */
.swal2-container {
  z-index: 99999 !important;
}
