/**
 * Skill Shiksha CTO Design System
 * Synthesis of Material Design 3 (M3) + Apple Human Interface Guidelines (HIG)
 * Pure CSS • Zero Framework Bloat • Accessible • High-Density Enterprise SaaS
 */

:root {
  /* ── 1. M3 & Apple HIG Typography Scale ─────────────────────────────────────── */
  --font-sans: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", ui-monospace, Menlo, Monaco, Consolas, monospace;

  --text-display: 2.25rem;   /* 36px - Bold 800 - -0.025em */
  --text-title-lg: 1.5rem;    /* 24px - Bold 700 - -0.020em */
  --text-title-md: 1.25rem;   /* 20px - SemiBold 600 - -0.015em */
  --text-title-sm: 1.05rem;   /* 17px - SemiBold 600 - -0.010em */
  --text-body: 0.875rem;      /* 14px - Regular 400 - 0.000em */
  --text-body-sm: 0.8125rem;  /* 13px - Regular 400 - 0.000em */
  --text-caption: 0.75rem;    /* 12px - Medium 500 - +0.010em */
  --text-micro: 0.6875rem;    /* 11px - Bold 700 - +0.040em (Uppercase) */

  /* ── 2. M3 Tonal Palette & Apple Vibrancy ──────────────────────────────────── */
  --md-sys-color-primary: #2563EB;
  --md-sys-color-on-primary: #FFFFFF;
  --md-sys-color-primary-container: #EFF6FF;
  --md-sys-color-on-primary-container: #1D4ED8;
  --md-sys-color-primary-border: #DBEAFE;

  --md-sys-color-secondary: #7C3AED;
  --md-sys-color-secondary-container: #F5F3FF;
  --md-sys-color-secondary-border: #DDD6FE;

  --md-sys-color-success: #059669;
  --md-sys-color-success-container: #ECFDF5;
  --md-sys-color-success-border: #A7F3D0;

  --md-sys-color-warning: #D97706;
  --md-sys-color-warning-container: #FFFBEB;
  --md-sys-color-warning-border: #FDE68A;

  --md-sys-color-danger: #DC2626;
  --md-sys-color-danger-container: #FEF2F2;
  --md-sys-color-danger-border: #FECACA;

  --md-sys-color-info: #0891B2;
  --md-sys-color-info-container: #F0F9FF;
  --md-sys-color-info-border: #BAE6FD;

  /* Surfaces */
  --md-sys-color-surface-canvas: #F6F8FB;       /* Soothing Slate Canvas */
  --md-sys-color-surface-white: #FFFFFF;        /* Pure White Card Base */
  --md-sys-color-surface-container-low: #F9FBFE; /* Table Header / Subtle Tile */
  --md-sys-color-surface-container: #F1F5F9;     /* Input Backdrop / Filter Strip */
  --md-sys-color-surface-container-high: #E2E8F0;/* Hover States */
  --md-sys-color-outline: rgba(226, 232, 240, 0.9);
  --md-sys-color-outline-variant: rgba(241, 245, 249, 0.8);

  /* Typography Colors */
  --text-primary: #0F172A;   /* Slate 900 */
  --text-secondary: #334155; /* Slate 700 */
  --text-muted: #64748B;     /* Slate 500 */
  --text-tertiary: #94A3B8;  /* Slate 400 */

  /* ── 3. Geometric Shapes & Elevation ────────────────────────────────────────── */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 9999px;

  /* Ambient Diffusion Shadows (Apple HIG Soft Lights + M3 Elevation) */
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.04), 0 1px 2px rgba(15, 23, 42, 0.02);
  --shadow-md: 0 4px 12px -1px rgba(15, 23, 42, 0.06), 0 2px 4px -1px rgba(15, 23, 42, 0.03);
  --shadow-lg: 0 12px 28px -4px rgba(15, 23, 42, 0.08), 0 4px 8px -2px rgba(15, 23, 42, 0.03);
  --shadow-xl: 0 24px 48px -12px rgba(15, 23, 42, 0.12);
  --inner-bevel: inset 0 1px 0 0 rgba(255, 255, 255, 0.9);

  /* Motion Curves */
  --ease-spring: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
}

/* ── 4. App Shell & Layout ─────────────────────────────────────────────────── */
body {
  font-family: var(--font-sans);
  background-color: var(--md-sys-color-surface-canvas);
  color: var(--text-primary);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.portal-layout {
  display: flex;
  min-height: 100vh;
}

/* ── 5. Left Sidebar (Apple Dock + M3 Navigation Rail) ───────────────────────── */
.portal-sidebar {
  width: 250px;
  background: var(--md-sys-color-surface-white);
  border-right: 1px solid var(--md-sys-color-outline);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.25s var(--ease-spring), transform 0.25s var(--ease-spring);
  position: fixed !important;
  top: 0 !important;
  bottom: 0 !important;
  left: 0 !important;
  height: 100vh !important;
  height: 100dvh !important;
  z-index: 1000 !important;
  overflow: hidden !important;
  padding: 0 !important;
  margin: 0 !important;
  box-sizing: border-box !important;
}

.portal-sidebar.collapsed {
  width: 72px !important;
}

.portal-sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 12px;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}

