/* ============================================================
   FILE    : assets/css/base.css
   PATH    : /httpdocs/assets/css/base.css
   PURPOSE : CSS reset, base body styles, typography scale,
             scrollbar styling, text selection, link styles,
             global animations, and utility base classes.
             Must load AFTER tokens.css.
   REQUIRES: assets/css/tokens.css
   ============================================================ */

/* ============================================================
   MODERN CSS RESET
   ============================================================ */

/* Box sizing */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Remove default list styles */
ul, ol {
  list-style: none;
}

/* Remove default border on images */
img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

/* Remove built-in form typography styles */
input, button, textarea, select {
  font: inherit;
  color: inherit;
}

/* Avoid text overflows */
p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

/* Remove default button styles */
button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

/* Remove default anchor styles */
a {
  color: inherit;
  text-decoration: none;
}

/* Table reset */
table {
  border-collapse: collapse;
  border-spacing: 0;
}

/* Remove default fieldset styles */
fieldset {
  border: none;
}

/* ============================================================
   ROOT & BODY
   ============================================================ */

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: 100%;
}

body {
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--font-normal);
  line-height: var(--leading-normal);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* Grid background pattern for page background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(var(--grid-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
  background-size: var(--grid-size) var(--grid-size);
  pointer-events: none;
  z-index: var(--z-below);
}

/* ============================================================
   CUSTOM SCROLLBAR
   ============================================================ */

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

/* WebKit / Blink */
::-webkit-scrollbar {
  width: var(--scrollbar-width);
  height: var(--scrollbar-width);
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: var(--radius-full);
  border: 1px solid var(--scrollbar-track);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-hover);
}

::-webkit-scrollbar-corner {
  background: var(--scrollbar-track);
}

/* ============================================================
   TEXT SELECTION
   ============================================================ */

::selection {
  background-color: var(--color-primary-subtle);
  color: var(--color-brand-300);
}

::-moz-selection {
  background-color: var(--color-primary-subtle);
  color: var(--color-brand-300);
}

/* ============================================================
   TYPOGRAPHY SCALE
   ============================================================ */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-sans);
  font-weight: var(--font-bold);
  line-height: var(--leading-tight);
  color: var(--text-primary);
  letter-spacing: var(--tracking-tight);
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); }

p {
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
  margin-bottom: var(--space-4);
}

p:last-child {
  margin-bottom: 0;
}

/* Small text */
small {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* Strong / bold */
strong, b {
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

/* Italic */
em, i {
  font-style: italic;
  color: var(--text-secondary);
}

/* Code inline */
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background-color: var(--bg-surface-2);
  color: var(--color-brand-300);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  white-space: nowrap;
}

/* Code block */
pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  padding: var(--space-5);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-color);
  overflow-x: auto;
  line-height: var(--leading-relaxed);
  white-space: pre-wrap;
  word-break: break-word;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
  white-space: inherit;
}

/* Blockquote */
blockquote {
  border-left: 3px solid var(--color-primary);
  padding-left: var(--space-4);
  margin: var(--space-4) 0;
  color: var(--text-secondary);
  font-style: italic;
}

/* Horizontal rule */
hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: var(--space-6) 0;
}

/* ============================================================
   LINKS
   ============================================================ */

a {
  color: var(--color-brand-400);
  text-decoration: none;
  transition: var(--transition-color);
}

a:hover {
  color: var(--color-brand-300);
  text-decoration: underline;
}

a:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* ============================================================
   FOCUS STYLES
   ============================================================ */

/* Remove default outline — we use custom focus styles */
*:focus {
  outline: none;
}

/* Show custom focus ring only for keyboard navigation */
*:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-md);
}

/* ============================================================
   MEDIA & IMAGES
   ============================================================ */

img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
}

/* Avatar images */
.avatar {
  display: inline-block;
  border-radius: var(--radius-full);
  object-fit: cover;
  flex-shrink: 0;
}

.avatar--xs  { width: 24px;  height: 24px; }
.avatar--sm  { width: 32px;  height: 32px; }
.avatar--md  { width: 40px;  height: 40px; }
.avatar--lg  { width: 48px;  height: 48px; }
.avatar--xl  { width: 64px;  height: 64px; }
.avatar--2xl { width: 80px;  height: 80px; }

/* Avatar fallback (initials) */
.avatar-initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background-color: var(--color-primary-subtle);
  color: var(--color-brand-400);
  font-family: var(--font-sans);
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  flex-shrink: 0;
  user-select: none;
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */

/* Display */
.block         { display: block; }
.inline-block  { display: inline-block; }
.inline        { display: inline; }
.flex          { display: flex; }
.inline-flex   { display: inline-flex; }
.grid          { display: grid; }
.hidden        { display: none !important; }

/* Flex helpers */
.flex-1        { flex: 1; }
.flex-shrink-0 { flex-shrink: 0; }
.flex-col      { flex-direction: column; }
.flex-wrap     { flex-wrap: wrap; }
.items-center  { align-items: center; }
.items-start   { align-items: flex-start; }
.items-end     { align-items: flex-end; }
.justify-center{ justify-content: center; }
.justify-between{justify-content: space-between; }
.justify-end   { justify-content: flex-end; }
.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-5         { gap: var(--space-5); }
.gap-6         { gap: var(--space-6); }
.gap-8         { gap: var(--space-8); }

