* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-secondary: #64748b;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}

.app-container {
  width: 100%;
  max-width: 800px;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Mobile: allow page scrolling */
@media (max-width: 768px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .app-container {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .output-wrapper {
    flex: none;
    height: 50vh;
  }

  .output-area {
    flex: none;
    height: 50vh;
  }

  .input-toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .toolbar-left {
    flex: 0 0 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  #modelSelect, #typeSelect {
    width: 47%;
    flex: none;
    font-size: 0.75rem;
    padding: 5px 20px 5px 6px;
    box-sizing: border-box;
  }

  #wordCountSelect {
    width: 47%;
    flex: none;
    font-size: 0.75rem;
    padding: 5px 20px 5px 6px;
    margin-top: 6px;
    box-sizing: border-box;
  }

  .custom-word-input {
    width: 55px;
    flex: none;
    font-size: 0.75rem;
    margin-top: 6px;
    box-sizing: border-box;
  }

  .toolbar-right {
    flex: 0 0 auto;
    margin-left: auto;
  }

  .app-header {
    padding: 16px 0 12px;
  }

  .app-header h1 {
    font-size: 1.3rem;
  }

  .app-header p {
    font-size: 0.8rem;
  }
}

/* Header */
.app-header {
  text-align: center;
  padding: 32px 0 24px;
}

.app-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.app-header p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Output area wrapper with copy button */
.output-wrapper {
  position: relative;
  flex: 1;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.output-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  line-height: 1.8;
  font-size: 0.95rem;
}

.output-area:empty::before {
  content: "通讯稿内容将在此处显示...";
  color: #cbd5e1;
}

.output-area::-webkit-scrollbar {
  width: 6px;
}

.output-area::-webkit-scrollbar-track {
  background: transparent;
}

.output-area::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

/* Copy button */
.btn-copy {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.9);
  color: var(--text-secondary);
  transition: all 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  z-index: 2;
}

.btn-copy:hover {
  background: #eef2ff;
  color: var(--primary);
}

.btn-copy.copied {
  color: #16a34a;
}

/* Input container */
.input-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 16px;
  margin-bottom: 32px;
  overflow: hidden;
}

.input-textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 16px;
  font-size: 0.95rem;
  line-height: 1.6;
  font-family: inherit;
  color: var(--text);
  min-height: calc(1.6em * 2 + 32px);
  max-height: calc(1.6em * 5 + 32px);
  overflow-y: auto;
}

.input-textarea::placeholder {
  color: #94a3b8;
}

.input-textarea::-webkit-scrollbar {
  width: 4px;
}

.input-textarea::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 2px;
}

/* Toolbar */
.input-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-top: 1px solid #f1f5f9;
  background: #fafbfc;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Select dropdowns */
.toolbar-select {
  appearance: none;
  -webkit-appearance: none;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 6px 28px 6px 10px;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: all 0.15s;
  font-family: inherit;
}

.toolbar-select:hover {
  border-color: var(--primary);
  background-color: #eef2ff;
}

.toolbar-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79,70,229,0.15);
}

/* Custom word count input */
.custom-word-input {
  width: 60px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.8rem;
  color: var(--text);
  outline: none;
  font-family: inherit;
  transition: all 0.15s;
}

.custom-word-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79,70,229,0.15);
}

/* Upload & Send buttons */
.btn-icon {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  background: transparent;
  color: var(--text-secondary);
}

.btn-icon:hover {
  background: #f1f5f9;
  color: var(--primary);
}

.btn-send {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: white;
  transition: all 0.15s;
}

.btn-send:hover {
  background: var(--primary-hover);
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* File input hidden */
.file-input {
  display: none;
}

/* File tag */
.file-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #eef2ff;
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  margin: 0 16px;
}

.file-tag .remove-file {
  cursor: pointer;
  font-weight: bold;
  margin-left: 2px;
}

.file-tag .remove-file:hover {
  color: #dc2626;
}

/* Modal overlay */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(2px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 28px;
  width: 480px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease-out;
}

.modal-wide {
  width: 560px;
}

.modal-small {
  width: 360px;
}

@keyframes modalIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal h2 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 20px;
}

.modal h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

.modal label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  margin-top: 14px;
}

.modal label:first-of-type {
  margin-top: 0;
}

.modal input, .modal select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}

.modal input:focus, .modal select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79,70,229,0.15);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  justify-content: flex-end;
}

.btn {
  padding: 8px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: #f1f5f9;
  color: var(--text);
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-verify {
  background: #f0fdf4;
  color: #16a34a;
  border: 1px solid #bbf7d0;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.btn-verify:hover {
  background: #dcfce7;
}

.verify-status {
  font-size: 0.8rem;
  margin-top: 6px;
}

.verify-status.success {
  color: #16a34a;
}

.verify-status.error {
  color: #dc2626;
}

/* Model type tabs */
.model-type-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  border-bottom: 2px solid #e2e8f0;
}

.model-type-tab {
  padding: 8px 16px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-family: inherit;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}

.model-type-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Manage list (models / themes) */
.manage-list {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.manage-list:empty::before {
  content: "暂无已添加项";
  color: #94a3b8;
  font-size: 0.85rem;
  display: block;
  text-align: center;
  padding: 16px;
}

.manage-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: #f8fafc;
}

.manage-item-info {
  flex: 1;
  min-width: 0;
}

.manage-item-name {
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.manage-item-detail {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.manage-item-actions {
  display: flex;
  gap: 6px;
  margin-left: 8px;
  flex-shrink: 0;
}

.btn-sm {
  padding: 4px 10px;
  border: none;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.btn-edit {
  background: #eef2ff;
  color: var(--primary);
}

.btn-edit:hover {
  background: #e0e7ff;
}

.btn-delete {
  background: #fef2f2;
  color: #dc2626;
}

.btn-delete:hover {
  background: #fee2e2;
}

.manage-divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* Reference modal */
.ref-option-group {
  display: flex;
  gap: 8px;
  margin: 16px 0;
}

.ref-option {
  flex: 1;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 0.85rem;
}

.ref-option:hover {
  border-color: var(--primary);
}

.ref-option.active {
  border-color: var(--primary);
  background: #eef2ff;
}

.ref-option svg {
  display: block;
  margin: 0 auto 6px;
}

.ref-content-area {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  min-height: 120px;
  max-height: 250px;
  overflow-y: auto;
  font-size: 0.85rem;
  line-height: 1.6;
  white-space: pre-wrap;
  margin-top: 12px;
  outline: none;
}

.ref-content-area:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79,70,229,0.15);
}

.ref-content-area:empty::before {
  content: "内容预览将在此处显示...";
  color: #94a3b8;
}

.ref-url-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
  font-family: inherit;
  margin-top: 8px;
}

.ref-url-input:focus {
  border-color: var(--primary);
}

.ref-file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.ref-file-hint {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Loading spinner */
.loading {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Typing cursor */
.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--primary);
  margin-left: 2px;
  animation: blink 0.8s infinite;
  vertical-align: text-bottom;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}
