:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #0b0f19;
  --border: #334155;
  --border-focus: #6366f1;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  background: rgba(30, 41, 59, 0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 12px 24px;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.brand-text h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

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

.engine-status {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  color: #34d399;
  font-weight: 500;
}

.engine-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

/* Main Container */
main {
  max-width: 1400px;
  margin: 20px auto;
  padding: 0 24px;
  width: 100%;
  flex: 1;
}

/* Solver Grid */
.solver-grid {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 950px) {
  .solver-grid { grid-template-columns: 1fr; }
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Input area */
.textarea-box {
  width: 100%;
  height: 190px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 14px;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.6;
  resize: vertical;
  transition: border-color 0.2s;
}

.textarea-box:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

/* Upload Dropzone */
.upload-zone {
  margin-top: 12px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
  background: rgba(11, 15, 25, 0.5);
  cursor: pointer;
  transition: all 0.2s;
}

.upload-zone:hover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.05);
}

.upload-zone p {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Controls */
.control-row {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toggle-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-input);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.toggle-info h4 {
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.toggle-info p {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Switch toggle */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #334155;
  transition: .3s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider { background-color: var(--success); }
input:checked + .slider:before { transform: translateX(20px); }

/* Buttons */
.btn-bar {
  margin-top: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
  padding: 8px 16px;
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: white;
  width: 100%;
  padding: 12px;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #4f46e5, #4338ca);
  transform: translateY(-1px);
}

.btn-success {
  background: #10b981;
  color: white;
}

.btn-success:hover {
  background: #059669;
}

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-outline:hover {
  background: rgba(255,255,255,0.05);
  border-color: var(--text-muted);
}

/* Output Card & Paper View */
.output-card {
  display: flex;
  flex-direction: column;
}

.output-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.2);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: #34d399;
  margin-bottom: 14px;
}

.output-preview {
  background: #ffffff;
  color: #0f172a;
  border-radius: var(--radius-sm);
  padding: 24px;
  font-family: 'Times New Roman', Times, serif;
  font-size: 13pt;
  line-height: 1.3;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.1);
  max-height: 680px;
  overflow-y: auto;
}

.output-preview h3 {
  font-size: 13.5pt;
  font-weight: bold;
  margin-top: 14px;
  margin-bottom: 4px;
  color: #0f172a;
}

.output-preview p {
  margin-bottom: 6px;
  text-align: justify;
}

.output-preview p.indent {
  text-indent: 1.5cm;
  margin-bottom: 6px;
}

/* Bảng Word 4 Cột */
.word-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 16px 0;
  font-size: 12pt;
}

.word-table th, .word-table td {
  border: 1px solid #cbd5e1;
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.word-table th {
  background: #f1f5f9;
  font-weight: bold;
  text-align: center;
  color: #0f172a;
}

.word-table td:first-child {
  background: #f8fafc;
  width: 20%;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #10b981;
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  gap: 8px;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 100;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.setting-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 14px;
}

.setting-box h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.setting-box p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 8px;
}

.model-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin: 10px 0 4px;
}

.model-select {
  width: 100%;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

.model-select:focus {
  outline: none;
  border-color: var(--border-focus);
}

/* Camera & Photo Action Bar */
.camera-action-bar {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.btn-camera {
  flex: 1;
  min-width: 135px;
  padding: 9px 14px;
  font-size: 12.5px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: #ffffff;
  border: none;
  box-shadow: 0 3px 12px rgba(14, 165, 233, 0.25);
}

.btn-camera:hover {
  opacity: 0.94;
  transform: translateY(-1px);
}

.btn-photo {
  flex: 1;
  min-width: 130px;
  padding: 9px 14px;
  font-size: 12.5px;
  background: rgba(16, 185, 129, 0.14);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.btn-photo:hover {
  background: rgba(16, 185, 129, 0.22);
}

.camera-preview-box {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(14, 165, 233, 0.08);
  border: 1px dashed rgba(56, 189, 248, 0.45);
  border-radius: var(--radius-sm);
}

/* Nhãn nguồn tài liệu [Đề cương, I, câu 1] / [Câu hỏi ngắn, I, câu 1] */
.source-tag-badge {
  display: inline-block;
  padding: 2px 8px;
  margin-right: 6px;
  border-radius: 5px;
  font-family: 'Inter', sans-serif;
  font-size: 10.5pt;
  font-weight: 700;
  color: #1e40af;
  background: #dbeafe;
  border: 1px solid #93c5fd;
  vertical-align: baseline;
}

.source-tag-badge.tag-chn {
  color: #065f46;
  background: #d1fae5;
  border-color: #6ee7b7;
}

.source-tag-badge.tag-ai {
  color: #6b21a8;
  background: #f3e8ff;
  border-color: #d8b4fe;
}

/* Responsive Mobile (768px & 480px) */
@media (max-width: 768px) {
  header { padding: 10px 14px; }
  .header-inner { flex-wrap: wrap; gap: 10px; }
  .brand-text h1 { font-size: 15px; }
  .brand-text p { font-size: 11px; }
  main { margin: 12px auto; padding: 0 12px; }
  .card { padding: 14px; }
  .output-preview { padding: 16px 14px; max-height: 75vh; overflow-x: auto; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal-content {
    max-width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 88vh;
    padding: 18px 16px;
  }
  .toast {
    left: 12px;
    right: 12px;
    bottom: 12px;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .camera-action-bar .btn { min-width: 46%; font-size: 12px; padding: 8px 10px; }
  .word-table { font-size: 10.5pt; display: block; overflow-x: auto; }
}
