:root {
  --cat-yellow: var(--erp-accent);
  --cat-black: var(--erp-bg);
  --cat-dark: var(--erp-surface);
  --cat-gray: var(--erp-control);
  --surface-0: var(--erp-bg);
  --surface-1: var(--erp-surface);
  --surface-2: var(--erp-bg-raised);
  --surface-3: var(--erp-hover);
  --text-light: var(--erp-text);
  --text-dim: var(--erp-muted);
  --text-muted: var(--erp-muted);
  --success-color: var(--erp-success);
  --danger-color: var(--erp-danger-soft);
  --warning-color: var(--erp-warning);
  --border-radius: var(--erp-radius-md);
  --border-color: var(--erp-border);
  --border-accent: rgba(255, 205, 17, .22);
  --shadow-sm: var(--erp-shadow-sm);
  --shadow-md: var(--erp-shadow-md);
  --font-sans: 'IBM Plex Sans', 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', monospace;
  --transition: color 0.18s ease, background-color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

/* Context Menu Styles */
.htContextMenu {
  background-color: var(--cat-dark) !important;
  border: 1px solid rgba(255, 205, 17, .3) !important;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5) !important;
}

.htContextMenu table.htCore {
  background-color: transparent !important;
}

.htContextMenu table tbody tr td {
  background-color: var(--cat-dark) !important;
  color: var(--text-light) !important;
  border-color: var(--erp-border) !important;
}

.htContextMenu table tbody tr td.htDivider {
  background-color: rgba(255, 205, 17, .2) !important;
}

.htContextMenu table tbody tr td:hover {
  background-color: rgba(255, 205, 17, .2) !important;
  color: var(--cat-yellow) !important;
}

.htContextMenu table tbody tr td.htDisabled:hover {
  background-color: var(--cat-dark) !important;
  color: var(--text-dim) !important;
}

.htContextMenu .htItemWrapper {
  padding: 6px 12px !important;
}

.htContextMenu .htItemWrapper:hover {
  background-color: rgba(255, 205, 17, .2) !important;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--surface-0);
  color: var(--text-light);
  line-height: 1.6;
  overflow-x: hidden;
  background-image:
    linear-gradient(180deg, rgba(255, 205, 17, .04), transparent 180px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: auto, 32px 32px, 32px 32px;
  padding-top: 0px !important;
}

body .app-container {
  max-width: 1520px;
  margin: 0 auto;
  padding: 1.5rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: stretch;
}

/* Mobile: wider orders table container */
@media (max-width: 768px) {
  body .app-container {
    max-width: 100%;
  }
}

/* Connection Status */
.connection-status {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.5rem !important;
  flex-wrap: wrap;
}

.edit-btn-clean {
  background: var(--warning-color);
  color: var(--cat-black);
}

.connection-card {
  flex: 1;
  min-width: 250px;
  background: var(--surface-1);
  padding: 1rem;
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  border-top: 2px solid var(--border-accent);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.connection-card h3 {
  color: var(--cat-yellow);
  margin-bottom: 0.75rem;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.connection-card p {
  margin: 0.3rem 0;
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.4;
}

.connection-card .ip-address {
  font-weight: 500;
  color: var(--text-light);
}

/* Status Colors */
.status-online {
  color: var(--success-color);
}

.status-offline {
  color: var(--danger-color);
}

.status-queue {
  color: var(--warning-color);
}

.status-processing {
  color: var(--erp-info);
}

.status-need-check {
  color: var(--erp-info) !important;
  background-color: rgba(96, 165, 250, .12) !important;
  border: 1px solid rgba(96, 165, 250, .34) !important;
}

/* Title Container */
/* Controls container - кнопки и переключатель режима */
.controls-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 5px 0 0.5rem 0;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.9rem 1rem;
  background: var(--surface-1);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
}

.controls-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Filter Toggle Button */
.filter-toggle-btn {
  background: var(--cat-yellow);
  color: var(--cat-black);
  border: 1px solid rgba(255, 205, 17, .34);
  padding: 0.75rem 1.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: none;
  letter-spacing: 0.04em;
}

.filter-toggle-btn.compact {
  padding: 0.8rem 1.2rem;
  font-size: 0.75rem;
  white-space: nowrap;
}

.filter-toggle-btn:hover {
  background: var(--erp-accent-hover);
  border-color: var(--erp-accent-hover);
}

.filter-toggle-btn:active {
  transform: none;
  box-shadow: none;
}

.filter-toggle-btn i {
  font-size: 1rem;
}

.filter-toggle-btn.compact i {
  font-size: 0.9rem;
}

.filter-toggle-btn span {
  font-weight: 700;
}

/* Заголовок теперь на отдельной строке */
.main-title {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--cat-yellow);
  margin: 0;
  text-align: left;
  text-shadow: none;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Устаревшие классы для обратной совместимости */
.title-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 5px 0 !important;
  flex-wrap: wrap;
  gap: 1rem;
}

