/* ===== CSS Variables / Design Tokens ===== */
:root {
  /* Primary */
  --primary: #1E82DF;
  --primary-hover: #1670C2;
  --primary-active: #125CA0;
  --primary-light: #E8F2FD;
  --primary-lighter: #F4F9FE;
  --primary-gradient: linear-gradient(135deg, #1E82DF 0%, #409EFF 100%);
  --primary-gradient-hover: linear-gradient(135deg, #1670C2 0%, #3590E8 100%);

  /* Dark sidebar */
  --dark: #1D2433;
  --dark-hover: #252D3D;
  --dark-active: #2D3648;
  --dark-gradient: linear-gradient(180deg, #1D2433 0%, #161C29 100%);

  /* Text */
  --text-primary: #1D2433;
  --text-secondary: #6B7280;
  --text-muted: #9CA3AF;
  --text-inverse: #FFFFFF;

  /* Background */
  --bg-page: #F5F7FA;
  --bg-card: #FFFFFF;
  --bg-hover: #F9FAFB;

  /* Border */
  --border: #E5E7EB;
  --border-light: #F3F4F6;
  --border-focus: #1E82DF;

  /* Status colors */
  --success: #10B981;
  --success-light: #ECFDF5;
  --warning: #F59E0B;
  --warning-light: #FFFBEB;
  --danger: #EF4444;
  --danger-light: #FEF2F2;
  --info: #6366F1;
  --info-light: #EEF2FF;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.15);
  --shadow-focus: 0 0 0 3px rgba(30, 130, 223, 0.15);

  /* Radius */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.25s ease;
  --transition-slow: 0.35s ease;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-page);
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--primary-hover); }

/* ===== Typography ===== */
h1, h2, h3, h4 { color: var(--text-primary); font-weight: 600; line-height: 1.3; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
h4 { font-size: 16px; }

.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-primary { color: var(--primary); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 24px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-base);
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: var(--primary-gradient);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  background: var(--primary-gradient-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}

.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-success:hover { background: #059669; box-shadow: var(--shadow-sm); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: #DC2626; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-sm { padding: 6px 14px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-lg { padding: 14px 32px; font-size: 16px; border-radius: var(--radius-lg); }

.btn-icon {
  width: 36px; height: 36px; padding: 0;
  border-radius: var(--radius-sm);
}

/* ===== Forms ===== */
.form-group {
  margin-bottom: 20px;
}
.form-label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}
.form-label .required {
  color: var(--danger);
  margin-left: 2px;
}
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-card);
  transition: all var(--transition-fast);
  outline: none;
}
.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-muted); }

