@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface2: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --card: #ffffff;
  --orange: #f97316;
  --orange-600: #ea580c;
  --accent: #f97316;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --radius: 12px;
  --sidebar-w: 270px;
  --shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] {
  --bg: #090d16;
  --surface: #131b2e;
  --surface2: #1e293b;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --border: #243048;
  --card: #131b2e;
  --orange: #fb923c;
  --orange-600: #f97316;
  --accent: #fb923c;
  --shadow: 0 4px 25px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }

.app-layout {
  display: flex; min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  z-index: 100;
}
.sidebar-header {
  display: flex; align-items: center; gap: 12px;
  padding: 20px; font-weight: 800; font-size: 16px;
  border-bottom: 1px solid var(--border);
}
.logo-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px;
  background: rgba(249,115,22,0.12); color: var(--orange);
}
.logo-title { font-weight: 800; font-size: 15px; letter-spacing: -0.01em; }
.logo-sub { font-size: 10.5px; color: var(--text-muted); font-weight: 500; }

.side-nav { padding: 16px 12px; flex: 1; overflow-y: auto; }
.nav-group-title {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  color: var(--text-muted); letter-spacing: 0.05em;
  padding: 12px 10px 4px; margin-top: 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 600; color: var(--text-muted);
  margin-bottom: 3px; transition: all 0.15s ease;
  background: transparent; border: none; width: 100%; text-align: left; cursor: pointer;
}
.nav-item:hover {
  background: var(--surface2); color: var(--text);
}
.nav-item.active {
  background: rgba(249,115,22,0.12);
  color: var(--orange-600);
}
.nav-item svg { color: currentColor; }

/* SIDEBAR FOOTER PLAN CARD */
.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); }
.plan-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px;
}

/* MAIN CONTENT & TOPBAR */
.main-content {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0; background: var(--bg);
}
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 28px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 90;
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 800; letter-spacing: -0.02em; }
.spacer { flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.user-badge {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px; border-radius: 8px;
  background: var(--surface2); border: 1px solid var(--border);
}
.avatar {
  width: 28px; height: 28px; border-radius: 6px;
  background: var(--orange); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800;
}

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

/* KPI BANNER */
.kpi-banner {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow);
}
.kpi-label {
  display: block; color: var(--text-muted); font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px;
}
.kpi-value {
  display: block; font-size: 24px; font-weight: 800; letter-spacing: -0.02em;
}

/* CARDS & TABLES */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 20px 24px; }
.table-container {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.data-table {
  width: 100%; border-collapse: collapse; text-align: left;
}
.data-table th {
  background: var(--surface2); font-size: 11.5px; text-transform: uppercase;
  color: var(--text-muted); font-weight: 700; letter-spacing: 0.05em;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 14px 18px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.data-table tbody tr:hover {
  background: rgba(249,115,22,0.02);
}

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; font-weight: 600; font-size: 13px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; transition: 0.15s ease;
}
.btn:hover { background: var(--surface2); }
.btn-primary { background: var(--orange); color: #fff; border-color: var(--orange); }
.btn-primary:hover { background: var(--orange-600); }
.btn.small { padding: 5px 10px; font-size: 11.5px; border-radius: 6px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
}

/* BADGES */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 700;
}
.badge.info { background: #dbeafe; color: #1e40af; }
.badge.success { background: #dcfce7; color: #166534; }
.badge.warning { background: #fef3c7; color: #92400e; }
.badge.danger { background: #fee2e2; color: #991b1b; }
.badge.neutral { background: var(--surface2); color: var(--text-muted); }

/* MODALS & OVERLAYS (HIDDEN BY DEFAULT) */
.modal,
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: none !important;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.open,
.modal-overlay.open {
  display: flex !important;
  animation: fadeIn 0.15s ease;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  position: relative;
}
.modal-card.large { max-width: 780px; }
.modal-head,
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3,
.modal-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}
.modal-body {
  padding: 20px;
  max-height: 75vh;
  overflow-y: auto;
}
.modal-foot,
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; width: 100%; max-width: 520px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.3); overflow: hidden;
}
.modal-card.large { max-width: 780px; }
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 800; }
.modal-body { padding: 20px; max-height: 75vh; overflow-y: auto; }
.modal-foot {
  padding: 14px 20px; border-top: 1px solid var(--border);
  background: var(--surface2); display: flex; justify-content: flex-end; gap: 8px;
}

/* TAB PANES */
.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* SKELETONS */
.skeleton-pill {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* RESPONSIVE */
.nav-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99; }
.nav-overlay.show { display: block; }

.show-sm { display: none !important; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: -100%; transition: left 0.25s ease; width: 280px; z-index: 100; }
  .sidebar.open { left: 0; }
  .hide-sm { display: none !important; }
  .show-sm { display: inline-flex !important; }
}
/* WIZARD & ONBOARDING ENHANCEMENTS */
.form-label {
  display: block; font-size: 12px; font-weight: 700;
  color: var(--text); margin-bottom: 6px;
}
.form-hint {
  display: block; font-size: 11px; color: var(--text-muted); margin-top: 4px;
}
.input-with-icon {
  position: relative; display: flex; align-items: center;
}
.input-with-icon .input-icon {
  position: absolute; left: 12px; color: var(--text-muted);
  pointer-events: none; display: flex; align-items: center;
}
.input-with-icon .input {
  padding-left: 38px !important; width: 100%;
}
.input {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); color: var(--text);
  font-size: 13px; font-family: inherit; transition: border-color 0.2s, box-shadow 0.2s;
}
.input:focus {
  outline: none; border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(249,115,22,0.18);
}

