/* ==========================================================================
   ChatGPT Projects OS — App PWA (v4.0.0 True Software Edition)
   Canone emaf205: Visione Monoculare, Font Base >= 16px, Contrasto > 10:1,
   Mobile-First, Bottom App Dock, 5 Schermate Dedicate Full-Screen, Zero Audio.
   ========================================================================== */

/* 1. VARIABILI DI TEMA & DESIGN TOKENS */
:root {
  /* LIGHT MODE (PREDEFINITO) */
  --bg-canvas: #f6f7fb;
  --bg-surface: #ffffff;
  --bg-subtle: #eef2f6;
  --bg-hover: #e2e8f0;
  --bg-active: #cbd5e1;
  --bg-card: #ffffff;

  --border-subtle: #e2e8f0;
  --border-mid: #cbd5e1;
  --border-strong: #94a3b8;

  /* Contrasto Massimo (>10:1 per Visione Monoculare) */
  --text-primary: #090d16;
  --text-secondary: #27303f;
  --text-muted: #475569;

  --accent-blue: #0284c7;
  --accent-blue-hover: #0369a1;
  --accent-blue-subtle: #e0f2fe;
  
  --accent-star: #d97706;
  --accent-star-bg: #fef3c7;
  
  --accent-green: #059669;
  --accent-green-bg: #d1fae5;
  
  --accent-danger: #dc2626;
  --accent-danger-bg: #fee2e2;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);

  --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "Menlo", "Monaco", "Consolas", monospace;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  --header-height: 64px;
  --dock-height: 64px;
}

[data-theme="dark"] {
  --bg-canvas: #090d16;
  --bg-surface: #111827;
  --bg-subtle: #1e293b;
  --bg-hover: #334155;
  --bg-active: #475569;
  --bg-card: #131c2e;

  --border-subtle: #1e293b;
  --border-mid: #334155;
  --border-strong: #64748b;

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;

  --accent-blue: #38bdf8;
  --accent-blue-hover: #0284c7;
  --accent-blue-subtle: #082f49;

  --accent-star: #fbbf24;
  --accent-star-bg: #451a03;

  --accent-green: #34d399;
  --accent-green-bg: #064e3b;

  --accent-danger: #f87171;
  --accent-danger-bg: #450a0a;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
}

/* 2. RESET GLOBALE & ACCESSIBILITÀ BASE */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-system);
  font-size: 16px; /* REGOLA FERREA: MAI SOTTO 16PX */
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 16px;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  touch-action: manipulation;
}

a {
  color: var(--accent-blue);
  text-decoration: none;
}

/* 3. LAYOUT APP CONTAINER */
.app-container {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-canvas);
}

/* 4. TOP APP HEADER */
.app-header {
  height: var(--header-height);
  min-height: var(--header-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  padding-top: env(safe-area-inset-top, 0);
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

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

.brand-badge-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background-color: var(--accent-blue-subtle);
  color: var(--accent-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  border: 1px solid var(--border-subtle);
}

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

.brand-app-name {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.2;
}

.brand-sub-badge {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-blue);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* DESKTOP NAV SWITCHER (5 SCHERMATE DEDICATE) */
.header-nav-desktop {
  display: none; /* Visibile su schermi >= 768px */
  align-items: center;
  gap: 6px;
  background-color: var(--bg-subtle);
  padding: 5px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
}

.nav-switch-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-secondary);
  transition: all 0.15s ease;
  min-height: 40px;
}

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

.nav-switch-btn.active {
  background-color: var(--bg-surface);
  color: var(--accent-blue);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-subtle);
}

.nav-icon {
  font-size: 17px;
}

.nav-count-badge {
  background-color: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.nav-switch-btn.active .nav-count-badge {
  background-color: var(--accent-blue-subtle);
  color: var(--accent-blue);
}

/* HEADER AZIONI DESTRA */
.header-actions-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.action-btn-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  background-color: var(--bg-subtle);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 700;
  border: 1px solid var(--border-subtle);
  min-height: 42px;
  transition: all 0.15s ease;
}

.action-btn-header:hover {
  background-color: var(--bg-hover);
  border-color: var(--border-mid);
}

.action-btn-header.primary {
  background-color: var(--accent-blue);
  color: #ffffff;
  border-color: var(--accent-blue);
}

.action-btn-header.primary:hover {
  background-color: var(--accent-blue-hover);
}