.title-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Mode Switch - Caterpillar черно-желтый стиль */
.mode-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-0);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  cursor: pointer;
  user-select: none;
  box-shadow: none;
}

.mode-switch input {
  display: none;
}

.mode-labels {
  display: flex;
  gap: 8px;
  position: relative;
  z-index: 2;
}

.mode-labels span {
  padding: 8px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: 6px;
  transition: all 0.3s ease;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* AUTO label - активен когда НЕ checked (желтый = активен) */
.mode-labels .auto-label {
  background: rgba(255, 205, 17, .16);
  color: var(--cat-yellow);
  box-shadow: none;
}

.mode-labels .manual-label {
  color: var(--text-dim);
  background: transparent;
}

/* MANUAL label - активен когда checked (серый = неактивен) */
.mode-switch input:checked ~ .mode-labels .auto-label {
  background: transparent;
  color: var(--text-dim);
  box-shadow: none;
}

.mode-switch input:checked ~ .mode-labels .manual-label {
  background: var(--surface-3);
  color: var(--text-light);
  box-shadow: none;
  border: 1px solid var(--border-color);
}

/* Добавляем иконки через ::before */
.auto-label::before {
  content: none;
}

.manual-label::before {
  content: none;
}

.mode-switch:hover {
  border-color: rgba(255, 205, 17, .28);
}

/* Mode indicators in status cards */
.mode-auto {
  color: var(--cat-yellow);
  font-weight: 700;
}

.mode-manual {
  color: var(--text-dim);
  font-weight: 500;
}

/* Orders Table */
#offerModal .orders-table {
  display: none;
}

.orders-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 0.5rem !important;
}

.orders-table th {
  text-align: left;
  padding: 0.85rem 0.9rem;
  font-weight: 700;
  color: var(--cat-yellow);
  font-size: 0.78rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-color);
  text-transform: uppercase;
  white-space: nowrap;
  letter-spacing: 0.08em;
}

.orders-table td {
  padding: 0.95rem 0.9rem;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border-color);
  transition: var(--transition);
  text-align: left;
  white-space: nowrap;
}

.orders-table td:last-child {
  text-align: center;
}

.orders-table tr:hover td {
  background: var(--erp-hover);
  cursor: pointer;
}

