/* ==========================================================================
   ACME Mobility – Design System
   main.css — Variables, Reset, Layout, Typography, Sidebar
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Google Fonts Import
   -------------------------------------------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* --------------------------------------------------------------------------
   2. CSS Custom Properties (Design Tokens)
   -------------------------------------------------------------------------- */
:root {
  /* Brand Colors */
  --primary:        #00B4D8;
  --primary-dark:   #0077B6;
  --primary-light:  #48CAE4;
  --primary-muted:  rgba(0, 180, 216, 0.12);
  --accent:         #90E0EF;

  /* Background Layers */
  --bg-base:        #0D1117;
  --bg-surface:     #161B22;
  --bg-card:        #1C2128;
  --bg-hover:       #21262D;
  --bg-border:      #30363D;
  --bg-border-subtle: #21262D;

  /* Text */
  --text-primary:   #E6EDF3;
  --text-secondary: #8B949E;
  --text-muted:     #6E7681;
  --text-inverse:   #0D1117;

  /* Status */
  --success:        #3FB950;
  --success-muted:  rgba(63, 185, 80, 0.15);
  --warning:        #D29922;
  --warning-muted:  rgba(210, 153, 34, 0.15);
  --danger:         #F85149;
  --danger-muted:   rgba(248, 81, 73, 0.15);
  --info:           #388BFD;
  --info-muted:     rgba(56, 139, 253, 0.15);

  /* Typography */
  --font-sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:  'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;
  --text-4xl:  2.25rem;
  --text-5xl:  3rem;
  --text-6xl:  3.75rem;

  --font-light:    300;
  --font-normal:   400;
  --font-medium:   500;
  --font-semibold: 600;
  --font-bold:     700;
  --font-extrabold:800;
  --font-black:    900;

  --leading-tight:  1.25;
  --leading-snug:   1.375;
  --leading-normal: 1.5;
  --leading-relaxed:1.625;
  --leading-loose:  2;

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;

  /* Layout */
  --sidebar-width:     280px;
  --sidebar-collapsed: 0px;
  --header-height:     60px;
  --content-max:       900px;

  /* Borders & Radii */
  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-xl:  16px;
  --radius-2xl: 24px;
  --radius-full:9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.4), 0 2px 4px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.5), 0 4px 6px rgba(0,0,0,0.3);
  --shadow-xl: 0 20px 25px rgba(0,0,0,0.5), 0 10px 10px rgba(0,0,0,0.3);
  --shadow-glow: 0 0 20px rgba(0, 180, 216, 0.3);
  --shadow-glow-sm: 0 0 10px rgba(0, 180, 216, 0.2);

  /* Transitions */
  --transition-fast:   150ms ease;
  --transition-base:   250ms ease;
  --transition-slow:   400ms ease;
  --transition-spring: 400ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Z-index scale */
  --z-base:    1;
  --z-overlay: 100;
  --z-sidebar: 200;
  --z-header:  300;
  --z-modal:   400;
  --z-toast:   500;
}

/* --------------------------------------------------------------------------
   3. Reset & Base
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--font-normal);
  line-height: var(--leading-relaxed);
  color: var(--text-primary);
  background-color: var(--bg-base);
  overflow-x: hidden;
}

/* --------------------------------------------------------------------------
   4. Layout Principale
   -------------------------------------------------------------------------- */

/* Wrapper generale: sidebar fissa + contenuto */
.layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--bg-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: var(--z-sidebar);
  transition: transform var(--transition-base);
  scrollbar-width: thin;
  scrollbar-color: var(--bg-border) transparent;
}

.sidebar::-webkit-scrollbar {
  width: 4px;
}
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb {
  background: var(--bg-border);
  border-radius: var(--radius-full);
}

/* Main content area */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Page wrapper */
.page-wrapper {
  flex: 1;
  padding: var(--space-12) var(--space-16);
  max-width: calc(var(--content-max) + var(--space-32));
}

@media (max-width: 1200px) {
  .page-wrapper { padding: var(--space-10) var(--space-12); }
}
@media (max-width: 900px) {
  .page-wrapper { padding: var(--space-8) var(--space-6); }
}

/* Content width limiter */
.content {
  max-width: var(--content-max);
}

/* --------------------------------------------------------------------------
   5. Sidebar – Brand Header
   -------------------------------------------------------------------------- */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5);
  border-bottom: 1px solid var(--bg-border-subtle);
  text-decoration: none;
  color: var(--text-primary);
  flex-shrink: 0;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-glow-sm);
}

.brand-icon svg {
  width: 20px;
  height: 20px;
  fill: white;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  color: var(--text-primary);
  letter-spacing: -0.01em;
  line-height: 1;
}

.brand-subtitle {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1;
}

/* --------------------------------------------------------------------------
   6. Sidebar – Navigation
   -------------------------------------------------------------------------- */
.sidebar-nav {
  flex: 1;
  padding: var(--space-4) 0;
}

.nav-section {
  margin-bottom: var(--space-2);
}

.nav-section-label {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: var(--space-3) var(--space-5) var(--space-1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-5);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  border-radius: 0;
  transition: color var(--transition-fast), background var(--transition-fast);
  position: relative;
  line-height: 1.4;
}

