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

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #d9e1ea;
  --border-strong: #b8c4d0;
  --text: #111827;
  --text-sub: #5f6b7a;
  --text-hint: #8492a6;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #047857;
  --success-soft: #ecfdf5;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --warning-soft: #fff7ed;
  --warning-border: #fed7aa;
  --radius: 8px;
  --shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 28px 16px 48px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 760px; margin: 0 auto; }

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.header-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  color: #0f766e;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 8px;
}

h1 {
  font-size: 30px;
  line-height: 1.2;
  font-weight: 800;
}

.subtitle,
.section-subtitle {
  color: var(--text-sub);
  font-size: 14px;
}

.user-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#user-name {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-sub);
  font-size: 14px;
  font-weight: 600;
}

.workspace { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 14px;
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.section-header h2 {
  font-size: 18px;
  font-weight: 750;
}

.compact-section-header {
  margin-bottom: 12px;
}

.config-divider {
  border-top: 1px solid var(--border);
  margin: 22px 0;
}

.form-stack { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.field label,
.option-group label {
  display: block;
  color: var(--text-sub);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  font: inherit;
  padding: 8px 10px;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

textarea {
  min-height: 220px;
  resize: vertical;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
}

input:disabled {
  background: var(--surface-soft);
  color: var(--text-hint);
}

.field-hint {
  color: var(--text-hint);
  font-size: 12px;
  margin-top: 5px;
}

.field-hint a {
  color: #1d4ed8;
  font-weight: 700;
  text-decoration: none;
}

.field-hint a:hover {
  text-decoration: underline;
}

.api-key-link {
  color: var(--text-sub);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  background: var(--surface-soft);
  margin-bottom: 16px;
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  background: var(--surface-soft);
  margin-bottom: 16px;
}

.mode-tab {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-sub);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.mode-tab.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.08);
}

.auth-tab {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-sub);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.auth-tab.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.08);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text-sub);
  font-size: 14px;
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.notice {
  color: #9a3412;
  background: var(--warning-soft);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
}

.notice a {
  color: #1d4ed8;
  font-weight: 700;
  text-decoration: none;
}

.notice a:hover {
  text-decoration: underline;
}

.form-error,
.form-success {
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
}

.form-error {
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  color: var(--danger);
}

.form-success {
  background: var(--success-soft);
  border: 1px solid #bbf7d0;
  color: var(--success);
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary { background: var(--primary); color: #ffffff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--primary-soft); color: var(--primary); border-color: #bfdbfe; }
.btn-ghost { background: #ffffff; color: var(--text-sub); border-color: var(--border); }
.btn-success { background: var(--success); color: #ffffff; }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.btn-compact { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.full-width { width: 100%; margin-top: 14px; }

.drop-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 34px 18px 28px;
  text-align: center;
  cursor: pointer;
  background: var(--surface-soft);
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-1px);
}

.drop-icon {
  width: 52px;
  height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  background: #ffffff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.drop-title {
  font-size: 16px;
  font-weight: 750;
}

.drop-sub,
.hint {
  color: var(--text-hint);
  font-size: 13px;
}

.hint { margin-top: 7px; }

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 16px;
}

.selected-file {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 14px;
  padding: 10px 12px;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  background: var(--primary-soft);
  font-size: 14px;
}

.file-icon {
  color: var(--primary);
  display: flex;
  flex-shrink: 0;
}

#file-name {
  flex: 1;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#file-size {
  color: var(--text-hint);
  font-size: 12px;
  flex-shrink: 0;
}

.progress-filename {
  text-align: center;
  color: var(--text-sub);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.progress-track {
  flex: 1;
  height: 9px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #0891b2, #059669);
  border-radius: 999px;
  transition: width 0.45s ease;
}

.progress-pct {
  color: var(--primary);
  font-size: 14px;
  font-weight: 800;
  min-width: 42px;
  text-align: right;
}

.status-label,
.chunk-info {
  text-align: center;
  color: var(--text-sub);
  font-size: 14px;
}

.chunk-info {
  color: var(--text-hint);
  font-size: 13px;
  margin-top: 2px;
}

.result-card { border-top: 3px solid var(--success); }
.result-desc { color: var(--text-hint); font-size: 13px; margin-bottom: 14px; }

.result-buttons {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 1fr 1fr;
  gap: 8px;
}

.result-buttons-compact {
  grid-template-columns: 1fr 1fr 1fr;
}

.result-buttons .btn {
  min-width: 0;
  padding-left: 8px;
  padding-right: 8px;
}

.error-card { border-top: 3px solid var(--danger); }

.error-summary {
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  color: var(--danger);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  padding: 10px 12px;
  word-break: break-word;
  margin-bottom: 12px;
}

.error-details summary {
  color: var(--text-sub);
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 8px;
}

.error-details pre {
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: #fff7f7;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  color: #7f1d1d;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 10px;
}

.history-list { display: grid; gap: 8px; }

.history-empty {
  color: var(--text-hint);
  font-size: 14px;
  text-align: center;
  padding: 18px 0;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.history-active {
  border-color: #93c5fd;
  background: var(--primary-soft);
}

.history-file-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--primary);
  background: #ffffff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
}

.history-info {
  flex: 1;
  min-width: 0;
}

.history-name {
  color: var(--text);
  font-size: 14px;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-sub {
  color: var(--text-hint);
  font-size: 12px;
  margin-top: 2px;
}

.history-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.history-status {
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  padding: 2px 8px;
  white-space: nowrap;
}

.status-done { background: var(--success-soft); color: var(--success); }
.status-error { background: var(--danger-soft); color: var(--danger); }
.status-active { background: var(--primary-soft); color: var(--primary); }

.history-actions {
  display: flex;
  gap: 5px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 3px 8px;
  font: inherit;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
  text-decoration: none;
}

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

.admin-create-form {
  margin-bottom: 6px;
}

.admin-list {
  display: grid;
  gap: 8px;
}

.admin-list h3 {
  color: var(--text-sub);
  font-size: 14px;
  margin-bottom: 4px;
}

.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.pdf-figure { margin: 24px auto; text-align: center; max-width: 100%; }
.pdf-figure img { max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.pdf-figure figcaption { font-size: 12px; color: var(--text-hint); margin-top: 6px; }

.hidden { display: none !important; }

@media (max-width: 640px) {
  body { padding: 18px 10px 36px; }
  .app-header { flex-direction: column; }
  h1 { font-size: 25px; }
  .card { padding: 16px; }
  .form-grid,
  .options,
  .result-buttons { grid-template-columns: 1fr; }
  .user-panel { justify-content: flex-start; }
  .section-header { align-items: stretch; flex-direction: column; }
  .history-item { align-items: flex-start; }
  .history-right { align-items: flex-start; }
}
