/**
 * DosiPlot v5.0 — Simulation Monte Carlo Interactive
 * © 2025 Pr. Yassine OULHOUQ
 * Université Mohammed Premier (UMP) — Oujda, Maroc
 * Module: Main — Design System, Reset, Typography, Layout
 */

/* ============================================
   GOOGLE FONTS
   ============================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@300;400;500;600;700&family=IBM+Plex+Mono:wght@300;400;500;600;700&family=DM+Sans:opsz,wght@9..40,300;9..40,400;9..40,500;9..40,600;9..40,700&family=Noto+Sans+Arabic:wght@400;500;600;700&display=swap');

/* ============================================
   DESIGN TOKENS — CSS Custom Properties
   ============================================ */
:root {
  /* --- Fluid Typography Scale (clamp-based) --- */
  --fs-2xs:  clamp(0.5rem,   0.45rem + 0.15vw,  0.625rem);   /* ~8-10px  */
  --fs-xs:   clamp(0.625rem,  0.575rem + 0.2vw,  0.75rem);    /* ~10-12px */
  --fs-sm:   clamp(0.6875rem, 0.625rem + 0.25vw, 0.8125rem);  /* ~11-13px */
  --fs-base: clamp(0.75rem,   0.7rem + 0.25vw,   0.875rem);   /* ~12-14px */
  --fs-md:   clamp(0.875rem,  0.8rem + 0.3vw,    1rem);       /* ~14-16px */
  --fs-lg:   clamp(1rem,      0.925rem + 0.35vw,  1.25rem);   /* ~16-20px */
  --fs-xl:   clamp(1.25rem,   1.1rem + 0.5vw,    1.5rem);     /* ~20-24px */
  --fs-2xl:  clamp(1.5rem,    1.3rem + 0.75vw,   2rem);       /* ~24-32px */
  --fs-3xl:  clamp(2rem,      1.75rem + 1vw,     2.75rem);    /* ~32-44px */

  /* --- Font Families --- */
  --ff-sans:  'DM Sans', 'Inter', system-ui, -apple-system, sans-serif;
  --ff-mono:  'IBM Plex Mono', 'JetBrains Mono', 'Fira Code', monospace;
  --ff-display: 'Inter', 'DM Sans', system-ui, sans-serif;
  --ff-arabic: 'Noto Sans Arabic', 'DM Sans', sans-serif;

  /* --- Font Weights --- */
  --fw-light:    300;
  --fw-regular:  400;
  --fw-medium:   500;
  --fw-semibold: 600;
  --fw-bold:     700;
  --fw-extrabold: 800;

  /* --- Spacing Scale (4px base) --- */
  --sp-0:   0;
  --sp-px:  1px;
  --sp-0-5: 0.125rem;  /* 2px  */
  --sp-1:   0.25rem;   /* 4px  */
  --sp-1-5: 0.375rem;  /* 6px  */
  --sp-2:   0.5rem;    /* 8px  */
  --sp-2-5: 0.625rem;  /* 10px */
  --sp-3:   0.75rem;   /* 12px */
  --sp-3-5: 0.875rem;  /* 14px */
  --sp-4:   1rem;      /* 16px */
  --sp-5:   1.25rem;   /* 20px */
  --sp-6:   1.5rem;    /* 24px */
  --sp-7:   1.75rem;   /* 28px */
  --sp-8:   2rem;      /* 32px */
  --sp-10:  2.5rem;    /* 40px */
  --sp-12:  3rem;      /* 48px */
  --sp-16:  4rem;      /* 64px */
  --sp-20:  5rem;      /* 80px */
  --sp-24:  6rem;      /* 96px */

  /* --- Border Radii --- */
  --radius-xs:    4px;
  --radius-sm:    6px;
  --radius-md:    8px;
  --radius-lg:    10px;
  --radius-xl:    12px;
  --radius-2xl:   14px;
  --radius-3xl:   16px;
  --radius-full:  9999px;
  --radius-pill:  20px;

  /* --- Transitions & Easing --- */
  --ease-out:      cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out:   cubic-bezier(0.65, 0, 0.35, 1);
  --ease-spring:   cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-bounce:   cubic-bezier(0.68, -0.55, 0.265, 1.55);
  --ease-smooth:   cubic-bezier(0.4, 0, 0.2, 1);

  --duration-fast:   150ms;
  --duration-base:   250ms;
  --duration-slow:   400ms;
  --duration-slower: 600ms;

  --transition-fast:   all 150ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-base:   all 250ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-slow:   all 400ms cubic-bezier(0.65, 0, 0.35, 1);
  --transition-colors: color 250ms, background-color 250ms, border-color 250ms, box-shadow 250ms;

  /* --- Z-Index Scale --- */
  --z-below:    -1;
  --z-base:      0;
  --z-raised:    1;
  --z-dropdown:  10;
  --z-sticky:    50;
  --z-header:    100;
  --z-overlay:   200;
  --z-modal:     500;
  --z-popover:   600;
  --z-toast:     999;
  --z-tooltip:   1000;
  --z-max:       9999;

  /* --- Line Heights --- */
  --lh-none:    1;
  --lh-tight:   1.25;
  --lh-snug:    1.375;
  --lh-normal:  1.5;
  --lh-relaxed: 1.625;
  --lh-loose:   1.8;

  /* --- Letter Spacing --- */
  --ls-tighter: -0.05em;
  --ls-tight:   -0.025em;
  --ls-normal:  0;
  --ls-wide:    0.025em;
  --ls-wider:   0.05em;
  --ls-widest:  0.1em;

  /* --- Layout --- */
  --sidebar-width: 270px;
  --header-height: 64px;
  --tab-height:    44px;
  --content-max-width: 1600px;

  /* --- Glassmorphism --- */
  --glass-blur: blur(20px);
  --glass-blur-sm: blur(8px);
  --glass-blur-lg: blur(40px);
}

