/* core.css — base + layout (improved) */

/* =========================
   Design Tokens
========================= */

:root {
  /* Colors */
  --primary-color: #295237;
  --primary-hover: #55823B;
  --secondary-color: #f8f9fa;
  --text-color: #333;
  --surface: #fff;
  --border: #e5e7eb;
  --text-muted: #64748b;
  --muted: #f1f5f9;
  --text: #0f172a;
  --error-bg: #fee;
  --error-text: #c00;
  
  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  
  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 15px rgba(0, 0, 0, 0.3);
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.2s ease;
  --transition-slow: 0.3s ease;
  
  /* Typography */
  --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  
  /* Layout */
  --container-max-width: 1400px;
  --header-height: 60px;
}

/* App wrapper with improved scaling */
#app-wrapper {
  transform: scale(0.8);
  transform-origin: top left;
  width: 125%;
  height: 125%;
  /* Prevent blurry text on scaled elements */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* =========================
   Reset & Base
========================= */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  /* Improve text rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

html, body {
  height: 100%;
}

body {
  background: #f5f5f5;
  color: var(--text-color);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.5;
  /* Prevent horizontal scrolling */
  overflow-x: hidden;
}

/* Improved focus styles for accessibility */
:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* =========================
   Layout
========================= */

.container {
  max-width: var(--container-max-width);
  margin: 0 auto;
  padding: var(--spacing-lg);
}

@media (max-width: 768px) {
  .container {
    padding: var(--spacing-md);
  }
}

/* =========================
   Header
========================= */

header {
  background: var(--secondary-color);
  box-shadow: var(--shadow-md);
  padding: 10px 0;
  margin-bottom: 24px;
  /* Make header sticky on scroll */
  position: sticky;
  top: 0;
  z-index: 1000;
  /* Smooth transitions */
  transition: box-shadow var(--transition-base);
}

/* Enhanced shadow on scroll - can be toggled with JS */
header.scrolled {
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
}

header .container {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

header .container > a {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  color: inherit;
  transition: opacity var(--transition-base);
}

header .container > a:hover {
  opacity: 0.8;
}

header .container > nav {
  margin-left: auto;
}

/* =========================
   Logo
========================= */

header .logo {
  margin-right: 100px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.logo img {
  display: block;
  height: 40px;
  width: auto;
  /* Prevent image drag */
  user-select: none;
  -webkit-user-drag: none;
}

.logo h1 {
  line-height: 1.2;
  font-size: 1.445rem;
  color: var(--primary-color);
  font-weight: 600;
}

/* =========================
   Navigation
========================= */

nav ul {
  display: flex;
  list-style: none;
  gap: 75px;
  margin: 0;
  padding: 0;
}

nav ul li {
  transition: transform var(--transition-slow);
}

nav ul li:hover {
  transform: scale(1.05);
}

nav ul li a {
  text-decoration: none;
  color: var(--text-color);
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-base);
  display: inline-block;
}

nav ul li:hover a,
nav ul li a.active {
  font-weight: 700;
  color: var(--primary-hover);
  background: rgba(85, 130, 59, 0.1);
}

/* Mobile navigation improvements */
@media (max-width: 768px) {
  nav ul {
    gap: var(--spacing-lg);
    flex-wrap: wrap;
  }
  
  nav ul li:hover {
    transform: scale(1.02);
  }
}

/* =========================
   Subnav
========================= */

.subnav {
  position: sticky;
  top: var(--header-height);
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  transition: box-shadow var(--transition-base);
}

.subnav.scrolled {
  box-shadow: var(--shadow-sm);
}

.subnav .container {
  display: flex;
  align-items: center;
}

.subnav-list {
  display: flex;
  gap: 100px;
  padding: var(--spacing-sm) 0;
  list-style: none;
  margin: 0;
}

.subnav a {
  display: inline-block;
  padding: var(--spacing-sm) 0.75rem;
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-muted);
  font-size: var(--font-size-base);
  font-weight: 500;
  transition: all var(--transition-base);
}

.subnav a.active,
.subnav a:focus-visible,
.subnav a:hover {
  color: var(--text);
  background: var(--muted);
}

.subsection {
  padding-block: var(--spacing-md) var(--spacing-xl);
}

/* =========================
   Dashboard Grid
========================= */

.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

/* Stacked layout */
.dashboard--stack {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.dashboard.dashboard--stack .card--status {
  order: 999;
}

/* Improved responsive grid */
@media (max-width: 1200px) {
  .dashboard {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  }
}

@media (max-width: 768px) {
  .dashboard {
    grid-template-columns: 1fr;
  }
}

/* =========================
   Recent Products / Contracts
========================= */

.recent-contracts {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 20px;
  margin-bottom: 30px;
}

.recent-contracts h2 {
  color: var(--primary-color);
  margin: 0 0 20px;
  font-size: var(--font-size-2xl);
  font-weight: 600;
}

/* =========================
   Status Box
========================= */

.status-box {
  min-height: 320px;
  white-space: pre-wrap;
  overflow: auto;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  /* Better scrollbar styling */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.status-box::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.status-box::-webkit-scrollbar-track {
  background: transparent;
}

.status-box::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-sm);
}

.status-box::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* =========================
   Utility Classes
========================= */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }
.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }

/* =========================
   Responsive
========================= */

@media (max-width: 768px) {
  header .container {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }
  
  header .logo {
    margin-right: 0;
  }
  
  .logo {
    justify-content: center;
  }
  
  .logo h1 {
    font-size: 1.2rem;
    text-align: center;
  }
  
  nav ul {
    justify-content: center;
  }
  
  .subnav-list {
    gap: var(--spacing-lg);
    flex-wrap: wrap;
    justify-content: center;
  }
  
  table {
    display: block;
    overflow-x: auto;
  }
}

/* Improved small screen support */
@media (max-width: 480px) {
  :root {
    font-size: 14px;
  }
  
  .container {
    padding: var(--spacing-sm);
  }
  
  nav ul {
    gap: var(--spacing-md);
  }
}

/* =========================
   Print Styles
========================= */

@media print {
  #app-wrapper {
    transform: none;
    width: 100%;
    height: auto;
  }
  
  header,
  nav,
  .btn,
  .subnav {
    display: none;
  }
  
  .card {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid var(--border);
  }
}



/* =========================
   Reduced Motion Support
========================= */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}