:root {
  --primary: #174c68;
  --primary-hover: #10364b;
  --secondary: #e9f0f4;
  --text-main: #183040;
  --text-muted: #5e7786;
  --success: #2e7d32;
  --warning: #ed6c02;
  --danger: #d32f2f;
  --bg-app: #f4f7f9;
  --card-bg: #ffffff;
  --border: #d0dde4;
  --radius: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  padding-bottom: 70px;
}

/* Górny pasek nawigacji */
.navbar {
  background: var(--primary);
  color: #fff;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

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

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

.brand {
  font-weight: 700;
  font-size: 1.1rem;
}

.status-badge {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 20px;
  background: #2e7d32;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Selektor Modułu na Pasku Górnym */
.module-selector-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 20px;
  padding: 2px 8px 2px 10px;
}

.module-select-label {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.85);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.module-select {
  background: transparent;
  color: #ffffff;
  border: none;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  outline: none;
  padding: 2px 4px;
}

.module-select option {
  background: #174c68;
  color: #ffffff;
  font-size: 0.88rem;
  padding: 6px;
}

/* Przełącznik schematu wyświetlania (Monitor PC vs Smartfon) */
.screen-mode-toggle {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 20px;
  padding: 2px;
  gap: 2px;
}

.screen-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.78);
  padding: 3px 8px;
  font-size: 0.74rem;
  font-weight: 700;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
}

.screen-btn:hover {
  color: #ffffff;
}

.screen-btn.active {
  background: #ffffff;
  color: #174c68;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

/* Przełącznik trybu Teren / Biuro */
.mode-switch {
  display: flex;
  background: #e2ebf0;
  margin: 12px auto;
  border-radius: 10px;
  padding: 4px;
  transition: max-width 0.25s ease;
}

.mode-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  font-weight: 600;
  font-size: 0.95rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
}

.mode-btn.active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 2px 5px rgba(0,0,0,0.08);
}

/* Kontenery i Karty - Obsługa trybu Szerokiego (PC) i Wąskiego (Smartfon) */
.container {
  margin: 0 auto;
  padding: 0 16px;
  transition: max-width 0.25s ease;
}

/* 1. Tryb Szeroki: Komputer / Monitor PC / Laptop */
body.mode-desktop .container {
  max-width: 1400px;
  width: 96%;
}

body.mode-desktop .mode-switch {
  max-width: 1400px;
  width: 96%;
}

body.mode-desktop #viewField {
  max-width: 900px;
  margin: 0 auto;
}

/* 2. Tryb Wąski: Smartfon / Android (Mobile-First) */
body.mode-mobile .container {
  max-width: 580px;
  width: 100%;
}

body.mode-mobile .mode-switch {
  max-width: 580px;
  width: 100%;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.03);
}

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Formularze i Dotyk */
.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  width: 100%;
  box-sizing: border-box !important;
  line-height: 1.5 !important;
  min-height: 42px;
  padding: 10px 14px 12px 14px !important;
  font-size: 0.95rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

select {
  padding-right: 32px !important;
  text-overflow: ellipsis;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #fff;
  border-radius: 12px;
  padding: 3px 9px 4px 9px;
  line-height: 1.4;
  font-weight: 600;
  white-space: nowrap;
  vertical-align: middle;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}

/* Nowoczesne, dotykowe karty pól wyboru (Checkboxy) */
.checkbox-card {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 12px !important;
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-main);
  transition: all 0.2s;
}

.checkbox-card:hover, .checkbox-card:active {
  background: #f0f4f8;
  border-color: #9cb2bd;
}

.checkbox-card input[type="checkbox"] {
  width: 22px !important;
  height: 22px !important;
  min-width: 22px;
  min-height: 22px;
  margin: 0 !important;
  padding: 0 !important;
  cursor: pointer;
  accent-color: var(--primary);
  flex-shrink: 0;
}

/* Przyciski */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-secondary {
  background: #e6eef2;
  color: var(--primary);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-small {
  width: auto;
  padding: 8px 14px;
  font-size: 0.88rem;
}

/* Miniatury zdjęć */
.photos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Alerty i Komunikaty */
.alert {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 0.92rem;
}

.alert-danger {
  background: #fde8e8;
  color: #981b1b;
  border: 1px solid #f8b4b4;
}

.alert-success {
  background: #e7f6e7;
  color: #1e5f22;
  border: 1px solid #b7e4b9;
}

/* --- Dedykowane okno podpisu (Full-height canvas + boczny panel) --- */
.sig-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 41, 61, 0.92);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.sig-modal-box {
  background: #ffffff;
  border-radius: 14px;
  width: 100%;
  max-width: 860px;
  height: 420px;
  max-height: 94vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 35px rgba(0,0,0,0.45);
}

