/* =====================================================================
   QRAppTEST — Stili applicazione
   ===================================================================== */
:root {
  --color-navy:        #122835;
  --color-teal:        #007B98;
  --color-teal-light:  #E8F4F7;
  --color-teal-dark:   #005B72;   /* hover/active su teal (SPEC §3-bis.3) */
  --color-green:       #16A34A;
  --color-green-bg:    #DCFCE7;
  --color-yellow:      #D97706;
  --color-yellow-bg:   #FEF3C7;
  --color-red:         #DC2626;
  --color-red-bg:      #FEE2E2;
  --color-bg:          #F8FAFC;
  --color-surface:     #FFFFFF;
  --color-text:        #1E293B;
  --color-text-muted:  #64748B;
  --color-border:      #E2E8F0;
  --radius-card:       12px;
  --shadow-card:       0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --font-base:         -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:         'SFMono-Regular', Menlo, Consolas, monospace;
  --header-h:          56px;
  --status-h:          64px;
  --search-h:          48px;
  --chips-h:           48px;
  --backbar-h:         48px;
  --assethdr-h:        108px;
  --quick-h:           56px;
  --input-h:           60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  font-family: var(--font-base);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font-family: inherit; }

img { display: block; }

/* ===================================================================
   Schermate (full viewport)
   =================================================================== */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
}

[hidden] { display: none !important; }

/* ===================================================================
   Login
   =================================================================== */
#screen-login {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  padding: 32px 24px;
  text-align: center;
}

.login-logo { width: 160px; margin: 0 auto 16px; }
.login-title { font-size: 24px; color: var(--color-navy); margin: 8px 0 16px; }
.login-text { color: var(--color-text-muted); line-height: 1.5; margin: 8px 0; }
.login-email {
  background: var(--color-teal-light);
  color: var(--color-navy);
  padding: 10px;
  border-radius: 8px;
  font-family: monospace;
  word-break: break-all;
  margin: 16px 0;
}
.login-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 14px 32px;
  background: var(--color-teal);
  color: white;
  text-decoration: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 16px;
  border: none;
  cursor: pointer;
  text-align: center;
  box-sizing: border-box;
}
.login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.login-footer {
  margin-top: 24px;
  font-size: 13px;
  color: var(--color-text-muted);
}

/* Form di login (flusso demo) */
.login-form {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 20px;
  width: 100%;
}
.login-input {
  width: 100%;
  box-sizing: border-box;
  padding: 13px 14px;
  font-size: 16px;
  border: 1.5px solid #CBD5E1;
  border-radius: 8px;
  outline: none;
  color: var(--color-navy);
  background: #F8FAFC;
  transition: border-color 0.15s;
}
.login-input:focus {
  border-color: var(--color-teal);
  background: white;
}
.login-feedback {
  margin-top: 18px;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
}
.login-feedback--ok {
  background: #ECFDF5;
  color: #065F46;
}
.login-feedback--error {
  background: #FEF2F2;
  color: #991B1B;
}

/* ===================================================================
   Header app
   =================================================================== */
.app-header {
  position: relative; /* necessario per posizionare il version-popover */
  height: var(--header-h);
  background: var(--color-navy);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  flex-shrink: 0;
}
.header-logo { display: flex; align-items: center; gap: 8px; padding: 8px 0; }
.header-titles { display: flex; align-items: center; gap: 8px; }

/* Logo statico (non interattivo) */
.header-logo-img {
  display: flex; align-items: center;
}

/* Titolo app come bottone — visivamente identico allo span precedente */
.app-title-btn {
  background: none; border: none; padding: 0; margin: 0;
  cursor: pointer;
  font-weight: 600; font-size: 17px; letter-spacing: 0.3px;
  color: white; font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.app-title-btn:active { opacity: 0.7; }

/* Popover versione */
.version-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 12px;
  z-index: 200;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.14);
  padding: 12px 16px;
  min-width: 220px;
}
.version-popover-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0;
}
.version-popover-row + .version-popover-row {
  border-top: 1px solid var(--color-border);
  margin-top: 4px;
  padding-top: 8px;
}
.version-popover-label {
  font-size: 12px;
  color: var(--color-text-muted);
  white-space: nowrap;
}
.version-popover-value {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-text);
  user-select: all;
  text-align: right;
}

