/* ============ DESIGN TOKENS ============ */
:root {
  --sidebar-w: 250px;
  --brand: #128c7e;
  --brand-2: #25d366;
  --brand-rgb: 18, 140, 126;
  --brand-dark: #0e6e63;
  --brand-light: #e7f4f2;
  --radius: 10px;
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
  --shadow:    0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
  --shadow-md: 0 10px 15px -3px rgba(0,0,0,0.07), 0 4px 6px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
  --text:     #1e293b;
  --text-mut: #64748b;
  --bg:       #f1f5f9;
  --bg-card:  #ffffff;
  --border:   #e2e8f0;
}

/* ============ DARK MODE ============ */
body[data-theme="dark"] {
  --text:     #e2e8f0;
  --text-mut: #94a3b8;
  --bg:       #0f172a;
  --bg-card:  #1e293b;
  --border:   #334155;
}

/* ============ BASE ============ */
* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,h2,h3,h4,h5,h6 { color: var(--text); font-weight: 600; letter-spacing: -0.01em; }
.text-muted { color: var(--text-mut) !important; }

a { color: var(--brand); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--brand-dark); }

/* ============ SIDEBAR ============ */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  position: sticky;
  top: 0;
  background: #1e293b;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  transition: background 0.3s;
}
.sidebar .brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 1.05rem;
}
.sidebar .brand .logo {
  width: 36px; height: 36px;
  background: var(--brand);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}
.sidebar .nav-link {
  color: rgba(255,255,255,0.65) !important;
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  margin-bottom: 2px;
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  transition: all 0.15s;
}
.sidebar .nav-link i { font-size: 1rem; width: 18px; text-align: center; }
.sidebar .nav-link:hover {
  background: rgba(255,255,255,0.06);
  color: #fff !important;
}
.sidebar .nav-link.active {
  background: var(--brand);
  color: #fff !important;
  box-shadow: 0 4px 12px rgba(var(--brand-rgb), 0.4);
}
.sidebar .nav-section {
  color: rgba(255,255,255,0.35);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 1rem 0.85rem 0.4rem;
}

/* Sidebar style: light */
body[data-sidebar-style="light"] .sidebar {
  background: #fff;
  color: var(--text);
  border-right: 1px solid var(--border);
}
body[data-sidebar-style="light"] .sidebar .nav-link { color: var(--text-mut) !important; }
body[data-sidebar-style="light"] .sidebar .nav-link:hover { background: var(--bg); color: var(--text) !important; }
body[data-sidebar-style="light"] .sidebar .nav-link.active { background: var(--brand); color: #fff !important; }
body[data-sidebar-style="light"] .sidebar .brand { border-bottom-color: var(--border); }
body[data-sidebar-style="light"] .sidebar .nav-section { color: #94a3b8; }

/* Sidebar style: gradient */
body[data-sidebar-style="gradient"] .sidebar {
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: rgba(255,255,255,0.85);
}
body[data-sidebar-style="gradient"] .sidebar .nav-link { color: rgba(255,255,255,0.8) !important; }
body[data-sidebar-style="gradient"] .sidebar .nav-link:hover { background: rgba(255,255,255,0.15); color: #fff !important; }
body[data-sidebar-style="gradient"] .sidebar .nav-link.active { background: rgba(0,0,0,0.25); color: #fff !important; box-shadow: none; }
body[data-sidebar-style="gradient"] .sidebar .brand .logo { background: rgba(255,255,255,0.2); }

/* ============ TOPBAR ============ */
.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.main-content { min-height: 100vh; background: var(--bg); }

/* ============ CARDS ============ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  color: var(--text);
}
.card-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  padding: 0.85rem 1.1rem;
}
.card-body { padding: 1.1rem; }

.stat-card {
  border-left: 4px solid var(--brand);
  transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card .num { font-size: 1.75rem; font-weight: 700; line-height: 1.1; color: var(--text); }
.stat-card .text-muted { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }

/* ============ TABLES ============ */
.table {
  color: var(--text);
  margin-bottom: 0;
  --bs-table-bg: transparent;
}
.table > :not(caption) > * > * { background: transparent; }
.table thead th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-mut);
  font-weight: 600;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
}
.table td {
  vertical-align: middle;
  padding: 0.85rem 1rem;
  border-color: var(--border);
}
.table tbody tr:hover { background: rgba(var(--brand-rgb), 0.03); }
body[data-theme="dark"] .table tbody tr:hover { background: rgba(255,255,255,0.04); }

/* ============ BUTTONS ============ */
.btn {
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.875rem;
  padding: 0.45rem 0.95rem;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn-lg { padding: 0.65rem 1.5rem; font-size: 1rem; }
.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
  background: var(--brand-dark) !important;
  border-color: var(--brand-dark) !important;
  color: #fff !important;
  box-shadow: 0 4px 12px rgba(var(--brand-rgb), 0.3);
  transform: translateY(-1px);
}
.btn-outline-primary {
  border-color: var(--brand);
  color: var(--brand);
}
.btn-outline-primary:hover, .btn-outline-primary:active {
  background: var(--brand) !important;
  border-color: var(--brand) !important;
  color: #fff !important;
}
.btn-success {
  background: var(--brand-2);
  border-color: var(--brand-2);
  color: #fff;
}
.btn-success:hover {
  background: var(--brand);
  border-color: var(--brand);
  transform: translateY(-1px);
}

/* ============ FORMS ============ */
.form-label {
  font-weight: 500;
  font-size: 0.825rem;
  color: var(--text);
  margin-bottom: 0.35rem;
}
.form-control, .form-select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg-card);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.12);
  background: var(--bg-card);
  color: var(--text);
}
.form-control-sm, .form-select-sm { font-size: 0.825rem; padding: 0.35rem 0.55rem; }

