/* ========================================
   PAITHON BOOK - CUSTOM UI/UX STYLES
   Ottimizzato per desktop, tablet e mobile
   ======================================== */

/* ===== VARIABILI CSS - OTTIMIZZATE PER LEGGIBILITÀ MASSIMA ===== */
:root {
  /* Colori principali - CONTRASTI AUMENTATI */
  --primary-color: #BD5FFF;
  --primary-light: #d89fff;
  --primary-dark: #8b2dc4;
  --accent-color: #00c4ee;
  --text-color: #1a202c;
  --text-light: #4a5568;
  --bg-main: #ffffff;
  --bg-secondary: #f7fafc;
  --bg-code: #edf2f7;
  --border-color: #cbd5e0;

  /* Tipografia - FONT SUPER LEGGIBILI */
  --font-body: 'Georgia', 'Charter', 'Iowan Old Style', 'Times New Roman', serif;
  --font-heading: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Monaco', 'Consolas', monospace;

  /* Dimensioni responsive - LARGHEZZA OTTIMALE PER LETTURA */
  --content-max-width: 900px;
  --sidebar-width: 300px;
  --spacing-unit: 1.5rem;

  /* Ombre - PIÙ PROFONDE */
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
  --shadow-md: 0 6px 16px rgba(0,0,0,0.12);
  --shadow-lg: 0 12px 36px rgba(0,0,0,0.16);

  /* Transizioni */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
}

/* Dark mode variables */
@media (prefers-color-scheme: dark) {
  :root {
    --text-color: #e4e6eb;
    --text-light: #b0b3b8;
    --bg-main: #18191a;
    --bg-secondary: #242526;
    --bg-code: #2d2d2d;
    --border-color: #3e4042;
  }
}

/* ===== TIPOGRAFIA SUPER LEGGIBILE ===== */
body {
  font-family: var(--font-body);
  line-height: 1.9;
  color: var(--text-color);
  font-size: 22px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  font-weight: 400;
}

/* Titoli - PIÙ GRANDI E SPAZIATI */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: 1.25;
  margin-top: 3rem;
  margin-bottom: 1.5rem;
  color: var(--text-color);
  letter-spacing: -0.02em;
}

h1 {
  font-size: 3.5rem;
  letter-spacing: -0.04em;
  margin-top: 0;
  margin-bottom: 2rem;
  line-height: 1.15;
}

h2 {
  font-size: 2.5rem;
  letter-spacing: -0.03em;
  padding-bottom: 0.75rem;
  border-bottom: 3px solid var(--primary-color);
  margin-top: 4rem;
  margin-bottom: 2rem;
}

h3 {
  font-size: 2rem;
  color: var(--primary-dark);
  margin-top: 3rem;
  margin-bottom: 1.25rem;
}

h4 {
  font-size: 1.6rem;
  margin-top: 2.5rem;
}

h5 {
  font-size: 1.35rem;
  margin-top: 2rem;
}

/* Paragrafi - SPAZIATURA GENEROSA */
p {
  margin-bottom: 2rem;
  max-width: 80ch;
  line-height: 1.9;
  font-size: 1.1em;
}

/* Primo paragrafo dopo titolo - PIÙ GRANDE */
h1 + p,
h2 + p,
h3 + p {
  font-size: 1.2em;
  line-height: 1.85;
  margin-top: 1.5rem;
}

/* Link */
a {
  color: var(--primary-color);
  text-decoration: none;
  transition: color var(--transition-fast);
  border-bottom: 1px solid transparent;
}

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

/* ===== LAYOUT PRINCIPALE - ULTRA LEGGIBILE ===== */
.bd-container {
  max-width: 100%;
}

.bd-main .bd-content {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 3rem 4rem;
}

/* Spaziatura extra tra sezioni */
.bd-content > section,
.bd-content > article {
  margin-bottom: 4rem;
}

