:root {
  --primary: #2463eb;
  --primary-hover: #1d4ed8;
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --border-color: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --feishu-blue: #3370ff;
  --feishu-green: #00b96b;
  --feishu-border: #dee0e3;
  --feishu-bg: #ffffff;
  --feishu-panel-bg: #f5f6f7;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header.navbar {
  height: 60px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
}

.badge {
  font-size: 11px;
  font-weight: 500;
  background: #eff6ff;
  color: var(--primary);
  padding: 2px 7px;
  border-radius: 12px;
  border: 1px solid #bfdbfe;
}

.nav-actions {
  display: flex;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border-color);
  background: #ffffff;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn:hover {
  background: #f1f5f9;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 4px;
}

/* Tab Bar for Mobile / Small Screens */
.mobile-tabbar {
  display: none;
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.mobile-tab {
  flex: 1;
  padding: 10px 0;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
  border-bottom: 2px solid transparent;
}

.mobile-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.layout-main {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

.panel-config {
  width: 530px;
  min-width: 360px;
  background: #ffffff;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 24px;
  gap: 24px;
}

.panel-preview {
  flex: 1;
  background: #f1f5f9;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 24px;
  overflow-y: auto;
}

.preview-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  background: #ffffff;
  padding: 6px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  max-width: 100%;
}

.btn-mode {
  padding: 6px 14px;
  border-radius: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.btn-mode.active {
  background: #eff6ff;
  color: var(--primary);
}

.feishu-simulator-wrap {
  width: 100%;
  max-width: 620px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  border: 1px solid #dee0e3;
  transition: max-width 0.2s ease;
}

.feishu-simulator-wrap.width-compact {
  max-width: 480px;
}

.feishu-simulator-wrap.width-fill {
  max-width: 720px;
}

.feishu-card-header {
  padding: 12px 16px;
  border-bottom: 1px solid #ebebeb;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
}

.feishu-card-header.blue {
  background: #e1eaff;
  color: #1f4e79;
}

.feishu-card-header.green {
  background: #e8f7ed;
  color: #0f6f36;
}

.feishu-card-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 14px;
  color: #1f2329;
}

.feishu-card-body.text-heading {
  font-size: 16px;
  font-weight: 500;
}

.feishu-card-body.text-notation {
  font-size: 12px;
  color: #646a73;
}

.card-cursor {
  display: inline-block;
  width: 2px;
  height: 14px;
  background-color: var(--feishu-blue);
  margin-left: 2px;
  vertical-align: middle;
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.feishu-collapsible {
  border: 1px solid #dee0e3;
  border-radius: 6px;
  overflow: hidden;
  background: #ffffff;
}

.feishu-collapsible-header {
  background: #f5f6f7;
  padding: 8px 12px;
  font-size: 12px;
  color: #646a73;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.feishu-collapsible-header-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.feishu-collapsible-content {
  padding: 10px 12px;
  background: #fafafa;
  font-size: 12px;
  display: none;
  flex-direction: column;
  gap: 6px;
}

.feishu-collapsible.expanded .feishu-collapsible-content {
  display: flex;
}

.tool-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-icon {
  font-size: 14px;
}

.feishu-card-footer {
  border-top: 1px solid #f0f1f2;
  padding-top: 10px;
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: #8f959e;
}

.footer-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.footer-line span {
  display: inline-flex;
  align-items: center;
}

.config-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.form-label {
  font-size: 13px;
  font-weight: 500;
  color: #334155;
}

.form-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.form-input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  font-size: 13px;
  outline: none;
  background: #ffffff;
  color: var(--text-main);
  transition: border-color 0.2s;
}

.form-input:focus {
  border-color: var(--primary);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #cbd5e1;
  transition: .3s;
  border-radius: 22px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary);
}

input:checked + .slider:before {
  transform: translateX(18px);
}

select.form-select {
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  font-size: 13px;
  outline: none;
  background: #ffffff;
}

select.form-select:focus {
  border-color: var(--primary);
}

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

