/* Import czcionki Outfit */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

/* Zmienne HSL dla spójnego Dark Mode */
:root {
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  --bg-base: 240 10% 4%;            /* Głęboka czerń/szary #0a0a0c */
  --bg-card: 240 8% 7%;             /* Tło kart #111114 */
  --border-card: 240 5% 15%;        /* Obramowania kart */
  
  --text-main: 240 5% 93%;          /* Jasnoszary tekst */
  --text-muted: 240 4% 65%;         /* Ciemniejszy, stonowany tekst */
  
  --primary: 250 84% 63%;           /* Indigo #6366f1 */
  --primary-hover: 250 84% 57%;     
  --primary-light: 250 84% 15%;
  
  --accent: 195 90% 48%;            /* Morski błękit #0ea5e9 */
  
  --success: 142 70% 45%;           /* Zielony #10b981 */
  --success-light: 142 70% 10%;
  
  --error: 0 84% 60%;               /* Czerwony #f87171 */
  --error-light: 0 84% 10%;
  
  --warning: 38 92% 50%;            /* Pomarańczowo-żółty #f59e0b */
  --warning-light: 38 92% 10%;
}

/* Globalne Reset i Style Podstawowe */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: hsl(var(--bg-base));
  color: hsl(var(--text-main));
  min-height: 100vh;
  padding: 16px 12px;
  overflow-y: auto;
}

.app-container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* Typografia */
h1 {
  font-size: 2rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.025em;
  margin-bottom: 6px;
}

h2 {
  font-size: 1.35rem;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: -0.015em;
}

h3 {
  font-size: 1.15rem;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: -0.01em;
}

p {
  font-size: 0.95rem;
  line-height: 1.5;
  color: hsl(var(--text-muted));
}

.subtitle {
  font-size: 0.9rem;
  color: hsl(var(--text-muted));
}

.text-muted {
  color: hsl(var(--text-muted)) !important;
}

.text-xs {
  font-size: 0.75rem;
}

/* Karta Szklana Premium (Glassmorphism) */
.card {
  background: rgba(22, 22, 26, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 20px;
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  margin-bottom: 20px;
  width: 100%;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Ekrany */
.screen {
  display: flex;
  flex-direction: column;
  width: 100%;
  animation: slideUpFade 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* 1. Ekran Blokady PIN */
#pin-screen {
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 40px);
}

.pin-card {
  text-align: center;
  width: 100%;
  max-width: 380px;
  padding: 40px 28px;
  border: 1px solid rgba(99, 102, 241, 0.1);
  box-sizing: border-box;
}

.logo-area {
  margin-bottom: 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.logo-icon {
  margin-bottom: 20px;
  filter: drop-shadow(0 8px 16px rgba(16, 185, 129, 0.25));
}

.input-group {
  margin-bottom: 20px;
}

#pin-input {
  width: 100%;
  background-color: rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 18px;
  color: #ffffff;
  font-size: 2.2rem;
  letter-spacing: 0.9rem;
  text-align: center;
  outline: none;
  transition: all 0.2s ease;
}

#pin-input:focus {
  border-color: hsl(var(--primary));
  background-color: rgba(0, 0, 0, 0.5);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
}

#pin-input::placeholder {
  color: rgba(255, 255, 255, 0.15);
  letter-spacing: normal;
  font-size: 1.5rem;
}

.error-msg {
  color: hsl(var(--error));
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 20px;
  text-align: center;
  animation: shake 0.25s ease-in-out 2;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

/* 2. Ekran Główny i Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

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

.header-logo-icon {
  filter: drop-shadow(0 2px 8px rgba(16, 185, 129, 0.2));
}

.app-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.015em;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: hsl(var(--text-muted));
  cursor: pointer;
  padding: 10px;
  border-radius: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.1);
}

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

/* Karta Aparatu */
.scan-card {
  padding: 36px 24px;
  border: 1px dashed rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.01);
}

.scan-card:hover {
  border-color: rgba(99, 102, 241, 0.3);
  background: rgba(99, 102, 241, 0.01);
}

