:root {  --table-font: 14px;
  --row-h: 40px;
}
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: #f4f6f9;
  margin: 0;
  padding: 0;
}
.form-wrapper {
  max-width: 900px;
  margin: 40px auto;
  padding: 30px;
  background-color: #ffffff;
  border-radius: 12px;  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}
form h2 {
  text-align: center;
  margin-bottom: 20px;
  color: #333;
}
h2 {
    text-align: center;
}
form {
  display: block;
}
.form-step {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px 30px;
}
form label {
  display: block;
  font-weight: 600;
  color: #444;
}
form input[type="text"],
form input[type="number"],
form input[type="date"],
form input[type="file"],
form input[type="url"],
form textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 14px;
  margin-top: 5px;
  box-sizing: border-box;
}
form textarea {
  resize: vertical;
  min-height: 80px;
}

form input:focus,
form textarea:focus {
  border-color: #007bff;
  outline: none;
}
form button {
  padding: 10px 20px;
  background-color: #007bff;
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.3s;
  min-width: 100px;
}
form button:hover {
  background-color: #0056b3;
}
.form-buttons {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: 15px;
  margin-top: 10px;
}
.form-btn {
  padding: 10px 20px;
  background-color: #007bff;
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.3s;
  min-width: 100px;
}
.form-btn:hover {
  background-color: #0056b3;
}
.search-form {
  background: #ffffff;
  padding: 20px;
  border-radius: 12px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 auto 40px;
}
.search-form input[type="text"] {
  padding: 12px;
}
.search-form input[type="submit"] {
  padding: 12px;
  background-color: #007bff;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.3s ease;
}
.search-form input[type="submit"]:hover {
  background-color: #0056b3;}
.clear-button {
  display: inline-block;
  padding: 10px 16px;
  background-color: #e74c3c;
  color: #fff;
  border-radius: 6px;
  text-decoration: none;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  margin-top: 6px;
}
.clear-button:hover {
  background-color: #c0392b;}
a.logout {
  display: inline-block;
  margin-bottom: 30px;
  background-color: #e74c3c;
  color: #fff;
  padding: 10px 16px;
  border-radius: 6px;
  font-weight: bold;
  text-decoration: none;
}
a.logout:hover {
  background-color: #c0392b;
}
.table-responsive {
  overflow-x: auto;
  margin-bottom: 20px;
}
.my-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.my-table th,
.my-table td {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}
.my-table tr:nth-child(even) {
  background-color: #f9f9f9;
}
.my-table tr:hover {
  background-color: #f1f1f1;}
.my-table th {
  background-color: #2980b9;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 2;
  font-size: 15px;
}
.my-table th.name { width: 25%; }
.my-table th.desc { width: 30%; }
.my-table th.default { width: 10%; }
.my-table .td-small {
  font-size: 0.85em;
  white-space: nowrap;
}
.my-table td a {
  color: #2980b9;
  text-decoration: none;
}
.my-table td a:hover {
  text-decoration: underline;
}
.btn {
  display: inline-block;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: background-color 0.3s;
  min-width: 100px;
  color: #fff;
}
.btnn {
  background-color: red;
}

.btnnn {
  background-color: green;
}
.btn-primary {
  background-color: #007bff;
}
.btn-primary:hover {
  background-color: #0056b3;
}
/* Zielony (Dodaj) */
.btn-success {
  background-color: #28a745;
}
.btn-success:hover {
  background-color: #218838;
}
.form-buttons {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: 15px;
  margin-top: 10px;
}
.full-height {
  min-height: calc(100vh - 80px);  /* odejmij ewentualne marginesy */
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-form {
  display: grid;
  gap: 15px;
}
.login-form h2 {
  grid-column: 1 / -1;
  margin-bottom: 10px;}
.login-form label {
  display: flex;
  flex-direction: column;
  font-weight: 600;
}
.login-form input {
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  margin-top: 5px;
  font-size: 14px;
}
.form-buttons {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  margin-top: 10px;
}
.btn-primary {
  background-color: #007bff;
}
.btn-primary:hover {
  background-color: #0056b3;
}
.my-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed; 
  font-size: var(--table-font, 14px);
}
.my-table tr {
  height: var(--row-h, 40px);
}
.my-table th:nth-child(1),
.my-table td:nth-child(1) {
  width: var(--col-1-w, 100px);
}
.my-table th,
.my-table td {
  padding: 8px;
  border: 1px solid #ddd;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.my-table th {
  background: #f4f4f4;
  font-weight: 600;
  text-align: left;}
/* ===============================
         Tabulator Tabela 
   =============================== */
.tabulator {
  font-size: var(--table-font);
  height: var(--row-h);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #ddd;
  margin: 0 auto;
  max-width: 95%;
}
.tabulator .tabulator-col .tabulator-arrow {
  display: none !important;
  width: 0;
  height: 0;
  overflow: hidden;
}
.tabulator .tabulator-header {
  background-color: #007bff;
  color: white;
  font-weight: bold;
  font-size: 14px;
}
.tabulator .tabulator-header .tabulator-col {
  border-right: 1px solid #ccc;
}
.tabulator .tabulator-row {
  background-color: #fff;
  transition: background-color 0.2s ease;
}
.tabulator .tabulator-row:nth-child(even) {
  background-color: #f8f9fa;}
.tabulator .tabulator-row:hover {
  background-color: #e9ecef;
}
.tabulator-cell {
  padding: 8px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tabulator-col .tabulator-col-title {
  white-space: normal; /* ← poprawnie obsługuje <br> */
  text-align: center;
  line-height: 1.3;
  font-weight: bold;
}
.tabulator-cell.wrap-text {
  white-space: normal;
  word-break: break-word;
  line-height: 1.6em;
  padding: 10px 6px;
  font-size: 14px;
}
/* ===============================
   Panel Sterowania Tabelą
   =============================== */
.table-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  margin: 20px auto 30px;
  flex-wrap: wrap;
}

.table-controls label {
  font-weight: bold;
  font-size: 14px;
  color: #333;}
.tabulator .tabulator-cell button {
  padding: 6px 12px;
  font-size: 13px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  min-width: 70px;
}
.tabulator .btn-warning {
  background-color: #ffc107;
  color: #212529;
}
.tabulator .btn-warning:hover {
  background-color: #e0a800;
}
.tabulator .btn-danger {
  background-color: #dc3545;
  color: white;}
.tabulator .btn-danger:hover {
  background-color: #c82333;
}
#ctrl-font,
#ctrl-rowh {
  display: none;
}
.search-bar {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-bottom: 20px;
  flex-wrap: wrap;}
.search-bar input {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid #ccc;
  font-size: 14px;
  width: 250px;
  box-sizing: border-box;}
.tabulator .tabulator-cell input[type="checkbox"] {
  transform: scale(1.2);
  cursor: pointer;
}
.tabulator-cell a {
  color: #007bff;
  font-weight: bold;
  text-decoration: none;
}
.tabulator-cell a:hover {
  text-decoration: underline;
}
.mini-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  margin: 2px;
  cursor: pointer;
  display: inline-block;
  border: 1px solid #ccc;
}
.mini-thumb:hover {
  outline: 2px solid #007bff;
  transform: scale(1.05);
  transition: transform 0.2s;
}
.lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  padding: 20px;
}

.lightbox-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  width: 100%;
  max-width: 100vw;
  max-height: 100vh;
}

.lightbox-img {
  max-height: 75vh;
  max-width: 95vw;
  width: auto;
  height: auto;
  border: 4px solid white;
  border-radius: 8px;
  object-fit: contain;
}

.lightbox-controls {
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.lightbox-prev,
.lightbox-next {
  background: rgba(255,255,255,0.95);
  color: #333;
  border: 2px solid #007bff;
  font-size: 1.8em;
  padding: 12px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
  min-width: 120px;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  transition: all 0.2s ease;
}

.lightbox-prev:hover,
.lightbox-next:hover {
  background: #007bff;
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.6);
}

.lightbox-prev:active,
.lightbox-next:active {
  transform: translateY(0);
}

.lightbox-prev:disabled,
.lightbox-next:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  border-color: #666;
  color: #666;
}

