/* ===========================
   飞书多维表格打印插件 - 样式表
   =========================== */

/* === 基础重置 === */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #f5f5f5;
  color: #333;
  line-height: 1.6;
}

/* === 演示表格区 === */
.demo-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 30px;
  text-align: center;
}

.demo-header h1 {
  font-size: 28px;
  margin-bottom: 10px;
}

.demo-header p {
  opacity: 0.9;
  font-size: 14px;
}

.launcher-btn {
  display: block;
  width: 240px;
  margin: 30px auto;
  padding: 15px 30px;
  background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
  color: white;
  border: none;
  border-radius: 50px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(17, 153, 142, 0.4);
  transition: all 0.3s ease;
}

.launcher-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(17, 153, 142, 0.5);
}

.demo-table-container {
  max-width: 1200px;
  margin: 0 auto 50px;
  padding: 0 20px;
}

.demo-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.demo-table th {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 15px 12px;
  text-align: left;
  font-weight: 500;
}

.demo-table td {
  padding: 12px;
  border-bottom: 1px solid #eee;
}

.demo-table tr:hover {
  background: #f8f9fa;
}

/* === 插件弹窗 === */
.printer-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 10000;
  backdrop-filter: blur(3px);
}

.printer-overlay.active {
  display: flex;
}

.printer-modal {
  width: 95%;
  max-width: 1400px;
  height: 90vh;
  background: white;
  margin: auto;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: scale(0.95) translateY(-20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.printer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 25px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.printer-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.printer-tabs {
  display: flex;
  gap: 10px;
}

.printer-tabs .tab-btn {
  padding: 8px 20px;
  background: rgba(255,255,255,0.2);
  border: none;
  border-radius: 20px;
  color: white;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.printer-tabs .tab-btn.active {
  background: white;
  color: #667eea;
}

.close-btn {
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,0.2);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s;
}

.close-btn:hover {
  background: rgba(255,255,255,0.3);
  transform: rotate(90deg);
}

/* === 插件主体 === */
.printer-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* --- 左侧选项面板 --- */
.options-panel {
  width: 280px;
  background: #f8f9fa;
  border-right: 1px solid #e9ecef;
  overflow-y: auto;
  padding: 20px;
}

.option-section {
  margin-bottom: 20px;
  background: white;
  border-radius: 10px;
  padding: 15px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.option-section h3 {
  font-size: 14px;
  color: #667eea;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.option-row {
  margin-bottom: 10px;
}

.option-row label {
  display: block;
  font-size: 12px;
  color: #666;
  margin-bottom: 5px;
}

.option-row select,
.option-row input[type="text"],
.option-row input[type="number"] {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
  transition: border-color 0.2s;
}

.option-row select:focus,
.option-row input:focus {
  outline: none;
  border-color: #667eea;
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  cursor: pointer;
}

.checkbox-item input {
  cursor: pointer;
}

/* --- 中间画布区 --- */
.canvas-panel {
  flex: 1;
  background: #e9ecef;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.canvas-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 15px;
  background: white;
  border-bottom: 1px solid #e9ecef;
}

.toolbar-left {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar-btn {
  padding: 6px 12px;
  background: #f1f3f5;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 4px;
}

.toolbar-btn:hover {
  background: #e9ecef;
  border-color: #667eea;
}

.toolbar-btn.active {
  background: #667eea;
  color: white;
  border-color: #667eea;
}

.toolbar-right {
  display: flex;
  gap: 8px;
}

.canvas-container {
  flex: 1;
  overflow: auto;
  padding: 20px;
  display: flex;
  justify-content: center;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 19px,
    #ddd 20px
  );
  background: repeating-linear-gradient(
    90deg,
    transparent,
    transparent 19px,
    #ddd 20px
  );
}

.canvas-wrapper {
  position: relative;
  background: white;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  transform-origin: top center;
}

.canvas-element {
  position: absolute;
  cursor: move;
  user-select: none;
  min-width: 50px;
  min-height: 30px;
}

.canvas-element.selected {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

.canvas-element .element-handle {
  display: none;
  position: absolute;
  width: 10px;
  height: 10px;
  background: #667eea;
  border: 2px solid white;
  border-radius: 2px;
}

.canvas-element.selected .element-handle {
  display: block;
}

.canvas-element .handle-nw { top: -5px; left: -5px; cursor: nw-resize; }
.canvas-element .handle-ne { top: -5px; right: -5px; cursor: ne-resize; }
.canvas-element .handle-sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.canvas-element .handle-se { bottom: -5px; right: -5px; cursor: se-resize; }

.element-toolbar {
  position: absolute;
  top: -40px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  background: #333;
  border-radius: 6px;
  padding: 5px 8px;
  gap: 5px;
  white-space: nowrap;
}

.canvas-element.selected .element-toolbar {
  display: flex;
}

.element-toolbar button {
  padding: 4px 8px;
  background: transparent;
  border: none;
  color: white;
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
}

.element-toolbar button:hover {
  background: #667eea;
}

/* --- 右侧预览区 --- */
.preview-panel {
  width: 350px;
  background: white;
  border-left: 1px solid #e9ecef;
  display: flex;
  flex-direction: column;
}

.preview-header {
  padding: 12px 15px;
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.preview-header h3 {
  font-size: 14px;
  color: #333;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.zoom-controls button {
  width: 28px;
  height: 28px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: 16px;
}

.zoom-controls span {
  font-size: 12px;
  min-width: 45px;
  text-align: center;
}

.preview-content {
  flex: 1;
  overflow: auto;
  padding: 20px;
  display: flex;
  justify-content: center;
  background: #e9ecef;
}

.preview-wrapper {
  background: white;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  overflow: hidden;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
}

/* --- 底部操作栏 --- */
.printer-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 15px 25px;
  background: #f8f9fa;
  border-top: 1px solid #e9ecef;
}

.footer-btn {
  padding: 10px 25px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.footer-btn.secondary {
  background: #e9ecef;
  color: #666;
}

.footer-btn.secondary:hover {
  background: #dee2e6;
}

.footer-btn.primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.footer-btn.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

/* === 打印样式 === */
.print-theme-nature {
  font-family: 'Times New Roman', Georgia, serif;
  font-size: 11pt;
  color: #333;
}

.print-theme-nature .print-table {
  border-collapse: collapse;
  width: 100%;
}

.print-theme-nature .print-table th {
  background: #f8f8f8;
  border: 1px solid #333;
  padding: 8px;
  text-align: left;
  font-weight: bold;
}

.print-theme-nature .print-table td {
  border: 1px solid #999;
  padding: 6px;
}

.print-theme-business {
  font-family: Arial, sans-serif;
  font-size: 10pt;
  color: #333;
}

.print-theme-business .print-table {
  border-collapse: collapse;
  width: 100%;
}

.print-theme-business .print-table th {
  background: #2c3e50;
  color: white;
  border: 1px solid #2c3e50;
  padding: 8px;
}

.print-theme-business .print-table td {
  border: 1px solid #bdc3c7;
  padding: 6px;
}

.print-theme-minimal {
  font-family: Arial, sans-serif;
  font-size: 10pt;
}

.print-theme-minimal .print-table {
  border-collapse: collapse;
  width: 100%;
}

.print-theme-minimal .print-table th {
  border-bottom: 2px solid #333;
  padding: 6px;
  text-align: left;
}

.print-theme-minimal .print-table td {
  border: none;
  border-bottom: 1px solid #eee;
  padding: 6px;
}

.print-theme-colorful {
  font-family: Arial, sans-serif;
  font-size: 10pt;
}

.print-theme-colorful .print-table {
  border-collapse: collapse;
  width: 100%;
}

.print-theme-colorful .print-table th {
  background: #3498db;
  color: white;
  padding: 8px;
}

.print-theme-colorful .print-table td {
  border: 1px solid #ecf0f1;
  padding: 6px;
}

/* === 打印媒体查询 === */
@media print {
  body * {
    visibility: hidden;
  }
  
  #printFrame, #printFrame * {
    visibility: visible;
  }
  
  #printFrame {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }
  
  .print-table th {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
  
  .print-table td {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}

/* === 隐藏的打印框架 === */
#printFrame {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 210mm;
  padding: 10mm;
}

/* === 预设模板选择 === */
.template-presets {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.template-preset {
  padding: 10px;
  border: 2px solid #e9ecef;
  border-radius: 8px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.template-preset:hover {
  border-color: #667eea;
}

.template-preset.active {
  border-color: #667eea;
  background: #f0f3ff;
}

.template-preset-icon {
  font-size: 24px;
  margin-bottom: 5px;
}

/* === 元素类型图标 === */
.element-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f3f5;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  font-size: 18px;
  cursor: grab;
  transition: all 0.2s;
}

.element-icon:hover {
  background: #667eea;
  color: white;
  border-color: #667eea;
}

.dragging {
  opacity: 0.5;
}

/* === 属性面板 === */
.properties-panel {
  padding: 15px;
  border-top: 1px solid #e9ecef;
  background: #f8f9fa;
}

.properties-panel h4 {
  font-size: 13px;
  color: #333;
  margin-bottom: 10px;
}

.prop-row {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.prop-row label {
  width: 70px;
  font-size: 12px;
  color: #666;
}

.prop-row input,
.prop-row select {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 12px;
}

.prop-row input[type="color"] {
  width: 50px;
  height: 28px;
  padding: 2px;
}

/* === 提示文字 === */
.helper-text {
  font-size: 11px;
  color: #999;
  margin-top: 5px;
}

/* === 加载动画 === */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.loading::after {
  content: '';
  width: 30px;
  height: 30px;
  border: 3px solid #e9ecef;
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === 响应式 === */
@media (max-width: 1200px) {
  .printer-body {
    flex-direction: column;
  }
  
  .options-panel {
    width: 100%;
    max-height: 200px;
  }
  
  .preview-panel {
    width: 100%;
    max-height: 300px;
  }
}

@media (max-width: 768px) {
  .printer-modal {
    width: 100%;
    height: 100vh;
    border-radius: 0;
  }
}

/* === 自动连接状态样式 === */
.auto-connect-state {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 20px;
  background: linear-gradient(135deg, #f0f3ff 0%, #e8f0ff 100%);
  border: 1px solid #667eea;
  border-radius: 12px;
  margin-bottom: 20px;
  animation: pulseBg 2s ease-in-out infinite;
}

@keyframes pulseBg {
  0%, 100% { background: linear-gradient(135deg, #f0f3ff 0%, #e8f0ff 100%); }
  50% { background: linear-gradient(135deg, #e8f0ff 0%, #f0f3ff 100%); }
}

.auto-connect-icon {
  font-size: 32px;
  animation: bounce 1s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.auto-connect-content {
  flex: 1;
}

.auto-connect-title {
  font-size: 16px;
  font-weight: 600;
  color: #667eea;
  margin-bottom: 4px;
}

.auto-connect-message {
  font-size: 13px;
  color: #666;
}

.auto-connect-state.success {
  background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
  border-color: #28a745;
  animation: none;
}

.auto-connect-state.success .auto-connect-title {
  color: #28a745;
}

.auto-connect-state.error {
  background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
  border-color: #dc3545;
  animation: none;
}

.auto-connect-state.error .auto-connect-title {
  color: #dc3545;
}

/* === 记住登录选项 === */
.remember-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
}

.remember-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: #666;
}

.remember-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: #667eea;
}

.switch-manual-btn {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 12px;
  color: #666;
  cursor: pointer;
  transition: all 0.2s;
}

.switch-manual-btn:hover {
  border-color: #667eea;
  color: #667eea;
}

/* === 连接状态动画 === */
@keyframes successPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

.connection-success {
  animation: successPulse 0.5s ease-out;
}

/* === 表单容器过渡效果 === */
#manualForm {
  transition: all 0.3s ease;
}

#manualForm.hidden {
  opacity: 0.5;
  pointer-events: none;
}

/* ==================== 授权引导样式 ==================== */
.auth-guide-section {
  display: flex;
  align-items: center;
  gap: 15px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 20px;
  border-radius: 12px;
  margin-bottom: 20px;
  animation: slideIn 0.3s ease;
}

.auth-guide-icon {
  font-size: 40px;
  flex-shrink: 0;
}

.auth-guide-content {
  flex: 1;
}

.auth-guide-title {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 5px;
}

.auth-guide-desc {
  font-size: 13px;
  opacity: 0.9;
  margin-bottom: 12px;
}

.go-to-auth-btn {
  background: white;
  color: #667eea;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 14px;
}

.go-to-auth-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.open-auth-page-btn {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 13px;
  margin-left: auto;
}

.open-auth-page-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.remember-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.remember-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  color: #666;
}

.remember-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.switch-manual-btn {
  background: #f0f0f0;
  color: #666;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s;
  margin-left: auto;
}

.switch-manual-btn:hover {
  background: #e0e0e0;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
