/* ==========================================================================
   CTC-Indonesia HSE AI Platform Design System (Light Theme)
   Countermeasure Training & Consulting
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* Brand Colors */
  --primary: #059669;
  --primary-hover: #047857;
  --primary-light: rgba(5, 150, 105, 0.09);
  --primary-glow: rgba(5, 150, 105, 0.2);
  --secondary: #0284c7;
  --accent: #d97706;
  --danger: #dc2626;
  --success: #16a34a;
  
  /* Light Mode Base */
  --bg-dark: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --border-color: #e2e8f0;
  --border-focus: rgba(5, 150, 105, 0.5);
  --border-light: #cbd5e1;
  
  /* Text */
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;
  
  /* Layout */
  --sidebar-width: 280px;
  --header-height: 70px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  
  /* Transitions & Shadows */
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 14px -1px rgba(0, 0, 0, 0.08), 0 2px 6px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 30px -4px rgba(0, 0, 0, 0.1), 0 4px 12px -2px rgba(0, 0, 0, 0.05);
  --shadow-glow: 0 0 25px rgba(5, 150, 105, 0.18);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(5, 150, 105, 0.05) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(2, 132, 199, 0.04) 0%, transparent 40%);
  background-attachment: fixed;
}

/* App Shell Container */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: #ffffff;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: var(--transition);
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.02);
}

.brand-section {
  padding: 22px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--border-color);
  background: #ffffff;
}

.brand-logo-badge {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.25);
}

.brand-info h2 {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #0f172a;
}

.brand-info p {
  font-size: 11px;
  color: var(--primary);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.nav-menu {
  flex: 1;
  padding: 18px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.nav-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
  padding: 14px 14px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
  transition: var(--transition);
  cursor: pointer;
  border: 1px solid transparent;
}

.nav-item:hover {
  background: #f1f5f9;
  color: #0f172a;
  transform: translateX(3px);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: rgba(5, 150, 105, 0.2);
  font-weight: 700;
}

.nav-item i {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  background: #f8fafc;
}

.status-card {
  background: rgba(5, 150, 105, 0.08);
  border: 1px solid rgba(5, 150, 105, 0.2);
  padding: 12px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 6px var(--primary);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

/* Main Content Wrapper */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Top Header */
.top-header {
  height: var(--header-height);
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.02);
}

.header-title-group h1 {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #0f172a;
}

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

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

/* Custom Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.25);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #047857 0%, #065f46 100%);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(5, 150, 105, 0.35);
}

.btn-secondary {
  background: #ffffff;
  border-color: var(--border-color);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #0f172a;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

/* Page Views */
.content-body {
  padding: 32px;
  flex: 1;
}

.page-view {
  display: none;
  animation: fadeIn 0.3s ease-in-out;
}

.page-view.active {
  display: block;
}

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

/* Card System */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

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

.card-title {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-main);
}

.card-title i {
  color: var(--primary);
}

/* Grid Layouts */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

/* Form Controls */
.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.form-control, .form-select {
  width: 100%;
  padding: 11px 16px;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 13.5px;
  transition: var(--transition);
  outline: none;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
  background: #ffffff;
}

textarea.form-control {
  min-height: 110px;
  resize: vertical;
}

/* Chat Copilot Interface */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 170px);
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.chat-role-bar {
  padding: 12px 20px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 12px;
  overflow-x: auto;
}

.role-chip {
  padding: 7px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  background: #ffffff;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

.role-chip:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.role-chip.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: rgba(5, 150, 105, 0.4);
}

.chat-messages {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: #ffffff;
}

.chat-msg {
  display: flex;
  gap: 14px;
  max-width: 85%;
  animation: fadeIn 0.25s ease;
}

.chat-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-msg.assistant {
  align-self: flex-start;
}

.chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.chat-msg.assistant .chat-avatar {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(5, 150, 105, 0.3);
}

.chat-msg.user .chat-avatar {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: white;
}

.chat-bubble {
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.6;
  position: relative;
}

.chat-msg.assistant .chat-bubble {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-top-left-radius: 4px;
}

.chat-msg.user .chat-bubble {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  color: #ffffff;
  border-top-right-radius: 4px;
}

.chat-input-area {
  padding: 16px 20px;
  background: #f8fafc;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quick-prompts-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.quick-btn {
  padding: 6px 14px;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: var(--transition);
}

.quick-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: rgba(5, 150, 105, 0.3);
}

.input-box-wrapper {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-textarea {
  flex: 1;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  color: var(--text-main);
  font-size: 14px;
  max-height: 120px;
  outline: none;
  resize: none;
  transition: var(--transition);
}

.chat-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
}

/* Markdown Formatted Content Inside Chat & Reports */
.markdown-body {
  font-size: 14px;
  line-height: 1.65;
  color: #1e293b;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 {
  color: #0f172a;
  margin-top: 16px;
  margin-bottom: 10px;
  font-weight: 800;
}

.markdown-body h3 {
  font-size: 15px;
  color: #059669;
}

.markdown-body p {
  margin-bottom: 10px;
}

.markdown-body ul, .markdown-body ol {
  padding-left: 20px;
  margin-bottom: 12px;
}

.markdown-body li {
  margin-bottom: 4px;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 13px;
  background: #ffffff;
}

.markdown-body table th {
  background: #f1f5f9;
  color: #0f172a;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  font-weight: 700;
}

.markdown-body table td {
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
}

.markdown-body blockquote {
  border-left: 4px solid var(--primary);
  padding: 8px 16px;
  background: rgba(5, 150, 105, 0.06);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 12px 0;
  color: #334155;
}

/* Report Viewer Container */
.report-paper {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 36px;
  box-shadow: var(--shadow-md);
  margin-top: 10px;
  position: relative;
}