.lightbox-prev:disabled:hover,
.lightbox-next:disabled:hover {
  background: rgba(255,255,255,0.95);
  color: #666;
  transform: none;
}
.selected-cell {
  outline: 2px solid #007bff;}
.upload-progress {
  width: 100%;
  height: 20px;
  background-color: #ddd;
  border-radius: 5px;
  overflow: hidden;
  margin-top: 15px;
  display: none;
}
.upload-progress .bar {
  height: 100%;
  width: 0%;
  background-color: #28a745;
  transition: width 0.4s ease;
}
.font-control {
  margin: 1rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
#font-size-picker {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid #ccc;
  font-size: 14px;
}
.tabulator-cell.wrap-text {
    white-space: normal !important;
    word-break: break-word;
    line-height: 1.3em;
}

/* MODAL STYLES - CRITICAL: Default is HIDDEN */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: none; /* HIDDEN BY DEFAULT */
  align-items: center;
  justify-content: center;
  z-index: 9999;
  overflow: hidden;
}

/* Only show modal when explicitly set to flex */
.modal-backdrop[style*="display: flex"],
.modal-backdrop[style*="display:flex"] {
  display: flex !important;
}

.modal-content {
  background: #fff;
  padding: 20px 30px;
  border-radius: 10px;
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  position: relative;
  z-index: 10000;
}