.portal-sidebar-nav:hover {
  scrollbar-color: rgba(148, 163, 184, 0.5) transparent;
}

.portal-sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.portal-sidebar-nav::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 4px;
}

.portal-sidebar-nav:hover::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.5);
}

.portal-sidebar-header {
  height: 64px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.portal-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.portal-brand-dock-logo {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--md-sys-color-primary) 0%, #1D4ED8 100%);
  color: #FFFFFF;
  font-weight: 800;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
  letter-spacing: -0.02em;
}

.portal-brand-name {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.portal-sidebar-badge {
  font-size: var(--text-micro);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-primary);
  display: inline-block;
  margin-top: 1px;
}

.portal-sidebar-collapse-btn {
  background: transparent;
  border: 1px solid var(--md-sys-color-outline);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.portal-sidebar-collapse-btn:hover {
  background: var(--md-sys-color-surface-container);
  color: var(--text-primary);
}

/* Nav Groups */
.portal-sidebar-group {
  padding: 14px 12px 6px;
}

.portal-sidebar-group-title {
  font-size: var(--text-micro);
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-tertiary);
  letter-spacing: 0.06em;
  padding: 0 10px 6px;
}

.portal-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--text-body);
  font-weight: 600;
  margin-bottom: 2px;
  transition: all 0.18s var(--ease-spring);
  position: relative;
}

.portal-nav-item:hover {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-primary);
}

.portal-nav-item.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-primary);
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.2);
}

.portal-nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--md-sys-color-primary);
}

.portal-nav-icon {
  font-size: 1.1rem;
  width: 22px;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.portal-sidebar.collapsed .portal-nav-text,
.portal-sidebar.collapsed .portal-sidebar-group-title,
.portal-sidebar.collapsed .portal-brand-text {
  display: none;
}

.portal-sidebar.collapsed .portal-nav-item {
  justify-content: center;
  padding: 10px;
}

/* Sidebar Footer */
.portal-sidebar-footer {
  margin-top: auto;
  padding: 12px 14px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.portal-footer-user {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.portal-dock-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 800;
  flex-shrink: 0;
}

.portal-footer-user-name {
  font-size: var(--text-body-sm);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.portal-footer-user-role {
  font-size: var(--text-caption);
  color: var(--text-muted);
}

.portal-dock-logout-btn {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.portal-dock-logout-btn:hover {
  background: var(--md-sys-color-danger-container);
  color: var(--md-sys-color-danger);
}

/* ── 6. TopBar Header (Apple Frosted Glass) ─────────────────────────────────── */
.portal-main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin-left: 250px;
  width: calc(100% - 250px);
  min-height: 100vh;
  min-height: 100dvh;
}

.portal-sidebar.collapsed + .portal-main-area,
.portal-sidebar.collapsed ~ .portal-main-area {
  margin-left: 72px !important;
  width: calc(100% - 72px) !important;
}

.portal-top-bar {
  height: 64px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--md-sys-color-outline);
  position: sticky;
  top: 0;
  z-index: 90;
}

.portal-top-greeting {
  font-size: var(--text-title-sm);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.015em;
}

.portal-top-subtitle {
  font-size: var(--text-caption);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 1px;
}

/* Pill Search */
.pill-search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  cursor: pointer;
  transition: all 0.18s var(--ease-spring);
}

.pill-search-bar:hover {
  background: var(--md-sys-color-surface-white);
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.pill-search-bar input {
  border: none;
  background: transparent;
  outline: none;
  font-size: var(--text-body-sm);
  color: var(--text-primary);
  width: 210px;
}

.icon-pill-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--md-sys-color-surface-white);
  border: 1px solid var(--md-sys-color-outline);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.icon-pill-btn:hover {
  background: var(--md-sys-color-surface-container);
  border-color: var(--md-sys-color-outline);
  color: var(--text-primary);
}

.user-avatar-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  background: var(--md-sys-color-surface-white);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-pill);
  font-size: var(--text-body-sm);
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
}

.user-avatar-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--md-sys-color-primary);
  color: #FFFFFF;
  font-size: 0.72rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── 7. Main Content & Cards ───────────────────────────────────────────────── */
.portal-content-area {
  padding: 24px 28px 48px;
  flex: 1;
}