/* Badge BETA — apre/chiude il banner sottotitolo */
.app-beta-badge {
  border: 1px solid rgba(255,255,255,0.45);
  background: rgba(255,255,255,0.10);
  color: rgba(255,255,255,0.9);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  padding: 2px 7px;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
.app-beta-badge:active { background: rgba(255,255,255,0.22); }

/* Banner sottotitolo "versione di test" */
.beta-banner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 16px;
  background: var(--color-teal-light);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.beta-banner-text {
  margin: 0;
  flex: 1;
  font-size: 12px;
  line-height: 1.4;
  color: var(--color-navy);
}
.beta-banner-close {
  flex-shrink: 0;
  width: 24px; height: 24px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 14px;
  cursor: pointer;
  border-radius: 50%;
}
.beta-banner-close:active { background: rgba(0,0,0,0.06); }

.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--color-teal);
  color: white;
  border: none;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

/* User menu popover */
.user-menu {
  position: fixed;
  top: calc(var(--header-h) + 8px);
  right: 12px;
  background: var(--color-surface);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 12px 16px;
  min-width: 220px;
  z-index: 300;
}
.user-menu-name  { font-weight: 600; color: var(--color-navy); }
.user-menu-email { font-size: 13px; color: var(--color-text-muted); margin-top: 2px; word-break: break-all; }
.user-menu-contact {
  display: block; width: 100%; margin-top: 12px;
  padding: 8px;
  background: var(--color-teal-light);
  color: var(--color-teal);
  border: none; border-radius: 6px;
  cursor: pointer; font-weight: 600;
  font-family: inherit; font-size: inherit;
}
.user-menu-contact:active { background: #d0eaf2; }
.user-menu-logout {
  display: block; width: 100%; margin-top: 8px;
  padding: 8px;
  background: var(--color-red-bg);
  color: var(--color-red);
  border: none; border-radius: 6px;
  cursor: pointer; font-weight: 600;
}

/* ===================================================================
   Status bar (semafori)
   =================================================================== */
.status-bar {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  flex-shrink: 0;
}
.status-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 56px;
  border-radius: 8px;
  border: 1px solid;
}
.status-box.green  { background: var(--color-green-bg);  border-color: var(--color-green);  color: var(--color-green); }
.status-box.yellow { background: var(--color-yellow-bg); border-color: var(--color-yellow); color: var(--color-yellow); }
.status-box.red    { background: var(--color-red-bg);    border-color: var(--color-red);    color: var(--color-red); }
.status-count { font-size: 20px; font-weight: 700; line-height: 1; }
.status-label { font-size: 11px; margin-top: 2px; text-transform: uppercase; letter-spacing: 0.4px; }

/* ===================================================================
   Search bar
   =================================================================== */
.search-bar {
  padding: 0 16px 8px;
  flex-shrink: 0;
}
.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 0 12px;
  height: 44px;
}
.search-icon { width: 18px; height: 18px; color: var(--color-text-muted); flex-shrink: 0; }
#searchInput {
  flex: 1;
  border: none;
  outline: none;
  padding: 0 10px;
  font-size: 15px;
  background: transparent;
}
.search-clear {
  background: var(--color-border);
  border: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  color: var(--color-text);
  font-size: 12px;
  cursor: pointer;
}

/* ===================================================================
   Filter chips
   =================================================================== */