/* ============ BADGES ============ */
.badge {
  font-weight: 500;
  font-size: 0.7rem;
  padding: 0.3em 0.6em;
  border-radius: 6px;
  letter-spacing: 0.02em;
}

/* ============ TAG PILL ============ */
.tag-pill {
  display: inline-block;
  background: rgba(var(--brand-rgb), 0.1);
  color: var(--brand);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 500;
  margin: 2px;
  border: 1px solid rgba(var(--brand-rgb), 0.15);
  transition: all 0.15s;
}
.tag-pill:hover { background: var(--brand); color: #fff !important; }

/* ============ STEP CARD ============ */
.step-card {
  border-left: 3px solid var(--brand-2);
  background: var(--bg-card);
}

/* ============ LOGIN ============ */
.login-bg {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  width: 100%;
  max-width: 420px;
  border-radius: 16px;
  border: none;
  box-shadow: 0 20px 50px rgba(0,0,0,0.15);
}
.login-icon { font-size: 3rem; color: var(--brand); }

/* ============ DROPDOWN ============ */
.dropdown-menu {
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  background: var(--bg-card);
  padding: 0.4rem;
}
.dropdown-item {
  border-radius: 6px;
  padding: 0.45rem 0.7rem;
  font-size: 0.875rem;
  color: var(--text);
  transition: background 0.15s;
}
.dropdown-item:hover {
  background: rgba(var(--brand-rgb), 0.08);
  color: var(--brand);
}

/* ============ MODAL ============ */
.modal-content {
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
}
.modal-header { border-bottom-color: var(--border); padding: 1rem 1.25rem; }
.modal-footer { border-top-color: var(--border); padding: 0.85rem 1.25rem; }
.modal-title { font-weight: 600; }

/* ============ ALERTS ============ */
.alert {
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
}

/* ============ PROGRESS ============ */
.progress {
  background: var(--border);
  border-radius: 100px;
  overflow: hidden;
}
.progress-bar { background: var(--brand); }

/* ============ NAV PILLS ============ */
.nav-pills .nav-link {
  border-radius: 8px;
  color: var(--text-mut);
  font-weight: 500;
  font-size: 0.85rem;
}
.nav-pills .nav-link.active {
  background: var(--brand);
  color: #fff;
}

/* ============ TOM SELECT (override to match theme) ============ */
.ts-wrapper { font-size: 0.9rem; }
.ts-wrapper.single .ts-control,
.ts-wrapper.multi .ts-control {
  border-radius: 8px !important;
  border-color: var(--border) !important;
  background: var(--bg-card) !important;
  color: var(--text) !important;
  padding: 0.42rem 0.75rem !important;
  min-height: auto;
  box-shadow: none !important;
}
.ts-wrapper.focus .ts-control {
  border-color: var(--brand) !important;
  box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.12) !important;
}
.ts-dropdown {
  border-radius: 8px !important;
  border-color: var(--border) !important;
  box-shadow: var(--shadow-md) !important;
  background: var(--bg-card) !important;
  margin-top: 4px !important;
}
.ts-dropdown .option {
  padding: 0.5rem 0.75rem !important;
  font-size: 0.875rem;
  color: var(--text);
}
.ts-dropdown .active {
  background: rgba(var(--brand-rgb), 0.1) !important;
  color: var(--brand) !important;
}
.ts-dropdown .option.selected { background: var(--brand) !important; color: #fff !important; }
.ts-wrapper.multi .ts-control > div {
  background: rgba(var(--brand-rgb), 0.12) !important;
  color: var(--brand) !important;
  border: 1px solid rgba(var(--brand-rgb), 0.2) !important;
  border-radius: 6px !important;
  padding: 2px 8px !important;
}
.ts-wrapper.form-select-sm .ts-control { padding: 0.3rem 0.6rem !important; min-height: 32px; font-size: 0.825rem; }

/* form-select size matching */
.ts-wrapper .ts-control { padding-right: 2rem !important; }

/* ============ CODE BLOCK ============ */
code {
  background: rgba(var(--brand-rgb), 0.08);
  color: var(--brand);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85em;
}
pre {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 0.8rem;
  color: var(--text);
}
body[data-theme="dark"] pre { background: #0f172a; }

/* ============ THEME PICKER (theme.php) ============ */
button.theme-preset,
.theme-preset {
  cursor: pointer;
  border: 2px solid var(--border) !important;
  border-radius: var(--radius);
  padding: 1rem !important;
  text-align: center;
  transition: all 0.2s;
  background: var(--bg-card) !important;
  color: var(--text) !important;
  display: block;
  width: 100%;
  font-family: inherit;
}
button.theme-preset:hover,
.theme-preset:hover {
  border-color: var(--brand) !important;
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  background: var(--bg-card) !important;
}
button.theme-preset.active,
.theme-preset.active {
  border-color: var(--brand) !important;
  background: var(--brand-light) !important;
}
.theme-preset .swatches {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 0.5rem;
}
.theme-preset .swatch {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  display: inline-block;
}
.theme-preset .name {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
}
.theme-preset:focus { outline: none; box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.15); }

/* ============ DARK MODE OVERRIDES ============ */
body[data-theme="dark"] { background: var(--bg); }
body[data-theme="dark"] .topbar { background: var(--bg-card); }
body[data-theme="dark"] .form-control,
body[data-theme="dark"] .form-select { background: #0f172a; color: var(--text); }
body[data-theme="dark"] .form-control::placeholder { color: #64748b; }
body[data-theme="dark"] .ts-wrapper.single .ts-control,
body[data-theme="dark"] .ts-wrapper.multi .ts-control { background: #0f172a !important; }
body[data-theme="dark"] .ts-dropdown { background: #1e293b !important; }
body[data-theme="dark"] code { background: rgba(var(--brand-rgb), 0.15); }
body[data-theme="dark"] .table-success { --bs-table-bg: rgba(34,197,94,0.1); color: #86efac; }
body[data-theme="dark"] .table-warning { --bs-table-bg: rgba(234,179,8,0.1); color: #fde047; }
body[data-theme="dark"] .table-danger { --bs-table-bg: rgba(239,68,68,0.1); color: #fca5a5; }

/* ============ MOBILE ============ */
@media (max-width: 768px) {
  .sidebar { display: none !important; }
  .content-area { padding: 1rem !important; }
}

/* ============ SCROLLBAR (webkit) ============ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-mut); }