/* shared/styles.css - Unified Portal Styles */

/* CSS Custom Properties - Unified Theme */
:root {
  /* Core Colors */
  --bg: #0f1216;
  --card: #151a21;
  --text: #e6edf3;
  --muted: #97a2b0;
  --accent: #6aa9ff;
  --accent-2: #8bffb0;
  --danger: #ff6a6a;
  --warning: #ffd36a;
  --success: #8bffb0;
  --link: #a0c2ff;
  --border: #2a3140;
  
  /* Semantic Color Mappings */
  --primary: var(--accent);
  --secondary: var(--accent-2);
  --background: var(--bg);
  --card-bg: var(--card);
  --text-color: var(--text);
  --muted-color: var(--muted);
  --border-color: var(--border);
  --danger-color: var(--danger);
  --warning-color: var(--warning);
  --success-color: var(--success);
  --link-color: var(--link);

  /* Site Theme Variables (overridden by JS theme system) */
  --nav-bg: #0c1118;
  --nav-text: #c7d2fe;
  --nav-hover: #a5b4fc;
  --nav-active-bg: #0b0f14;
  --input-bg: #0e1319;
  --surface-bg: #0b1017;
  --surface-border: #1a2330;
  --text-light: #e5e7eb;
  --class-card-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --class-card-hover-shadow: rgba(102, 126, 234, 0.3);
  --bg-image: none;
  --bg-overlay: rgba(15, 18, 22, 0.85);

  /* Button Color Scheme (overridden by JS) */
  --btn-bg: linear-gradient(135deg, #6aa9ff, #8bffb0);
  --btn-text: #0b0f14;
  --btn-shadow: rgba(106, 169, 255, 0.3);
  
  /* Spacing Scale */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  
  /* Typography Scale */
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 18px;
  --text-xl: 20px;
  --text-2xl: 24px;
  --text-3xl: 30px;
  
  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  
  /* Shadows */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 8px 25px rgba(0, 0, 0, 0.25);
  --shadow-xl: 0 16px 40px rgba(0, 0, 0, 0.35);
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.2s ease;
  --transition-slow: 0.3s ease;
}

/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
  scroll-behavior: smooth;
  overflow-x: hidden;
  scrollbar-gutter: stable;
}

body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  background: var(--background);
  color: var(--text-color);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Background image layer (set via theme system) */
body.has-bg-image {
  background: transparent;
  position: relative;
  z-index: 0; /* create stacking context so pseudo-elements stay behind content but visible */
}
body.has-bg-image::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  background-image: var(--bg-image);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  pointer-events: none;
}
body.has-bg-image::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--bg-overlay);
  pointer-events: none;
}

/* Background image element transparency is injected dynamically by
   PortalUI.applyBgImage() via a <style id="bg-image-alpha-styles"> tag
   to guarantee it loads last and overrides all inline <style> blocks. */

/* Typography */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-color);
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: var(--space-sm);
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-base); }
h6 { font-size: var(--text-sm); }

p {
  margin-bottom: var(--space-md);
  color: var(--muted-color);
}

a {
  color: var(--link-color);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--primary);
}

/* Layout Components */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-md);
}

.container-fluid {
  width: 100%;
  padding: 0 var(--space-md);
}

/* Card Component */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-md);
  transition: box-shadow var(--transition-normal);
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.card-header {
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border-color);
  margin-bottom: var(--space-md);
}

.card-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-color);
  margin: 0;
}

.card-subtitle {
  font-size: var(--text-sm);
  color: var(--muted-color);
  margin: var(--space-xs) 0 0 0;
}

/* Button Component */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--card-bg);
  color: var(--text-color);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(106, 169, 255, 0.1);
  background: rgba(106, 169, 255, 0.05);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Button Variants — primary & secondary both use the user's color scheme */
.btn-primary,
.btn-secondary {
  background: var(--btn-bg);
  color: var(--btn-text);
  border-color: transparent;
  font-weight: 600;
}

.btn-primary:hover,
.btn-secondary:hover {
  background: var(--btn-bg);
  filter: brightness(1.05);
  box-shadow: 0 4px 12px var(--btn-shadow);
  color: var(--btn-text);
  transform: translateY(-2px);
}

.btn-danger {
  background: var(--danger-color);
  color: white;
  border-color: var(--danger-color);
}

.btn-danger:hover {
  background: #e55a5a;
  border-color: #e55a5a;
  box-shadow: 0 4px 12px rgba(255, 106, 106, 0.3);
}

.btn-success {
  background: var(--success-color);
  color: #0b0f14;
  border-color: var(--success-color);
  font-weight: 600;
}

.btn-success:hover {
  filter: brightness(0.95);
  box-shadow: 0 4px 12px rgba(139, 255, 176, 0.3);
}

.btn-warning {
  background: var(--warning-color);
  color: #0b0f14;
  border-color: var(--warning-color);
  font-weight: 600;
}

.btn-warning:hover {
  filter: brightness(0.95);
  box-shadow: 0 4px 12px rgba(255, 211, 106, 0.3);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted-color);
}

.btn-ghost:hover {
  background: rgba(106, 169, 255, 0.1);
  color: var(--primary);
}

/* Button Sizes */
.btn-sm,
.btn.small {
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--text-xs);
}

.btn-lg {
  padding: var(--space-md) var(--space-lg);
  font-size: var(--text-base);
}

/* Form Components */
.form-group {
  margin-bottom: var(--space-md);
}

.form-label {
  display: block;
  margin-bottom: var(--space-xs);
  font-weight: 600;
  color: var(--text-color);
  font-size: var(--text-sm);
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--card-bg);
  color: var(--text-color);
  font-size: var(--text-sm);
  font-family: inherit;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(106, 169, 255, 0.2);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