.filter-chips-wrapper { flex-shrink: 0; }
.filter-chips {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  white-space: nowrap;
}
.filter-chips::-webkit-scrollbar { display: none; }
.chip {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.chip.active {
  background: var(--color-teal);
  border-color: var(--color-teal);
  color: white;
}

/* ===================================================================
   Asset list (home)
   =================================================================== */
.asset-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 80px;
  -webkit-overflow-scrolling: touch;
}

.asset-card {
  display: flex;
  align-items: stretch;
  background: var(--color-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  margin-bottom: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.08s ease;
}
.asset-card:active { transform: scale(0.98); }
.asset-card-status-bar { width: 4px; flex-shrink: 0; }
.asset-card-status-bar.green  { background: var(--color-green); }
.asset-card-status-bar.yellow { background: var(--color-yellow); }
.asset-card-status-bar.red    { background: var(--color-red); }
.asset-card-body { flex: 1; padding: 12px 14px; min-width: 0; }
.asset-card-header { display: flex; justify-content: space-between; gap: 8px; }
.asset-partner {
  font-weight: 600; color: var(--color-navy);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.asset-city { font-size: 12px; color: var(--color-text-muted); }
.asset-card-meta {
  display: flex; gap: 8px; margin-top: 6px;
  font-size: 13px; color: var(--color-text-muted);
}
.asset-model { color: var(--color-teal); font-weight: 500; }
.asset-card-extra {
  display: flex; align-items: center; gap: 8px; margin-top: 4px;
  font-size: 12px; color: var(--color-text-muted); min-width: 0;
}
.asset-card-name {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
.asset-card-sep { opacity: 0.5; flex-shrink: 0; }
.asset-card-smartid {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 11px;
  color: var(--color-teal-dark);
  background: var(--color-teal-light);
  padding: 1px 6px;
  border-radius: 5px;
  flex-shrink: 0;
}
.asset-card-chevron {
  display: flex; align-items: center; justify-content: center;
  width: 28px; color: var(--color-text-muted); font-size: 20px;
}

/* Skeleton */
.asset-skeleton {
  height: 64px;
  border-radius: var(--radius-card);
  margin-bottom: 10px;
  background: linear-gradient(90deg, #eee 0%, #f5f5f5 50%, #eee 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

.asset-empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--color-text-muted);
}

/* ===================================================================
   FAB
   =================================================================== */
.fab {
  position: fixed;
  bottom: 24px; right: 24px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--color-teal);
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(0,123,152,0.4);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.fab svg { width: 24px; height: 24px; }

/* ===================================================================
   Scheda Asset — Back bar
   =================================================================== */
.back-bar {
  height: var(--backbar-h);
  background: var(--color-surface);
  display: flex; align-items: center;
  padding: 0 8px 0 4px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.back-btn {
  width: 40px; height: 40px;
  border: none; background: transparent;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--color-text);
}
.back-btn svg { width: 22px; height: 22px; }
.back-title {
  flex: 1;
  font-weight: 600; color: var(--color-navy);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ===================================================================
   Asset header
   =================================================================== */
.asset-header {
  background: var(--color-navy);
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex-shrink: 0;
  cursor: default;
  overflow: hidden;
  max-height: 200px;
  transition: max-height 220ms cubic-bezier(.4,0,.2,1), padding 220ms;
}
.asset-header-status-dot {
  width: 12px; height: 12px; border-radius: 50%;
  flex-shrink: 0;
  margin-top: 3px;
}
.asset-header-status-dot.green  { background: var(--color-green);  box-shadow: 0 0 0 3px rgba(22,163,74,0.25); }
.asset-header-status-dot.yellow { background: var(--color-yellow); box-shadow: 0 0 0 3px rgba(217,119,6,0.25); }
.asset-header-status-dot.red    { background: var(--color-red);    box-shadow: 0 0 0 3px rgba(220,38,38,0.25); }
.asset-header-info { flex: 1; min-width: 0; }
.asset-header-row-top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.asset-header-type {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px;
  opacity: 0.8;
}
.asset-header-smartid {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: #fff;
  background: rgba(255,255,255,0.14);
  padding: 1px 7px;
  border-radius: 5px;
  flex-shrink: 0;
}
.asset-header-identity { font-size: 15px; margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset-header-identity strong { color: white; }
.asset-separator { margin: 0 6px; opacity: 0.5; }
.asset-header-model { font-size: 13px; opacity: 0.85; }
.asset-header-customer {
  font-size: 12px; margin-top: 4px; opacity: 0.85;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.asset-customer-sep { margin: 0 5px; opacity: 0.5; }
.asset-customer-address { color: rgba(255,255,255,0.9); text-decoration: underline; text-underline-offset: 2px; }

/* Stato collassato (al scroll della chat) */
.asset-header.is-collapsed {
  max-height: 28px;
  padding-top: 4px; padding-bottom: 4px;
  cursor: pointer;
}
.asset-header.is-collapsed .asset-header-row-top .asset-header-smartid,
.asset-header.is-collapsed .asset-header-customer {
  display: none;
}
.asset-header.is-collapsed .asset-header-identity {
  font-size: 13px; line-height: 20px; margin-top: 0;
}
.asset-header.is-collapsed .asset-header-status-dot { margin-top: 4px; }

/* ===================================================================
   Quick actions
   =================================================================== */
.quick-actions {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: var(--color-surface);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
  border-bottom: 1px solid var(--color-border);
  transition: max-height 0.25s ease, padding 0.25s ease;
  max-height: 80px;
}
.quick-actions.collapsed { max-height: 0; padding-top: 0; padding-bottom: 0; overflow: hidden; }
.quick-actions::-webkit-scrollbar { display: none; }
.quick-btn {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--color-teal-light);
  border: 1px solid var(--color-teal);
  color: var(--color-teal);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

/* Chip "Suggerimenti" nella back-bar — sempre visibile, togola quick-actions */
.suggestions-pill {
  flex-shrink: 0;
  margin-left: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.suggestions-pill.is-active {
  background: var(--color-teal-light);
  border-color: var(--color-teal);
  color: var(--color-teal);
}
.suggestions-pill:active { opacity: 0.7; }

/* ===================================================================
   Chat area
   =================================================================== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
  background: var(--color-bg);
}

.chat-message {
  display: flex; flex-direction: column;
  margin-bottom: 14px;
  max-width: 88%;
}
.chat-message.user { align-self: flex-end; margin-left: auto; align-items: flex-end; }
.chat-message.ai   { align-self: flex-start; align-items: flex-start; }

.chat-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.chat-message.user .chat-bubble {
  background: var(--color-teal);
  color: white;
  border-bottom-right-radius: 4px;
}
.chat-message.ai .chat-bubble {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 4px;
  white-space: normal;
}
.chat-meta {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

/* Markdown content inside AI bubble */
.chat-message.ai .chat-bubble strong { font-weight: 600; color: var(--color-navy); }
.chat-message.ai .chat-bubble ul,
.chat-message.ai .chat-bubble ol { margin: 6px 0 6px 22px; padding: 0; }
.chat-message.ai .chat-bubble code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SFMono-Regular', Menlo, monospace;
  font-size: 13px;
}
.chat-message.ai .chat-bubble pre {
  background: #f1f5f9;
  padding: 8px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 13px;
}
.chat-message.ai .chat-bubble p { margin: 6px 0; }
.chat-message.ai .chat-bubble p:first-child { margin-top: 0; }
.chat-message.ai .chat-bubble p:last-child  { margin-bottom: 0; }

/* Typing indicator */
.chat-message.typing .chat-bubble {
  display: flex; gap: 6px;
  padding: 14px 18px;
}
.typing-dot {
  width: 7px; height: 7px;
  background: var(--color-text-muted);
  border-radius: 50%;
  animation: blink 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
  40%           { opacity: 1;   transform: scale(1); }
}

.chat-error { color: var(--color-red); }

/* ===================================================================
   Chat input bar
   =================================================================== */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}
#chatInput {
  flex: 1;
  resize: none;
  border: 1px solid var(--color-border);
  border-radius: 18px;
  padding: 10px 14px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  max-height: 120px;
  line-height: 1.3;
  background: var(--color-bg);
}
#chatInput:focus { border-color: var(--color-teal); background: white; }

.send-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--color-teal);
  color: white;
  border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.send-btn:disabled { background: var(--color-border); color: var(--color-text-muted); cursor: not-allowed; }
.send-btn svg { width: 20px; height: 20px; }

/* ===================================================================
   Chat toolbar (pillole Documenti / Dettagli sopra l'input)
   Adattato da uiverse.io/Cybercom682/empty-wolverine-58 — MIT
   =================================================================== */
.chat-toolbar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}
.docs-pill, .info-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-teal);
  border-radius: 8px;
  background: #F1F5F9;
  color: var(--color-navy);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s;
}
.docs-pill:active, .info-pill:active { background: var(--color-teal-light); }
.docs-pill svg, .info-pill svg { width: 16px; height: 16px; color: var(--color-teal); flex-shrink: 0; }
.docs-pill-count {
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--color-teal);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

