:root {
  --sidebar-bg: #1a1f2e;
  --sidebar-text: #8892a4;
  --sidebar-active: #4f9cf9;
  --sidebar-hover-bg: #252b3b;
  --sidebar-border: #2d3548;
  --primary: #4f9cf9;
  --primary-dark: #3a7fd4;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;
  --sidebar-width: 260px;
  --topbar-height: 60px;
  --body-bg: #f0f2f5;
  --card-bg: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Segoe UI', 'Microsoft JhengHei', 'PingFang TC', sans-serif;
  background: var(--body-bg);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 1000;
  transition: transform 0.3s ease;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 20px 24px;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.sidebar-brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
}

.sidebar-brand-name {
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.5px;
}

.sidebar-brand-sub {
  color: var(--sidebar-text);
  font-size: 10px;
  line-height: 1.4;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 0;
}

.sidebar-section-label {
  color: #4a5568;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 8px 24px 4px;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 24px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  border-left: 3px solid transparent;
  cursor: pointer;
}

.sidebar-nav-item:hover {
  background: var(--sidebar-hover-bg);
  color: #cbd5e1;
  text-decoration: none;
}

.sidebar-nav-item.active {
  background: rgba(79, 156, 249, 0.12);
  color: var(--sidebar-active);
  border-left-color: var(--sidebar-active);
}

.sidebar-nav-item .nav-icon {
  font-size: 17px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
  font-size: 11px;
  text-align: center;
}

/* ===== MAIN CONTENT ===== */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 16px;
}

.topbar-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-content {
  padding: 28px;
  flex: 1;
}

/* ===== CARDS ===== */
.stat-card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 22px 24px;
  border: 1px solid var(--border-color);
  transition: box-shadow 0.2s;
}

.stat-card:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}

.stat-card-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.stat-card-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 6px;
}

.stat-card-sub {
  font-size: 12px;
  color: var(--text-secondary);
}

