/* =============================================================================
   RUTS SSO Portal — Stylesheet (Grid Card Layout)
   ============================================================================= */

:root {
  --primary: #1a3a6c;
  --primary-light: #2a5298;
  --primary-dark: #0d1f3c;
  --accent: #f0a500;
  --accent-light: #ffd166;
  --surface: #ffffff;
  --bg-gradient: linear-gradient(160deg, #0d1f3c 0%, #1a3a6c 40%, #2a5298 100%);
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --text-dark: #1e293b;
  --text-muted: #64748b;
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.12);
  --shadow-hover: 0 8px 40px rgba(0, 0, 0, 0.18);
  --radius: 16px;
  --radius-sm: 12px;
  --font: 'Noto Sans Thai', 'Inter', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg-gradient);
  min-height: 100vh;
  color: var(--text-primary);
}

/* --- Loading Screen --- */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 1rem;
  color: var(--text-secondary);
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s ease-in-out infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Header --- */
.portal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-logo {
  height: 36px;
  width: auto;
}

.logo-text {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.logo-ruts {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 2px;
}

.logo-sso {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-secondary);
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #e08900);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--primary-dark);
  flex-shrink: 0;
}

.user-info-header {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.user-display-name {
  font-size: 0.85rem;
  font-weight: 600;
}

.user-org-name {
  font-size: 0.7rem;
  color: var(--text-secondary);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-secondary);
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  font-size: 0.78rem;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

/* --- Profile Section --- */
.profile-section {
  padding: 2rem 1.5rem 0.5rem;
  max-width: 960px;
  margin: 0 auto;
}

.profile-card {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  background: rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  padding: 1.5rem 2rem;
}

.profile-avatar-large {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #e08900);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.8rem;
  color: var(--primary-dark);
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(240, 165, 0, 0.3);
}

.profile-info { flex: 1; }

.profile-name {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.profile-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.12);
  padding: 0.15rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  margin-bottom: 0.6rem;
}

.profile-badge.badge-staff {
  background: rgba(37, 99, 235, 0.2);
  color: #93c5fd;
}

.profile-badge.badge-student {
  background: rgba(202, 138, 4, 0.2);
  color: var(--accent-light);
}

.profile-details {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
}

.detail-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.detail-item svg {
  opacity: 0.6;
  flex-shrink: 0;
}

/* --- Apps Section --- */
.apps-section {
  padding: 1.5rem 1.5rem 1rem;
  max-width: 960px;
  margin: 0 auto;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.section-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
}

/* Tab Group */
.tab-group {
  display: flex;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.tab {
  padding: 0.35rem 0.8rem;
  font-size: 0.75rem;
  font-family: var(--font);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}

.tab.active {
  background: var(--accent);
  color: var(--primary-dark);
  font-weight: 600;
}

.tab:hover:not(.active) {
  background: rgba(255, 255, 255, 0.08);
}

/* --- App Cards Grid --- */
.apps-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.app-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  text-decoration: none;
  color: var(--text-dark);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.75rem;
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
}

.app-card::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--card-color, var(--primary));
  transform: scaleX(0);
  transition: transform 0.3s;
}

.app-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
  border-color: var(--card-color, var(--primary));
}

.app-card:hover::after {
  transform: scaleX(1);
}

.app-icon-wrapper {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--card-color, #1a3a6c) 10%, white);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.app-icon {
  font-size: 1.5rem;
}

.app-text {
  flex: 1;
}

.app-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary-dark);
  margin-bottom: 0.15rem;
  line-height: 1.3;
}

.app-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* --- Footer --- */
.portal-footer {
  text-align: center;
  padding: 1.5rem;
  color: rgba(255, 255, 255, 0.3);
  font-size: 0.72rem;
  line-height: 1.6;
  max-width: 960px;
  margin: 0 auto;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .apps-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .user-info-header {
    display: none;
  }

  .profile-card {
    flex-direction: column;
    text-align: center;
    padding: 1.25rem;
    gap: 1rem;
  }

  .profile-details {
    justify-content: center;
    flex-direction: column;
    align-items: center;
  }

  .profile-name {
    font-size: 1.2rem;
  }
}

@media (max-width: 480px) {
  .apps-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .app-card {
    padding: 1rem 0.75rem;
  }

  .app-icon-wrapper {
    width: 48px;
    height: 48px;
  }

  .app-name {
    font-size: 0.78rem;
  }

  .portal-header {
    padding: 0.5rem 1rem;
  }

  .profile-section,
  .apps-section {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}

/* --- Print --- */
@media print {
  body { background: #fff; color: #333; }
  .portal-header { background: var(--primary) !important; print-color-adjust: exact; }
  .btn-logout { display: none; }
}