/* Loading & Error States */
.loading {
  text-align: center;
  padding: 3rem;
  font-size: 1.1rem;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.loading i {
  font-size: 2.5rem;
  color: var(--cat-yellow);
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.error {
  color: var(--danger-color);
  text-align: center;
  padding: 2rem;
  font-size: 1.1rem;
  background: #3c1414;
  border-radius: var(--border-radius);
  margin: 1.5rem 0;
  border-left: 4px solid #7a2a2a;
}

/* Buttons */
.cat-btn {
  position: relative;
  background: var(--cat-yellow);
  color: var(--cat-black);
  border: 1px solid rgba(255, 205, 17, .34);
  padding: 0.75rem 1.2rem;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  overflow: hidden;
  transition: var(--transition);
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.cat-btn:hover {
  background: var(--erp-accent-hover);
  border-color: var(--erp-accent-hover);
}

.cat-btn:disabled {
  background: var(--cat-gray);
  color: var(--text-dim);
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(6, 8, 11, 0.82);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(3px);
}

.modal-content {
  background: var(--surface-1);
  padding: 2rem;
  border-radius: var(--border-radius);
  width: 95%;
  max-width: 95%;
  max-height: 95vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  position: relative;
  animation: modalFadeIn 0.3s ease;
  border: 1px solid var(--border-color);
  padding-right: 3rem;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

.close-btn {
  position: fixed;
  top: 20px;
  right: 50px;
  font-size: 1.7rem;
  cursor: pointer;
  color: var(--text-dim);
  transition: var(--transition);
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  z-index: 2000;
}

.close-btn:hover {
  color: var(--danger-color);
  background: rgba(255, 76, 66, .14);
  transform: none;
}

.modal-title {
  font-size: 1.2rem;
  margin-bottom: 1.25rem;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 0.65rem;
  letter-spacing: 0.04em;
}

.debug-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.debug-modal-header .modal-title {
  margin-bottom: 0;
}

.status-message {
  margin-bottom: 1.5rem;
  font-weight: 500;
  font-size: 1.1rem;
}

.timer {
  margin-bottom: 1.5rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-pill {
  display: inline-block;
  padding: 0.28rem 0.55rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
}

.status-pill.status-ms-color {
  color: var(--status-color);
  background-color: color-mix(in srgb, var(--status-color) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--status-color) 42%, transparent);
}

@supports not (background-color: color-mix(in srgb, red 14%, transparent)) {
  .status-pill.status-ms-color {
    background-color: rgba(255, 255, 255, 0.08);
    border-color: var(--status-color);
  }
}

/* Tooltip */
.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted var(--cat-yellow);
  cursor: help;
}

.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: var(--cat-dark);
  color: var(--text-light);
  text-align: center;
  border-radius: 6px;
  padding: 5px;
  position: absolute;
  z-index: 1000;
  top: 125%;
  left: 50%;
  margin-left: -60px;
  opacity: 0;
  transition: opacity 0.3s;
  border: 1px solid var(--cat-yellow);
  font-size: 0.8rem;
}

.tooltip .tooltiptext::after {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: transparent transparent var(--cat-yellow) transparent;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
  opacity: 1;
}

.connection-info {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.3rem;
  font-size: 0.8rem;
}

.connection-info i {
  color: var(--cat-yellow);
  font-size: 0.9rem;
}

.btn-group {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
}

/* Debug Modal Styles */
.debug-modal-content {
  background: var(--surface-1);
  padding: 2rem;
  border-radius: var(--border-radius);
  width: 95%;
  max-width: 95%;
  max-height: 95vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  position: relative;
  animation: modalFadeIn 0.3s ease;
  border: 1px solid var(--border-color);
}

.debug-close-btn {
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid var(--border-color);
  background: var(--surface-2);
  color: var(--text-light);
  box-shadow: var(--shadow-sm);
  font-size: 1.5rem;
  line-height: 1;
  border-radius: 8px;
  cursor: pointer;
}

.debug-close-btn:hover {
  color: var(--text-light);
  border-color: var(--accent-color);
  background: var(--surface-3);
}

.debug-section {
  margin-bottom: 30px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-1);
}

.debug-section-header {
  padding: 15px;
  background-color: var(--surface-2);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.debug-section-header h3 {
  margin: 0;
  font-size: 1rem;
  color: var(--text-light);
  letter-spacing: 0.03em;
}

.debug-table-container {
  position: relative;
  overflow: auto;
  max-height: 400px;
  width: 100%;
}

.debug-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.debug-table th {
  background-color: var(--surface-2);
  color: var(--text-light);
  padding: 11px 14px;
  text-align: left;
  position: sticky;
  top: 0;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-color);
}

.debug-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
  white-space: nowrap;
}

.debug-table tr:last-child td {
  border-bottom: none;
}

.debug-table tr:hover {
  background-color: var(--erp-hover);
}

.debug-table th:first-child,
.debug-table td:first-child {
  position: sticky;
  left: 0;
  background-color: var(--cat-dark);
  z-index: 1;
  width: 50px;
  min-width: 50px;
  max-width: 50px;
  text-align: center;
  padding-left: 8px !important;
  padding-right: 8px !important;
}

.debug-table th:first-child {
  z-index: 2;
}

.debug-table tr:hover td:first-child {
  background-color: var(--erp-hover);
}