.preset-card {
  border: 1px solid var(--border-color);
  padding: 10px;
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  background: #ffffff;
}

.preset-card:hover {
  border-color: var(--primary);
  background: #f8fafc;
}

.preset-card.active {
  border-color: var(--primary);
  background: #eff6ff;
  font-weight: 600;
  color: var(--primary);
}

.preset-name {
  font-size: 13px;
}

/* ================= Custom Template Details Section ================= */
.template-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.template-card {
  border: 1px solid var(--border-color);
  padding: 10px 12px;
  border-radius: 8px;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

.template-card:hover {
  border-color: var(--primary);
  background: #f8fafc;
}

.template-card.active {
  border-color: var(--primary);
  background: #eff6ff;
}

.template-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
}

.template-header-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.template-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.template-card.active .template-name {
  color: var(--primary);
}

.template-time {
  font-size: 11px;
  color: #94a3b8;
}

.template-meta-badge {
  font-size: 11px;
  color: var(--text-muted);
  background: #f1f5f9;
  padding: 1px 6px;
  border-radius: 4px;
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 320px;
}

.template-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-del-template {
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 15px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.15s;
}

.btn-del-template:hover {
  color: #ef4444;
  background: #fee2e2;
}

/* ================= Footer Drag-and-Drop Per-Row Layout ================= */
.footer-row-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 4px;
}

.footer-row-box {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.footer-row-badge {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
  background: #e2e8f0;
  padding: 2px 8px;
  border-radius: 4px;
}

.footer-row-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.footer-row-dropzone {
  min-height: 42px;
  background: #ffffff;
  border: 1.5px dashed #cbd5e1;
  border-radius: 6px;
  padding: 6px 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.footer-row-dropzone.drag-over {
  background: #eff6ff;
  border-color: var(--primary);
}

.drag-item {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: grab;
  user-select: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
  transition: transform 0.15s, opacity 0.15s;
}

.drag-item:active {
  cursor: grabbing;
}

.drag-item.dragging {
  opacity: 0.4;
  transform: scale(0.95);
}

.drag-item.drop-target {
  border-left: 3px solid var(--primary);
}

.drag-handle {
  color: #94a3b8;
  font-size: 12px;
}

.drag-item .btn-remove {
  cursor: pointer;
  color: #94a3b8;
  font-size: 13px;
  border: none;
  background: transparent;
  padding: 0 2px;
}

.drag-item .btn-remove:hover {
  color: #ef4444;
}

.footer-available-wrap {
  margin-top: 6px;
}

.footer-available-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.footer-add-chip {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: var(--primary);
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.footer-add-chip:hover {
  background: #dbeafe;
  border-color: var(--primary);
}

/* Modal for saving template */
.modal-mask {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal-mask.open {
  display: flex;
}

.modal-box {
  background: #ffffff;
  border-radius: 10px;
  width: 90%;
  max-width: 420px;
  padding: 20px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: 8px;
  background: #0f172a;
  color: #ffffff;
  font-size: 14px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  display: none;
  z-index: 1000;
}

/* ================= Mobile & Small Screen Responsive ================= */
@media (max-width: 768px) {
  header.navbar {
    padding: 0 12px;
  }
  .brand span:first-child {
    font-size: 15px;
  }
  .btn {
    padding: 6px 10px;
    font-size: 12px;
  }

  .mobile-tabbar {
    display: flex;
  }

  .layout-main {
    flex-direction: column;
  }

  .panel-config {
    width: 100%;
    min-width: unset;
    border-right: none;
    padding: 16px;
    display: flex;
  }

  .panel-preview {
    width: 100%;
    padding: 16px 12px;
    display: none;
  }

  body.show-preview .panel-config {
    display: none;
  }
  body.show-preview .panel-preview {
    display: flex;
  }

  .preset-grid {
    grid-template-columns: 1fr;
  }
}

/* Model Brand Icon in Collapsible Header */
.model-brand-icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  vertical-align: middle;
}

.model-brand-icon img,
.model-brand-icon svg {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.model-selector-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  background: #ffffff;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.model-selector-bar label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}