.close-btn,
.close-modal {
  position: absolute;
  top: 8px;
  right: 10px;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  font-size: 24px;
  cursor: pointer;
  z-index: 10002;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-weight: bold;
  color: #333;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  pointer-events: auto !important;
  user-select: none;
  line-height: 1;
  padding: 0;
}

.close-btn:hover,
.close-modal:hover {
  background: #dc3545;
  color: white;
}

.close-btn:active,
.close-modal:active {
  transform: scale(0.95);
}

.modal-content label {
  display:block;
  margin:10px 0;
}
.modal-content input {
  width:100%; padding:6px;
  margin-top:4px;
}
.modal-content h3 {
  margin-top: 0;
  font-size: 1.2em;
}
.modal-content .preview-section {
  margin-bottom: 10px;
}
.modal-content .preview-label {
  font-weight: bold;
}

.preview-section {
  margin-bottom: 10px;
}
.preview-label {
  font-weight: bold;
}
.edit-form textarea[name="opis"] {
  font-size: 16px;
  padding: 12px;
  min-height: 200px;
  height: auto;
  resize: vertical;
}
.btn-delete-icon {
  all: unset;
  width: 20px !important;
  height: 20px !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  background-color: #e74c3c;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
  font-size: 14px;
  font-weight: bold;
  color: white;
  box-sizing: border-box !important;
}
.btn-delete-icon::before {
  content: "×";
  pointer-events: none;
}
.tabulator .tabulator-cell .btn-delete-icon {
  min-width: unset !important;
  padding: 0 !important;
  font-size: 14px !important;
  width: 20px !important;
  height: 20px !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
}
.tabulator-cell .btn-delete-icon,
.tabulator-cell .btn-edit,
.tabulator-cell .btn-preview {
  margin-right: 4px;
}
.tabulator-cell[tabulator-field="akcje"] {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  padding: 4px !important;
}

/* Row layout for forms (used in maszyny) */
.row {
  display: flex;
  gap: 20px;
  justify-content: space-between;
  flex-wrap: wrap;
}

.row label {
  flex: 1;
  min-width: 250px;
}