/* ===================================================================
   Sheet modal (full-screen bottom sheet) — Documenti / Dettagli
   =================================================================== */
.sheet-modal {
  position: fixed; inset: 0;
  z-index: 550;
  display: flex;
  align-items: flex-end;
}
.sheet-modal[hidden] { display: none !important; }
.sheet-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.45);
  opacity: 0;
  transition: opacity 280ms ease;
}
.sheet-modal.is-open .sheet-modal-backdrop { opacity: 1; }
.sheet-modal-sheet {
  position: relative;
  background: #fff;
  width: 100%;
  height: 90vh;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 280ms cubic-bezier(.32,.72,0,1);
}
.sheet-modal.is-open .sheet-modal-sheet { transform: translateY(0); }
.sheet-modal-grabber {
  width: 40px; height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  margin: 10px auto 4px;
  flex-shrink: 0;
}
.sheet-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px 10px;
  flex-shrink: 0;
}
.sheet-modal-header h2 { margin: 0; font-size: 18px; color: var(--color-navy); }
.sheet-modal-close {
  width: 32px; height: 32px;
  border: none; background: var(--color-bg);
  color: var(--color-text-muted);
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.sheet-modal-close:active { background: var(--color-border); }
.sheet-modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  padding: 0 8px;
}
.sheet-modal-tabs button {
  flex: 1;
  padding: 12px 0;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-family: inherit;
}
.sheet-modal-tabs button.active {
  color: var(--color-teal);
  border-bottom-color: var(--color-teal);
}
.sheet-modal-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
}

