/* ─── CSS Variables ──────────────────────────────────────────────────────── */
:root {
  --primary: #5c6ac4;
  --primary-dark: #4959bd;
  --primary-light: #eef0fb;
  --success: #108043;
  --success-light: #e3f1df;
  --danger: #de3618;
  --danger-light: #fbeae5;
  --warning: #f49342;
  --warning-light: #fdf3e7;
  --info: #006fbb;
  --info-light: #e0f0ff;
  --text: #212b36;
  --text-secondary: #637381;
  --border: #dfe3e8;
  --bg: #f6f6f7;
  --white: #ffffff;
  --sidebar-width: 240px;
  --header-height: 56px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

/* ─── Reset & Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-width); background: #1a1a2e; color: #fff; display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; z-index: 100; overflow-y: auto; }
.main-content { margin-left: var(--sidebar-width); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.page-content { flex: 1; padding: 24px; max-width: 1200px; }

/* ─── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar-logo { padding: 20px 20px 16px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-logo h2 { font-size: 16px; font-weight: 700; color: #fff; margin: 0; }
.sidebar-logo span { font-size: 11px; color: rgba(255,255,255,0.5); display: block; margin-top: 2px; }
.sidebar-nav { padding: 12px 0; flex: 1; }
.sidebar-section { padding: 8px 16px 4px; font-size: 10px; font-weight: 600; color: rgba(255,255,255,0.35); text-transform: uppercase; letter-spacing: 0.8px; }
.sidebar-link { display: flex; align-items: center; gap: 10px; padding: 10px 20px; color: rgba(255,255,255,0.7); font-size: 14px; font-weight: 500; transition: all 0.15s; border-left: 3px solid transparent; text-decoration: none; }
.sidebar-link:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.sidebar-link.active { background: rgba(92,106,196,0.25); color: #fff; border-left-color: var(--primary); }
.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.1); font-size: 12px; color: rgba(255,255,255,0.4); }

/* ─── Top Header ─────────────────────────────────────────────────────────── */
.page-header { background: var(--white); border-bottom: 1px solid var(--border); padding: 0 24px; height: var(--header-height); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50; }
.page-header h1 { font-size: 18px; font-weight: 600; color: var(--text); margin: 0; }
.header-actions { display: flex; gap: 10px; align-items: center; }

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }
.card-footer { padding: 12px 20px; border-top: 1px solid var(--border); background: #fafafa; border-radius: 0 0 var(--radius) var(--radius); }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 6px; font-size: 14px; font-weight: 500; border: 1px solid transparent; transition: all 0.15s; white-space: nowrap; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-secondary { background: var(--white); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #c42f14; }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; border-radius: 6px; background: transparent; border: 1px solid var(--border); color: var(--text-secondary); }
.btn-icon:hover { background: var(--bg); color: var(--text); }

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-control { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; color: var(--text); background: var(--white); transition: border-color 0.15s, box-shadow 0.15s; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(92,106,196,0.15); }
.form-control.error { border-color: var(--danger); }
.form-hint { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.form-error { font-size: 12px; color: var(--danger); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23637381' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-check { display: flex; align-items: center; gap: 8px; }
.form-check input[type="checkbox"], .form-check input[type="radio"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.form-check label { font-size: 14px; cursor: pointer; }

/* ─── Tables ─────────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th { background: #f9fafb; padding: 10px 16px; text-align: left; font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafafa; }

/* ─── Badges ─────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: #8a5700; }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-default { background: #f0f0f0; color: var(--text-secondary); }
.badge-primary { background: var(--primary-light); color: var(--primary); }

/* ─── Type Badges ────────────────────────────────────────────────────────── */
.type-badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; background: var(--primary-light); color: var(--primary); text-transform: uppercase; letter-spacing: 0.3px; }

/* ─── Stats Cards ────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--white); border-radius: var(--radius); padding: 20px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.stat-card .stat-value { font-size: 32px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-card .stat-label { font-size: 13px; color: var(--text-secondary); margin-top: 6px; }
.stat-card .stat-icon { width: 40px; height: 40px; border-radius: 8px; display: flex; align-items: center; justify-content: center; margin-bottom: 12px; }

/* ─── Alerts ─────────────────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 6px; font-size: 14px; display: flex; align-items: flex-start; gap: 10px; margin-bottom: 16px; }
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid #b3d9c4; }
.alert-danger { background: var(--danger-light); color: var(--danger); border: 1px solid #f5c6be; }
.alert-info { background: var(--info-light); color: var(--info); border: 1px solid #b3d9f5; }
.alert-warning { background: var(--warning-light); color: #8a5700; border: 1px solid #f5d9b3; }

/* ─── Modal ──────────────────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow-md); width: 100%; max-width: 600px; max-height: 90vh; overflow-y: auto; }
.modal-lg { max-width: 800px; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--text-secondary); cursor: pointer; padding: 4px; line-height: 1; }
.modal-close:hover { color: var(--text); }

/* ─── Options Builder ────────────────────────────────────────────────────── */
.options-list { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.option-item { display: grid; grid-template-columns: 1fr 1fr auto auto; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--white); }
.option-item:last-child { border-bottom: none; }
.option-item:hover { background: #fafafa; }
.option-add { padding: 10px 12px; border-top: 1px solid var(--border); background: #fafafa; }

/* ─── Empty State ────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-secondary); }
.empty-state svg { width: 64px; height: 64px; margin-bottom: 16px; opacity: 0.3; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 14px; margin-bottom: 20px; }

/* ─── Loading ────────────────────────────────────────────────────────────── */
.loading { display: flex; align-items: center; justify-content: center; padding: 60px; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Toast Notifications ────────────────────────────────────────────────── */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 8px; box-shadow: var(--shadow-md); font-size: 14px; font-weight: 500; min-width: 280px; max-width: 400px; animation: slideIn 0.2s ease; }
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-info { background: var(--info); color: #fff; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Search & Filter Bar ────────────────────────────────────────────────── */
.filter-bar { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.search-input { position: relative; flex: 1; min-width: 200px; }
.search-input input { padding-left: 36px; }
.search-input svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-secondary); width: 16px; height: 16px; }

/* ─── Tabs ───────────────────────────────────────────────────────────────── */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; gap: 0; }
.tab { padding: 10px 20px; font-size: 14px; font-weight: 500; color: var(--text-secondary); border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.15s; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ─── Toggle Switch ──────────────────────────────────────────────────────── */
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; inset: 0; background: #ccc; border-radius: 22px; transition: 0.3s; }
.toggle-slider:before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.3s; }
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider:before { transform: translateX(18px); }

/* ─── Drag Handle ────────────────────────────────────────────────────────── */
.drag-handle { cursor: grab; color: var(--text-secondary); padding: 4px; }
.drag-handle:active { cursor: grabbing; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main-content { margin-left: 0; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ─── Utilities ──────────────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.text-sm { font-size: 12px; }
.text-secondary { color: var(--text-secondary); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.font-semibold { font-weight: 600; }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