.card {
  background: var(--md-sys-color-surface-white);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm), var(--inner-bevel);
  padding: 20px;
  transition: transform 0.2s var(--ease-spring), box-shadow 0.2s var(--ease-spring);
}

.card:hover {
  box-shadow: var(--shadow-md), var(--inner-bevel);
}

/* ── 8. KPI & Stat Cards ───────────────────────────────────────────────────── */
.kpi-compact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card-deluxe {
  background: var(--md-sys-color-surface-white);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm), var(--inner-bevel);
  transition: transform 0.2s var(--ease-spring), box-shadow 0.2s var(--ease-spring);
}

.stat-card-deluxe:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-card-title {
  font-size: var(--text-caption);
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.stat-card-value {
  font-size: 1.75rem;
  font-weight: 900;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.stat-card-subtitle {
  font-size: var(--text-caption);
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── 9. Faceted Filters & M3 Chips ─────────────────────────────────────────── */
.faceted-filter-bar {
  background: var(--md-sys-color-surface-white);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}

.filter-pill {
  border-radius: var(--radius-pill);
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface-container-low);
  padding: 6px 12px;
  font-size: var(--text-body-sm);
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  outline: none;
}

.filter-pill:hover {
  background: var(--md-sys-color-surface-container);
  border-color: var(--text-tertiary);
}

.filter-pill.has-value {
  background: var(--md-sys-color-primary-container);
  border-color: var(--md-sys-color-primary-border);
  color: var(--md-sys-color-on-primary-container);
}

/* ── 10. Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 10px;
  font-size: var(--text-body-sm);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s var(--ease-spring);
  border: none;
  line-height: 1.3;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(135deg, var(--md-sys-color-primary) 0%, #1D4ED8 100%);
  color: #FFFFFF;
  border: 1px solid #1D4ED8;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #1D4ED8 0%, #1E40AF 100%);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-outline {
  background: var(--md-sys-color-surface-white);
  border: 1px solid var(--md-sys-color-outline);
  color: var(--text-secondary);
}

.btn-outline:hover {
  background: var(--md-sys-color-surface-container-low);
  border-color: var(--text-tertiary);
  color: var(--text-primary);
}

.btn-sm {
  padding: 5px 11px;
  font-size: var(--text-caption);
  border-radius: var(--radius-sm);
}

/* ── 11. Data Tables ───────────────────────────────────────────────────────── */
.data-table-container,
.table-responsive {
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--md-sys-color-surface-white);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-body-sm);
}

thead tr {
  background: var(--md-sys-color-surface-container-low);
  border-bottom: 1px solid var(--md-sys-color-outline);
}

thead th {
  padding: 11px 16px;
  text-align: left;
  font-size: var(--text-micro);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

tbody tr {
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  transition: background 0.12s ease;
}

tbody tr:hover {
  background: #F8FAFF;
}

tbody tr:last-child {
  border-bottom: none;
}

tbody td {
  padding: 12px 16px;
  color: var(--text-primary);
  vertical-align: middle;
}

/* ── 12. Status Badges & Pills ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: var(--text-caption);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.badge-success {
  background: var(--md-sys-color-success-container);
  color: var(--md-sys-color-success);
  border: 1px solid var(--md-sys-color-success-border);
}

.badge-warning {
  background: var(--md-sys-color-warning-container);
  color: var(--md-sys-color-warning);
  border: 1px solid var(--md-sys-color-warning-border);
}

.badge-danger {
  background: var(--md-sys-color-danger-container);
  color: var(--md-sys-color-danger);
  border: 1px solid var(--md-sys-color-danger-border);
}

.badge-primary,
.badge-info {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-primary);
  border: 1px solid var(--md-sys-color-primary-border);
}

/* ── 13. Modals & Dialogs (Apple Vibrancy) ─────────────────────────────────── */
.portal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9990;
  display: none;
}

.modal-dialog-deluxe {
  background: var(--md-sys-color-surface-white);
  border-radius: var(--radius-xl);
  border: 1px solid var(--md-sys-color-outline);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  max-width: 580px;
  width: 90%;
  margin: auto;
}

/* ── 14. Responsive Layouts ────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .portal-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: -280px;
    width: 270px !important;
    z-index: 10000;
    box-shadow: var(--shadow-xl);
    transition: left 0.3s var(--ease-spring);
  }
  .portal-sidebar.open {
    left: 0;
  }
  .portal-menu-toggle {
    display: flex !important;
  }
  .portal-content-area {
    padding: 16px;
  }
  .portal-top-bar {
    padding: 0 16px;
  }
  .kpi-compact-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .kpi-compact-grid {
    grid-template-columns: 1fr;
  }
  .pill-search-bar input {
    width: 120px;
  }
}