/* ===================================================================
   Doc card (griglia documenti nel modal)
   Adattato da uiverse.io/adamgiebl/new-crab-79 — MIT
   =================================================================== */
.doc-card-grid { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.doc-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: transform 0.08s ease;
}
.doc-card:active { transform: scale(0.985); }
.doc-card-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--color-teal-light);
  color: var(--color-teal);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
}
.doc-card-icon svg { width: 20px; height: 20px; }
.doc-card-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.doc-card-title {
  font-weight: 600; color: var(--color-navy); font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.doc-card-type { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }
.doc-card-open {
  width: 32px; height: 32px;
  border: none; background: transparent;
  color: var(--color-teal);
  font-size: 22px; line-height: 1;
  cursor: pointer; flex-shrink: 0;
}

.doc-empty, .details-empty {
  padding: 24px 16px; text-align: center; color: var(--color-text-muted);
}

/* Details pane (dentro #detailsModal) */
.details-section-title {
  margin: 18px 0 8px; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.6px; color: var(--color-text-muted);
}
.details-section-title:first-child { margin-top: 0; }
.details-list {
  margin: 0; padding: 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px;
  font-size: 14px;
}
.details-list dt {
  color: var(--color-text-muted); font-size: 12px; align-self: end;
}
.details-list dd { margin: 0; font-weight: 500; color: var(--color-navy); }
.date-ok      { color: var(--color-green); }
.date-warning { color: var(--color-yellow); }
.date-expired { color: var(--color-red); }

/* ===================================================================
   QR Modal
   =================================================================== */
.qr-modal {
  position: fixed; inset: 0;
  background: #000;
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
.qr-modal video {
  width: 100%; height: 100%;
  object-fit: cover;
}
.qr-modal canvas { display: none; }

.qr-close {
  position: absolute; top: 16px; right: 16px;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: white; border: none;
  font-size: 20px;
  cursor: pointer;
  z-index: 510;
}

.qr-frame {
  position: absolute;
  width: 70vmin; height: 70vmin;
  pointer-events: none;
}
.qr-corner {
  position: absolute;
  width: 30px; height: 30px;
  border: 4px solid var(--color-teal);
}
.qr-corner.top-left     { top: 0; left: 0; border-right: none; border-bottom: none; }
.qr-corner.top-right    { top: 0; right: 0; border-left:  none; border-bottom: none; }
.qr-corner.bottom-left  { bottom: 0; left: 0; border-right: none; border-top: none; }
.qr-corner.bottom-right { bottom: 0; right: 0; border-left:  none; border-top: none; }

.qr-status {
  position: absolute;
  bottom: 32px;
  background: rgba(0,0,0,0.7);
  color: white;
  padding: 8px 16px;
  border-radius: 16px;
  font-size: 14px;
}

/* ===================================================================
   Toast
   =================================================================== */
.toast {
  position: fixed;
  bottom: 80px; left: 50%;
  transform: translateX(-50%);
  background: var(--color-navy);
  color: white;
  padding: 10px 18px;
  border-radius: 22px;
  font-size: 14px;
  z-index: 900;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  animation: toastIn 0.2s ease;
}
.toast.error { background: var(--color-red); }
.toast.success { background: var(--color-green); }
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ===================================================================
   File Preview Modal
   =================================================================== */
.file-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 600;
  background: #f0f0f0;
  display: flex;
  flex-direction: column;
}

/* Barra superiore con "Chiudi" + titolo + download */
.fp-bar {
  height: 56px;
  background: var(--color-navy);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 8px 0 4px;
  gap: 8px;
  flex-shrink: 0;
}

/* Pulsante "Chiudi" — prominente a sinistra, facile da toccare su mobile */
.fp-close {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 40px;
  padding: 0 12px 0 8px;
  border-radius: 8px;
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.fp-close:active { background: rgba(255,255,255,0.25); }

/* Titolo documento — al centro, troncato se lungo */
.fp-title {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  min-width: 0;
}

/* Bottone download — a destra */
.fp-download {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: rgba(255,255,255,0.15);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.fp-download:active { background: rgba(255,255,255,0.25); }

/* iframe che occupa tutto lo spazio rimanente */
.fp-frame {
  flex: 1;
  min-height: 0;
  border: none;
  width: 100%;
  background: white;
}

/* Immagine: fit-to-window con sfondo scuro */
.fp-image {
  flex: 1;
  min-height: 0;
  width: 100%;
  object-fit: contain;
  background: #111;
  display: block;
}

/* Pannello fallback PDF su mobile */
.fp-mobile-pdf {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px 24px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 15px;
  line-height: 1.5;
  background: var(--color-bg);
}
.fp-mobile-pdf svg { color: var(--color-text-muted); opacity: 0.5; }
.fp-mobile-pdf p { margin: 0; }
.fp-open-btn {
  display: inline-block;
  padding: 14px 32px;
  background: var(--color-teal);
  color: white;
  border-radius: 10px;
  font-weight: 600;
  font-size: 16px;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.fp-open-btn:active { opacity: 0.85; }

/* ===================================================================
   Adattamenti tablet/desktop
   =================================================================== */
@media (min-width: 720px) {
  .asset-list, .chat-area { max-width: 720px; margin-left: auto; margin-right: auto; }
}

/* ===================================================================
   RFC-013 — Header right group (badge profilo + avatar)
   =================================================================== */
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Badge profilo attivo */
.profile-badge {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255,255,255,0.15);
  border: 1.5px solid rgba(255,255,255,0.35);
  color: white;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
  letter-spacing: 0;
  font-family: inherit;
}
.profile-badge:active { background: rgba(255,255,255,0.28); }

/* Items nel pannello di selezione profilo */
.profile-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 20px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s;
}
.profile-item:last-child { border-bottom: none; }
.profile-item:active     { background: var(--color-teal-light); }
.profile-item.is-active  { background: var(--color-teal-light); }

.profile-item-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--color-navy);
  color: white;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.profile-item.is-active .profile-item-icon { background: var(--color-teal); }

.profile-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.profile-item-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
}
.profile-item-desc {
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 1.4;
}
.profile-item-check {
  font-size: 18px;
  color: var(--color-teal);
  font-weight: 700;
}

