/* ============================================================
   Sam The Wise — Essay Trial Page
   Simple layout: sidebar with types | big chat center
   ============================================================ */

:root {
  --emerald: #00E5A0;
  --emerald-dim: #00C98C;
  --emerald-dark: #0E4B43;
  --emerald-bg1: #0D2F2B;
  --emerald-bg2: #0A2420;
  --navy: #1a1f36;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-hover: rgba(255, 255, 255, 0.1);
  --surface-active: rgba(255, 255, 255, 0.14);
  --border: rgba(255, 255, 255, 0.1);
  --text-primary: #FFFFFF;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --text-muted: rgba(255, 255, 255, 0.45);
  --success: #22C55E;
  --warning: #F59E0B;
  --error: #EF4444;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--navy);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  height: 100vh;
  overflow: hidden;
}

/* ---- Main Layout: sidebar | chat ---- */

.app-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}

@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
  }
  .sidebar { display: none; }
  .sidebar.mobile-open { display: flex; position: fixed; inset: 0; z-index: 1000; }
}

/* ---- Sidebar ---- */

.sidebar {
  background: var(--emerald-bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 800;
  color: white;
  text-decoration: none;
  margin-bottom: 4px;
}

.sidebar-logo img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

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

.sidebar-section {
  padding: 16px 12px 8px;
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--emerald);
  padding: 0 8px;
  margin-bottom: 8px;
}

/* Quick-grade button */
.quick-grade-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px dashed rgba(0, 229, 160, 0.3);
  background: rgba(0, 229, 160, 0.04);
  color: var(--emerald);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}

.quick-grade-btn:hover {
  background: rgba(0, 229, 160, 0.1);
  border-color: rgba(0, 229, 160, 0.5);
}

.quick-grade-btn.selected {
  background: rgba(0, 229, 160, 0.15);
  border-color: var(--emerald);
  border-style: solid;
}

.quick-grade-btn svg {
  flex-shrink: 0;
  opacity: 0.8;
}

.quick-grade-hint {
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 14px 0;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 12px 4px;
}

/* Upload button in input area */
.upload-btn {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.upload-btn:hover {
  background: var(--surface-hover);
  color: var(--emerald);
  border-color: var(--emerald);
}

/* Drag-and-drop overlay */
.chat-area.drag-over {
  position: relative;
}
.chat-area.drag-over::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 229, 160, 0.08);
  border: 2px dashed var(--emerald);
  border-radius: var(--radius-md);
  pointer-events: none;
  z-index: 10;
}

/* Essay type bars */
.type-bar-row {
  display: flex;
  align-items: center;
  gap: 0;
}

.type-info-link {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.type-bar-row:hover .type-info-link {
  opacity: 1;
}

.type-info-link:hover {
  color: var(--emerald);
  background: var(--surface-hover);
}

.type-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  flex: 1;
  min-width: 0;
  text-align: left;
}

.type-bar:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.type-bar.selected {
  background: rgba(0, 229, 160, 0.12);
  color: var(--emerald);
  font-weight: 600;
}