.btn-label-desktop {
  display: none;
}

/* 5. MAIN VIEWPORT & SCHERMATE */
.app-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background-color: var(--bg-canvas);
}

.screen-view {
  display: none;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
  padding-bottom: calc(var(--dock-height) + 24px + env(safe-area-inset-bottom, 0));
}

.screen-view.active {
  display: block;
}

.screen-content-wrapper {
  max-width: 1380px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* BANNER INTESTATURA SCHERMATA */
.screen-header-banner {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.screen-title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.screen-subtitle {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-secondary);
  line-height: 1.4;
  max-width: 780px;
}

.screen-stat-chip {
  background-color: var(--accent-blue-subtle);
  border: 1px solid var(--accent-blue);
  border-radius: var(--radius-md);
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.stat-chip-number {
  font-size: 26px;
  font-weight: 800;
  color: var(--accent-blue);
  line-height: 1.1;
}

.stat-chip-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
}

/* 6. VIEW CONTROLS (SEARCH & FILTRI) */
.view-controls-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
}

.search-field-wrapper {
  flex: 1;
  min-width: 240px;
  position: relative;
  display: flex;
  align-items: center;
}

.search-lens-icon {
  position: absolute;
  left: 14px;
  font-size: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

.app-input-search {
  width: 100%;
  height: 48px;
  padding: 0 42px 0 44px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-mid);
  background-color: var(--bg-subtle);
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.app-input-search:focus {
  outline: none;
  border-color: var(--accent-blue);
  background-color: var(--bg-surface);
  box-shadow: 0 0 0 3px var(--accent-blue-subtle);
}

.search-clear-btn {
  position: absolute;
  right: 12px;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background-color: var(--bg-hover);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.filter-pills-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.scrollable-pills {
  overflow-x: auto;
  white-space: nowrap;
  padding-bottom: 2px;
}

.filter-pill-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  background-color: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 700;
  border: 1px solid var(--border-subtle);
  min-height: 42px;
  transition: all 0.15s ease;
}

.filter-pill-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.filter-pill-btn.active {
  background-color: var(--accent-blue);
  color: #ffffff;
  border-color: var(--accent-blue);
}

.pill-badge {
  font-size: 12.5px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background-color: rgba(0, 0, 0, 0.1);
  color: inherit;
}

.select-wrapper {
  position: relative;
}

.app-select {
  height: 48px;
  padding: 0 34px 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-mid);
  background-color: var(--bg-subtle);
  color: var(--text-primary);
  font-size: 15.5px;
  font-weight: 600;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
}

.app-select:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-blue-subtle);
}

/* 7. SCHERMATA PROGETTI (BENTO GRID & CARDS) */
.projects-hub-container {
  max-width: 1380px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.projects-bento-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.project-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  cursor: pointer;
}

.project-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-mid);
  box-shadow: var(--shadow-md);
}

.project-card.favorite {
  border-color: var(--accent-star);
}

