/* styles.css - LabAI */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@400;500;600;700&family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg-main: #f1f2f4;
  --bg-card: #ffffff;
  --bg-hover: #fafafa;
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --text-tertiary: #999999;
  --border: #e0e0e0;
  --border-light: #efefef;
  --chart-green: #40c057;
  --chart-dark: #1a1a1a;
  --chart-orange: #fd7e14;
  --chart-blue: #339af0;
  --chart-brown: #be6e46;
  --chart-purple: #7950f2;
  --chart-pink: #f06595;
  --chart-teal: #20c997;
  --chart-red: #c92a2a;
  --sidebar-width: 200px;
}

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.4;
  font-size: 14px;
}

/* ============================
   LAYOUT - FIX UTAMA
   ============================ */
.layout {
  display: flex;
  min-height: 100vh;
}

/* Left Sidebar */
.sidebar {
  background: var(--bg-hover);
  border-right: 1px solid var(--border);
  padding: 16px;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  overflow-y: auto;
  flex-shrink: 0;
  z-index: 100;
}

.sidebar-header {
  font-family: 'Cormorant Garamond', serif;
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 20px;
  padding: 8px 10px;
  color: var(--text-primary);
}

.menu-group {
  margin-bottom: 20px;
}

.menu-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  padding: 0 10px;
}

.menu-item {
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 2px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.15s;
  text-decoration: none;
}

.menu-item:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.menu-item.active {
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.menu-item .count {
  font-size: 10px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-tertiary);
  background: var(--bg-main);
  padding: 2px 5px;
  border-radius: 4px;
}

/* Main Content - FIX: gunakan margin-left + width auto */
main {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

.main-content {
  padding: 20px;
  min-width: 900px; /* minimum supaya tabel tidak collapse */
}

/* ============================
   TOOLBAR
   ============================ */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
  gap: 12px;
}

.page-heading {
  font-family: 'Cormorant Garamond', serif;
  font-size: 26px;
  font-weight: 600;
  color: var(--text-primary);
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* ============================
   BUTTONS
   ============================ */
.btn {
  padding: 7px 14px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-primary);
  text-decoration: none;
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--text-secondary);
}

.btn-primary {
  background: var(--text-primary);
  color: white;
  border-color: var(--text-primary);
}

.btn-primary:hover {
  background: #2d2d2d;
  border-color: #2d2d2d;
  color: white;
}

.btn-success {
  background: var(--chart-green);
  color: white;
  border-color: var(--chart-green);
}

.btn-success:hover {
  background: #2fa34a;
  border-color: #2fa34a;
  color: white;
}

.btn-danger {
  background: var(--chart-red);
  color: white;
  border-color: var(--chart-red);
}

.btn-danger:hover {
  background: #a82424;
  border-color: #a82424;
  color: white;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 11px;
}

.btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* ============================
   STATS INLINE
   ============================ */
.stats-inline {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.stat-inline {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.stat-inline-label {
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 600;
}

.stat-inline-value {
  font-family: 'Cormorant Garamond', serif;
  font-size: 22px;
  font-weight: 600;
}

/* ============================
   FILTER BAR
   ============================ */
.filter-bar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-bar label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
}

.filter-bar select,
.filter-bar input[type="date"] {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 12px;
  background: var(--bg-hover);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
}

.filter-bar select:focus,
.filter-bar input:focus {
  outline: none;
  border-color: var(--text-primary);
}

/* ============================
   TABLE
   ============================ */
.table-container {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-card);
  margin-bottom: 16px;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

.data-table th {
  background: var(--bg-hover);
  padding: 9px 12px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--border);
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background: var(--bg-hover);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* ============================
   BADGES
   ============================ */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
}

