/* ROOT COLORS */
:root {
  --color-primary: #0000EE;
  --color-primary-light: #e0e0ff;
  --color-bg: #f5f5f0;
  --color-surface: #ffffff;
  --color-border: #d0d0c8;
  --color-text: #1a1a1a;
  --color-text-muted: #666660;
  --color-success: #2d6a2d;
  --color-warning: #7a5c00;
  --color-warning-bg: #fff8e0;
  --color-error: #8b1a1a;
  --color-copy-flash: #d4edda;
}

/* RESET & BASE */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

/* CONTAINER & LAYOUT */
.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.header {
  background-color: var(--color-surface);
  padding: 16px 20px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.header-left {
  flex: 1;
  display: flex;
  justify-content: center;
}

.logo {
  font-size: 28px;
  font-weight: 700;
  color: var(--color-primary);
  letter-spacing: 0.05em;
}

.header-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.api-key-section {
  display: flex;
  gap: 8px;
  align-items: center;
}

.api-key-input {
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 13px;
  font-family: 'Courier New', monospace;
  width: 200px;
}

.api-key-input.error {
  border-color: var(--color-error);
  background-color: #fff5f5;
}

.api-key-status {
  font-size: 12px;
  white-space: nowrap;
}

.api-key-status.success {
  color: var(--color-success);
}

.api-key-status.error {
  color: var(--color-error);
}

.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 1px;
  background-color: var(--color-border);
}

.panel-left {
  width: 40%;
  background-color: var(--color-surface);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-right {
  width: 60%;
  background-color: var(--color-surface);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* INPUT SECTIONS */
.input-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-section label {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
}

.nim-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background-color: var(--color-primary-light);
  border-radius: 4px;
}

.nim-section label {
  font-size: 12px;
}

.nim-inputs {
  display: flex;
  gap: 8px;
}

.nim-input {
  width: 40px;
  padding: 6px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  text-align: center;
  font-size: 14px;
}

/* TEXTAREA */
.soal-textarea,
.csv-textarea {
  padding: 10px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  resize: vertical;
}

.soal-textarea {
  min-height: 120px;
}

.csv-textarea {
  min-height: 80px;
}

/* DROP ZONE */
.drop-zone {
  border: 2px dashed var(--color-border);
  border-radius: 4px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: background-color 200ms, border-color 200ms;
  background-color: #fafaf8;
}

.drop-zone:hover {
  background-color: var(--color-primary-light);
  border-color: var(--color-primary);
}

.drop-zone.drag-over {
  background-color: var(--color-primary-light);
  border-color: var(--color-primary);
}

.drop-zone p {
  margin: 0;
  font-size: 13px;
  color: var(--color-text);
}

/* IMAGE QUEUE */
#imageQueueList {
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 8px;
  background-color: #fafaf8;
}

.image-queue-item {
  padding: 6px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.image-queue-item-name {
  flex: 1;
  word-break: break-word;
}

.image-queue-item-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-error);
  font-size: 16px;
  padding: 0 4px;
  transition: opacity 200ms;
}

.image-queue-item-remove:hover {
  opacity: 0.7;
}

.image-queue-item-size {
  color: var(--color-text-muted);
  font-size: 11px;
  margin-top: 2px;
}

/* COLLAPSIBLE */
.collapsible-header {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  padding: 8px 0;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  transition: color 200ms;
}

.collapsible-header:hover {
  color: var(--color-primary);
}

.toggle-arrow {
  display: inline-block;
  transition: transform 200ms;
}

.collapsible-header.open .toggle-arrow {
  transform: rotate(90deg);
}

.collapsible-content {
  padding: 8px 0;
}