.project-card-toprow {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.project-icon-box {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background-color: var(--accent-blue-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
  border: 1px solid var(--border-subtle);
}

.project-card-name {
  font-size: 19px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.3;
  flex: 1;
}

.star-button {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--text-muted);
  transition: transform 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}

.star-button:hover {
  transform: scale(1.15);
  color: var(--accent-star);
}

.star-button.active {
  color: var(--accent-star);
}

.project-card-desc {
  font-size: 16px;
  color: var(--text-secondary);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.project-card-badges {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.badge-tag {
  background-color: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.badge-tag.chats {
  background-color: var(--accent-blue-subtle);
  color: var(--accent-blue);
  border-color: var(--accent-blue);
}

.badge-tag.generated {
  background-color: #fef3c7;
  color: #b45309;
  border-color: #fde68a;
}

[data-theme="dark"] .badge-tag.generated {
  background-color: #451a03;
  color: #fbbf24;
  border-color: #78350f;
}

.badge-tag.files {
  background-color: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}

[data-theme="dark"] .badge-tag.files {
  background-color: #064e3b;
  color: #34d399;
  border-color: #065f46;
}

.badge-model {
  background-color: var(--text-primary);
  color: var(--bg-surface);
  font-size: 12.5px;
  font-weight: 800;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
}

/* 8. SOTTO-SCHERMATA DETTAGLIO PROGETTO DEDICATO */
.project-detail-screen {
  max-width: 1380px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.detail-nav-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.detail-back-button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-mid);
  color: var(--text-primary);
  font-size: 16.5px;
  font-weight: 800;
  min-height: 48px;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}

.detail-back-button:hover {
  background-color: var(--bg-hover);
  border-color: var(--text-primary);
  transform: translateX(-2px);
}

.back-arrow {
  font-size: 20px;
  font-weight: 900;
}

.detail-top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.detail-hero-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 20px;
  box-shadow: var(--shadow-sm);
}

.detail-hero-left {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  flex: 1;
  min-width: 280px;
}

.detail-project-icon {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-lg);
  background-color: var(--accent-blue-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  flex-shrink: 0;
  border: 1px solid var(--border-subtle);
}

.detail-title-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.detail-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.detail-project-name {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.25;
}

.detail-star-toggle {
  font-size: 28px;
  color: var(--text-muted);
  cursor: pointer;
}

.detail-star-toggle.active {
  color: var(--accent-star);
}

.detail-project-desc {
  font-size: 16.5px;
  color: var(--text-secondary);
  line-height: 1.45;
  max-width: 820px;
}

.detail-badges-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.model-badge {
  background-color: var(--text-primary);
  color: var(--bg-surface);
  font-size: 13px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
}

.date-badge {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}

.detail-stats-summary {
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat-box {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  text-align: center;
  min-width: 100px;
}

.stat-number {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-primary);
  display: block;
}

.stat-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* TABS SEZIONI DETTAGLIO */
.detail-tabs-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  white-space: nowrap;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 6px;
  box-shadow: var(--shadow-sm);
}

.detail-tab-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-secondary);
  min-height: 46px;
  transition: all 0.15s ease;
}

.detail-tab-btn:hover {
  color: var(--text-primary);
  background-color: var(--bg-hover);
}

.detail-tab-btn.active {
  background-color: var(--accent-blue);
  color: #ffffff;
}