.nav-item:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.nav-item.active {
  color: var(--primary);
  background: var(--primary-muted);
  font-weight: var(--font-semibold);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.nav-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active svg,
.nav-item:hover svg {
  opacity: 1;
}

/* --------------------------------------------------------------------------
   7. Sidebar – Footer
   -------------------------------------------------------------------------- */
.sidebar-footer {
  border-top: 1px solid var(--bg-border-subtle);
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.sidebar-footer a {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-muted);
  text-decoration: none;
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  transition: color var(--transition-fast);
}

.sidebar-footer a:hover { color: var(--text-primary); }

.sidebar-footer svg {
  width: 14px;
  height: 14px;
}

/* --------------------------------------------------------------------------
   8. Mobile Header (hamburger)
   -------------------------------------------------------------------------- */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--bg-border);
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  z-index: var(--z-header);
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
}

.hamburger-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-primary);
  padding: var(--space-2);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}

.hamburger-btn:hover { background: var(--bg-hover); }
.hamburger-btn svg { width: 20px; height: 20px; }

/* Overlay per mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: calc(var(--z-sidebar) - 1);
  opacity: 0;
  transition: opacity var(--transition-base);
  backdrop-filter: blur(2px);
}

/* --------------------------------------------------------------------------
   9. Responsive – Mobile
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .mobile-header { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    top: 0;
    box-shadow: var(--shadow-xl);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: block;
  }

  .sidebar-overlay.visible {
    opacity: 1;
  }

  .main-content {
    margin-left: 0;
    padding-top: var(--header-height);
  }

  .page-wrapper {
    padding: var(--space-6) var(--space-4);
  }
}

/* --------------------------------------------------------------------------
   10. Progress Bar di lettura
   -------------------------------------------------------------------------- */
.reading-progress {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: 2px;
  background: transparent;
  z-index: var(--z-header);
}

.reading-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-dark), var(--primary), var(--primary-light));
  width: 0%;
  transition: width 100ms linear;
}

@media (max-width: 768px) {
  .reading-progress { left: 0; top: var(--header-height); }
}

/* --------------------------------------------------------------------------
   11. Typography
   -------------------------------------------------------------------------- */
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: -0.02em;
}

h1 { font-size: var(--text-4xl); font-weight: var(--font-extrabold); }
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; }

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

a:hover { color: var(--primary-light); }

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

em { font-style: italic; }

/* Section headings */
.section-label {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--primary);
  display: block;
  margin-bottom: var(--space-2);
}

.section-title {
  font-size: var(--text-3xl);
  font-weight: var(--font-extrabold);
  color: var(--text-primary);
  margin-bottom: var(--space-4);
  letter-spacing: -0.03em;
}

.section-subtitle {
  font-size: var(--text-lg);
  color: var(--text-secondary);
  font-weight: var(--font-normal);
  max-width: 640px;
  line-height: var(--leading-relaxed);
}

/* Page header */
.page-header {
  margin-bottom: var(--space-12);
  padding-bottom: var(--space-8);
  border-bottom: 1px solid var(--bg-border-subtle);
}

.page-header .section-label { margin-bottom: var(--space-3); }
.page-header .section-title { font-size: var(--text-4xl); margin-bottom: var(--space-4); }
.page-header .section-subtitle { font-size: var(--text-xl); }

/* --------------------------------------------------------------------------
   12. Code
   -------------------------------------------------------------------------- */
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-card);
  color: var(--primary-light);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--bg-border);
}

pre {
  background: var(--bg-card);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  overflow-x: auto;
  margin: var(--space-6) 0;
  white-space: pre;
  font-family: var(--font-mono);
  tab-size: 2;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-primary);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  font-family: var(--font-mono);
  white-space: pre;
}

/* --------------------------------------------------------------------------
   13. Dividers & Spacing utilities
   -------------------------------------------------------------------------- */
.divider {
  height: 1px;
  background: var(--bg-border-subtle);
  margin: var(--space-12) 0;
}

.section-gap { margin-bottom: var(--space-16); }
.content-gap { margin-bottom: var(--space-8); }

/* --------------------------------------------------------------------------
   14. Tables
   -------------------------------------------------------------------------- */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--bg-border);
  margin: var(--space-6) 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

thead {
  background: var(--bg-card);
  border-bottom: 1px solid var(--bg-border);
}

th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-weight: var(--font-semibold);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--bg-border-subtle);
  color: var(--text-secondary);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

tbody tr {
  transition: background var(--transition-fast);
}

tbody tr:hover { background: var(--bg-hover); }

td code { font-size: var(--text-xs); }

/* --------------------------------------------------------------------------
   15. Lists
   -------------------------------------------------------------------------- */
ul, ol {
  padding-left: var(--space-6);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
}

li { margin-bottom: var(--space-2); }
li:last-child { margin-bottom: 0; }

ul li::marker { color: var(--primary); }
ol li::marker { color: var(--text-muted); }

/* --------------------------------------------------------------------------
   16. Scrollbar global
   -------------------------------------------------------------------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb {
  background: var(--bg-border);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --------------------------------------------------------------------------
   17. Selection
   -------------------------------------------------------------------------- */
::selection {
  background: var(--primary-muted);
  color: var(--primary-light);
}

/* --------------------------------------------------------------------------
   18. Focus (accessibility)
   -------------------------------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
