/* --- Panel Tabs --- */
.panel-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  background: rgba(8, 12, 23, 0.4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding: 8px;
  gap: 6px;
  width: 100%;
  flex: 0 0 auto;
}
.ptab {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 8px 6px;
  text-align: center;
  font-size: 12px;
  font-weight: 750;
  color: #94a3b8;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 10px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  font-family: inherit;
}
.ptab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  min-width: 18px;
  font-size: 15px;
  line-height: 1;
}
.ptab-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ptab:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.03);
}
.ptab.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.18) 0%, rgba(6, 182, 212, 0.12) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(99, 102, 241, 0.25);
}
.panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 16px;
  scrollbar-gutter: stable;
}

/* --- Templates Grid --- */
.tpl-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.tpl-filter-bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.tpl-filter-bar select {
  width: 100%;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: #111726;
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 600;
  outline: none;
}
.tpl-item {
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  background: #111726;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  position: relative;
}
.tpl-item:hover {
  border-color: #6366f1;
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.2);
}
.tpl-item.selected {
  border-color: #06b6d4;
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.35);
}
.tpl-item img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
  background: #090d16;
  transition: filter 0.2s;
}
.tpl-item:hover img {
  filter: brightness(1.05);
}
.tpl-item .tpl-name {
  font-size: 11px;
  padding: 8px;
  color: #94a3b8;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  border-top: 1px solid rgba(255, 255, 255, 0.03);
}
.tpl-badges {
  position: absolute;
  left: 6px;
  right: 6px;
  top: 6px;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  pointer-events: none;
}
.tpl-badge {
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.78);
  color: #e2e8f0;
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  backdrop-filter: blur(8px);
}
.tpl-item:hover::after {
  content: "";
  position: fixed;
  z-index: 500;
  width: 320px;
  height: 240px;
  left: 300px;
  top: 96px;
  border-radius: 10px;
  background: var(--tpl-preview) center / contain no-repeat #0f172a;
  border: 1px solid rgba(255,255,255,.16);
  box-shadow: 0 24px 70px rgba(0,0,0,.45);
  pointer-events: none;
}
.tpl-none {
  border: 2px dashed rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #64748b;
  font-weight: 600;
  min-height: 80px;
  border-radius: 12px;
  cursor: pointer;
  grid-column: 1 / -1;
  transition: all 0.2s;
  gap: 6px;
}
.tpl-none:hover {
  border-color: #6366f1;
  color: #cbd5e1;
  background: rgba(99, 102, 241, 0.03);
}

/* --- Canva-style Tools Grid --- */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.tool-add-card {
  background: #111625;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  padding: 12px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
  text-align: center;
  user-select: none;
  outline: none;
  font-family: inherit;
  color: #e2e8f0;
}
.tool-add-card:hover {
  border-color: #6366f1;
  background: linear-gradient(180deg, #111625 0%, rgba(99, 102, 241, 0.05) 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(99, 102, 241, 0.1);
}
.tool-add-card:active {
  transform: translateY(0);
}
.tool-add-card .tc-icon {
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  color: #818cf8;
  transition: all 0.2s;
}
.tool-add-card:hover .tc-icon {
  background: #6366f1;
  color: #fff;
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.35);
}
.tool-add-card .tc-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* --- Layers Section --- */
.layers-section {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  margin-top: 16px;
  padding-top: 16px;
}
.layers-section h3 {
  font-family: 'Outfit', sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 12px;
}

/* --- Fields List & Chips --- */
.field-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-chip {
  background: #111625;
  border: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}