/* Migliore spaziatura per elementi */
.bd-content > * + * {
  margin-top: 2rem;
}

/* Sidebar - ULTRA LEGGIBILE */
.bd-sidebar {
  background: var(--bg-secondary);
  border-right: 2px solid var(--border-color);
  box-shadow: var(--shadow-md);
  font-size: 16px;
}

.bd-sidebar .nav-link {
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  margin: 0.3rem 0.75rem;
  transition: all var(--transition-fast);
  font-size: 1rem;
  line-height: 1.6;
  font-weight: 500;
}

.bd-sidebar .nav-link:hover {
  background: var(--primary-light);
  color: white;
  transform: translateX(6px);
  box-shadow: var(--shadow-sm);
}

.bd-sidebar .nav-link.active {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
  color: white;
  font-weight: 700;
  box-shadow: var(--shadow-md);
}

/* Table of contents nel sidebar */
.bd-sidebar nav ul {
  padding-left: 0;
}

.bd-sidebar nav li {
  margin: 0.25rem 0;
  list-style: none;
}

/* ===== CODE BLOCKS ULTRA LEGGIBILI ===== */
code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--bg-code);
  padding: 0.25em 0.6em;
  border-radius: 5px;
  color: #c7254e;
  border: 1px solid var(--border-color);
  font-weight: 500;
}

pre {
  background: var(--bg-code);
  border: 2px solid var(--border-color);
  border-radius: 10px;
  padding: 2rem;
  overflow-x: auto;
  box-shadow: var(--shadow-md);
  margin: 2.5rem 0;
  line-height: 1.7;
  font-size: 0.95rem;
}

pre code {
  background: none;
  padding: 0;
  border: none;
  font-size: 0.95rem;
  color: inherit;
  line-height: 1.7;
}

/* Jupyter cell styling */
.cell {
  margin: 2rem 0;
  border-radius: 8px;
  overflow: hidden;
}

.cell_input {
  background: var(--bg-code);
  border-left: 4px solid var(--primary-color);
  padding: 1rem;
}

.cell_output {
  background: var(--bg-secondary);
  padding: 1rem;
  border-left: 4px solid var(--accent-color);
  margin-top: 0.5rem;
}