.debug-action-buttons {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.debug-btn {
  position: relative;
  background: var(--surface-2);
  color: var(--text-light);
  border: 1px solid var(--border-color);
  padding: 0.75rem 1.15rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  overflow: hidden;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.debug-btn:hover {
  background: var(--surface-3);
  border-color: rgba(255, 205, 17, .24);
}

.debug-btn-warning {
  background: rgba(255, 205, 17, .16);
  border-color: rgba(255, 205, 17, .45);
  color: var(--erp-accent);
}

.debug-btn-primary {
  background: rgba(47, 109, 255, 0.14);
  border-color: rgba(47, 109, 255, 0.4);
  color: var(--erp-accent-2, #8fb6ff);
}

.debug-btn-success {
  background: var(--erp-success-strong);
  border-color: #3d8b40;
  color: #fff;
}

.empty-value {
  color: #999;
  font-style: italic;
}

.positive-diff {
  color: var(--erp-danger-soft);
  background-color: rgba(255, 76, 66, .12);
}

.negative-diff {
  color: var(--erp-danger-soft);
  background-color: rgba(255, 76, 66, .12);
}

.refresh-btn {
  background: var(--surface-2);
  color: var(--text-light);
  border: 1px solid var(--border-color);
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: none;
}

.refresh-btn:hover {
  background: var(--surface-3);
  border-color: rgba(255, 205, 17, .24);
  transform: none;
}

.refresh-btn i {
  transition: transform 0.3s ease;
}

.refresh-btn:active i {
  transform: rotate(360deg);
}

/* Handsontable Styles */
.handsontable {
  background-color: var(--cat-dark);
  color: var(--text-light);
  margin-bottom: 1.5rem;
}

.handsontable th {
  background-color: var(--cat-gray);
  color: var(--text-light);
}

.handsontable td {
  background-color: var(--cat-dark);
  border-color: var(--erp-border);
}

.handsontable .ht_master .wtHolder {
  background-color: var(--cat-dark);
}

.handsontable .ht_clone_top th {
  background-color: var(--cat-gray);
}

.handsontable .ht_clone_left th {
  background-color: var(--cat-gray);
}

.handsontable .ht_clone_top_left_corner th {
  background-color: var(--cat-gray);
}

.handsontable .currentRow {
  background-color: rgba(255, 205, 17, .12) !important;
}

.handsontable .currentCol {
  background-color: rgba(255, 205, 17, .12) !important;
}

/* Edit Modal Styles */
.edit-modal-content {
  background: var(--surface-1);
  padding: 2rem;
  border-radius: var(--border-radius);
  width: 95%;
  max-width: 1000px;
  max-height: 95vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  position: relative;
  animation: modalFadeIn 0.3s ease;
  border: 1px solid var(--border-color);
}

.edit-title {
  font-size: 1.2rem;
  margin-bottom: 1.25rem;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.edit-info {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--surface-2);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
}

.edit-info-row {
  display: flex;
  margin-bottom: 0.5rem;
}

.edit-info-label {
  font-weight: 500;
  color: var(--cat-yellow);
  min-width: 120px;
}

.edit-info-value {
  flex: 1;
}

.edit-buttons {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
  justify-content: flex-end;
  position: relative;
  z-index: 20;
  pointer-events: auto;
}

#editTableContainer {
  position: relative;
  z-index: 10;
  margin-bottom: 1.5rem;
}

.edit-btn {
  padding: 0.75rem 1.15rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid transparent;
}

.edit-btn-primary {
  background: var(--cat-yellow);
  color: var(--cat-black);
}

.edit-btn-secondary {
  background: var(--cat-gray);
  color: var(--text-light);
  border-color: var(--erp-border);
}

.edit-btn-danger {
  background: #3c1414;
  color: var(--erp-danger-soft);
  border-color: #7a2a2a;
}

.edit-btn-success {
  background: var(--erp-success-strong);
  color: #fff;
  border-color: #3d8b40;
}

.edit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Pagination Controls */
.pagination-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 16px;
}

.pagination-controls .page-indicator {
  color: var(--text-dim);
  font-weight: 500;
  min-width: 70px;
  text-align: center;
}

.status-toggle {
  margin-left: 12px;
  display: flex;
  align-items: center;
}

.status-toggle .cat-btn {
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1rem;
}

.status-toggle .cat-btn:active {
  transform: translateY(1px);
}

.status-hidden #statusContainer {
  display: none;
}

