:root {
  --bg: #0b0f14; --fg: #e6edf3; --muted: #9aa7b2; --accent: #74c0fc; --panel: #121820; --border: #1f2933;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji"; }

/* Default layout - full width centered content */
.app { display: flex; height: 100vh; }

/* Content container - centered with max width when no PDF */
.content-container { 
  background: var(--panel); 
  padding: 32px; 
  display: flex; 
  flex-direction: column; 
  gap: 24px; 
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  align-self: flex-start;
  min-height: 100vh;
}

/* When PDF is loaded - split layout */
.app.pdf-loaded { 
  display: grid; 
  grid-template-columns: 2fr 1fr; 
}

.app.pdf-loaded .content-container {
  max-width: none;
  margin: 0;
  border-right: 1px solid var(--border);
  min-height: auto;
}

.brand { font-weight: 700; letter-spacing: 0.4px; color: var(--muted); margin-bottom: 8px; }

.dropzone { 
  border: 2px dashed var(--border); 
  border-radius: 12px; 
  display: grid; 
  place-items: center; 
  padding: 32px; 
  height: 200px; 
  background: rgba(255,255,255,0.02); 
  transition: border-color .2s, background .2s; 
  cursor: pointer; 
}
.dropzone.dragover { border-color: var(--accent); background: rgba(116,192,252,0.06); }
.dz-inner { text-align: center; color: var(--muted); }
.dz-inner h2 { margin: 0 0 12px; color: var(--fg); font-size: 20px; }

.editor { display: flex; flex-direction: column; gap: 16px; }
.editor label { font-weight: 500; color: var(--fg); }

#contentInput { 
  width: 100%; 
  height: 300px; 
  background: var(--bg); 
  border: 1px solid var(--border); 
  border-radius: 8px; 
  padding: 12px; 
  color: var(--fg); 
  font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
  font-size: 13px;
  line-height: 1.4;
  resize: vertical;
}

.actions { display: flex; justify-content: center; margin: 8px 0; }

.apply-btn { 
  background: var(--accent); 
  color: #000; 
  border: none; 
  border-radius: 12px; 
  padding: 16px 32px; 
  font-size: 16px;
  font-weight: 600;
  cursor: pointer; 
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(116, 192, 252, 0.3);
}
.apply-btn:hover:not(:disabled) { 
  background: #5fb3f9; 
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(116, 192, 252, 0.4);
}
.apply-btn:disabled { 
  background: var(--border); 
  color: var(--muted); 
  cursor: not-allowed; 
  transform: none;
  box-shadow: none;
}

.advanced-section { margin-top: 16px; }