/* ============================================
   CSS RESET & BASE
   ============================================ */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--ff-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--t1);
  background: var(--bg0);
  min-height: 100vh;
  overflow-x: hidden;
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(0,180,255,0.04) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(255,176,32,0.03) 0%, transparent 60%);
}

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

input, button, textarea, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: inherit;
  text-decoration: none;
}

ul, ol {
  list-style: none;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

/* ============================================
   BASE TYPOGRAPHY
   ============================================ */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--ff-display);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-tight);
}

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

p {
  line-height: var(--lh-relaxed);
  color: var(--t2);
}

code, kbd, samp, pre {
  font-family: var(--ff-mono);
  font-size: 0.9em;
}

small {
  font-size: var(--fs-xs);
}

strong, b {
  font-weight: var(--fw-bold);
}

/* ============================================
   LAYOUT GRID
   ============================================ */
.main {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: calc(100vh - 100px);
}

.cnt {
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg0);
  min-height: calc(100vh - 100px);
}

/* TP full-width mode — hide sidebar + cnt, show only TP dashboard */
.main.tp-active {
  grid-template-columns: 1fr;
}

.main.tp-active .sb {
  display: none !important;
}

.main.tp-active .cnt {
  display: none !important;
}

.main.tp-active > .tc.tp-dashboard.active {
  padding: var(--sp-4);
  overflow-y: auto;
  max-height: calc(100vh - 100px);
}

.tc {
  display: none;
}

.tc.active {
  display: flex;
  flex-direction: column;
}

.sim-row {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: var(--sp-3-5);
  min-height: 450px;
}

/* ============================================
   RTL SUPPORT
   ============================================ */
body.rtl {
  direction: rtl;
  text-align: right;
  font-family: var(--ff-arabic);
}

body.rtl .hdr-l {
  flex-direction: row-reverse;
}

body.rtl .hdr-r {
  flex-direction: row-reverse;
}

body.rtl .linac-tree {
  flex-direction: row-reverse;
  margin-left: 0;
  margin-right: 14px;
}

body.rtl .linac-conn {
  transform: scaleX(-1);
}

body.rtl .app-author::before {
  margin-right: 0;
  margin-left: 7px;
}

body.rtl .sb {
  direction: rtl;
}

body.rtl .tabs {
  direction: rtl;
}

body.rtl .fl {
  text-align: right;
}