.badge-success { background: rgba(64,192,87,0.15); color: var(--chart-green); }
.badge-warning { background: rgba(253,126,20,0.15); color: var(--chart-orange); }
.badge-error   { background: rgba(201,42,42,0.15); color: var(--chart-red); }
.badge-info    { background: rgba(51,154,240,0.15); color: var(--chart-blue); }
.badge-purple  { background: rgba(121,80,242,0.15); color: var(--chart-purple); }
.badge-neutral { background: var(--bg-hover); color: var(--text-secondary); border: 1px solid var(--border); }

/* ============================
   SCORE
   ============================ */
.score {
  font-family: 'Cormorant Garamond', serif;
  font-size: 17px;
  font-weight: 600;
}
.score.high   { color: var(--chart-green); }
.score.medium { color: var(--chart-orange); }
.score.low    { color: var(--chart-red); }
.score.zero   { color: var(--text-tertiary); }

/* ============================
   CARDS
   ============================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 16px;
}

.card-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title svg {
  width: 16px;
  height: 16px;
  color: var(--chart-blue);
  flex-shrink: 0;
}

/* ============================
   GRID LAYOUTS
   ============================ */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.grid-2-left {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

/* ============================
   FORM ELEMENTS
   ============================ */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-family: 'JetBrains Mono', monospace;
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: all 0.2s;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  background: var(--bg-card);
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px rgba(26,26,26,0.06);
}

.form-textarea {
  min-height: 90px;
  resize: vertical;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.6;
}

/* ============================
   MODAL
   ============================ */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9999;
  padding: 30px;
  overflow-y: auto;
}

.modal.active {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.modal-content {
  background: var(--bg-card);
  width: 100%;
  max-width: 900px;
  border-radius: 12px;
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: -24px;
  background: var(--bg-card);
  z-index: 10;
  margin-top: -24px;
  padding-top: 24px;
}

.modal-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 22px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 26px;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.15s;
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ============================
   TABS
   ============================ */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}

.tab-btn {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-tertiary);
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
  white-space: nowrap;
  font-family: 'Inter', sans-serif;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  color: var(--text-primary);
  border-bottom-color: var(--text-primary);
  font-weight: 600;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ============================
   EMPTY STATE
   ============================ */
.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-tertiary);
}

.empty-state svg {
  width: 40px;
  height: 40px;
  margin-bottom: 12px;
  opacity: 0.3;
}

.empty-state p {
  font-size: 14px;
  margin-top: 6px;
}

/* ============================
   PROGRESS BAR
   ============================ */
.progress-bar {
  height: 7px;
  background: var(--bg-hover);
  border-radius: 4px;
  overflow: hidden;
  margin: 14px 0;
  border: 1px solid var(--border-light);
}

.progress-fill {
  height: 100%;
  background: var(--chart-blue);
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* ============================
   LOADING
   ============================ */
.loading {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--text-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================
   PAGINATION
   ============================ */
.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.pagination .btn {
  min-width: 34px;
  padding: 5px 10px;
  justify-content: center;
  font-size: 12px;
}

.pagination .btn.active {
  background: var(--text-primary);
  color: white;
  border-color: var(--text-primary);
}

/* ============================
   DETAIL LIST
   ============================ */
.detail-list {
  background: var(--bg-hover);
  border-radius: 6px;
  padding: 14px;
  margin-bottom: 14px;
}

.detail-item {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border-light);
}

.detail-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.detail-label {
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.detail-value {
  font-size: 13px;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  word-break: break-all;
}

/* ============================
   CHART SECTION
   ============================ */
.chart-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.chart-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-family: 'JetBrains Mono', monospace;
}

.chart-wrap {
  position: relative;
}

/* ============================
   MODEL BADGE (optimization page)
   ============================ */
.model-badge {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  background: rgba(51,154,240,0.08);
  border: 2px solid var(--chart-blue);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  transition: all 0.2s;
}

.model-badge:hover {
  background: var(--chart-blue);
  color: white;
}

.model-badge.empty {
  background: var(--bg-hover);
  border: 2px dashed var(--border);
  color: var(--text-tertiary);
}

.model-badge.empty:hover {
  border-color: var(--chart-blue);
  color: var(--chart-blue);
}

.badge-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  background: rgba(201,42,42,0.15);
  color: var(--chart-red);
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.badge-remove:hover {
  background: var(--chart-red);
  color: white;
}

.add-model-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: var(--bg-hover);
  border: 2px dashed var(--border);
  border-radius: 8px;
  color: var(--text-tertiary);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s;
}