/* ===================================================================
   RFC-009 — Evidenziazione documenti usati nella risposta
   =================================================================== */
.doc-card--used {
  border-color: var(--color-green);
  background: var(--color-green-bg);
  position: relative;
  overflow: hidden;
}

.doc-used-badge {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 10px;
  font-weight: 700;
  color: var(--color-green);
  letter-spacing: 0.04em;
  pointer-events: none;
}

/* ===================================================================
   RFC-004 — Feedback utente (thumbs up/down)
   =================================================================== */
.chat-feedback {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 2px;
  flex-wrap: wrap;
}

.fb-btn {
  padding: 4px 12px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.fb-btn:hover  { border-color: var(--color-teal); color: var(--color-teal); }
.fb-btn:active { background: var(--color-teal-light); }
.fb-btn:disabled { opacity: 0.4; pointer-events: none; }

.fb-thanks {
  font-size: 12px;
  color: var(--color-text-muted);
  padding: 4px 4px 2px;
}

/* Form nota opzionale (thumbs down) */
.fb-note-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0 2px;
  width: 100%;
}
.fb-note-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--color-text);
  background: var(--color-surface);
  resize: none;
  line-height: 1.4;
}
.fb-note-input:focus { outline: none; border-color: var(--color-teal); }
.fb-note-actions {
  display: flex;
  gap: 8px;
}
.fb-note-send {
  padding: 6px 14px;
  background: var(--color-teal);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.fb-note-send:active { opacity: 0.85; }
.fb-note-skip {
  padding: 6px 14px;
  background: none;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.fb-note-skip:active { background: var(--color-teal-light); }

/* ===================================================================
   RFC-004 — Modal "Scrivi al team"
   =================================================================== */
.msg-form-hint {
  font-size: 13px;
  color: var(--color-text-muted);
  margin: 0 0 14px;
  line-height: 1.5;
}
.msg-form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-surface);
  resize: none;
  line-height: 1.5;
  box-sizing: border-box;
  display: block;
}
.msg-form-textarea:focus { outline: none; border-color: var(--color-teal); }
.msg-form-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}
.msg-form-send {
  padding: 10px 24px;
  background: var(--color-teal);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.msg-form-send:active   { opacity: 0.85; }
.msg-form-send:disabled { opacity: 0.4; pointer-events: none; }
.msg-form-thanks {
  text-align: center;
  color: var(--color-green);
  font-size: 14px;
  font-weight: 600;
  padding: 20px 0 4px;
}

/* Toast info (variante teal scuro) */
.toast.info { background: var(--color-teal-dark); }