/* DATA PREVIEW TABLE */
.data-preview {
  overflow-x: auto;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.preview-table th,
.preview-table td {
  border: 1px solid var(--color-border);
  padding: 4px 6px;
  text-align: left;
}

.preview-table th {
  background-color: var(--color-primary-light);
  font-weight: 500;
}

/* BUTTONS */
.btn {
  padding: 8px 16px;
  border: 1px solid var(--color-border);
  background-color: var(--color-surface);
  color: var(--color-text);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: background-color 200ms, border-color 200ms;
}

.btn:hover:not(:disabled) {
  background-color: #eaeae5;
}

.btn:active:not(:disabled) {
  background-color: #d5d5ce;
}

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

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-primary {
  background-color: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
  width: 100%;
  font-weight: 500;
}

.btn-primary:hover:not(:disabled) {
  background-color: #0f2540;
}

.btn-primary:active:not(:disabled) {
  background-color: #081520;
}

/* OUTPUT AREA */
.output-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background-color: #fafaf8;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 14px;
  line-height: 1.7;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.output-area p {
  margin: 12px 0 !important;
  text-align: left;
  white-space: normal;
}

.output-area p:first-child {
  margin-top: 0 !important;
}

.output-area p:last-child {
  margin-bottom: 0 !important;
}

.output-area h1,
.output-area h2,
.output-area h3,
.output-area h4,
.output-area h5,
.output-area h6 {
  margin-top: 20px;
  margin-bottom: 12px;
  color: var(--color-primary);
  clear: both;
}

.output-area h1:first-child,
.output-area h2:first-child,
.output-area h3:first-child {
  margin-top: 0;
}

.output-area h1 {
  font-size: 18px;
  border-bottom: 2px solid var(--color-primary);
  padding-bottom: 8px;
}

.output-area h2 {
  font-size: 16px;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 6px;
}

.output-area h3 {
  font-size: 14px;
  font-weight: 600;
}

.output-area h4 {
  font-size: 13px;
  font-weight: 600;
}

.output-area strong {
  font-weight: 600;
  color: var(--color-primary);
}

.output-area code {
  font-family: 'Courier New', monospace;
  background-color: #e8e8e0;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 13px;
  word-break: break-all;
}

.output-area pre {
  background-color: #e8e8e0;
  padding: 12px;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 12px;
  margin: 12px 0;
  line-height: 1.5;
  border-left: 3px solid var(--color-primary);
}

.output-area pre code {
  background-color: transparent;
  padding: 0;
  font-size: 12px;
}

.output-area table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}

.output-area table th,
.output-area table td {
  border: 1px solid var(--color-border);
  padding: 6px 8px;
  text-align: left;
}

.output-area table th {
  background-color: var(--color-primary-light);
  font-weight: 500;
}

.output-area ul,
.output-area ol {
  margin: 12px 0 12px 24px;
  padding: 0;
}

.output-area li {
  margin: 6px 0;
  line-height: 1.6;
}

.output-area ul ul,
.output-area ol ol,
.output-area ul ol,
.output-area ol ul {
  margin: 6px 0 6px 24px;
}

.output-area blockquote {
  border-left: 4px solid var(--color-primary);
  padding: 8px 0 8px 12px;
  margin: 12px 0;
  color: var(--color-text-muted);
  font-style: italic;
  background-color: #f9f9f6;
}

.output-area hr {
  border: none;
  border-top: 2px solid var(--color-border);
  margin: 20px 0;
}

.output-area strong {
  font-weight: 700;
  color: var(--color-primary);
}

.output-area em {
  font-style: italic;
  color: var(--color-text);
}

/* ANSWER WRAPPER */
.answer-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: #f0f8f0;
  padding: 3px 6px;
  border-radius: 3px;
  border: 1px solid var(--color-success);
}

.answer-value {
  font-family: 'Courier New', monospace;
  font-weight: 600;
  color: var(--color-success);
}

.copy-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-success);
  padding: 0;
  font-size: 12px;
  transition: opacity 200ms;
}

.copy-btn:hover {
  opacity: 0.7;
}

.copy-btn.copied {
  animation: copyFlash 1.5s ease-out;
}

@keyframes copyFlash {
  0% { background-color: var(--color-copy-flash); border-radius: 3px; padding: 0 4px; }
  100% { background-color: transparent; }
}

/* TOOLTIPS */
.tooltip-trigger {
  border-bottom: 1px dotted var(--color-primary);
  cursor: help;
  position: relative;
  display: inline;
}

.tooltip-popup {
  position: absolute;
  bottom: 120%;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--color-primary);
  color: white;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 12px;
  white-space: normal;
  width: 200px;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms;
}

.tooltip-trigger:hover .tooltip-popup,
.tooltip-trigger.active .tooltip-popup {
  opacity: 1;
}

.tooltip-popup::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--color-primary);
}

/* SESSION HISTORY */
.session-history-section {
  border-top: 1px solid var(--color-border);
  padding-top: 12px;
}

.session-history-section h3 {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--color-text);
}

.session-history-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 150px;
  overflow-y: auto;
}

.history-item {
  padding: 6px 8px;
  background-color: #fafaf8;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  transition: background-color 200ms;
}

.history-item:hover {
  background-color: var(--color-primary-light);
}

.history-item-text {
  margin-bottom: 2px;
}