body.rtl .sim-row {
  direction: ltr;
}

body.rtl .phantom-box {
  direction: ltr;
}

body.rtl .chart-box {
  direction: ltr;
}

body.rtl .trs-steps {
  direction: rtl;
}

body.rtl .step {
  flex-direction: row-reverse;
  text-align: right;
}

body.rtl .step-num {
  margin-right: 0;
  margin-left: 12px;
}

body.rtl .pnl-t {
  text-align: right;
}

body.rtl .pc-l {
  text-align: center;
}

body.rtl .mc-msg {
  text-align: right;
  direction: rtl;
}

body.rtl .mode-label {
  text-align: right;
}

body.rtl .pw-box {
  direction: rtl;
  text-align: right;
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
  * {
    background: transparent !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  body {
    font-size: 12pt;
    line-height: 1.5;
    background-image: none !important;
  }

  .hdr,
  .tabs,
  .sb,
  .btn-run,
  .btn-pause,
  .btn-s,
  .btn-grp,
  .mode-toggle,
  .theme-btn,
  .lang-sel,
  .pw-modal,
  .toast {
    display: none !important;
  }

  .main {
    display: block;
    grid-template-columns: 1fr;
  }

  .cnt {
    padding: 0;
  }

  .chart-box,
  .phantom-box,
  .trs-chart,
  .trs-steps {
    break-inside: avoid;
    border: 1px solid #ccc;
    page-break-inside: avoid;
  }

  .tc.active {
    display: block !important;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
  }
}

/* ============================================
   SPLASH SCREEN
   ============================================ */
.splash-screen {
  position: fixed;
  inset: 0;
  z-index: var(--z-max);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #080c14;
  background: var(--bg0, #080c14);
  transition: opacity 0.5s ease-out, visibility 0.5s ease-out;
}

.splash-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
}

.splash-hero {
  margin-bottom: 16px;
  animation: splashHeroFloat 3s ease-in-out infinite;
}

.splash-hero-img {
  width: 220px;
  height: auto;
  border-radius: 18px;
  box-shadow:
    0 0 40px rgba(0, 180, 255, 0.25),
    0 0 80px rgba(0, 180, 255, 0.1),
    0 8px 32px rgba(0, 0, 0, 0.4);
  filter: brightness(1.05) contrast(1.02);
  transition: transform 0.3s ease;
}

@keyframes splashHeroFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.splash-logo {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  animation: splashPulse 2s ease-in-out infinite;
}

.splash-logo-icon {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--blue, #00b4ff), var(--cyan, #00e5cc));
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 700;
  font-size: 22px;
  color: #fff;
  box-shadow: 0 0 30px rgba(0, 180, 255, 0.3);
}

.splash-logo-text {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 28px;
  font-weight: 700;
  color: var(--t1, #e8ecf4);
  letter-spacing: -0.5px;
}

.splash-logo-text span {
  color: var(--blue, #00b4ff);
}

.splash-subtitle {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--t3, #607090);
  text-transform: uppercase;
  letter-spacing: 3px;
}

.splash-version {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  color: var(--blue, #00b4ff);
  font-weight: 600;
  margin-top: 4px;
  padding: 2px 12px;
  border: 1px solid rgba(0, 180, 255, 0.25);
  border-radius: 20px;
  background: rgba(0, 180, 255, 0.05);
}

.splash-bar-wrap {
  width: 200px;
  height: 3px;
  background: var(--bg3, #1a2540);
  border-radius: 9999px;
  margin-top: 24px;
  overflow: hidden;
}

.splash-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--blue, #00b4ff), var(--cyan, #00e5cc));
  border-radius: 9999px;
  transition: width 0.3s ease-out;
}

.splash-author {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--t3, #607090);
  margin-top: 20px;
  letter-spacing: 0.5px;
}

@keyframes splashPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.85; }
}

/* ============================================
   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: 0;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.no-scrollbar::-webkit-scrollbar {
  display: none;
}

.no-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.glass {
  background: var(--bg-glass);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}

.text-mono {
  font-family: var(--ff-mono);
}

.text-sans {
  font-family: var(--ff-sans);
}

.text-center {
  text-align: center;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