.report-header-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 3px double #047857;
  padding-bottom: 16px;
  margin-bottom: 24px;
}

.report-title-box h2 {
  font-size: 20px;
  color: #047857;
  font-weight: 800;
}

.report-title-box p {
  font-size: 12px;
  color: #64748b;
  font-weight: 600;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}

.report-table th, .report-table td {
  border: 1px solid #cbd5e1;
  padding: 8px 12px;
  font-size: 12.5px;
  text-align: left;
}

.report-table th {
  background: #f1f5f9;
  font-weight: 700;
  color: #1e293b;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-high { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }
.badge-medium { background: #fef3c7; color: #b45309; border: 1px solid #fde68a; }
.badge-low { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }

/* KPI Stats Card */
.stat-box {
  background: #ffffff;
  border: 1px solid var(--border-color);
  padding: 20px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.stat-val {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: #0f172a;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 540px;
  padding: 28px;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95);
  transition: var(--transition);
}

.modal-overlay.active .modal-content {
  transform: scale(1);
}

/* Print Optimization */
@media print {
  @page {
    size: A4;
    margin: 15mm;
  }

  html, body {
    background: #ffffff !important;
    color: #0f172a !important;
    min-height: auto !important;
    height: auto !important;
    overflow: visible !important;
    font-size: 11pt;
  }

  .sidebar, 
  .top-header, 
  .btn, 
  .chat-role-bar, 
  .chat-input-area, 
  .quick-prompts-row, 
  .modal-overlay,
  .no-print,
  #jsa-form,
  form {
    display: none !important;
  }

  .print-official-header {
    display: block !important;
  }

  .app-container, .main-wrapper, .content-body {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
  }

  .page-view {
    display: none !important;
  }
  
  .page-view.active {
    display: block !important;
  }

  .chat-container {
    height: auto !important;
    border: none !important;
    background: transparent !important;
  }

  .chat-messages {
    overflow: visible !important;
    padding: 0 !important;
    gap: 16px !important;
  }

  .chat-msg {
    max-width: 100% !important;
    page-break-inside: avoid;
    margin-bottom: 12px;
  }

  .chat-msg.assistant .chat-bubble {
    background: #f8fafc !important;
    color: #0f172a !important;
    border: 1px solid #cbd5e1 !important;
  }

  .chat-msg.user .chat-bubble {
    background: #f1f5f9 !important;
    color: #047857 !important;
    border: 1px solid #94a3b8 !important;
    font-weight: 600;
  }

  .chat-avatar {
    border: 1px solid #cbd5e1 !important;
    color: #047857 !important;
    background: #ffffff !important;
  }

  .markdown-body {
    color: #0f172a !important;
  }

  .markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 {
    color: #047857 !important;
  }

  .markdown-body table {
    width: 100% !important;
    border-collapse: collapse !important;
  }

  .markdown-body table th {
    background: #e2e8f0 !important;
    color: #0f172a !important;
    border: 1px solid #94a3b8 !important;
  }

  .markdown-body table td {
    border: 1px solid #cbd5e1 !important;
    color: #0f172a !important;
  }

  .grid-2 {
    display: block !important;
  }

  .card {
    background: transparent !important;
    border: 1px solid #cbd5e1 !important;
    box-shadow: none !important;
    page-break-inside: avoid;
    color: #0f172a !important;
    margin-bottom: 20px;
  }

  .card-title {
    color: #047857 !important;
  }

  .stat-box {
    background: #f8fafc !important;
    border: 1px solid #cbd5e1 !important;
    color: #0f172a !important;
  }

  .stat-label {
    color: #64748b !important;
  }

  .report-paper {
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    page-break-inside: avoid;
  }

  .report-table th {
    background: #e2e8f0 !important;
    color: #0f172a !important;
  }

  .badge-high { background: #fee2e2 !important; color: #b91c1c !important; border: 1px solid #f87171 !important; }
  .badge-medium { background: #fef3c7 !important; color: #b45309 !important; border: 1px solid #fbbf24 !important; }
  .badge-low { background: #dcfce7 !important; color: #15803d !important; border: 1px solid #86efac !important; }
}

/* Mobile Sidebar Toggle Button & Overlay */
.mobile-sidebar-toggle {
  display: none;
  background: #ffffff;
  border: 1px solid var(--border-color);
  color: #0f172a;
  font-size: 18px;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.mobile-sidebar-toggle:hover {
  background: #f1f5f9;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 99;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
}

.sidebar-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Responsive Table Wrapper */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 14px 0;
}

/* Responsive Media Queries */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .main-wrapper {
    margin-left: 0;
  }
  .mobile-sidebar-toggle {
    display: inline-flex;
  }
  .top-header {
    padding: 0 18px;
  }
  .content-body {
    padding: 20px 16px;
  }
  .grid-4, .grid-3, .grid-2 {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .chat-container {
    height: calc(100vh - 140px);
  }
}

@media (max-width: 640px) {
  .top-header {
    height: auto;
    padding: 12px 14px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .header-title-group h1 {
    font-size: 16px;
  }
  .header-title-group p {
    font-size: 11px;
    display: none;
  }
  .header-actions {
    justify-content: flex-end;
    width: 100%;
  }
  .btn-text-responsive {
    display: none;
  }
  .chat-messages {
    padding: 14px;
    gap: 14px;
  }
  .chat-msg {
    max-width: 95%;
  }
  .chat-bubble {
    padding: 12px 14px;
    font-size: 13.5px;
  }
  .report-paper {
    padding: 20px 14px;
  }
  .report-header-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .card {
    padding: 18px 14px;
  }
}