.history-item-time {
  font-size: 11px;
  color: var(--color-text-muted);
}

/* OUTPUT MODE TOGGLE */
.output-mode-row {
  display: flex;
  gap: 16px;
  font-size: 13px;
}

.output-mode-row label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

/* FOOTER */
.footer {
  background-color: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 8px 20px;
  text-align: center;
  font-size: 12px;
  color: var(--color-text-muted);
}

/* BATCH RESULT CONTAINERS */
.batch-result {
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 16px;
  margin-bottom: 16px;
}
.batch-result:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}
.batch-status {
  font-size: 13px;
  color: var(--color-text-muted);
  transition: opacity 200ms;
}
.batch-content p { margin: 12px 0; }
.batch-content p:first-child { margin-top: 0; }
.batch-content p:last-child { margin-bottom: 0; }
.batch-content h1,
.batch-content h2,
.batch-content h3,
.batch-content h4 {
  margin-top: 20px;
  margin-bottom: 12px;
  color: var(--color-primary);
}
.batch-content h1:first-child,
.batch-content h2:first-child,
.batch-content h3:first-child { margin-top: 0; }
.batch-content h1 { font-size: 18px; border-bottom: 2px solid var(--color-primary); padding-bottom: 8px; }
.batch-content h2 { font-size: 16px; border-bottom: 1px solid var(--color-border); padding-bottom: 6px; }
.batch-content h3 { font-size: 14px; font-weight: 600; }
.batch-content strong { font-weight: 700; color: var(--color-primary); }
.batch-content em { font-style: italic; }
.batch-content code {
  font-family: 'Courier New', monospace;
  background-color: #e8e8e0;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 13px;
}
.batch-content pre {
  background-color: #e8e8e0;
  padding: 12px;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 12px;
  margin: 12px 0;
  line-height: 1.5;
  border-left: 3px solid var(--color-primary);
}
.batch-content pre code { background: transparent; padding: 0; }
.batch-content table { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.batch-content table th,
.batch-content table td {
  border: 1px solid var(--color-border);
  padding: 6px 8px;
  text-align: left;
}
.batch-content table th { background-color: var(--color-primary-light); font-weight: 500; }
.batch-content ul,
.batch-content ol { margin: 12px 0 12px 24px; padding: 0; }
.batch-content li { margin: 6px 0; line-height: 1.6; }
.batch-content blockquote {
  border-left: 4px solid var(--color-primary);
  padding: 8px 0 8px 12px;
  margin: 12px 0;
  color: var(--color-text-muted);
  font-style: italic;
}
.batch-content hr { border: none; border-top: 2px solid var(--color-border); margin: 20px 0; }
.batch-content .answer-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: #f0f8f0;
  padding: 3px 6px;
  border-radius: 3px;
  border: 1px solid var(--color-success);
}
.batch-content .answer-value {
  font-family: 'Courier New', monospace;
  font-weight: 600;
  color: var(--color-success);
}
.batch-content .copy-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-success);
  padding: 0;
  font-size: 12px;
}
.batch-content .tooltip-trigger {
  border-bottom: 1px dotted var(--color-primary);
  cursor: help;
  position: relative;
}
.batch-content .tooltip-popup {
  position: absolute;
  bottom: 120%;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--color-primary);
  color: white;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 12px;
  width: 200px;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms;
  white-space: normal;
}
.batch-content .tooltip-trigger:hover .tooltip-popup { opacity: 1; }

/* OCR BANNER */
.ocr-banner {
  position: fixed;
  top: 60px;
  left: 0;
  right: 0;
  background-color: var(--color-warning-bg);
  border-bottom: 2px solid var(--color-warning);
  padding: 12px 20px;
  text-align: center;
  font-size: 13px;
  color: var(--color-warning);
  z-index: 999;
  animation: slideDown 300ms ease-out;
}

@keyframes slideDown {
  from { transform: translateY(-100%); }
  to { transform: translateY(0); }
}

/* LOADING SPINNER */
.loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* RESPONSIVE */
@media (max-width: 1200px) {
  .panel-left {
    width: 35%;
  }
  .panel-right {
    width: 65%;
  }
}

@media (max-width: 1024px) {
  .main-content {
    flex-direction: column;
  }
  .panel-left {
    width: 100%;
    max-height: 40%;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }
  .panel-right {
    width: 100%;
    max-height: 60%;
  }
}

@media (max-width: 768px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
  }
  .api-key-input {
    width: 100%;
  }
  .api-key-section {
    width: 100%;
    flex-wrap: wrap;
  }
}