/* Przyciski */
.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 16px 24px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
  text-decoration: none;
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-primary {
  background-color: hsl(var(--primary));
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover:not(:disabled) {
  background-color: hsl(var(--primary-hover));
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-primary:disabled {
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.2);
  box-shadow: none;
  cursor: not-allowed;
}

.btn-secondary {
  background-color: rgba(255, 255, 255, 0.04);
  color: hsl(var(--text-main));
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-secondary:active {
  transform: scale(0.98);
}

.btn-accent {
  background-color: hsl(var(--accent));
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(14, 165, 233, 0.25);
}

.btn-accent:hover:not(:disabled) {
  background-color: #0284c7;
  box-shadow: 0 6px 20px rgba(14, 165, 233, 0.35);
}

.btn-accent:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-accent:disabled {
  background-color: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.2);
  box-shadow: none;
  cursor: not-allowed;
}

.btn-large {
  padding: 24px;
  font-size: 1.15rem;
  border-radius: 16px;
}

.btn-text {
  background: none;
  border: none;
  color: hsl(var(--primary));
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.btn-text:hover {
  background-color: rgba(99, 102, 241, 0.08);
}

/* Podgląd zdjęcia */
.preview-container {
  width: 100%;
  margin-top: 28px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 24px;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.preview-header .btn-text {
  color: hsl(var(--error));
}

.preview-header .btn-text:hover {
  background-color: rgba(248, 113, 113, 0.08);
}

.image-wrapper {
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background-color: #050507;
  aspect-ratio: 4/3;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 14px;
}

#document-preview {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.file-info {
  font-size: 0.8rem;
  margin-bottom: 20px;
  text-align: center;
}

/* Baner Ostrzeżeń (Alert) */
.alert-banner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 0.88rem;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 24px;
  animation: fadeIn 0.25s ease-out;
}

.warning-banner {
  background-color: hsla(var(--warning), 0.12);
  border: 1px solid hsla(var(--warning), 0.3);
  color: #fcd34d;
}

.warning-banner svg {
  flex-shrink: 0;
  color: hsl(var(--warning));
  margin-top: 2px;
}

/* Siatka Wyekstrahowanych Pól */
.extracted-fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
}

@media (max-width: 420px) {
  .extracted-fields-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

.field-item {
  background-color: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: all 0.2s ease;
}

.field-item label {
  font-size: 0.78rem;
  font-weight: 600;
  color: hsl(var(--text-muted));
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.value-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.field-value {
  font-size: 1rem;
  font-weight: 500;
  color: #ffffff;
  word-break: break-word;
}

.warning-icon {
  font-size: 1.05rem;
  cursor: help;
  animation: pulseWarning 2s infinite ease-in-out;
}

@keyframes pulseWarning {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.95); }
}

/* Wyróżnienie niskiej pewności pola */
.field-item.low-confidence {
  background-color: hsla(var(--warning), 0.09) !important;
  border-color: hsla(var(--warning), 0.35) !important;
  box-shadow: inset 0 0 4px rgba(245, 158, 11, 0.1);
}

.field-item.low-confidence label {
  color: #f59e0b;
}

/* Przycisk CRM w wynikach */
.crm-action-group {
  margin-bottom: 24px;
}

/* Toggler dla Surowego JSON */
.json-toggle-wrapper {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 16px;
  text-align: center;
}

.json-toggle-wrapper .btn-text {
  color: hsl(var(--text-muted));
}

.json-toggle-wrapper .btn-text:hover {
  color: #ffffff;
}

#json-raw-wrapper {
  margin-top: 16px;
  text-align: left;
}

/* Karta Błędu i Spinner */
.status-card {
  background-color: hsla(var(--primary), 0.1);
  border-color: hsla(var(--primary), 0.25);
  animation: pulseCard 2s infinite ease-in-out;
}

@keyframes pulseCard {
  0%, 100% { transform: scale(1); opacity: 0.95; }
  50% { transform: scale(0.995); opacity: 0.8; }
}

.status-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-weight: 600;
  font-size: 1.05rem;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3.5px solid rgba(99, 102, 241, 0.15);
  border-top-color: hsl(var(--primary));
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

.error-card {
  background-color: hsla(var(--error), 0.08);
  border-color: hsla(var(--error), 0.25);
}