.field-chip:hover {
  border-color: rgba(99, 102, 241, 0.4);
  background: rgba(255, 255, 255, 0.02);
}
.field-chip.active {
  border-color: #6366f1;
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.15) 0%, rgba(99, 102, 241, 0.03) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.field-chip.locked {
  border-color: rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.08);
}
.field-chip .fc-icon {
  font-size: 14px;
  color: #818cf8;
  background: rgba(255, 255, 255, 0.03);
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.field-chip.active .fc-icon {
  background: #6366f1;
  color: #fff;
}
.field-chip .fc-label {
  font-size: 12px;
  font-weight: 600;
  color: #cbd5e1;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.field-chip .fc-del {
  font-size: 11px;
  color: #475569;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 5px;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.field-chip .fc-del:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
}

/* --- Properties Panel Groupings --- */
.right-panel h3 {
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding-bottom: 8px;
}
.prop-panel-group {
  background: rgba(17, 22, 37, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  margin-bottom: 12px;
  overflow: hidden;
}
.ppg-header {
  background: rgba(17, 22, 37, 0.8);
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  color: #94a3b8;
  font-family: 'Outfit', sans-serif;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.ppg-body {
  padding: 12px 14px;
}
.prop-group {
  margin-bottom: 14px;
}
.prop-group:last-child {
  margin-bottom: 0;
}
.prop-label {
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 6px;
  display: block;
}
.prop-input {
  width: 100%;
  padding: 9px 12px;
  background: #111726;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: #f1f5f9;
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.2s;
}
.prop-input:focus {
  outline: none;
  border-color: #6366f1;
}
.prop-row {
  display: flex;
  gap: 8px;
}
.prop-row-input {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}
.prop-unit {
  position: absolute;
  right: 12px;
  font-size: 11px;
  font-weight: 600;
  color: #475569;
  pointer-events: none;
}
.prop-color {
  width: 44px;
  height: 38px;
  padding: 3px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: #111726;
  cursor: pointer;
}
.prop-select {
  width: 100%;
  padding: 9px 12px;
  background: #111726;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: #f1f5f9;
  font-size: 13px;
  font-family: inherit;
}
.prop-select:focus {
  outline: none;
  border-color: #6366f1;
}
.prop-readonly {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  background: #0f172a;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 8px;
  color: #e2e8f0;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
}
.prop-btn-sm {
  min-height: auto;
  height: 32px;
  font-size: 11px;
  padding: 0 10px;
  border-radius: 6px;
}
.align-btns {
  display: flex;
  gap: 6px;
}
.align-btn {
  flex: 1;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #111726;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: #94a3b8;
  cursor: pointer;
  transition: all 0.2s;
}
.align-btn svg {
  transition: stroke 0.2s;
}
.align-btn:hover, .align-btn.active {
  border-color: #6366f1;
  color: #ffffff;
  background: #1e1b4b;
}

/* --- Properties Empty State Selection --- */
.no-selection {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px 10px;
}
.empty-state-card {
  position: relative;
  background: #111625;
  border: 1px dashed rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 24px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  overflow: hidden;
  max-width: 240px;
  transition: all 0.3s;
}
.empty-state-card:hover {
  border-color: #6366f1;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.08);
}
.esc-glow {
  position: absolute;
  width: 100px;
  height: 100px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, transparent 70%);
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}
.esc-icon {
  font-size: 32px;
  animation: floatAnim 4s ease-in-out infinite;
}
@keyframes floatAnim {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.esc-title {
  font-size: 13px;
  font-weight: 700;
  color: #e2e8f0;
  font-family: 'Outfit', sans-serif;
}
.esc-desc {
  font-size: 11px;
  color: #64748b;
  line-height: 1.5;
}

/* ──────────────────────────────────────────────────────────────
   PREMIUM LIGHT MODE OVERRIDES
   ────────────────────────────────────────────────────────────── */
.panel-tabs {
  background: #f8fafc !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
}
.ptab {
  color: #64748b !important;
  background: #ffffff !important;
  border-color: rgba(148, 163, 184, 0.22) !important;
}
.ptab:hover {
  color: #0f172a !important;
  background: #f8fafc !important;
}
.ptab.active {
  color: #4f46e5 !important;
  background: rgba(79, 70, 229, 0.08) !important;
  border: 1px solid rgba(79, 70, 229, 0.24) !important;
  box-shadow: 0 6px 14px rgba(79, 70, 229, 0.08) !important;
}

.tpl-item {
  background: #f8fafc !important;
}
.tpl-item:hover {
  border-color: #4f46e5 !important;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.1) !important;
}
.tpl-item .tpl-name {
  color: #475569 !important;
  border-top: 1px solid rgba(0, 0, 0, 0.04) !important;
}
.tpl-none {
  border: 2px dashed rgba(0, 0, 0, 0.1) !important;
  color: #64748b !important;
}
.tpl-none:hover {
  border-color: #4f46e5 !important;
  color: #4f46e5 !important;
  background: rgba(79, 70, 229, 0.02) !important;
}

.tool-add-card {
  background: #f8fafc !important;
  border: 1px solid rgba(0, 0, 0, 0.06) !important;
  color: #334155 !important;
}
.tool-add-card:hover {
  border-color: #4f46e5 !important;
  background: linear-gradient(180deg, #f8fafc 0%, rgba(79, 70, 229, 0.04) 100%) !important;
  box-shadow: 0 6px 14px rgba(79, 70, 229, 0.06) !important;
}
.tool-add-card .tc-icon {
  background: rgba(0, 0, 0, 0.03) !important;
  color: #4f46e5 !important;
}
.tool-add-card:hover .tc-icon {
  background: #4f46e5 !important;
  color: #fff !important;
}

.layers-section h3 {
  color: #64748b !important;
}
.field-chip {
  background: #f8fafc !important;
  border: 1px solid rgba(0, 0, 0, 0.04) !important;
}
.field-chip:hover {
  border-color: rgba(79, 70, 229, 0.3) !important;
}
.field-chip.active {
  border-color: #4f46e5 !important;
  background: linear-gradient(90deg, rgba(79, 70, 229, 0.08) 0%, rgba(79, 70, 229, 0.02) 100%) !important;
}
.field-chip .fc-icon {
  background: rgba(0, 0, 0, 0.03) !important;
  color: #4f46e5 !important;
}
.field-chip.active .fc-icon {
  background: #4f46e5 !important;
  color: #fff !important;
}
.field-chip .fc-label {
  color: #334155 !important;
}

.right-panel h3 {
  color: #475569 !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
}
.prop-panel-group {
  background: rgba(0, 0, 0, 0.01) !important;
  border: 1px solid rgba(0, 0, 0, 0.05) !important;
}
.ppg-header {
  background: rgba(0, 0, 0, 0.02) !important;
  color: #475569 !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.03) !important;
}
.prop-label {
  color: #64748b !important;
}
.prop-input, .prop-select {
  background: #ffffff !important;
  border: 1px solid #cbd5e1 !important;
  color: #0f172a !important;
}
.prop-input:focus, .prop-select:focus {
  border-color: #4f46e5 !important;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1) !important;
}
.prop-color {
  border: 1px solid #cbd5e1 !important;
  background: #ffffff !important;
}
.align-btn {
  background: #ffffff !important;
  border: 1px solid #cbd5e1 !important;
  color: #64748b !important;
}
.align-btn:hover, .align-btn.active {
  border-color: #4f46e5 !important;
  color: #4f46e5 !important;
  background: rgba(79, 70, 229, 0.04) !important;
}

.no-selection {
  color: #64748b !important;
}
.empty-state-card {
  background: #f8fafc !important;
  border: 1px dashed rgba(0, 0, 0, 0.12) !important;
}
.empty-state-card:hover {
  border-color: #4f46e5 !important;
}
.esc-title {
  color: #334155 !important;
}
.esc-desc {
  color: #64748b !important;
}

/* ──────────────────────────────────────────────────────────────
   RESPONSIVE DESIGN OVERRIDES
   ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .side-tool-menu {
    order: 2;
    width: 100%;
    flex: 0 0 auto;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding: 10px 14px;
    align-items: center;
    justify-content: flex-start;
  }
  .side-tool-menu .tbtn {
    width: auto;
    height: auto;
    padding: 8px 12px;
    flex: 0 0 auto;
  }
  .side-tool-menu .tool-sep {
    width: 1px;
    height: 34px;
    margin: 0 4px;
    flex: 0 0 auto;
  }
  .panel-tabs {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #0d121f;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 8px;
    gap: 6px;
  }
  .ptab {
    min-height: 48px;
    flex-direction: column;
    gap: 3px;
    padding: 7px 4px;
    font-size: 11px;
  }
  .ptab-icon {
    width: 18px;
    min-width: 18px;
    font-size: 16px;
  }
  .panel-body {
    max-height: 260px;
    padding: 12px;
  }
  .tpl-grid {
    display: flex;
    overflow-x: auto;
    gap: 10px;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }
  .tpl-item,
  .tpl-none {
    width: 140px;
    min-width: 140px;
  }
  .field-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .field-chip {
    min-width: 0;
  }
  .prop-row,
  .align-btns {
    gap: 8px;
  }
  .prop-input,
  .prop-select,
  .prop-readonly,
  .form-row input,
  #d-doctype {
    min-height: 42px;
    font-size: 16px !important;
  }
}
