/**
 * BHSST E-OFFICE — BASE STYLES (base.css) [S2 — Enterprise Edition]
 * Reset, typography foundation, layout wrappers, accessibility defaults.
 */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=IBM+Plex+Mono:wght@400;500;600&family=Inter:wght@300;400;500;600;700&display=swap');
@import './tokens.css';

/* 1. Universal Box-Sizing & Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
html.font-size-sm {
  font-size: 14px; /* Default Compact Enterprise Density (Small) */
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

html.font-size-md {
  font-size: 16px; /* Standard Font Size (Medium) */
}

html.font-size-lg {
  font-size: 18px; /* High-Visibility Font Size (Large) */
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--color-text-main);
  background-color: var(--color-bg);
  background-image:
    radial-gradient(circle at 1px 1px, var(--theme-grid-dot, rgba(79, 70, 229, 0.07)) 1px, transparent 0);
  background-size: 24px 24px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* 2. Typography Defaults */
h1, h2, h3, h4, h5, h6 {
  color: var(--color-primary-dark);
  font-weight: var(--font-weight-bold);
  line-height: 1.2;
  letter-spacing: -0.01em;
  font-family: var(--font-display);
}

h1 { font-size: var(--text-3xl); margin-bottom: var(--space-4); letter-spacing: -0.02em; }
h2 { font-size: var(--text-2xl); margin-bottom: var(--space-3); letter-spacing: -0.015em; }
h3 { font-size: var(--text-xl);  margin-bottom: var(--space-2); }
h4 { font-size: var(--text-lg);  margin-bottom: var(--space-2); }

p {
  margin-bottom: var(--space-3);
  color: var(--color-text-muted);
  line-height: 1.6;
}

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-accent-hover);
  text-decoration: underline;
  text-underline-offset: 2px;
}

ul, ol {
  padding-left: var(--space-6);
  margin-bottom: var(--space-4);
  color: var(--color-text-muted);
}

code, pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

img, svg {
  display: block;
  max-width: 100%;
}

/* 3. Layout Utilities */
.app-container {
  width: 100%;
  max-width: var(--max-width-container);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-5);
  padding-right: var(--space-5);
}

.main-content {
  flex: 1 0 auto;
  padding-top: var(--space-6);
  padding-bottom: var(--space-12);
}

.flex { display: flex; }
.flex-col { flex-direction: column; }
.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

@media (max-width: 1024px) {
  .grid-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
  .grid-cols-2, .grid-cols-3, .grid-cols-4 {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }
}

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--color-text-muted); }
.text-subtle { color: var(--color-text-subtle); }
.font-mono { font-family: var(--font-mono); }
.font-bold { font-weight: var(--font-weight-bold); }
.font-semibold { font-weight: var(--font-weight-semibold); }
.font-medium { font-weight: var(--font-weight-medium); }
.justify-end { justify-content: flex-end; }

/* 4. Accessibility & Focus States */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* 5. Loading Skeleton Animation */
@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.skeleton {
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
  color: transparent !important;
  pointer-events: none;
  user-select: none;
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* 6. Page Loading Overlay */
#page-loading-guard {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: var(--space-4);
  transition: opacity 250ms ease;
}

#page-loading-guard.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 2.5px solid var(--color-border);
  border-top-color: var(--color-secondary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

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

/* 7. Session Timeout Warning Banner */
.session-timeout-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: linear-gradient(90deg, #4338ca, #7c3aed);
  color: white;
  padding: 10px var(--space-6);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  box-shadow: var(--shadow-md);
  animation: slideDown 300ms ease;
  transform-origin: top;
  letter-spacing: 0.01em;
}

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* 8. Mobile-Responsive Flex Stack */
@media (max-width: 640px) {
  .flex-mobile-col {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .flex-mobile-col .btn {
    width: 100%;
    justify-content: center;
  }

  .app-container {
    padding-left: var(--space-3);
    padding-right: var(--space-3);
  }

  h1 { font-size: var(--text-2xl); }
  h2 { font-size: var(--text-xl); }
}

/* 9. Table Horizontal Scroll on Mobile */
@media (max-width: 768px) {
  .table-wrapper {
    -webkit-overflow-scrolling: touch;
  }

  .table th, .table td {
    white-space: nowrap;
  }
}

/* 10. Print Media — Hide Interactive Chrome */
@media print {
  .app-header, .gov-banner, footer, .btn, .toast-container, .modal-backdrop, #page-loading-guard, .session-timeout-banner {
    display: none !important;
  }
}