.stat-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.icon-blue { background: rgba(79, 156, 249, 0.15); color: var(--primary); }
.icon-green { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.icon-yellow { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.icon-red { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.icon-cyan { background: rgba(6, 182, 212, 0.15); color: var(--info); }

/* ===== CONTENT CARD ===== */
.content-card {
  background: var(--card-bg);
  border-radius: 14px;
  border: 1px solid var(--border-color);
  overflow: hidden;
}

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

.content-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.content-card-body {
  padding: 20px 24px;
}

/* ===== TABLES ===== */
.table-responsive {
  overflow-x: auto;
}

.custom-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.custom-table th {
  background: #f8fafc;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 16px;
  text-align: left;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

.custom-table td {
  padding: 13px 16px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text-primary);
  vertical-align: middle;
}

.custom-table tr:last-child td {
  border-bottom: none;
}

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

.custom-table tbody tr.clickable {
  cursor: pointer;
}

/* ===== BADGES ===== */
.badge-type {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.badge-d1 { background: rgba(79, 156, 249, 0.12); color: #2563eb; }
.badge-d7 { background: rgba(245, 158, 11, 0.12); color: #d97706; }
.badge-dm7 { background: rgba(239, 68, 68, 0.12); color: #dc2626; }
.badge-pending { background: rgba(245, 158, 11, 0.12); color: #d97706; }
.badge-sent { background: rgba(34, 197, 94, 0.12); color: #16a34a; }
.badge-skipped { background: rgba(148, 163, 184, 0.15); color: #64748b; }

/* ===== BUTTONS ===== */
.btn-primary-custom {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary-custom:hover {
  background: var(--primary-dark);
}

.btn-primary-custom:active {
  transform: scale(0.98);
}

.btn-outline-custom {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-outline-custom:hover {
  background: #f8fafc;
  color: var(--text-primary);
}

/* ===== FILTERS ===== */
.filter-bar {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px 20px;
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-control {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-primary);
  background: #fff;
  min-width: 140px;
  transition: border-color 0.2s;
}

.filter-control:focus {
  outline: none;
  border-color: var(--primary);
}

/* ===== TABS ===== */
.custom-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 20px;
}

.custom-tab {
  padding: 11px 20px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.custom-tab:hover {
  color: var(--primary);
}

.custom-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content-panel {
  display: none;
}

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

/* ===== FORMS ===== */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.form-label .required {
  color: var(--danger);
  margin-left: 3px;
}

.form-control-custom {
  width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text-primary);
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control-custom:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 156, 249, 0.12);
}

.form-control-custom.is-invalid {
  border-color: var(--danger);
}

/* ===== MODALS ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.show {
  display: flex;
}

.modal-box {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  animation: modalIn 0.25s ease;
}

.modal-box.modal-lg {
  max-width: 780px;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(-10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: color 0.2s;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ===== ALERTS ===== */
.alert-bar {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}

.alert-item {
  padding: 13px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.12);
  animation: alertIn 0.3s ease;
  cursor: pointer;
}

@keyframes alertIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.alert-success { background: #ecfdf5; color: #065f46; border-left: 4px solid var(--success); }
.alert-error { background: #fef2f2; color: #7f1d1d; border-left: 4px solid var(--danger); }
.alert-warning { background: #fffbeb; color: #78350f; border-left: 4px solid var(--warning); }
.alert-info { background: #eff6ff; color: #1e3a8a; border-left: 4px solid var(--primary); }

/* ===== DRAG & DROP ===== */
.drop-zone {
  border: 2px dashed var(--border-color);
  border-radius: 12px;
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: #fafbfc;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--primary);
  background: rgba(79, 156, 249, 0.04);
}

.drop-zone-icon {
  font-size: 48px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.drop-zone-text {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.drop-zone-hint {
  font-size: 12px;
  color: #94a3b8;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 56px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state-text {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 6px;
}

.empty-state-sub {
  font-size: 13px;
  opacity: 0.7;
}

/* ===== LOADING ===== */
.loading-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(79, 156, 249, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ===== TEMPLATE CARDS ===== */
.template-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 18px 20px;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.template-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.07);
  border-color: #cbd5e1;
}

.template-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.template-card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.template-card-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.template-card-content {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  background: #f8fafc;
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

.template-card-actions {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  justify-content: flex-end;
}

/* ===== MEMBER AVATAR ===== */
.member-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

/* ===== PROGRESS BAR ===== */
.progress-bar-custom {
  height: 6px;
  background: var(--border-color);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-wrapper {
    margin-left: 0;
  }
  .page-content {
    padding: 16px;
  }
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-control {
    min-width: 100%;
  }
}

/* ===== UTILS ===== */
.text-ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.cursor-pointer { cursor: pointer; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.gap-8 { gap: 8px; }

.action-btn {
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s;
}

.action-btn:hover { opacity: 0.85; }
.action-btn-success { background: rgba(34,197,94,0.12); color: #16a34a; }
.action-btn-skip { background: rgba(148,163,184,0.15); color: #64748b; }
.action-btn-edit { background: rgba(79,156,249,0.12); color: #2563eb; }
.action-btn-delete { background: rgba(239,68,68,0.12); color: #dc2626; }
.action-btn-view { background: rgba(6,182,212,0.12); color: #0891b2; }

.chart-container {
  position: relative;
  height: 280px;
}

.store-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #f1f5f9;
}
.store-bar:last-child { border-bottom: none; }
.store-bar-name { width: 70px; font-size: 13px; font-weight: 600; flex-shrink: 0; }
.store-bar-track { flex: 1; }
.store-bar-count { width: 50px; text-align: right; font-size: 13px; color: var(--text-secondary); }

.variable-hint {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.variable-tag {
  padding: 2px 8px;
  background: rgba(79,156,249,0.1);
  color: var(--primary);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.variable-tag:hover {
  background: rgba(79,156,249,0.2);
}

.section-divider {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 16px 0 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-color);
}