.status-hidden #orders-container {
  margin-top: 0;
}

.connection-status,
.controls-container,
.title-container,
#orders-container {
  width: 100%;
}

/* Section Toggles */
.debug-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.debug-section-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.section-toggle {
  background: transparent;
  border: none;
  color: var(--cat-yellow);
  cursor: pointer;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.section-toggle:hover {
  color: var(--text-light);
}

.section-toggle .icon-plus {
  display: none;
}

.debug-section.collapsed .section-toggle .icon-minus {
  display: none;
}

.debug-section.collapsed .section-toggle .icon-plus {
  display: inline;
}

.debug-section.collapsed .debug-table-container,
.debug-section.collapsed .no-data {
  display: none !important;
}

.section-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.section-fullscreen-toggle {
  background: transparent;
  border: none;
  color: var(--cat-yellow);
  cursor: pointer;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.section-fullscreen-toggle:hover {
  color: var(--text-light);
}

.section-fullscreen-toggle .icon-compress {
  display: none;
}

.debug-section.fullscreen .section-fullscreen-toggle .icon-expand {
  display: none;
}

.debug-section.fullscreen .section-fullscreen-toggle .icon-compress {
  display: inline;
}

/* Final Order Table Fullscreen Styles */
.debug-section.fullscreen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  z-index: 1001;
  background: var(--cat-dark);
  margin: 0;
  border-radius: 0;
  border: none;
}

.debug-section.fullscreen .debug-table-container {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: none;
  height: 100%;
  min-height: 0;
}

.debug-section.fullscreen .debug-table {
  display: table;
  width: auto;
  min-width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: auto;
}

.table-scroll {
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow-x: scroll;
  overflow-y: auto;
  scrollbar-gutter: stable;
  box-sizing: border-box;
  padding-bottom: 10px;
  -webkit-overflow-scrolling: touch;
}

#debugRemarkTable {
  min-width: 1400px;
}

.debug-table {
  display: table;
  width: auto;
  min-width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: auto;
}

.table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface-2);
}

#orders-container {
  background: var(--surface-1);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.orders-table td:first-child,
.orders-table th:first-child,
.page-indicator,
.ip-address,
.auto-badge {
  font-family: var(--font-mono);
}