.form-input:hover,
.form-select:hover,
.form-textarea:hover { border-color: var(--text-muted); }

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-input-error {
  border-color: var(--danger) !important;
}
.form-input-error:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15) !important;
}
.form-error-text {
  font-size: 12px;
  color: var(--danger);
  margin-top: 4px;
}

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* File upload */
.form-file {
  width: 100%;
  padding: 28px 20px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
  text-align: center;
  color: var(--text-secondary);
  background: var(--bg-hover);
}
.form-file:hover {
  border-color: var(--primary);
  background: var(--primary-lighter);
  color: var(--primary);
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-xs);
  border: 1px solid var(--border-light);
  transition: all var(--transition-base);
}
.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.card-header {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
}
.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}
.card-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.card-stat {
  text-align: center;
  padding: 24px 20px;
}
.card-stat .stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px;
}
.card-stat .stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}
.card-stat .stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-light); color: #059669; }
.badge-warning { background: var(--warning-light); color: #B45309; }
.badge-danger { background: var(--danger-light); color: #DC2626; }
.badge-info { background: #DBEAFE; color: #1D4ED8; }
.badge-teal { background: #CCFBF1; color: #0D9488; }
.badge-amber { background: #FEF3C7; color: #B45309; }
.badge-pending { background: #FEE2E2; color: #C53030; }
.badge-approved { background: var(--primary-light); color: var(--primary); }
.badge-rejected { background: var(--danger-light); color: #DC2626; }

/* ===== Messages ===== */
.message {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  font-size: 14px;
  display: none;
  line-height: 1.5;
}
.message-error {
  background: var(--danger-light);
  color: #991B1B;
  border: 1px solid #FECACA;
}
.message-success {
  background: var(--success-light);
  color: #065F46;
  border: 1px solid #A7F3D0;
}
.message-warning {
  background: var(--warning-light);
  color: #92400E;
  border: 1px solid #FCD34D;
}
.message-info {
  background: var(--info-light);
  color: #3730A3;
  border: 1px solid #C7D2FE;
}

/* ===== Tables ===== */
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
}
table th, table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
}
table th {
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
table tbody tr:hover { background: var(--bg-hover); }
table tbody tr:last-child td { border-bottom: none; }

/* ===== SVG Icons ===== */
.svg-icon {
  width: 20px; height: 20px;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}
.svg-icon-sm { width: 16px; height: 16px; }
.svg-icon-lg { width: 24px; height: 24px; }
.svg-icon-xl { width: 32px; height: 32px; }

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-16px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.animate-fade-in { animation: fadeIn 0.35s ease; }
.animate-fade-in-up { animation: fadeInUp 0.4s ease; }
.animate-fade-in-scale { animation: fadeInScale 0.25s ease; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: fadeIn 0.2s ease;
}
.modal-dialog {
  background: var(--bg-card, #fff);
  border-radius: 16px;
  padding: 36px 32px 28px;
  width: 420px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  animation: fadeInScale 0.25s ease;
}
.modal-icon-circle {
  width: 64px; height: 64px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 18px;
  font-size: 30px;
}
.modal-icon-circle.warning { background: #FEF3C7; color: #F59E0B; }
.modal-icon-circle.error { background: #FEE2E2; color: #EF4444; }
.modal-dialog h3 {
  font-size: 18px; font-weight: 600;
  color: var(--text-primary, #1D2433);
  margin-bottom: 10px;
}
.modal-dialog p {
  color: var(--text-secondary, #6B7280);
  font-size: 17px; line-height: 1.8;
  margin-bottom: 24px;
}
.modal-dialog .btn-modal {
  padding: 10px 40px;
  border: none;
  border-radius: 8px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--primary-gradient, linear-gradient(135deg, #1E82DF 0%, #155BA5 100%));
  color: #fff;
  font-family: inherit;
}

/* ===== Spinner ===== */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }

/* ===== Skeleton loading ===== */
.skeleton {
  background: linear-gradient(90deg, var(--border-light) 25%, #E5E7EB 50%, var(--border-light) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-title { height: 20px; width: 60%; margin-bottom: 12px; }
.skeleton-card { height: 100px; border-radius: var(--radius-md); }

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border-light);
  margin-bottom: 20px;
}
.tab-item {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition-fast);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: inherit;
}
.tab-item:hover { color: var(--text-primary); }
.tab-item.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ===== Chip / Tag ===== */
.chip-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.chip {
  padding: 8px 18px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-base);
  font-family: inherit;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active {
  border-color: var(--primary);
  background: var(--primary-gradient);
  color: #fff;
}

/* ===== Utility ===== */
.section {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-xs);
  border: 1px solid var(--border-light);
  margin-bottom: 20px;
}
.section-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 20px;
}
.section-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.7;
}

.grid-2 { display: grid; grid-template-columns: repeat(2, 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; }

.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-gap { gap: 12px; }
.flex-wrap { flex-wrap: wrap; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ===== Toast Notifications ===== */
#toast-container {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 9999; display: flex; flex-direction: column; align-items: center;
  gap: 8px; pointer-events: none;
}
.toast {
  padding: 12px 24px; border-radius: 8px; font-size: 14px; font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12); pointer-events: auto;
  animation: toastIn 0.3s ease; max-width: 480px; text-align: center;
}
.toast-error { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.toast-success { background: #D1FAE5; color: #065F46; border: 1px solid #A7F3D0; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .section { padding: 16px; }
}