/* Delete image button */
.delete-img-btn {
  position: absolute;
  top: 0;
  right: 0;
  background: transparent;
  color: red;
  border: none;
  font-size: 24px;
  font-weight: bold;
  line-height: 1;
  padding: 0 5px;
  cursor: pointer;
  transition: transform 0.2s;
}

.delete-img-btn:hover {
  transform: scale(1.2);
}

/* Modal buttons */
.modal-buttons {
  margin-top: 16px;
  text-align: right;
}

.modal-buttons .btn {
  margin-left: 8px;
}

.footer-stats {
  display: flex;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
  margin: 30px auto 40px;
  padding: 20px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  max-width: 900px;
}

.stat-box {
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  border-radius: 8px;
  padding: 15px 10px;
  color: white;
}

.stat-box.blue {
  background-color: #007bff;
}

.stat-box.gray {
  background-color: #6c757d;
}

.stat-box.green {
  background-color: #28a745;
}

.stat-box.red {
  background-color: #c0392b;
}

/* ===============================
   MOBILE RESPONSIVE STYLES
   =============================== */

/* Mobile devices (phones, 0-767px) */
@media (max-width: 767px) {
  /* General body adjustments */
  body {
    padding: 0;
  }

  /* Form responsiveness */
  .form-wrapper {
    max-width: 100%;
    margin: 10px;
    padding: 15px;
    border-radius: 8px;
  }

  .form-step {
    grid-template-columns: 1fr !important;
    gap: 15px;
  }

  form h2, h2 {
    font-size: 20px;
    margin-bottom: 15px;
  }

  form input[type="text"],
  form input[type="number"],
  form input[type="date"],
  form input[type="file"],
  form input[type="url"],
  form textarea {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 10px;
  }

  /* Search forms */
  .search-form {
    max-width: 100%;
    margin: 10px;
    padding: 15px;
  }

  .search-bar {
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
  }

  .search-bar input {
    width: 100% !important;
    max-width: 100%;
  }

  #search-nazwa,
  #search-nr,
  #search-name,
  #search-number {
    width: 100% !important;
  }

  /* Button improvements */
  .form-buttons {
    flex-direction: column;
    gap: 10px;
  }

  .btn, .form-btn {
    width: 100%;
    min-width: unset;
    padding: 12px 20px;
    font-size: 16px;
  }

  .btn-delete-icon {
    width: 32px !important;
    height: 32px !important;
    font-size: 18px !important;
  }

  /* Table controls */
  .table-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin: 15px 10px;
  }

  .table-controls label {
    text-align: center;
  }

  .table-controls select,
  .table-controls button {
    width: 100%;
    margin: 0 !important;
  }

  #font-size-picker {
    width: 100%;
    padding: 10px;
    font-size: 16px;
  }

  /* Tabulator table adjustments */
  .tabulator {
    font-size: 12px;
    max-width: 100%;
    margin: 0 10px;
    overflow-x: auto !important;
  }

  /* Enable horizontal scrolling for table on mobile */
  #product-table,
  #maszyny-table {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    margin: 0 10px !important;
    max-width: calc(100% - 20px) !important;
    position: relative;
  }

  /* Force horizontal scroll on Tabulator's inner container */
  #product-table .tabulator-tableholder,
  #maszyny-table .tabulator-tableholder {
    overflow-x: auto !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* Make scrollbar more visible on mobile */
  #product-table .tabulator-tableholder::-webkit-scrollbar,
  #maszyny-table .tabulator-tableholder::-webkit-scrollbar {
    height: 12px;
    -webkit-appearance: none;
  }

  #product-table .tabulator-tableholder::-webkit-scrollbar-thumb,
  #maszyny-table .tabulator-tableholder::-webkit-scrollbar-thumb {
    background-color: rgba(0, 123, 255, 0.7);
    border-radius: 6px;
    border: 2px solid #f4f6f9;
  }

  #product-table .tabulator-tableholder::-webkit-scrollbar-track,
  #maszyny-table .tabulator-tableholder::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 6px;
  }

  #maszyny-table .tabulator {
    font-size: 11px;
  }

  .tabulator .tabulator-header {
    font-size: 11px;
  }

  .tabulator-cell {
    padding: 6px 4px;
    font-size: 12px;
  }

  .tabulator .tabulator-cell button {
    padding: 6px 10px;
    font-size: 12px;
    min-width: 60px;
  }

  /* CRITICAL FIX: Ensure ALL action buttons (Podgląd, Edytuj, Delete) are ALWAYS visible */
  .tabulator .btn-warning,
  .tabulator .btn-success,
  .tabulator .btn-info,
  .tabulator .btn-sm,
  .tabulator-cell button,
  .tabulator-cell .btn-warning,
  .tabulator-cell .btn-success,
  .tabulator-cell .btn-info,
  .tabulator-cell .btnnn,
  button.btn-warning,
  button.btn-success,
  button.btn-info,
  button.btn-sm,
  button.btnnn {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    padding: 7px 4px !important;
    font-size: 16px !important;
    min-width: 50px !important;
    max-width: 100% !important;
    width: auto !important;
    margin: 0 !important;
    border: none !important;
    border-radius: 6px !important;
    cursor: pointer !important;
    color: #fff !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    white-space: nowrap !important;
    text-align: center !important;
    font-weight: 600 !important;
    line-height: 1.2 !important;
    box-sizing: border-box !important;
    position: relative !important;
    z-index: 100 !important;
  }

  /* Specific button colors - FORCE OVERRIDE */
  .tabulator .btn-warning,
  .tabulator-cell .btn-warning,
  button.btn-warning {
    background-color: #ffc107 !important;
    color: #212529 !important;
  }

  .tabulator .btn-success,
  .tabulator-cell .btn-success,
  button.btn-success {
    background-color: #28a745 !important;
    color: #fff !important;
  }

  .tabulator .btn-info,
  .tabulator-cell .btn-info,
  button.btn-info {
    background-color: #17a2b8 !important;
    color: #fff !important;
  }

  .tabulator .btnnn,
  .tabulator-cell .btnnn,
  button.btnnn {
    background-color: #28a745 !important;
    color: #fff !important;
  }

  /* Actions column - VERTICAL STACK for mobile */
  .tabulator-cell[tabulator-field="akcje"],
  .tabulator-col[tabulator-field="akcje"] {
    padding: 8px 4px !important;
    white-space: normal !important;
    min-height: 130px !important;
    min-width: 80px !important;
    width: 80px !important;
    max-width: 80px !important;
    display: flex !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    align-items: stretch !important;
    justify-content: center !important;
    gap: 6px !important;
    overflow: visible !important;
  }

  /* Ensure Actions column header matches cell width */
  .tabulator .tabulator-header .tabulator-col[tabulator-field="akcje"] {
    min-width: 80px !important;
    width: 80px !important;
    max-width: 80px !important;
    display: table-cell !important;
    overflow: visible !important;
  }

  /* Individual button container in akcje column - FORCE DISPLAY */
  .tabulator-cell[tabulator-field="akcje"] button,
  .tabulator-cell[tabulator-field="akcje"] .btn-warning,
  .tabulator-cell[tabulator-field="akcje"] .btn-success,
  .tabulator-cell[tabulator-field="akcje"] .btn-info,
  .tabulator-cell[tabulator-field="akcje"] .btnnn {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    margin: 0 !important;
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent !important;
    position: relative !important;
    z-index: 100 !important;
  }

  /* FORCE all button types in the row to be visible */
  .tabulator-row .btn-warning,
  .tabulator-row .btn-success,
  .tabulator-row .btn-info,
  .tabulator-row .btn-sm,
  .tabulator-row .btnnn,
  .tabulator-row button {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    z-index: 100 !important;
  }

  /* Ensure delete button icon is also visible */
  .tabulator-row .btn-delete-icon,
  .tabulator-cell .btn-delete-icon {
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    z-index: 100 !important;
    width: 32px !important;
    height: 32px !important;
  }

  /* Hide or shrink less important columns on mobile */
  .my-table th,
  .my-table td {
    padding: 6px 4px;
    font-size: 12px;
  }

  /* Stat boxes */
  .footer-stats {
    flex-direction: column;
    margin: 15px 10px;
    padding: 15px;
    gap: 10px;
  }

  .stat-column {
    width: 100% !important;
    align-items: center !important;
  }

  .stat-box {
    width: 100% !important;
    max-width: 100% !important;
    padding: 12px !important;
    font-size: 14px;
    text-align: center;
    box-sizing: border-box;
  }

  /* Row layout for maszyny forms */
  .row {
    flex-direction: column;
    gap: 10px;
  }

  .row label {
    min-width: 100%;
    width: 100%;
  }

  /* Modal adjustments - ENSURE HIDDEN BY DEFAULT ON MOBILE TOO */
  .modal-backdrop,
  #editModal.modal-backdrop {
    display: none !important; /* Hidden by default even on mobile */
  }

  .modal-backdrop[style*="display: flex"],
  .modal-backdrop[style*="display:flex"],
  #editModal[style*="display: flex"],
  #editModal[style*="display:flex"] {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: fixed !important;
    inset: 0 !important;
    z-index: 10000 !important;
  }

  .modal-content,
  #editModal .modal-content {
    width: 95% !important;
    max-width: 95% !important;
    padding: 15px;
    max-height: 85vh;
    position: relative !important;
    background: white !important;
    border-radius: 10px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .modal-content div[style*="display: flex"],
  #editModal .modal-content div[style*="display: flex"] {
    flex-direction: column !important;
  }

  .modal-content label[style*="flex:1"],
  #editModal .modal-content label[style*="flex:1"] {
    width: 100% !important;
  }

  #existing-images {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
  }

  .modal-content h3 {
    font-size: 18px;
  }

  .modal-content input,
  .modal-content textarea {
    font-size: 16px;
    padding: 10px;
  }

  .close-btn,
  .close-modal {
    font-size: 32px !important;
    top: 5px;
    right: 10px;
    width: 44px !important;
    height: 44px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: rgba(255, 255, 255, 0.95) !important;
    border-radius: 6px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2) !important;
    z-index: 10002 !important;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent !important;
    cursor: pointer !important;
  }

  .close-btn:active,
  .close-modal:active {
    background: #dc3545 !important;
    color: white !important;
  }

  /* Edit form specific */
  .edit-form {
    max-width: 100%;
    margin: 10px;
    padding: 15px;
  }

  .edit-form input,
  .edit-form textarea {
    font-size: 16px;
    padding: 10px;
  }

  .edit-form textarea {
    min-height: 150px;
  }

  /* Media gallery */
  .media-gallery {
    gap: 8px;
    justify-content: center;
  }

  .media-thumb {
    width: 80px;
  }

  .mini-thumb {
    width: 30px;
    height: 30px;
  }

  /* Lightbox adjustments for mobile */
  .lightbox-backdrop {
    padding: 10px;
  }

  .lightbox-container {
    gap: 15px;
  }

  .lightbox-img {
    max-width: 95vw;
    max-height: 70vh;
    border: 3px solid white;
  }

  .lightbox-controls {
    gap: 15px;
    flex-wrap: wrap;
  }

  .lightbox-prev,
  .lightbox-next {
    font-size: 1.5em !important;
    padding: 10px 20px !important;
    min-width: 100px !important;
    min-height: 48px !important;
    flex: 1;
    max-width: 45%;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent !important;
  }

  /* Navigation buttons */
  div[style*="text-align: right"],
  div[style*="text-align: center"] {
    padding: 5px !important;
  }

  a.logout {
    display: block;
    width: 100%;
    text-align: center;
    margin-bottom: 15px;
  }

  /* Adjust top navigation */
  div[style*="text-align: center"] a.btn {
    font-size: 14px !important;
    padding: 8px 12px !important;
    display: inline-block;
    max-width: 95%;
    width: auto;
    margin: 0 auto;
    white-space: normal;
    line-height: 1.3;
  }

  /* Fix logout button overflow */
  div[style*="text-align: right"] {
    text-align: center !important;
    padding: 10px 5px !important;
  }

  div[style*="text-align: right"] .btn,
  div[style*="text-align: right"] .btnn {
    max-width: 95%;
    width: auto;
    padding: 10px 15px !important;
    font-size: 14px !important;
  }

  /* Center stat columns content */
  .stat-column {
    align-items: center !important;
  }

  .stat-box br {
    display: block;
  }

  /* Preview section */
  .preview-section {
    margin-bottom: 8px;
    font-size: 14px;
  }

  .preview-label {
    display: block;
    margin-bottom: 4px;
  }
}