.search-box {
  background: var(--surface-0);
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

.search-box input {
  font-family: var(--font-sans);
  appearance: none !important;
  -webkit-appearance: none !important;
  background: transparent !important;
  border: 0 !important;
  border-radius: 0 !important;
  outline: 0 !important;
  box-shadow: none !important;
  height: 100%;
  min-width: 0;
  padding: 0;
}

.search-box input:focus,
.search-box input:focus-visible,
.search-box input:hover {
  background: transparent !important;
  border: 0 !important;
  outline: 0 !important;
  box-shadow: none !important;
}

.search-box input:-webkit-autofill,
.search-box input:-webkit-autofill:hover,
.search-box input:-webkit-autofill:focus {
  -webkit-text-fill-color: #fff;
  caret-color: #fff;
  box-shadow: 0 0 0 1000px var(--surface-0) inset !important;
  border: 0 !important;
  outline: 0 !important;
}

.auto-badge {
  background: rgba(255, 205, 17, .16);
  color: var(--erp-accent);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.64rem;
  font-weight: 600;
  margin-left: 8px;
  vertical-align: middle;
  letter-spacing: 0.08em;
  box-shadow: none;
  text-transform: uppercase;
  border: 1px solid rgba(255, 205, 17, .45);
}

.auto-badge:hover {
  box-shadow: none;
  transform: none;
  transition: none;
}

.debug-section.fullscreen .debug-table {
  display: table;
  width: auto;
  min-width: max-content;
}

/* Responsive Design */
@media (max-width: 768px) {
  body {
    padding-top: 0 !important;
  }
  
  .app-container {
    padding: 0.5rem;
    gap: 15px;
    max-width: 100%;
  }
  
  /* Connection Cards - Stack vertically */
  .connection-status {
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 0.5rem !important;
  }
  
  .connection-card {
    min-width: 100%;
    padding: 0.75rem;
  }
  
  .connection-card h3 {
    font-size: 0.9rem;
    gap: 0.4rem;
  }
  
  .connection-card p {
    font-size: 0.75rem;
    margin: 0.2rem 0;
  }
  
  .connection-info {
    font-size: 0.7rem;
  }
  
  /* Controls Container - Better mobile layout */
  .controls-container {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    margin: 0 0 0.5rem 0;
    padding-bottom: 0.5rem;
  }

  .controls-left {
    width: 100%;
    justify-content: space-between;
    gap: 0.5rem;
  }

  .controls-left .refresh-btn,
  .controls-left .cat-btn {
    flex: 1;
    min-width: 60px;
    padding: 0.7rem 0.5rem;
    font-size: 0.9rem;
  }

  /* Mode Switch - Full width on mobile */
  .mode-switch {
    width: 100%;
    justify-content: center;
    padding: 5px;
    gap: 8px;
  }

  .mode-labels {
    width: 100%;
    gap: 4px;
  }

  .mode-labels span {
    flex: 1;
    padding: 8px 16px;
    font-size: 0.8rem;
    justify-content: center;
  }
  
  .auto-label::before,
  .manual-label::before {
    font-size: 0.95rem;
  }

  /* Filter Toggle Button - Mobile */
  .filter-toggle-btn.compact {
    padding: 0.7rem 0.8rem;
    font-size: 0.7rem;
    min-height: 44px;
  }

  .filter-toggle-btn.compact i {
    font-size: 0.85rem;
  }
  
  .filter-toggle-btn.compact span {
    display: inline; /* Показываем текст на планшетах */
  }

  /* Main Title */
  .main-title {
    font-size: 1.6rem;
    margin: 0.2rem 0 0.5rem 0;
    letter-spacing: 0.5px;
  }
  
  /* Modal Windows - Better mobile experience */
  .modal-content, .debug-modal-content, .edit-modal-content {
    width: 98%;
    max-width: 98%;
    padding: 1rem;
    padding-right: 1rem;
    max-height: 92vh;
    border-radius: 8px;
  }

  .close-btn {
    top: 10px;
    right: 10px;
    font-size: 1.8rem;
    width: 2.2rem;
    height: 2.2rem;
  }

  .modal-title, .edit-title {
    font-size: 1.2rem;
    gap: 0.5rem;
    margin-bottom: 1rem;
  }
  
  /* Tables - Horizontal scroll enabled, wider on mobile */
  .orders-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    margin-top: 0.5rem !important;
    margin-left: -0.5rem;
    margin-right: -0.5rem;
    width: calc(100% + 1rem);
  }
  
  .orders-table thead,
  .orders-table tbody {
    display: table;
    width: 100%;
    table-layout: auto;
  }
  
  .orders-table td, .orders-table th {
    padding: 0.7rem 0.5rem;
    font-size: 0.75rem;
    min-width: 80px;
  }
  
  .orders-table td:first-child,
  .orders-table th:first-child {
    min-width: 120px; /* Order number needs more space */
    padding-left: 0.75rem;
  }
  
  .orders-table td:last-child,
  .orders-table th:last-child {
    padding-right: 0.75rem;
  }

  /* Debug Tables - Ensure horizontal scroll */
  .debug-table-container {
    max-height: 300px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .debug-table td,
  .debug-table th {
    padding: 8px 10px;
    font-size: 0.75rem;
    min-width: 80px;
  }
  
  .debug-table th:first-child,
  .debug-table td:first-child {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    padding: 8px 5px !important;
  }

  /* Buttons - Touch-friendly sizing */
  .cat-btn {
    padding: 0.75rem 1.2rem;
    font-size: 0.9rem;
    min-height: 44px; /* iOS recommended touch target */
  }

  .cat-btn.icon-only {
    min-width: 44px;
    padding: 0.7rem;
  }

  .btn-group {
    flex-direction: column;
    gap: 0.6rem;
    margin-top: 1rem;
  }

  .cat-btn, .debug-btn {
    width: 100%;
    justify-content: center;
  }
  
  .debug-btn {
    padding: 0.75rem 1.2rem;
    font-size: 0.9rem;
    min-height: 44px;
  }

  .refresh-btn {
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
    min-height: 44px;
  }
  
  /* Status Pills - Better sizing */
  .status-pill {
    padding: 0.35rem 0.7rem;
    font-size: 0.7rem;
  }

  /* Auto Badge - Smaller on mobile */
  .auto-badge {
    padding: 2px 8px;
    font-size: 0.6rem;
    margin-left: 6px;
  }
  
  /* Loading & Error States */
  .loading {
    padding: 2rem;
    font-size: 1rem;
    gap: 1rem;
  }
  
  .loading i {
    font-size: 2rem;
  }
  
  .error {
    padding: 1.5rem;
    font-size: 1rem;
    margin: 1rem 0;
  }
  
  /* Edit Modal - Better mobile layout */
  .edit-info {
    padding: 0.75rem;
    margin-bottom: 1rem;
  }
  
  .edit-info-row {
    flex-direction: column;
    margin-bottom: 0.5rem;
  }
  
  .edit-info-label {
    min-width: auto;
    margin-bottom: 0.2rem;
    font-size: 0.85rem;
  }
  
  .edit-info-value {
    font-size: 0.9rem;
  }
  
  #editTableContainer {
    margin-bottom: 1rem;
  }
  
  .edit-buttons {
    flex-direction: column;
    gap: 0.6rem;
  }
  
  .edit-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    min-height: 44px;
  }

  /* Debug Section Headers */
  .debug-section-header {
    padding: 12px;
  }

  .debug-section-header h3 {
    font-size: 1rem;
  }

  .section-toggle,
  .section-fullscreen-toggle {
    font-size: 0.9rem;
    padding: 0.3rem;
    min-width: 40px;
    min-height: 40px;
  }

  /* Debug Action Buttons */
  .debug-action-buttons {
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 1rem;
  }
  
  /* Tooltips - Position better on mobile */
  #debugExcelTable .tooltip .tooltiptext {
    top: 125%;
    bottom: auto;
    width: 100px;
    margin-left: -50px;
  }
  
  #debugExcelTable .tooltip .tooltiptext::after {
    bottom: 100%;
    top: auto;
    border-color: transparent transparent var(--cat-yellow) transparent;
  }

  /* Handsontable on mobile */
  .handsontable {
    font-size: 0.75rem;
  }

  /* Timer and Status Messages */
  .timer {
    font-size: 0.85rem;
    margin-bottom: 1rem;
  }

  .status-message {
    font-size: 0.95rem;
    margin-bottom: 1rem;
  }

  /* Connection Info */
  #connectionInfo {
    font-size: 0.75rem;
  }
  
  /* Orders Container - Remove extra margins */
  #orders-container {
    margin-top: 0;
  }

  /* Ensure text doesn't break awkwardly */
  .ip-address {
    word-break: break-all;
  }
}

