/* =====================================================================
   QRAppTEST — Stili applicazione
   ===================================================================== */
:root {
  --color-navy:        #122835;
  --color-teal:        #007B98;
  --color-teal-light:  #E8F4F7;
  --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;
  --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: inline-block;
  margin-top: 16px;
  padding: 14px 32px;
  background: var(--color-teal);
  color: white;
  text-decoration: none;
  border-radius: 8px;
  font-weight: 600;
}
.login-footer {
  margin-top: 24px;
  font-size: 13px;
  color: var(--color-text-muted);
}

/* ===================================================================
   Header app
   =================================================================== */
.app-header {
  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: 12px; }
.app-title { font-weight: 600; font-size: 17px; letter-spacing: 0.3px; }

.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-logout {
  display: block; width: 100%; margin-top: 12px;
  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-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 {
  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: center;
  gap: 12px;
  flex-shrink: 0;
}
.asset-header-status-dot {
  width: 12px; height: 12px; border-radius: 50%;
  flex-shrink: 0;
}
.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-type {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px;
  opacity: 0.8;
}
.asset-header-identity { font-size: 15px; margin-top: 2px;
  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; margin-top: 2px; }

/* ===================================================================
   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;
}

/* ===================================================================
   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; }

/* ===================================================================
   Bottom panel
   =================================================================== */
.bottom-panel {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
  max-height: 80px;
  transition: max-height 0.3s ease;
  overflow: hidden;
}
.bottom-panel.expanded { max-height: 65vh; }

.bottom-panel-handle {
  height: 18px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.handle-bar {
  width: 40px; height: 4px;
  background: var(--color-border);
  border-radius: 2px;
}

.bottom-panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.tab-btn {
  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;
}
.tab-btn.active {
  color: var(--color-teal);
  border-bottom-color: var(--color-teal);
}
.bottom-panel-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.tab-pane { display: none; padding: 12px 0; }
.tab-pane.active { display: block; }

/* Doc list */
.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
}
.doc-item:last-child { border-bottom: none; }
.doc-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--color-teal-light);
  color: var(--color-teal);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.doc-icon svg { width: 18px; height: 18px; }
.doc-info { flex: 1; min-width: 0; }
.doc-title {
  font-weight: 500; color: var(--color-navy);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.doc-meta { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }
.doc-action { background: transparent; border: none; color: var(--color-teal); }

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

/* Details pane */
.details-section-title {
  margin: 16px 16px 8px; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.6px; color: var(--color-text-muted);
}
.details-list {
  margin: 0; padding: 0 16px;
  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;
  border: none;
  width: 100%;
  height: 100%;
  background: white;
}

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