/* Reset & Base Styles */
:root {
  --primary: #0284c7;
  --primary-dark: #0369a1;
  --primary-light: #e0f2fe;
  --secondary: #475569;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --radius: 12px;

  /* Risk Level Colors */
  --risk-critical: #8b5cf6; /* สูงมาก (Very High) - Violet */
  --risk-critical-bg: #f3e8ff;
  --risk-high: #ef4444;     /* สูง (High) - Red */
  --risk-high-bg: #fef2f2;
  --risk-medium: #f59e0b;   /* ปานกลาง (Medium) - Amber */
  --risk-medium-bg: #fffbeb;
  --risk-low: #10b981;      /* ต่ำ (Low) - Emerald */
  --risk-low-bg: #ecfdf5;

  /* Cause Category Colors */
  --cause-people: #ec4899;   /* คน - Pink */
  --cause-people-bg: #fdf2f8;
  --cause-process: #3b82f6;  /* ขั้นตอน - Blue */
  --cause-process-bg: #eff6ff;
  --cause-it: #8b5cf6;       /* ระบบไอที - Purple */
  --cause-it-bg: #f5f3ff;

  /* Status Colors */
  --status-open: #ef4444;
  --status-open-bg: #fef2f2;
  --status-progress: #f59e0b;
  --status-progress-bg: #fffbeb;
  --status-closed: #10b981;
  --status-closed-bg: #ecfdf5;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Prompt', 'Sarabun', system-ui, -apple-system, sans-serif;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header & Navigation */
header {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 50%, #0284c7 100%);
  color: #ffffff;
  padding: 1.25rem 2rem;
  box-shadow: var(--shadow-lg);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.logo-area {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-icon {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  color: #38bdf8;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.logo-text h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.logo-text p {
  font-size: 0.85rem;
  color: #93c5fd;
  font-weight: 400;
}

nav {
  display: flex;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.1);
  padding: 4px;
  border-radius: 10px;
  backdrop-filter: blur(8px);
}

.nav-btn {
  background: transparent;
  border: none;
  color: #e2e8f0;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

.nav-btn.active {
  background: #ffffff;
  color: var(--primary-dark);
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Main Layout */
main {
  max-width: 1400px;
  margin: 2rem auto;
  padding: 0 1.5rem;
  flex: 1;
  width: 100%;
}

.tab-content {
  display: none;
  animation: fadeIn 0.3s ease;
}

.tab-content.active {
  display: block;
}

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

/* Section Header */
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.section-title h2 {
  font-size: 1.4rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* Card Styling */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

/* Filter Bar */
.filter-bar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  align-items: end;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-main);
}

.form-control, select.form-control {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.925rem;
  background-color: #ffffff;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

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

/* Stats Cards Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 1.25rem;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 5px;
  height: 100%;
  background: var(--primary);
}

.stat-card.card-people::before { background: var(--cause-people); }
.stat-card.card-process::before { background: var(--cause-process); }
.stat-card.card-it::before { background: var(--cause-it); }
.stat-card.card-causes::before { background: #6366f1; }

.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  background: var(--primary-light);
  color: var(--primary);
  flex-shrink: 0;
}

.stat-card.card-people .stat-icon { background: var(--cause-people-bg); color: var(--cause-people); }
.stat-card.card-process .stat-icon { background: var(--cause-process-bg); color: var(--cause-process); }
.stat-card.card-it .stat-icon { background: var(--cause-it-bg); color: var(--cause-it); }
.stat-card.card-causes .stat-icon { background: #eef2ff; color: #6366f1; }

.stat-info .stat-value {
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-main);
}

.stat-info .stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-subtext {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Dashboard Charts Grid */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

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

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.chart-card h3 {
  font-size: 1.1rem;
  color: var(--text-main);
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chart-container {
  position: relative;
  height: 300px;
  width: 100%;
}

/* Multiple Cause Dynamic Repeater */
.causes-builder {
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  padding: 1.25rem;
  margin-top: 0.5rem;
}

.cause-item {
  display: grid;
  grid-template-columns: 200px 1fr 40px;
  gap: 0.75rem;
  align-items: start;
  background: #ffffff;
  border: 1px solid var(--border);
  padding: 0.85rem;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

@media (max-width: 640px) {
  .cause-item {
    grid-template-columns: 1fr;
  }
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-risk-critical { background: var(--risk-critical-bg); color: var(--risk-critical); border: 1px solid #ddd6fe; }
.badge-risk-high { background: var(--risk-high-bg); color: var(--risk-high); border: 1px solid #fecaca; }
.badge-risk-medium { background: var(--risk-medium-bg); color: var(--risk-medium); border: 1px solid #fef3c7; }
.badge-risk-low { background: var(--risk-low-bg); color: var(--risk-low); border: 1px solid #a7f3d0; }

.badge-cause-people { background: var(--cause-people-bg); color: var(--cause-people); }
.badge-cause-process { background: var(--cause-process-bg); color: var(--cause-process); }
.badge-cause-it { background: var(--cause-it-bg); color: var(--cause-it); }

.badge-status-open { background: var(--status-open-bg); color: var(--status-open); }
.badge-status-progress { background: var(--status-progress-bg); color: var(--status-progress); }
.badge-status-closed { background: var(--status-closed-bg); color: var(--status-closed); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  font-size: 0.925rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}
.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3);
}

.btn-secondary {
  background: #e2e8f0;
  color: var(--text-main);
}
.btn-secondary:hover {
  background: #cbd5e1;
}

.btn-success {
  background: #10b981;
  color: #ffffff;
}
.btn-success:hover {
  background: #059669;
}

.btn-warning {
  background: #f59e0b;
  color: #ffffff;
}
.btn-warning:hover {
  background: #d97706;
}

.btn-danger {
  background: #ef4444;
  color: #ffffff;
}
.btn-danger:hover {
  background: #dc2626;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.825rem;
  border-radius: 6px;
}

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 6px;
}

/* Data Table */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  background: #ffffff;
  font-size: 0.9rem;
}

table.data-table th {
  background: #f1f5f9;
  color: var(--text-main);
  font-weight: 600;
  padding: 1rem;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

table.data-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.data-table tbody tr:hover {
  background-color: #f8fafc;
}

.cause-list-mini {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.cause-item-mini {
  font-size: 0.825rem;
  line-height: 1.4;
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
}

/* Toolbar & Utility Actions */
.toolbar-flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.utility-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-backdrop.active {
  display: flex;
}

.modal-card {
  background: #ffffff;
  border-radius: 16px;
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  animation: modalSlide 0.25s ease;
}

@keyframes modalSlide {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8fafc;
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  background: #f8fafc;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
  background: #f8fafc;
  padding: 1rem;
  border-radius: 10px;
}

.detail-item label {
  font-size: 0.775rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.detail-item p {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.detail-section {
  margin-bottom: 1.25rem;
}

.detail-section h4 {
  font-size: 0.95rem;
  color: var(--primary-dark);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.detail-box {
  background: #ffffff;
  border: 1px solid var(--border);
  padding: 1rem;
  border-radius: 8px;
  white-space: pre-wrap;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 3rem;
  color: #cbd5e1;
  margin-bottom: 1rem;
}

/* Footer */
footer {
  background: #ffffff;
  border-top: 1px solid var(--border);
  padding: 1.25rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: auto;
}