/* Extra small devices (phones in portrait, less than 480px) */
@media (max-width: 480px) {
  .app-container {
    padding: 0.5rem;
  }

  .main-title {
    font-size: 1.4rem;
  }

  .connection-card h3 {
    font-size: 0.85rem;
  }

  .connection-card p {
    font-size: 0.7rem;
  }

  .controls-left .refresh-btn,
  .controls-left .cat-btn {
    padding: 0.6rem 0.4rem;
    font-size: 0.85rem;
  }

  .mode-labels span {
    padding: 7px 12px;
    font-size: 0.75rem;
  }

  /* Filter on small screens - только иконка */
  .filter-toggle-btn.compact {
    padding: 0.65rem;
    font-size: 0.7rem;
    min-width: 44px;
  }
  
  .filter-toggle-btn.compact span {
    display: none; /* Скрываем текст, только иконка */
  }
  
  .filter-toggle-btn.compact i {
    font-size: 1rem;
  }

  .orders-table td, .orders-table th {
    padding: 0.6rem 0.4rem;
    font-size: 0.7rem;
    min-width: 70px;
  }

  .modal-content, .debug-modal-content, .edit-modal-content {
    padding: 0.75rem;
  }

  .modal-title, .edit-title {
    font-size: 1.1rem;
  }
}

/* Landscape mode optimization */
@media (max-width: 768px) and (orientation: landscape) {
  .connection-status {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .connection-card {
    flex: 1 1 calc(50% - 0.5rem);
    min-width: 200px;
  }

  .modal-content, .debug-modal-content, .edit-modal-content {
    max-height: 85vh;
  }
}
