/* ==============================================================================
   BIBLIONOTES - DESIGN SYSTEM & STYLES (iOS iPhone & Desktop Responsive)
   ============================================================================== */

:root {
  /* Dimensioni & Safe Area iOS */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tabbar-height: 64px;
  --header-height: 52px;
  --app-max-width: 680px;

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-xl: 30px;

  /* Palette Dark Mode (Default OLED iPhone) */
  --bg-primary: #0A0C10;
  --bg-secondary: #141721;
  --bg-tertiary: #1E2332;
  --bg-card: rgba(22, 26, 37, 0.85);
  --bg-card-hover: rgba(30, 36, 52, 0.95);
  --bg-sheet: #141722;
  --bg-glass: rgba(12, 14, 20, 0.88);

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --border-focus: #E5A454;

  --text-primary: #F5F6F9;
  --text-secondary: #A0A7B6;
  --text-muted: #677186;
  --text-inverse: #0A0C10;

  /* Accenti caldi e nobili per libri */
  --accent-gold: #E5A454;
  --accent-gold-soft: rgba(229, 164, 84, 0.15);
  --accent-gold-hover: #F2B567;

  /* Stati & Categorie */
  --status-reading: #3B82F6;
  --status-to_read: #F59E0B;
  --status-completed: #10B981;
  --status-paused: #8B5CF6;
  --status-abandoned: #6B7280;

  --note-idea: #F59E0B;
  --note-summary: #3B82F6;
  --note-quote: #10B981;
  --note-reflection: #A855F7;

  --sync-online: #10B981;
  --sync-syncing: #F59E0B;
  --sync-offline: #F97316;
  --sync-error: #EF4444;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.65);
}

/* Light Mode Overrides */
[data-theme="light"] {
  --bg-primary: #F8F9FA;
  --bg-secondary: #FFFFFF;
  --bg-tertiary: #EDF0F5;
  --bg-card: #FFFFFF;
  --bg-card-hover: #F2F4F8;
  --bg-sheet: #FFFFFF;
  --bg-glass: rgba(255, 255, 255, 0.92);

  --border-subtle: rgba(0, 0, 0, 0.07);
  --border-strong: rgba(0, 0, 0, 0.14);
  --border-focus: #D4892A;

  --text-primary: #111827;
  --text-secondary: #4B5563;
  --text-muted: #8E98A8;
  --text-inverse: #FFFFFF;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 16px 36px rgba(0, 0, 0, 0.12);
}

/* Reset Globale */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* Testi selezionabili */
.selectable, p, blockquote, .note-content, .note-citation-box {
  user-select: text;
  -webkit-user-select: text;
}

/* Container responsive centrale (ottimizzato sia per iPhone che per Desktop) */
.app-wrapper {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--app-max-width);
  height: 100%;
  height: 100dvh; /* Dynamic Viewport Height iOS */
  margin: 0 auto;
  position: relative;
  background-color: var(--bg-primary);
  overflow: hidden;
}

@media (min-width: 681px) and (min-height: 600px) {
  body {
    background-color: #050608;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .app-wrapper {
    height: 96vh;
    max-width: 780px;
    border-radius: var(--radius-xl);
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
    border: 1px solid var(--border-subtle);
  }
}

@media (max-height: 550px) {
  :root {
    --header-height: 44px;
    --tabbar-height: 52px;
  }
}

/* Header Glassmorphism */
.app-header {
  height: calc(var(--header-height) + var(--safe-top));
  padding-top: var(--safe-top);
  padding-left: max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-glass);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  border-bottom: 1px solid var(--border-subtle);
  position: relative;
  z-index: 50;
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  object-fit: cover;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.brand-title span {
  color: var(--accent-gold);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.header-btn-icon:active {
  transform: scale(0.92);
}

.header-btn-icon svg {
  width: 18px;
  height: 18px;
}

/* Banner Offline Informato */
.offline-alert {
  background: rgba(249, 115, 22, 0.14);
  border-bottom: 1px solid rgba(249, 115, 22, 0.3);
  color: #FB923C;
  padding: 8px 16px;
  font-size: 11.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  line-height: 1.35;
  z-index: 49;
  flex-shrink: 0;
}

.offline-alert svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Viewport Principale */
.main-viewport {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-left: max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
  padding-top: 14px;
  padding-bottom: 24px;
  scroll-behavior: smooth;
}

/* Bottom Tab Bar (4 Tab iPhone Thumb Zone) */
.app-tabbar {
  flex-shrink: 0;
  position: relative;
  width: 100%;
  height: calc(var(--tabbar-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-glass);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 50;
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  gap: 3px;
  transition: all 0.2s ease;
  cursor: pointer;
  background: transparent;
  border: none;
  min-width: 60px;
  min-height: 44px; /* Apple Human Interface Guidelines tap target */
}

.tab-item svg {
  width: 23px;
  height: 23px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  transition: transform 0.15s ease, stroke 0.2s ease;
}

.tab-item.active {
  color: var(--accent-gold);
}

.tab-item.active svg {
  stroke: var(--accent-gold);
  transform: translateY(-1px);
}

.tab-item:active {
  transform: scale(0.92);
}

/* Indicatore Sincronizzazione Badge */
.sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  cursor: pointer;
  min-height: 32px;
}

.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--sync-online);
}

.sync-dot.online { background-color: var(--sync-online); }
.sync-dot.syncing { background-color: var(--sync-syncing); animation: pulseSync 1.2s infinite; }
.sync-dot.offline { background-color: var(--sync-offline); }
.sync-dot.error { background-color: var(--sync-error); }

/* Titoli di sezione */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  margin-top: 22px;
}

.section-header:first-of-type {
  margin-top: 4px;
}

.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--text-primary);
}

.section-link {
  font-size: 12.5px;
  color: var(--accent-gold);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
}

/* ---- Blocco scorrimento laterale ---- */
html, body { overflow-x: hidden; overscroll-behavior-x: none; position: fixed; inset: 0; }
.app-wrapper, .main-viewport, .view-section, .sheet-backdrop, .bottom-sheet { max-width: 100%; overflow-x: clip; }
.app-wrapper, .main-viewport, .sheet-content { touch-action: pan-y; overscroll-behavior-x: none; }
.sheet-content { overflow-x: hidden; }
img, video, svg { max-width: 100%; }
/* Su iOS un input sotto i 16px fa zoomare/spostare la pagina al focus */
input, select, textarea, .search-input { font-size: 16px; }
/* Le liste a scorrimento orizzontale intenzionale restano scorrevoli */
.reading-carousel, .segmented-scroll { touch-action: pan-x pan-y; overscroll-behavior-x: contain; }
