/* Quadra.ai PWA — Mobile-first, bianco/celeste */

:root {
  --primary: #4A90D9;
  --primary-dark: #3A7BC8;
  --bg: #F5F8FC;
  --surface: #FFFFFF;
  --text: #1A1A1A;
  --text-muted: #6B7280;
  --success: #22C55E;
  --error: #EF4444;
  --warning: #F59E0B;
  --tab-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
  height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ===== VISTE ===== */

.view {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: calc(var(--tab-height) + var(--safe-bottom));
  display: none;
  overflow-y: auto;
}

.view.active { display: flex; flex-direction: column; }

.view-content {
  padding: 24px 16px;
  flex: 1;
}

.view-content h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
}

.hint {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

/* ===== SCANNER ===== */

#view-scan {
  background: #000;
  justify-content: center;
  align-items: center;
}

#camera {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#scan-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
}

#scan-guide {
  position: absolute;
  top: 5%;
  left: 5%;
  right: 5%;
  bottom: 13%;
  border: 3px solid rgba(74, 144, 217, 0.85);
  border-radius: 12px;
  box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.3);
}

#scan-guide::before,
#scan-guide::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: rgba(74, 144, 217, 1);
  border-style: solid;
}

#scan-guide::before {
  top: -3px; left: -3px;
  border-width: 4px 0 0 4px;
  border-radius: 4px 0 0 0;
}

#scan-guide::after {
  bottom: -3px; right: -3px;
  border-width: 0 4px 4px 0;
  border-radius: 0 0 4px 0;
}

#btn-capture {
  position: absolute;
  bottom: calc(var(--tab-height) + var(--safe-bottom) + 4px);
  left: 50%;
  transform: translateX(-50%);
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--primary);
  cursor: pointer;
  z-index: 10;
  transition: transform 0.1s;
}

#btn-capture:active {
  transform: translateX(-50%) scale(0.9);
}

#scan-fallback {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

#scan-fallback p {
  color: var(--text-muted);
  font-size: 18px;
}

#btn-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 16px 32px;
  background: var(--primary);
  color: #fff;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
}

/* ===== RISULTATO SCANSIONE ===== */

#scan-result, #scan-loading {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  gap: 16px;
  text-align: center;
}

#result-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
}

#result-icon.success { background: #DCFCE7; }
#result-icon.error { background: #FEE2E2; }

#result-title {
  font-size: 22px;
  font-weight: 600;
}

#result-detail {
  color: var(--text-muted);
  font-size: 16px;
  max-width: 300px;
}

/* ===== SPINNER ===== */

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #E5E7EB;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#scan-loading p {
  color: var(--text-muted);
  font-size: 18px;
  margin-top: 8px;
}

/* ===== UPLOAD ZONE ===== */

.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 24px;
  border: 2px dashed #D1D5DB;
  border-radius: 16px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  text-align: center;
}

.upload-zone:active {
  border-color: var(--primary);
  background: #EBF5FF;
}

.upload-zone span {
  font-size: 16px;
  color: var(--text);
  font-weight: 500;
}

.upload-formats {
  font-size: 13px !important;
  color: var(--text-muted) !important;
  font-weight: 400 !important;
}

/* File choices */
.file-choices {
  display: flex;
  gap: 16px;
}

.file-choice {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px 16px;
  border: 2px solid #E5E7EB;
  border-radius: 16px;
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
}

.file-choice:active {
  border-color: var(--primary);
  background: #EBF5FF;
}

.file-choice strong {
  font-size: 16px;
  color: var(--text);
}

.file-choice span {
  font-size: 13px;
  color: var(--text-muted);
}

.upload-result {
  margin-top: 24px;
  padding: 24px;
  background: var(--surface);
  border-radius: 12px;
  text-align: center;
}

/* ===== BUTTONS ===== */

.btn-primary {
  padding: 14px 28px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
}

.btn-primary:active { background: var(--primary-dark); }

.btn-secondary {
  padding: 12px 24px;
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: 12px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  min-height: 48px;
}

/* ===== STORICO ===== */

#history-list {
  list-style: none;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid #E5E7EB;
}

.history-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.history-dot.success { background: var(--success); }
.history-dot.error { background: var(--error); }
.history-dot.processing { background: var(--warning); }

.history-info {
  flex: 1;
  min-width: 0;
}

.history-info strong {
  display: block;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-info small {
  color: var(--text-muted);
  font-size: 13px;
}

.history-type {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.history-type.tag-ddt {
  background: #DBEAFE;
  color: #1E40AF;
}

.history-type.tag-listino {
  background: #FEF3C7;
  color: #92400E;
}

.history-type.tag-fattura {
  background: #D1FAE5;
  color: #065F46;
}

/* ===== DASHBOARD ===== */

#view-dashboard {
  background: var(--bg);
}

#dash-frame {
  width: 100%;
  height: 100%;
  border: none;
}

#dash-placeholder {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-size: 16px;
}

/* ===== TAB BAR ===== */

#tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tab-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid #E5E7EB;
  display: flex;
  z-index: 100;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11px;
  padding: 8px 0;
  min-height: 48px;
  transition: color 0.15s;
}

.tab.active {
  color: var(--primary);
}

.tab svg {
  width: 22px;
  height: 22px;
}

.tab span {
  font-weight: 500;
}