/* Spacing */
.p-0  { padding: var(--space-0); }
.p-2  { padding: var(--space-2); }
.p-3  { padding: var(--space-3); }
.p-4  { padding: var(--space-4); }
.p-5  { padding: var(--space-5); }
.p-6  { padding: var(--space-6); }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

/* Width */
.w-full  { width: 100%; }
.w-auto  { width: auto; }
.h-full  { height: 100%; }
.min-w-0 { min-width: 0; }

/* Text alignment */
.text-left   { text-align: left; }
.text-center { text-align: center; }
.text-right  { text-align: right; }

/* Font size helpers */
.text-xs   { font-size: var(--text-xs); }
.text-sm   { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-md   { font-size: var(--text-md); }
.text-lg   { font-size: var(--text-lg); }
.text-xl   { font-size: var(--text-xl); }
.text-2xl  { font-size: var(--text-2xl); }
.text-3xl  { font-size: var(--text-3xl); }

/* Font weight helpers */
.font-normal   { font-weight: var(--font-normal); }
.font-medium   { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold     { font-weight: var(--font-bold); }

/* Overflow */
.overflow-hidden { overflow: hidden; }
.overflow-auto   { overflow: auto; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Position */
.relative { position: relative; }
.absolute { position: absolute; }
.fixed    { position: fixed; }
.sticky   { position: sticky; }

/* Border radius */
.rounded-sm   { border-radius: var(--radius-sm); }
.rounded-md   { border-radius: var(--radius-md); }
.rounded-lg   { border-radius: var(--radius-lg); }
.rounded-xl   { border-radius: var(--radius-xl); }
.rounded-2xl  { border-radius: var(--radius-2xl); }
.rounded-full { border-radius: var(--radius-full); }

/* Cursor */
.cursor-pointer { cursor: pointer; }
.cursor-default { cursor: default; }
.cursor-not-allowed { cursor: not-allowed; }

/* Opacity */
.opacity-0   { opacity: 0; }
.opacity-50  { opacity: 0.5; }
.opacity-75  { opacity: 0.75; }
.opacity-100 { opacity: 1; }

/* User select */
.select-none { user-select: none; }

/* Pointer events */
.pointer-events-none { pointer-events: none; }

/* Visually hidden (accessible) */
.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;
}

/* ============================================================
   DIVIDER
   ============================================================ */

.divider {
  height: 1px;
  background-color: var(--border-color);
  border: none;
  margin: var(--space-4) 0;
}

.divider--vertical {
  width: 1px;
  height: auto;
  background-color: var(--border-color);
  margin: 0 var(--space-4);
  align-self: stretch;
}

/* ============================================================
   GLOBAL ANIMATIONS
   ============================================================ */

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-16px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

@keyframes shimmer {
  0%   { background-position: -1000px 0; }
  100% { background-position:  1000px 0; }
}

@keyframes scoreRing {
  from { stroke-dashoffset: 440; }
  to   { stroke-dashoffset: var(--target-offset, 0); }
}

@keyframes bounceIn {
  0%   { transform: scale(0.3); opacity: 0; }
  50%  { transform: scale(1.05); }
  70%  { transform: scale(0.9); }
  100% { transform: scale(1); opacity: 1; }
}

/* Animation utility classes */
.animate-fade-in    { animation: fadeIn    0.3s ease both; }
.animate-fade-up    { animation: fadeUp    0.3s ease both; }
.animate-fade-down  { animation: fadeDown  0.3s ease both; }
.animate-slide-left { animation: slideInLeft  0.3s ease both; }
.animate-scale-in   { animation: scaleIn   0.2s ease both; }
.animate-spin       { animation: spin      1s linear infinite; }
.animate-pulse      { animation: pulse     2s ease-in-out infinite; }

/* Staggered animation delays */
.delay-1 { animation-delay: 0.05s; }
.delay-2 { animation-delay: 0.10s; }
.delay-3 { animation-delay: 0.15s; }
.delay-4 { animation-delay: 0.20s; }
.delay-5 { animation-delay: 0.25s; }
.delay-6 { animation-delay: 0.30s; }

/* ============================================================
   SKELETON / LOADING SHIMMER
   ============================================================ */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-surface)    25%,
    var(--bg-surface-2)  50%,
    var(--bg-surface)    75%
  );
  background-size: 1000px 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
  color: transparent;
  user-select: none;
  pointer-events: none;
}

.skeleton--text  { height: 14px; border-radius: var(--radius-sm); }
.skeleton--title { height: 20px; width: 60%; border-radius: var(--radius-sm); }
.skeleton--card  { height: 120px; border-radius: var(--radius-card); }
.skeleton--avatar{ width: 40px; height: 40px; border-radius: var(--radius-full); }

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */

/* Mobile first — breakpoints defined here for reference:
   sm:  640px
   md:  768px
   lg:  1024px
   xl:  1280px
   2xl: 1536px
*/

@media (max-width: 768px) {
  html { font-size: 15px; }

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

@media (max-width: 480px) {
  html { font-size: 14px; }
}

/* ============================================================
   PRINT STYLES
   ============================================================ */

@media print {
  body::before { display: none; }

  body {
    background: #fff;
    color: #000;
    font-size: 12pt;
  }

  .no-print { display: none !important; }

  a { color: #000; text-decoration: underline; }
  a[href]::after { content: ' (' attr(href) ')'; }

  h1, h2, h3 { page-break-after: avoid; }
  img         { page-break-inside: avoid; }
}