/* Tablet devices (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
  .form-wrapper {
    max-width: 90%;
    margin: 20px auto;
    padding: 20px;
  }

  .form-step {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .search-form {
    max-width: 500px;
  }

  .tabulator {
    max-width: 98%;
  }

  .footer-stats {
    max-width: 95%;
  }

  .stat-box {
    min-width: 200px;
  }

  .modal-content {
    max-width: 80%;
  }

  .edit-form {
    max-width: 600px;
  }

  .table-controls {
    max-width: 95%;
  }
}

/* Landscape phone orientation */
@media (max-width: 767px) and (orientation: landscape) {
  .modal-content {
    max-height: 90vh;
    overflow-y: auto;
  }

  .lightbox-backdrop {
    padding: 5px;
  }

  .lightbox-img {
    max-height: 60vh;
    max-width: 90vw;
  }

  .lightbox-container {
    gap: 10px;
  }

  .lightbox-prev,
  .lightbox-next {
    min-width: 90px !important;
    min-height: 44px !important;
    font-size: 1.3em !important;
    padding: 8px 16px !important;
  }
}

/* Touch-friendly button sizes for mobile */
@media (hover: none) and (pointer: coarse) {
  /* Touch devices - increase button tap targets */
  .tabulator .btn-warning,
  .tabulator .btn-success,
  .tabulator .btn-info,
  .tabulator .btn-sm,
  .tabulator-cell button,
  .tabulator-cell .btn-warning,
  .tabulator-cell .btn-success,
  .tabulator-cell .btn-info,
  .tabulator-cell .btnnn,
  button.btn-warning,
  button.btn-success,
  button.btn-info,
  button.btnnn {
    min-height: 40px !important;
    min-width: 50px !important;
    width: auto !important;
    padding: 8px 6px !important;
    font-size: 16px !important;
  }

  .btn-delete-icon {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    font-size: 20px !important;
  }

  /* Ensure adequate spacing for touch */
  .tabulator-cell[tabulator-field="akcje"] {
    gap: 8px !important;
    padding: 10px 6px !important;
    min-height: 80px !important;
  }

  /* Touch-friendly lightbox arrows */
  .lightbox-prev,
  .lightbox-next {
    min-width: 110px !important;
    min-height: 52px !important;
    font-size: 1.6em !important;
    padding: 12px 20px !important;
  }
}

/* Small mobile devices (very small phones) */
@media (max-width: 375px) {
  .form-wrapper {
    margin: 5px;
    padding: 10px;
  }

  h2 {
    font-size: 18px;
  }

  .btn, .form-btn {
    font-size: 14px;
    padding: 10px 15px;
  }

  .tabulator {
    font-size: 11px;
  }

  .stat-box {
    font-size: 13px;
    padding: 10px !important;
  }

  .tabulator-cell[tabulator-field="akcje"] {
    min-width: 80px !important;
  }
}