/* Grid System */
.grid {
  display: grid;
  gap: var(--space-lg);
}

.grid-1 { grid-template-columns: 1fr; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* Flex Utilities */
.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-center {
  justify-content: center;
}

.justify-between {
  justify-content: space-between;
}

.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }

/* Navigation Components */
.nav {
  display: flex;
  gap: 0;
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border-color);
}

.nav-item {
  flex: 1;
  padding: var(--space-md);
  text-align: center;
  cursor: pointer;
  border: 0;
  background: transparent;
  color: var(--nav-text);
  text-decoration: none;
  font-family: inherit;
  font-size: var(--text-sm);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.02);
  color: var(--nav-hover);
}

.nav-item.active {
  color: var(--primary);
  font-weight: 700;
  border-bottom: 3px solid var(--primary);
  background: var(--nav-active-bg);
}

/* List Components */
.list {
  list-style: none;
}

.list-item {
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.list-item:last-child {
  border-bottom: none;
}

.list-item-content {
  flex: 1;
}

.list-item-title {
  font-weight: 600;
  color: var(--text-color);
  margin-bottom: var(--space-xs);
}

.list-item-meta {
  font-size: var(--text-xs);
  color: var(--muted-color);
}

/* Alert Components */
.alert {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  border: 1px solid var(--border-color);
}

.alert-info {
  background: rgba(106, 169, 255, 0.1);
  color: #a0c2ff;
  border-color: rgba(106, 169, 255, 0.3);
}

.alert-success {
  background: rgba(139, 255, 176, 0.1);
  color: #b5ffd0;
  border-color: rgba(139, 255, 176, 0.3);
}

.alert-error {
  background: rgba(255, 106, 106, 0.1);
  color: #ffb3b3;
  border-color: rgba(255, 106, 106, 0.3);
}

.alert-warning {
  background: rgba(255, 211, 106, 0.1);
  color: #ffd36a;
  border-color: rgba(255, 211, 106, 0.3);
}

/* Progress Components */
.progress {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  height: 16px;
  overflow: hidden;
  margin: var(--space-sm) 0;
}

.progress-bar {
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  height: 100%;
  border-radius: var(--radius-lg);
  transition: width var(--transition-slow);
}

/* Stats Components */
.stats {
  display: flex;
  justify-content: space-between;
  gap: var(--space-md);
  margin: var(--space-md) 0;
}

.stat {
  text-align: center;
  flex: 1;
}

.stat-value {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--primary);
  display: block;
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--muted-color);
  margin-top: var(--space-xs);
}

/* Utility Classes */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-normal { font-weight: 400; }

.text-primary { color: var(--primary); }
.text-secondary { color: var(--secondary); }
.text-muted { color: var(--muted-color); }
.text-danger { color: var(--danger-color); }
.text-warning { color: var(--warning-color); }

/* Spacing Utilities */
.m-0 { margin: 0; }
.m-1 { margin: var(--space-xs); }
.m-2 { margin: var(--space-sm); }
.m-3 { margin: var(--space-md); }
.m-4 { margin: var(--space-lg); }
.m-5 { margin: var(--space-xl); }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--space-xs); }
.mt-2 { margin-top: var(--space-sm); }
.mt-3 { margin-top: var(--space-md); }
.mt-4 { margin-top: var(--space-lg); }
.mt-5 { margin-top: var(--space-xl); }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--space-xs); }
.mb-2 { margin-bottom: var(--space-sm); }
.mb-3 { margin-bottom: var(--space-md); }
.mb-4 { margin-bottom: var(--space-lg); }
.mb-5 { margin-bottom: var(--space-xl); }

.p-0 { padding: 0; }
.p-1 { padding: var(--space-xs); }
.p-2 { padding: var(--space-sm); }
.p-3 { padding: var(--space-md); }
.p-4 { padding: var(--space-lg); }
.p-5 { padding: var(--space-xl); }

/* Responsive Design */
@media (max-width: 768px) {
  .container {
    padding: 0 var(--space-sm);
  }
  
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }
  
  .nav-item {
    padding: var(--space-sm);
    font-size: var(--text-xs);
  }
  
  .card {
    padding: var(--space-md);
  }
  
  .btn {
    padding: var(--space-sm);
    font-size: var(--text-xs);
  }
  
  .stats {
    flex-direction: column;
    gap: var(--space-sm);
  }
  
  .stat {
    text-align: left;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0 var(--space-xs);
  }
  
  .card {
    padding: var(--space-sm);
  }
  
  h1 { font-size: var(--text-2xl); }
  h2 { font-size: var(--text-xl); }
  h3 { font-size: var(--text-lg); }
}

/* Animation Classes */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes slideInUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.animate-fade-in {
  animation: fadeIn 0.3s ease-out;
}

.animate-slide-in-right {
  animation: slideInRight 0.3s ease-out;
}

.animate-slide-in-up {
  animation: slideInUp 0.3s ease-out;
}

/* Portal-specific unification classes */
.portal-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.portal-content {
  flex: 1;
  padding: var(--space-lg) 0;
}

.portal-container {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  margin: var(--space-lg) auto;
  max-width: 1200px;
  min-height: 600px;
  overflow: hidden;
  box-shadow: var(--shadow-xl);
}

/* Authenticated state modifications */
.authenticated .portal-container {
  margin: 0;
  border-radius: 0;
  border: none;
  box-shadow: none;
  background: transparent;
  max-width: none;
  width: 100%;
}