/* ===== TABS MIGLIORATI (sphinx-inline-tabs) ===== */
.sphinx-tabs {
  margin: 2rem 0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.sphinx-tabs-tab {
  padding: 0.75rem 1.5rem;
  background: var(--bg-secondary);
  border: none;
  border-bottom: 3px solid transparent;
  font-weight: 600;
  font-size: 0.95rem;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.sphinx-tabs-tab:hover {
  background: var(--primary-light);
  color: white;
}

.sphinx-tabs-tab[aria-selected="true"] {
  background: var(--primary-color);
  color: white;
  border-bottom-color: var(--primary-dark);
}

.sphinx-tabs-panel {
  padding: 2rem;
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-top: none;
}

/* ===== ADMONITIONS E BOX - ULTRA LEGGIBILI ===== */
.admonition {
  padding: 2rem 2.5rem;
  margin: 3rem 0;
  border-radius: 12px;
  border-left: 6px solid;
  box-shadow: var(--shadow-md);
  background: var(--bg-secondary);
  font-size: 1.05em;
  line-height: 1.85;
}

.admonition.note {
  border-left-color: #0288d1;
  background: #e3f2fd;
}

.admonition.warning {
  border-left-color: #f57c00;
  background: #fff3e0;
}

.admonition.tip {
  border-left-color: #388e3c;
  background: #e8f5e9;
}

.admonition.important,
.admonition.attention {
  border-left-color: #d32f2f;
  background: #ffebee;
}

.admonition-title {
  font-weight: 700;
  margin-bottom: 1.25rem;
  font-size: 1.25rem;
  font-family: var(--font-heading);
  letter-spacing: -0.01em;
}

/* Contenuto admonition */
.admonition p {
  margin-bottom: 1.25rem;
}

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

/* ===== TABELLE - ULTRA LEGGIBILI ===== */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 3rem 0;
  box-shadow: var(--shadow-md);
  border-radius: 10px;
  overflow: hidden;
  font-size: 1.02em;
  line-height: 1.75;
}

thead {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
  color: white;
}

th {
  padding: 1.5rem;
  text-align: left;
  font-weight: 700;
  font-family: var(--font-heading);
  font-size: 1.05em;
  letter-spacing: 0.02em;
}

td {
  padding: 1.25rem 1.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

tbody tr:hover {
  background: var(--bg-secondary);
  transition: background 0.2s ease;
}

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

/* ===== IMMAGINI E FIGURE ===== */
img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  margin: 2rem 0;
}

figure {
  margin: 2rem 0;
  text-align: center;
}

figcaption {
  font-style: italic;
  color: var(--text-light);
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

/* ===== LISTE - SUPER LEGGIBILI ===== */
ul, ol {
  padding-left: 2.5rem;
  margin: 2rem 0;
  max-width: 80ch;
}

li {
  margin: 1rem 0;
  line-height: 1.9;
  font-size: 1.1em;
}

li::marker {
  color: var(--primary-color);
  font-weight: bold;
}

/* Liste annidate */
li > ul,
li > ol {
  margin-top: 0.75rem;
  margin-bottom: 0.75rem;
}

/* Miglior distanziamento tra punti elenco */
li + li {
  margin-top: 0.75rem;
}

/* ===== HEADER E NAVBAR ===== */
.navbar-brand {
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--primary-color) !important;
  transition: transform var(--transition-fast);
  cursor: pointer;
}

.navbar-brand:hover {
  transform: scale(1.05);
}

.navbar {
  box-shadow: var(--shadow-md);
  background: var(--bg-main) !important;
  border-bottom: 2px solid var(--primary-color);
}

/* Fix navigation links to prevent external redirects */
.navbar a,
.bd-sidebar a,
nav a {
  cursor: pointer;
}

/* Visual feedback for all internal navigation */
.bd-links a {
  transition: all var(--transition-fast);
}

.bd-links a:hover {
  text-decoration: none;
}

/* ===== BUTTONS ===== */
.btn, button {
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  font-weight: 600;
  transition: all var(--transition-fast);
  border: none;
  cursor: pointer;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* ===== SCROLLBAR CUSTOM ===== */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--primary-color);
  border-radius: 5px;
}

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

/* ===== RESPONSIVE DESIGN ===== */

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) {
  body {
    font-size: 16px;
  }

  h1 { font-size: 2rem; }
  h2 { font-size: 1.75rem; }
  h3 { font-size: 1.4rem; }

  .bd-main .bd-content {
    padding: 1.5rem 1rem;
  }

  .bd-sidebar {
    width: 240px;
  }
}

/* Mobile (max 767px) - LEGGIBILITÀ MANTENUTA */
@media (max-width: 767px) {
  body {
    font-size: 19px;
    line-height: 1.8;
  }

  h1 {
    font-size: 2.5rem;
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
  }

  h2 {
    font-size: 2rem;
    margin-top: 3rem;
    margin-bottom: 1.5rem;
  }

  h3 {
    font-size: 1.65rem;
    margin-top: 2.5rem;
  }

  h4 { font-size: 1.35rem; }

  .bd-main .bd-content {
    padding: 2rem 1.5rem;
    max-width: 100%;
  }

  p {
    margin-bottom: 1.75rem;
    font-size: 1.05em;
  }

  /* Sidebar mobile */
  .bd-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  /* Tabs mobile friendly */
  .sphinx-tabs-tab {
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
  }

  .sphinx-tabs-panel {
    padding: 1rem;
  }

  /* Code blocks mobile */
  pre {
    padding: 1rem;
    font-size: 0.85rem;
  }

  /* Tables mobile */
  table {
    font-size: 0.9rem;
  }

  th, td {
    padding: 0.75rem 0.5rem;
  }

  /* Immagini mobile */
  img {
    margin: 1rem 0;
  }

  /* Liste mobile */
  ul, ol {
    padding-left: 1.5rem;
  }

  /* Admonitions mobile */
  .admonition {
    padding: 1rem;
    margin: 1.5rem 0;
  }
}