.detail-tab-btn.active .pill-badge {
  background-color: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

.detail-content-viewport {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

/* SEZIONE ISTRUZIONI (SYSTEM PROMPT) */
.instructions-container-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.instructions-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.instructions-heading {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
}

.instructions-subtext {
  font-size: 15px;
  color: var(--text-muted);
}

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

.token-estimate-badge {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: var(--radius-md);
}

.instructions-markdown-body {
  font-size: 16.5px;
  line-height: 1.65;
  color: var(--text-primary);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  max-height: 540px;
  overflow-y: auto;
  user-select: text;
}

.instructions-markdown-body h1,
.instructions-markdown-body h2,
.instructions-markdown-body h3 {
  margin-top: 16px;
  margin-bottom: 8px;
  font-weight: 800;
  color: var(--text-primary);
}

.instructions-markdown-body p {
  margin-bottom: 12px;
}

.instructions-markdown-body ul,
.instructions-markdown-body ol {
  margin-left: 24px;
  margin-bottom: 12px;
}

.instructions-markdown-body pre {
  background-color: #0f172a;
  color: #f8fafc;
  padding: 14px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 15px;
  margin: 12px 0;
}

.instructions-markdown-body code {
  font-family: var(--font-mono);
  background-color: rgba(0, 0, 0, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.95em;
}

/* 9. SCHERMATA TUTTE LE CHAT (FEED CARD LIST) */
.feed-items-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-card-item {
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}

.chat-card-item:hover {
  border-color: var(--border-mid);
  transform: translateX(2px);
  background-color: var(--bg-subtle);
}

.chat-item-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

.chat-icon-badge {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background-color: var(--accent-blue-subtle);
  color: var(--accent-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.chat-meta-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.chat-title-text {
  font-size: 17.5px;
  font-weight: 800;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-details-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.project-tag-pill {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.project-tag-pill:hover {
  background-color: var(--accent-blue-subtle);
  color: var(--accent-blue);
  border-color: var(--accent-blue);
}

.chat-date-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}

.chat-actions-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* 10. SCHERMATA FILE GENERATI (CARDS GRID) */
.generated-cards-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.gen-file-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}

.gen-file-card:hover {
  border-color: var(--border-mid);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.gen-card-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

.artifact-icon-box {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-md);
  background-color: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
  border: 1px solid var(--border-subtle);
}

.artifact-icon-box.image {
  background-color: #fdf2f8;
  color: #db2777;
}

.artifact-icon-box.report {
  background-color: #eff6ff;
  color: #2563eb;
}

.artifact-icon-box.sheet {
  background-color: #ecfdf5;
  color: #059669;
}

.artifact-icon-box.writing_block {
  background-color: #fefce8;
  color: #ca8a04;
}

.gen-file-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.gen-file-name {
  font-size: 17.5px;
  font-weight: 800;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gen-file-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.artifact-badge {
  font-size: 13px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-subtle);
  color: var(--text-secondary);
}

.gen-file-size {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}

.gen-actions-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* 11. SCHERMATA ALLEGATI KB (TABELLA & DROPZONE) */
.global-dropzone-box,
.project-dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 24px;
  background-color: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  gap: 10px;
  transition: all 0.2s ease;
  cursor: pointer;
}

.global-dropzone-box.drag-over,
.project-dropzone.drag-over {
  border-color: var(--accent-blue);
  background-color: var(--accent-blue-subtle);
}

.dropzone-icon {
  font-size: 36px;
}

.dropzone-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
}

.dropzone-subtitle {
  font-size: 15px;
  color: var(--text-muted);
}

.attachments-table-container {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
}

.app-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.app-table th {
  background-color: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.app-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 16px;
  color: var(--text-primary);
  vertical-align: middle;
}

.app-table tr:hover td {
  background-color: var(--bg-subtle);
}

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

.table-file-name {
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
}

.table-file-name:hover {
  color: var(--accent-blue);
}

/* 12. SCHERMATA STRUMENTI & SYNC */
.tools-status-pills {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.status-pill-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 700;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.status-pill-indicator.online {
  background-color: var(--accent-green-bg);
  color: var(--accent-green);
  border-color: var(--accent-green);
}

.dot-beacon {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background-color: var(--accent-green);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.dot-beacon.gray {
  background-color: var(--text-muted);
  box-shadow: none;
}

.tools-cards-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

.tool-operation-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.tool-card-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.tool-icon-wrapper {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background-color: var(--accent-blue-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
}

.tool-card-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.tool-card-desc {
  font-size: 16px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.badge-recommended {
  background-color: var(--accent-green-bg);
  color: var(--accent-green);
  font-size: 13px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  margin-left: auto;
  flex-shrink: 0;
}

.terminal-command-box {
  background-color: #0f172a;
  border-radius: var(--radius-md);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  overflow-x: auto;
}

.terminal-command-box code {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: #38bdf8;
  white-space: nowrap;
  overflow-x: auto;
}

.btn-copy-terminal {
  background-color: #1e293b;
  color: #ffffff;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  transition: background-color 0.15s ease;
}

.btn-copy-terminal:hover {
  background-color: var(--accent-blue);
}

.tool-card-footer-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.tool-footer-hint {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.quick-steps-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background-color: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 16px;
  color: var(--text-primary);
}

.step-badge {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background-color: var(--accent-blue);
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tool-actions-flex {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.pwa-status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.pwa-metric-box {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-label {
  font-size: 13.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.metric-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
}

.install-guide-box {
  background-color: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.install-guide-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--text-primary);
}

.install-guide-list {
  margin-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 15.5px;
  color: var(--text-secondary);
}

/* 13. PULSANTI & COMPONENTI GENERALI */
.btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 700;
  border: 1px solid var(--border-mid);
  min-height: 48px;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-action:hover {
  background-color: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn-action.primary {
  background-color: var(--accent-blue);
  color: #ffffff;
  border-color: var(--accent-blue);
}

.btn-action.primary:hover {
  background-color: var(--accent-blue-hover);
}

.btn-action.danger {
  background-color: var(--accent-danger);
  color: #ffffff;
  border-color: var(--accent-danger);
}

.btn-action.danger-outline {
  color: var(--accent-danger);
  border-color: var(--accent-danger);
}

.btn-action.danger-outline:hover {
  background-color: var(--accent-danger-bg);
}

.btn-action-small {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-size: 14.5px;
  font-weight: 700;
  border: 1px solid var(--border-mid);
  min-height: 38px;
}

.btn-action-small:hover {
  background-color: var(--bg-hover);
}

.btn-icon-only {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-mid);
  color: var(--text-primary);
  font-size: 18px;
}

.btn-icon-only:hover {
  background-color: var(--bg-hover);
}

/* 14. EMPTY STATES & PAGINATION */
.empty-state-box {
  background-color: var(--bg-surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 48px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.empty-state-icon {
  font-size: 48px;
}

.empty-state-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
}

.empty-state-text {
  font-size: 16px;
  color: var(--text-secondary);
  max-width: 480px;
}

.pagination-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  padding: 16px 20px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.pagination-info {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
}

/* 15. MOBILE BOTTOM APP DOCK */
.app-dock-mobile {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--dock-height) + env(safe-area-inset-bottom, 0));
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 8px;
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 200;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
}

.dock-item-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: var(--dock-height);
  min-height: var(--dock-height);
  color: var(--text-muted);
  transition: all 0.15s ease;
  position: relative;
}

.dock-icon {
  font-size: 22px;
  line-height: 1;
}

.dock-label {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.dock-item-btn.active {
  color: var(--accent-blue);
}

.dock-item-btn.active .dock-icon {
  transform: translateY(-2px);
}

.dock-item-btn.active::after {
  content: "";
  position: absolute;
  top: 6px;
  width: 24px;
  height: 3px;
  border-radius: var(--radius-full);
  background-color: var(--accent-blue);
}

/* 16. MODALI (QUICK LOOK & EDIT) */
.app-modal-dialog {
  border: none;
  background: transparent;
  padding: 20px;
  max-width: 100vw;
  max-height: 100vh;
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.app-modal-dialog[open] {
  display: flex;
}

.app-modal-dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-card-sheet {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background-color: var(--bg-subtle);
}

.modal-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.modal-file-icon {
  font-size: 32px;
}

.modal-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
}

.modal-subtitle {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}

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

.btn-modal-close {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background-color: var(--bg-hover);
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-modal-close:hover {
  background-color: var(--border-strong);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.quick-look-viewport {
  background-color: var(--bg-canvas);
  min-height: 320px;
  font-size: 16.5px;
  line-height: 1.6;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--bg-subtle);
}

.modal-footer-hint {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}

/* FORM STYLES */
.form-body-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-row-2col {
  display: flex;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.flex-1 { flex: 1; }
.flex-3 { flex: 3; }

.form-label {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.app-input-text {
  height: 48px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-mid);
  background-color: var(--bg-subtle);
  color: var(--text-primary);
  font-size: 16px;
}

.app-input-text:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-blue-subtle);
}

.center-text {
  text-align: center;
  font-size: 24px;
}

.app-textarea {
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-mid);
  background-color: var(--bg-subtle);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.5;
  resize: vertical;
}

.app-textarea:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-blue-subtle);
}

/* 17. TOAST NOTIFICATIONS */
.app-toast-container {
  position: fixed;
  bottom: calc(var(--dock-height) + 16px + env(safe-area-inset-bottom, 0));
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1100;
  pointer-events: none;
}

.toast-msg {
  background-color: #0f172a;
  color: #ffffff;
  padding: 14px 22px;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  border: 1px solid #334155;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
}

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

/* 18. RESPONSIVE BREAKPOINTS (DESKTOP & TABLET >= 768px) */
@media (min-width: 768px) {
  .header-nav-desktop {
    display: flex;
  }

  .btn-label-desktop {
    display: inline;
  }

  .app-dock-mobile {
    display: none;
  }

  .screen-view {
    padding-bottom: 30px;
  }

  .projects-bento-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .generated-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .tools-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .app-toast-container {
    bottom: 24px;
  }
}

@media (min-width: 1180px) {
  .projects-bento-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .tools-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* 19. STANDALONE PWA MODE */
@media (display-mode: standalone) {
  .app-header {
    padding-top: calc(12px + env(safe-area-inset-top, 0));
    height: calc(var(--header-height) + 12px);
  }
}

/* 20. STILI DI STAMPA A4 (@media print) */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
    overflow: visible !important;
    height: auto !important;
  }

  .app-header,
  .app-dock-mobile,
  .view-controls-bar,
  .detail-nav-topbar,
  .detail-tabs-bar,
  .app-toast-container {
    display: none !important;
  }

  .app-container,
  .app-viewport,
  .screen-view {
    overflow: visible !important;
    height: auto !important;
    padding: 0 !important;
  }

  .detail-content-viewport {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }

  .instructions-markdown-body {
    max-height: none !important;
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    font-size: 12pt !important;
    color: #000000 !important;
  }
}