/* CONNECTED PROGRESS STEPPER */
.wizard-stepper-container {
  display: flex; flex-direction: column; align-items: center;
}
.wizard-track-line {
  position: absolute; top: 18px; left: 60px; right: 60px;
  height: 3px; background: var(--border); z-index: 1;
}
.wizard-track-progress {
  height: 100%; background: var(--orange); transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.wizard-steps-strip {
  display: flex; justify-content: space-between; width: 100%;
  position: relative; z-index: 2;
}
.wizard-step {
  display: flex; flex-direction: column; align-items: center;
  cursor: pointer; user-select: none;
}
.step-circle {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--border);
  color: var(--text-muted); font-weight: 800; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.25s ease; box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}
.wizard-step.active .step-circle {
  background: var(--orange); border-color: var(--orange); color: #fff;
  box-shadow: 0 0 0 4px rgba(249,115,22,0.22);
}
.wizard-step.completed .step-circle {
  background: var(--success); border-color: var(--success); color: #fff;
}
.step-text {
  text-align: center; margin-top: 8px;
}
.step-title {
  display: block; font-size: 12px; font-weight: 700; color: var(--text);
}
.step-subtitle {
  display: block; font-size: 10.5px; color: var(--text-muted);
}

/* CIDB SELECTION CARDS */
.cidb-card {
  border: 1.5px solid var(--border); border-radius: 10px; padding: 14px;
  background: var(--surface); cursor: pointer; transition: all 0.2s ease;
  position: relative; text-align: center;
}
.cidb-card:hover {
  border-color: var(--orange); transform: translateY(-2px);
}
.cidb-card.selected {
  border-color: var(--orange); background: rgba(249,115,22,0.04);
  box-shadow: 0 4px 12px rgba(249,115,22,0.12);
}
.cidb-tag {
  position: absolute; top: -8px; right: 10px; font-size: 9.5px; font-weight: 800;
  padding: 1px 6px; border-radius: 999px; background: var(--surface2); color: var(--text-muted);
}
.cidb-grade-title { font-weight: 800; font-size: 13px; margin: 4px 0 2px; }
.cidb-limit { font-size: 11px; color: var(--text-muted); }

/* PILL CHECKBOXES */
.pill-checkbox {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: 12px; cursor: pointer; transition: 0.15s ease;
  user-select: none;
}
.pill-checkbox.selected {
  background: rgba(249,115,22,0.08); border-color: var(--orange); color: var(--orange-600);
}
.pill-checkbox input { accent-color: var(--orange); }

/* SPINNER & LOADING STATES */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  display: inline-block;
  vertical-align: middle;
  animation: spin 0.6s linear infinite;
}
.btn.small .spinner {
  width: 12px;
  height: 12px;
  border-width: 1.8px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

/* ==========================================================================
   ELEVATED USER PROFILE PILL & FLOATING DIALOGUE CARD (MEDICORE PATTERN)
   ========================================================================== */
.bp-user-menu-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.bp-user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 4px 5px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.bp-user-pill:hover,
.bp-user-pill.active {
  background: var(--surface);
  border-color: var(--orange);
  box-shadow: 0 2px 8px rgba(249,115,22,0.15);
}

.bp-user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #F97316, #EA580C);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.76rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.bp-user-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  text-align: left;
}

.bp-user-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.bp-user-role {
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.bp-user-chevron {
  color: var(--text-muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.bp-user-pill.active .bp-user-chevron,
.bp-user-menu-wrap.active .bp-user-chevron {
  transform: rotate(180deg);
}

/* Elevated Floating Dialogue Card */
.bp-user-dropdown,
.bp-dropdown-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 290px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  z-index: 250;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.2s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.2s;
  padding: 8px;
  overflow: hidden;
  pointer-events: none;
}

.bp-user-dropdown.show,
.bp-dropdown-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

[data-theme="light"] .bp-user-dropdown,
[data-theme="light"] .bp-dropdown-menu {
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.12);
  background: #ffffff;
}

.bp-user-dropdown-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}

.bp-user-dropdown-header .bp-user-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.bp-user-dropdown-header .bp-user-name {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.bp-user-dropdown-header .bp-plan-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #EA580C;
  background: rgba(249,115,22,0.12);
  padding: 2px 7px;
  border-radius: 999px;
  margin-top: 3px;
}

.bp-dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

.bp-user-dropdown-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 0;
}

.bp-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  border-radius: 6px;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: all 0.15s ease;
  font-family: inherit;
  box-sizing: border-box;
}

.bp-dropdown-item:hover {
  background: var(--surface2);
  color: var(--orange);
}

.bp-dropdown-item svg {
  color: var(--text-muted);
  flex-shrink: 0;
  transition: color 0.15s;
}

.bp-dropdown-item:hover svg {
  color: var(--orange);
}

.bp-dropdown-item.danger {
  color: var(--danger);
}

.bp-dropdown-item.danger:hover {
  background: var(--danger-light);
  color: var(--danger);
}

.bp-dropdown-item.danger svg {
  color: var(--danger);
}

.bp-user-dropdown-footer {
  padding-top: 2px;
}

/* ==========================================================================
   MODULAR SETTINGS SUB-TABS NAVIGATION
   ========================================================================== */
.bp-settings-nav {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding: 0 0 14px;
  margin-bottom: 22px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.bp-settings-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  font-family: inherit;
}

.bp-settings-tab-btn:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
}

.bp-settings-tab-btn.active {
  background: linear-gradient(135deg, rgba(249,115,22,0.12), rgba(234,88,12,0.18));
  color: var(--orange);
  border-color: rgba(249,115,22,0.4);
  font-weight: 700;
}

.bp-settings-tab-btn.active svg {
  color: var(--orange);
}

.bp-settings-panel {
  display: none;
  animation: fadeIn 0.2s ease;
}

.bp-settings-panel.active {
  display: block;
}