/* Small mobile (max 480px) - LEGGIBILITÀ MANTENUTA */
@media (max-width: 480px) {
  body {
    font-size: 18px;
    line-height: 1.75;
  }

  h1 {
    font-size: 2.15rem;
    margin-top: 1rem;
  }

  h2 {
    font-size: 1.8rem;
    margin-top: 2.5rem;
  }

  h3 {
    font-size: 1.5rem;
    margin-top: 2rem;
  }

  h4 { font-size: 1.3rem; }

  .bd-main .bd-content {
    padding: 1.5rem 1rem;
  }

  p {
    margin-bottom: 1.5rem;
  }

  .sphinx-tabs-tab {
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
  }
}

/* ===== ANIMAZIONI E TRANSIZIONI ===== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.bd-content > * {
  animation: fadeIn 0.5s ease-out;
}

/* Smooth scroll */
html {
  scroll-behavior: smooth;
}

/* Focus states accessibili */
:focus-visible {
  outline: 3px solid var(--primary-color);
  outline-offset: 2px;
}

/* ===== PRINT STYLES ===== */
@media print {
  body {
    font-size: 12pt;
    line-height: 1.5;
  }

  .bd-sidebar,
  .navbar,
  button,
  .btn {
    display: none;
  }

  .bd-main .bd-content {
    max-width: 100%;
    padding: 0;
  }

  a {
    color: black;
    text-decoration: underline;
  }

  img {
    max-width: 100%;
    page-break-inside: avoid;
  }
}

/* ===== MIGLIORAMENTI PERFORMANCE ===== */
* {
  -webkit-tap-highlight-color: transparent;
}

img, video {
  will-change: transform;
}

/* ===== BLOCKQUOTES - ULTRA LEGGIBILI ===== */
blockquote {
  margin: 2.5rem 0;
  padding: 2rem 2.5rem;
  border-left: 6px solid var(--primary-color);
  background: var(--bg-secondary);
  font-size: 1.15em;
  line-height: 1.85;
  font-style: italic;
  color: var(--text-light);
  border-radius: 0 10px 10px 0;
  box-shadow: var(--shadow-sm);
}

blockquote p {
  margin-bottom: 1rem;
}

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

blockquote cite {
  display: block;
  margin-top: 1rem;
  font-size: 0.9em;
  font-style: normal;
  color: var(--text-color);
  font-weight: 600;
}

blockquote cite::before {
  content: "— ";
}

/* ===== STRONG & EM - ENFATIZZATI ===== */
strong, b {
  font-weight: 700;
  color: var(--text-color);
}

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

/* ===== HORIZONTAL RULE ===== */
hr {
  border: none;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--primary-color), transparent);
  margin: 4rem 0;
  border-radius: 2px;
}

/* ===== UTILITY CLASSES ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-2 { margin-top: 2rem; }
.mb-2 { margin-bottom: 2rem; }
.p-2 { padding: 2rem; }

/* ===== FOOTER ===== */
footer {
  margin-top: 4rem;
  padding: 2rem 0;
  border-top: 2px solid var(--border-color);
  color: var(--text-light);
  font-size: 0.9rem;
  text-align: center;
}

/* ===== SPECIAL: Buy me a coffee button ===== */
.bmc-btn {
  box-shadow: var(--shadow-md) !important;
  transition: transform var(--transition-fast) !important;
}

.bmc-btn:hover {
  transform: translateY(-3px) !important;
  box-shadow: var(--shadow-lg) !important;
}