/* W trybie mobilnym / na smartfonie okno zajmuje CAŁY ekran telefonu */
.sig-modal-backdrop.sig-mobile-mode {
  padding: 0;
}
.sig-modal-backdrop.sig-mobile-mode .sig-modal-box {
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  border-radius: 0;
}

@media (max-width: 768px) {
  .sig-modal-backdrop {
    padding: 0;
  }
  .sig-modal-box {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
  }
}

.sig-orient-hint {
  background: #fff3cd;
  color: #856404;
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  padding: 6px 10px;
  border-bottom: 1px solid #ffeeba;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.sig-modal-body {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100%;
  flex: 1;
  overflow: hidden;
}

.sig-modal-canvas-wrapper {
  flex: 1;
  height: 100%;
  position: relative;
  background: #ffffff;
  border-right: 2px dashed #97b5c6;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.sig-modal-canvas-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
  touch-action: none;
}

.sig-baseline-guide {
  position: absolute;
  bottom: 24px;
  left: 16px;
  right: 16px;
  color: #9cb4c2;
  font-size: 0.88rem;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
}

.sig-modal-sidebar {
  width: 135px;
  min-width: 120px;
  background: #f1f5f8;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 10px;
}

.sig-side-btn {
  width: 100%;
  padding: 14px 6px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 8px;
  text-align: center;
}

.sig-btn-accept {
  padding: 18px 6px;
  font-size: 1.05rem;
  font-weight: 700;
}

/* Podgląd podpisu w formularzu */
.sig-preview-card {
  border: 1.5px solid #c7dbe6;
  border-radius: 8px;
  padding: 10px;
  background: #fafcfd;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.sig-preview-img {
  max-height: 55px;
  max-width: 160px;
  border: 1px solid #d0dde4;
  border-radius: 4px;
  background: #fff;
}

/* ==========================================================================
   Responsywność Mobilna (Smartfon / Wąski Ekran)
   ========================================================================== */
@media (max-width: 820px) {
  /* Ukrycie przycisków deweloperskich i screenshotów na telefonie */
  .desktop-dev-tool {
    display: none !important;
  }

  /* Smukły, jednolinijkowy nagłówek mobilny (wysokość ok. 46px) */
  .navbar {
    padding: 6px 8px;
    min-height: 44px;
    height: 46px;
    gap: 4px;
    flex-wrap: nowrap;
    overflow: hidden;
    align-items: center;
  }

  .nav-left {
    gap: 6px !important;
    flex-wrap: nowrap !important;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
  }

  .nav-right {
    gap: 4px !important;
    flex-wrap: nowrap !important;
    flex-shrink: 0;
  }

  .brand-text {
    display: none; /* Ukrywa długi napis "Antigravity", zostaje sama zwięzła błyskawica ⚡ */
  }

  .brand {
    font-size: 1.15rem;
    font-weight: 800;
    white-space: nowrap;
    flex-shrink: 0;
    line-height: 1;
  }

  .module-selector-wrap {
    padding: 2px 6px;
    gap: 2px;
    flex: 1 1 auto;
    max-width: 170px;
    min-width: 0;
  }

  .module-select-label {
    display: none; /* Schowanie etykiety "MODUŁ:" na małym ekranie */
  }

  .module-select {
    font-size: 0.80rem;
    width: 100%;
    max-width: 160px;
    text-overflow: ellipsis;
  }

  #userBadge {
    font-size: 0.70rem;
    padding: 3px 6px;
    white-space: nowrap;
    max-width: 95px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #btnLogout {
    font-size: 0.70rem;
    padding: 3px 6px !important;
  }

  #connStatus {
    font-size: 0.70rem;
    padding: 3px 6px;
    white-space: nowrap;
  }

  /* Pasek pod-zakładek z płynnym przewijaniem w poziomie zamiast ściskania */
  .mode-switch {
    margin: 6px auto 10px auto;
    padding: 3px;
    gap: 4px;
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    border-radius: 8px;
  }

  .mode-switch::-webkit-scrollbar {
    display: none;
  }

  .mode-btn {
    flex: 0 0 auto;
    padding: 6px 14px;
    font-size: 0.82rem;
    white-space: nowrap;
    border-radius: 6px;
  }

  .container {
    padding: 6px 8px;
  }
}