.error-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.error-header h3 {
  color: #fca5a5;
}

.error-body {
  font-size: 0.92rem;
  line-height: 1.5;
  color: #fca5a5;
  word-break: break-word;
}

/* 3. Karta Historii (FIFO) */
.history-card {
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.badge {
  background-color: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  color: hsl(var(--text-muted));
}

.history-empty {
  text-align: center;
  padding: 32px 16px;
  font-size: 0.9rem;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 480px;
  overflow-y: auto;
  padding-right: 2px;
}

/* Styl pojedynczego wiersza w historii */
.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background-color: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.history-item:hover {
  background-color: rgba(255, 255, 255, 0.06);
  border-color: rgba(99, 102, 241, 0.3);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.history-item:active {
  transform: translateY(0);
}

.hist-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Kropki statusu */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.success {
  background-color: hsl(var(--success));
  box-shadow: 0 0 8px hsla(var(--success), 0.6);
}

.status-dot.error {
  background-color: hsl(var(--error));
  box-shadow: 0 0 8px hsla(var(--error), 0.6);
}

.hist-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hist-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #ffffff;
}

.hist-time {
  font-size: 0.78rem;
  color: hsl(var(--text-muted));
}

.hist-right {
  display: flex;
  align-items: center;
}

/* Karta odpowiedzi nagłówki */
.response-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.response-card {
  border: 1px solid rgba(16, 185, 129, 0.15);
  background: rgba(16, 185, 129, 0.02);
}

.response-body {
  background-color: rgba(0, 0, 0, 0.25);
  border-radius: 14px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

pre {
  margin: 0;
  overflow-x: auto;
}

code {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.85rem;
  color: #34d399;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Modale i Nakładki */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  z-index: 1000;
  animation: fadeIn 0.2s ease-out;
}

.modal {
  max-width: 420px;
  margin-bottom: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.close-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: hsl(var(--text-muted));
  font-size: 1.5rem;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.2s ease;
}

.close-btn:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.form-group {
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 0.88rem;
  font-weight: 600;
  color: #ffffff;
}

.form-group input[type="url"] {
  background-color: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 14px;
  color: #ffffff;
  font-size: 0.95rem;
  outline: none;
  transition: all 0.2s ease;
}

.form-group input[type="url"]:focus {
  border-color: hsl(var(--primary));
  background-color: rgba(0, 0, 0, 0.5);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

.form-help {
  font-size: 0.78rem;
  color: hsl(var(--text-muted));
  line-height: 1.4;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 28px;
}

/* Optymalizacja dla urządzeń mobilnych (ekrany <= 480px) */
@media (max-width: 480px) {
  body {
    padding: 16px 12px;
  }
  
  .card {
    padding: 20px 16px;
    border-radius: 16px;
    margin-bottom: 16px;
  }
  
  /* Ekran PIN jako wyśrodkowana, szeroka karta na mobile */
  #pin-screen {
    min-height: calc(100vh - 32px);
    justify-content: center;
    align-items: center;
    padding: 0 4px;
  }
  
  .pin-card {
    align-self: stretch;
    max-width: 100%;
    width: auto;
    padding: 36px 20px;
  }
  
  .logo-area {
    margin-bottom: 40px;
  }
  
  .logo-icon {
    width: 90px;
    height: 90px;
    margin-bottom: 20px;
  }
  
  h1 {
    font-size: 2.2rem;
  }
  
  .subtitle {
    font-size: 0.95rem;
  }
  
  #pin-input {
    font-size: 2.6rem;
    padding: 16px;
    letter-spacing: 0.8rem;
    border-radius: 16px;
    background-color: rgba(0, 0, 0, 0.4);
    border-width: 1px;
  }
  
  .btn-large {
    padding: 20px;
    font-size: 1.1rem;
  }
  
  /* Formularz szczegółów i wyników */
  .field-item {
    padding: 12px 14px;
  }
  
  .field-value {
    font-size: 0.95rem;
  }
  
  /* Modal ustawień */
  .modal {
    padding: 20px 16px;
    border-radius: 16px;
    width: calc(100% - 8px);
    margin: 4px;
  }
}