.advanced-link { 
  color: var(--accent); 
  text-decoration: none; 
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.advanced-link:hover { text-decoration: underline; }
.advanced-link::after { 
  content: '▼'; 
  font-size: 10px; 
  transition: transform 0.2s;
}
.advanced-link.expanded::after { transform: rotate(180deg); }

.options { 
  margin-top: 16px; 
  padding: 16px; 
  background: rgba(255,255,255,0.02); 
  border-radius: 8px; 
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.option-item { 
  display: flex; 
  align-items: flex-start; 
  gap: 8px; 
  cursor: pointer;
  font-size: 14px;
  line-height: 1.4;
}
.option-item input[type="checkbox"] { 
  margin-top: 2px;
  flex-shrink: 0;
}
.option-item span { color: var(--muted); }

.hint { font-size: 12px; color: var(--muted); opacity: 0.9; line-height: 1.4; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); font-size: 11px; color: var(--muted); }

.main { position: relative; }
.viewer { position: absolute; inset: 0; display: grid; grid-template-rows: 44px 1fr; }

.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: #0e141b; }
.toolbar .spacer { flex: 1; }
button { background: #19212b; color: var(--fg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; cursor: pointer; }
button:hover { border-color: var(--accent); }

.pdf-frame { width: 100%; height: 100%; border: 0; background: #0a0f15; }

.wm-offcanvas { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; opacity: 0.0001; clip-path: inset(50%); pointer-events: none; user-select: none; z-index: -1; }
.wm-offcanvas[aria-hidden="true"] { display: block; }

.wm-overlay { position: absolute; right: 8px; bottom: 6px; max-width: 40%; pointer-events: none; font-size: 1px; line-height: 1; letter-spacing: -0.25px; opacity: 0.006; filter: blur(0.15px); user-select: none; color: #000; mix-blend-mode: multiply; }

/* Duplicate content warning styles */
.duplicate-warning-header {
  background: #fbbf24;
  color: #000;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.duplicate-warning-button {
  background: #fef3c7;
  border: 1px solid #fbbf24;
  color: #92400e;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.4;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

@media print {
  .wm-offcanvas, .wm-overlay { display: none !important; }
  .toolbar { display: none !important; }
}

/* Responsive design */
@media (max-width: 1024px) {
  .app.pdf-loaded { 
    grid-template-columns: 1fr; 
    grid-template-rows: auto 1fr;
  }
  .content-container { 
    max-height: 50vh; 
    overflow-y: auto;
  }
}
/* OpenAI Modal Styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  color: var(--fg);
  font-size: 20px;
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}

.close-btn:hover {
  color: var(--fg);
  background: rgba(255, 255, 255, 0.1);
}

.modal-body {
  padding: 24px;
}

.form-section {
  margin-bottom: 24px;
}

.form-section:last-child {
  margin-bottom: 0;
}

.form-section label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--fg);
}

.pdf-source-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  transition: background 0.2s;
}

.radio-option:hover {
  background: rgba(255, 255, 255, 0.05);
}

.radio-option input[type="radio"] {
  margin: 0;
}

.upload-section {
  padding: 16px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 8px;
}

.upload-section input[type="file"] {
  width: 100%;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  cursor: pointer;
}

.file-info {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

#openaiPrompt {
  width: 100%;
  min-height: 100px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  color: var(--fg);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  resize: vertical;
}

.prompt-selector {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  font-size: 14px;
  margin-bottom: 16px;
  cursor: pointer;
}

.prompt-selector:focus {
  outline: none;
  border-color: var(--accent);
}

.char-count {
  text-align: right;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.analyze-btn {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

.analyze-btn:hover:not(:disabled) {
  background: #5fb3f9;
  transform: translateY(-1px);
}

.analyze-btn:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
  transform: none;
}

.loading-section {
  text-align: center;
  padding: 32px 16px;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.results-section {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.results-section h3 {
  margin: 0 0 12px;
  color: var(--fg);
  font-size: 16px;
}

.result-meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 16px;
}

.result-prompt,
.result-analysis {
  margin-bottom: 16px;
}

.result-prompt strong,
.result-analysis strong {
  display: block;
  margin-bottom: 8px;
  color: var(--fg);
}

.result-prompt div,
.result-analysis div {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  color: var(--fg);
  line-height: 1.5;
  white-space: pre-wrap;
}

.result-usage {
  text-align: right;
  margin-top: 8px;
}

.error-section {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 8px;
  padding: 16px;
}

.error-message {
  margin-bottom: 16px;
}

.error-message strong {
  display: block;
  margin-bottom: 8px;
  color: #ef4444;
}

.error-message div {
  color: var(--fg);
  line-height: 1.4;
}

.retry-btn {
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.retry-btn:hover {
  background: #dc2626;
}

.test-openai-btn {
  background: #10b981;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-left: 12px;
}

.test-openai-btn:hover:not(:disabled) {
  background: #059669;
  transform: translateY(-1px);
}

.test-openai-btn:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
  transform: none;
}

/* Responsive modal */
@media (max-width: 640px) {
  .modal-content {
    width: 95%;
    margin: 20px;
  }
  
  .modal-header,
  .modal-body {
    padding: 16px;
  }
  
  .pdf-source-options {
    gap: 12px;
  }
}