.type-bar-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.type-bar.selected .type-bar-dot {
  background: var(--emerald);
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.sidebar-footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.sidebar-footer a:hover { color: var(--emerald); }

/* Language switcher in sidebar */
.sidebar-lang {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.sidebar-lang button {
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
}

.sidebar-lang button.active {
  background: var(--emerald);
  color: var(--navy);
  border-color: var(--emerald);
}

/* Mobile menu toggle */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 999;
  width: 40px;
  height: 40px;
  border: none;
  background: var(--surface);
  color: white;
  border-radius: 8px;
  font-size: 20px;
  cursor: pointer;
}

@media (max-width: 768px) {
  .mobile-menu-btn { display: flex; align-items: center; justify-content: center; }
}

/* ---- Chat Area ---- */

.chat-area {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: linear-gradient(180deg, var(--navy) 0%, #141824 100%);
}

/* Chat messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-welcome {
  text-align: center;
  padding: 60px 20px 40px;
  max-width: 500px;
  margin: 0 auto;
}

.chat-welcome-avatar {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  margin-bottom: 16px;
}

.chat-welcome h2 {
  font-size: 22px;
  margin-bottom: 8px;
}

.chat-welcome p {
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.6;
}

/* Message bubbles */
.message {
  display: flex;
  gap: 12px;
  max-width: 700px;
  animation: fadeUp 0.3s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.sam { align-self: flex-start; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: var(--emerald);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
}

.message-bubble {
  padding: 14px 18px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.6;
  max-width: 100%;
}

.message.sam .message-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
}

.message.user .message-bubble {
  background: rgba(0, 229, 160, 0.15);
  border: 1px solid rgba(0, 229, 160, 0.2);
  border-top-right-radius: 4px;
}

/* Typing indicator */
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ---- Feedback in chat ---- */

.feedback-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 600px;
  width: 100%;
}

.feedback-grade-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.grade-badge {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 800;
}

.grade-A { background: linear-gradient(135deg, #22C55E, #16A34A); color: white; }
.grade-B { background: linear-gradient(135deg, #3B82F6, #2563EB); color: white; }
.grade-C { background: linear-gradient(135deg, #F59E0B, #D97706); color: white; }
.grade-D { background: linear-gradient(135deg, #F97316, #EA580C); color: white; }
.grade-F { background: linear-gradient(135deg, #EF4444, #DC2626); color: white; }

.grade-score {
  font-size: 32px;
  font-weight: 800;
  color: var(--emerald);
  font-variant-numeric: tabular-nums;
}

.grade-score span {
  font-size: 16px;
  color: var(--text-muted);
}

.feedback-summary {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 20px;
}

.feedback-section {
  margin-bottom: 16px;
}

.feedback-section h4 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.feedback-section h4.green { color: var(--success); }
.feedback-section h4.amber { color: var(--warning); }

/* Rubric bars */
.rubric-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
}

.rubric-name { flex: 1; font-weight: 500; }

.rubric-bar {
  width: 80px;
  height: 5px;
  background: rgba(255,255,255,0.08);
  border-radius: 3px;
  overflow: hidden;
}

.rubric-fill {
  height: 100%;
  border-radius: 3px;
}

.rubric-val {
  font-weight: 700;
  min-width: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

/* Strength/improvement items */
.fb-item {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.fb-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-top: 8px;
  flex-shrink: 0;
}

.fb-dot.green { background: var(--success); }
.fb-dot.amber { background: var(--warning); }

/* Before/after */
.ba-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 8px 0;
  font-size: 13px;
}

@media (max-width: 600px) { .ba-pair { grid-template-columns: 1fr; } }

.ba-box {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  line-height: 1.5;
}

.ba-before {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.15);
}

.ba-after {
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.15);
}

.ba-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.ba-before .ba-label { color: var(--error); }
.ba-after .ba-label { color: var(--success); }

/* Sam message */
.sam-quote {
  background: linear-gradient(135deg, rgba(0, 229, 160, 0.08), rgba(14, 75, 67, 0.2));
  border: 1px solid rgba(0, 229, 160, 0.15);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  font-style: italic;
}

/* Annotations */
.annotation-card {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  border-left: 3px solid;
  font-size: 13px;
}

.annotation-card.type-strength {
  background: rgba(34, 197, 94, 0.08);
  border-left-color: var(--success);
}

.annotation-card.type-improvement {
  background: rgba(245, 158, 11, 0.08);
  border-left-color: var(--warning);
}

.annotation-card.type-suggestion {
  background: rgba(91, 155, 213, 0.08);
  border-left-color: #5B9BD5;
}

.annotation-type-chip {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.type-strength .annotation-type-chip {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.type-improvement .annotation-type-chip {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

.type-suggestion .annotation-type-chip {
  background: rgba(91, 155, 213, 0.15);
  color: #5B9BD5;
}

.annotation-quote {
  font-style: italic;
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.annotation-comment {
  color: var(--text-secondary);
  line-height: 1.5;
}

/* PDF download button */
.pdf-download-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.pdf-download-btn:hover {
  background: var(--surface-hover);
  border-color: var(--emerald);
  color: var(--emerald);
}

/* ---- Chat Input ---- */

.chat-input-area {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  background: var(--navy);
}

.chat-input-row {
  display: flex;
  gap: 10px;
  max-width: 700px;
  margin: 0 auto;
}

.chat-textarea {
  flex: 1;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  resize: none;
  outline: none;
  min-height: 48px;
  max-height: 200px;
  line-height: 1.5;
}

.chat-textarea:focus { border-color: var(--emerald); }

.chat-textarea::placeholder { color: var(--text-muted); }

.chat-send-btn {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--emerald);
  color: var(--navy);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.chat-send-btn:hover { background: var(--emerald-dim); }
.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.chat-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* ---- Grading progress overlay ---- */

.grading-overlay {
  display: none;
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 28px;
  backdrop-filter: blur(20px);
  min-width: 280px;
  text-align: center;
}

.grading-overlay.visible { display: block; }

.grading-overlay h4 {
  font-size: 14px;
  margin-bottom: 12px;
}

.grading-step-text {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--surface);
  border-top-color: var(--emerald);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ---- Conversion Popup ---- */

.popup-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  z-index: 50000;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.popup-overlay.visible {
  display: flex;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.popup-card {
  background: linear-gradient(135deg, #0D2F2B, #0E4B43);
  border: 1px solid rgba(0, 229, 160, 0.2);
  border-radius: 20px;
  padding: 36px;
  max-width: 480px;
  width: 100%;
  animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.popup-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 30px;
  height: 30px;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.popup-close:hover { background: var(--surface-hover); color: white; }

.popup-card h2 { font-size: 20px; margin-bottom: 10px; line-height: 1.3; }

.popup-body { color: var(--text-secondary); font-size: 14px; margin-bottom: 16px; }

.popup-features {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.popup-features li {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.popup-features li::before {
  content: '\2713';
  color: var(--emerald);
  font-weight: 700;
}

.popup-personal {
  font-size: 14px;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 6px;
}

.popup-signoff { font-weight: 700; margin-bottom: 20px; }

.popup-buttons { display: flex; gap: 10px; flex-wrap: wrap; }

.btn-primary {
  padding: 12px 24px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--emerald);
  color: var(--navy);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex: 1;
  min-width: 140px;
}

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

.btn-secondary {
  padding: 12px 24px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-width: 120px;
}

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

/* ---- Utility ---- */

.hidden { display: none !important; }

.error-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--error);
  color: white;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  z-index: 60000;
  animation: fadeUp 0.3s ease;
}