.add-model-btn:hover {
  background: rgba(51,154,240,0.08);
  border-color: var(--chart-blue);
  color: var(--chart-blue);
}

.model-dropdown {
  position: fixed;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  z-index: 10000;
  min-width: 280px;
  max-height: 320px;
  overflow-y: auto;
}

.dropdown-item {
  padding: 10px 14px;
  cursor: pointer;
  transition: all 0.15s;
  border-bottom: 1px solid var(--border-light);
}

.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item.disabled { opacity: 0.4; cursor: not-allowed; }
.dropdown-item.disabled:hover { background: transparent; }

/* ============================
   LOG ENTRIES
   ============================ */
.log-entry {
  padding: 5px 0;
  border-bottom: 1px solid var(--border-light);
}
.log-entry:last-child { border-bottom: none; }
.log-timestamp { color: var(--text-tertiary); font-size: 9px; margin-right: 6px; }
.log-status {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 700;
  margin-right: 5px;
}
.log-status.info    { background: rgba(51,154,240,0.2); color: var(--chart-blue); }
.log-status.success { background: rgba(64,192,87,0.2); color: var(--chart-green); }
.log-status.warning { background: rgba(253,126,20,0.2); color: var(--chart-orange); }
.log-status.error   { background: rgba(201,42,42,0.2); color: var(--chart-red); }
.log-output {
  margin-top: 3px;
  padding: 5px;
  background: var(--bg-card);
  border-radius: 3px;
  font-size: 10px;
  max-height: 80px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ============================
   KNOWLEDGE BASE
   ============================ */
.kb-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 10px;
  transition: all 0.2s;
}

.kb-card:hover {
  border-color: var(--chart-blue);
  box-shadow: 0 2px 8px rgba(51,154,240,0.08);
}

.kb-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
  gap: 10px;
}

.kb-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.kb-card-content {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
}

.kb-card-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  flex-wrap: wrap;
}

/* ============================
   PREDICTION
   ============================ */
.prediction-item {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
}

.prediction-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.prediction-prompt-text {
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

.prediction-score {
  font-family: 'Cormorant Garamond', serif;
  font-size: 28px;
  font-weight: 700;
}

.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(121,80,242,0.1);
  color: var(--chart-purple);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 600;
}

.manual-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(51,154,240,0.1);
  color: var(--chart-blue);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 600;
}

/* ============================
   RESPONSIVE
   ============================ */
@media (max-width: 1100px) {
  :root { --sidebar-width: 180px; }
  .main-content { min-width: 700px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    position: relative;
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .layout { flex-direction: column; }
  main { margin-left: 0; }
  .main-content { min-width: 0; padding: 12px; }
  .grid-2, .grid-2-left, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: flex-start; }
}

/* ============================
   WORKSPACE SWITCHER
   ============================ */
.ws-switcher {
  position: relative;
  margin-bottom: 16px;
}

.ws-current {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-card);
  transition: all 0.15s;
}

.ws-current:hover {
  border-color: var(--text-secondary);
  background: var(--bg-hover);
}

.ws-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ws-info {
  flex: 1;
  min-width: 0;
}

.ws-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ws-role {
  font-size: 10px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.ws-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  z-index: 200;
  padding: 4px;
}

.ws-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}

.ws-menu-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.ws-menu-item.active { background: var(--bg-hover); color: var(--text-primary); font-weight: 600; }

/* ============================
   WORKSPACE BADGE (in page)
   ============================ */
.ws-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid currentColor;
  opacity: 0.8;
}