* {
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", Arial, sans-serif;
  margin: 0;
  background: #f5f6f8;
  color: #1f2937;
}

a {
  color: #1d4ed8;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.page-header {
  margin-bottom: 16px;
}

.app-header {
  background: #1e3a8a;
  color: #fff;
  padding: 18px 24px;
  font-size: 18px;
}

.app-header-inner {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header h1 {
  margin: 0;
  font-size: 20px;
  flex: 1 1 auto;
}

.title-short {
  display: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: calc(100vh - 88px);
}

.app-sidebar {
  background: #ffffff;
  border-right: 1px solid #e2e8f0;
  padding: 16px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 14px;
}

.sidebar-nav a {
  padding: 8px 10px;
  border-radius: 6px;
  color: #1f2937;
}

.sidebar-nav a:hover {
  background: #eef2ff;
  text-decoration: none;
}

.app-content {
  padding: 20px 24px 32px;
}

.nav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.actions-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  justify-items: start;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #cbd5f5;
  color: #1f2937;
  background: #fff;
  text-decoration: none;
  font-size: 14px;
}

.page-link:hover {
  background: #eef2ff;
  text-decoration: none;
}

.page-link.active {
  background: #1d4ed8;
  color: #fff;
  border-color: #1d4ed8;
}

.page-link.disabled {
  pointer-events: none;
  opacity: 0.5;
}

.home-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  background: #3B6EEA;
  color: #fff;
  border: 1px solid rgba(15, 23, 42, 0.12);
  width: 500px;
  height: 70px;
  border-radius: 12px;
  font-size: 17px;
  font-family: Arial, sans-serif;
  font-weight: 600;
  box-shadow: 0 6px 14px rgba(31, 72, 148, 0.25);
  transition: transform 0.05s ease, box-shadow 0.2s ease, filter 0.2s ease, background 0.2s ease;
}

.home-action:hover {
  background: #6e97f3;
  color: #fff;
  text-decoration: none;
  box-shadow: 0 8px 18px rgba(31, 72, 148, 0.28);
}

.home-action:active {
  transform: translateY(1px);
  box-shadow: 0 4px 10px rgba(31, 72, 148, 0.25);
}

.filter-row {
  margin-bottom: 12px;
}

.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.filter-panel {
  display: none;
  margin-top: 12px;
}

.filter-panel.open {
  display: block;
}

.card {
  background: #ffffff;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(220px, 1fr));
  gap: 12px;
  align-items: end;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}

.form-grid label.checkbox-row {
  flex-direction: row;
  align-items: center;
  cursor: pointer;
}

.form-grid .full {
  grid-column: 1 / -1;
}
.form-grid .half {
  grid-column: span 3;
}
input,
select,
button {
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid #cbd5f5;
  border-radius: 6px;
}

input[type="number"] {
  text-align: right;
}

button {
  background: #2563eb;
  color: #fff;
  border: none;
  cursor: pointer;
}

button:hover {
  background: #1d4ed8;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid #e2e8f0;
}

.num {
  text-align: right;
}

.name-col {
  width: 45%;
}

.desc-col {
  width: 35%;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: #1d4ed8;
  cursor: pointer;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.icon {
  width: 16px;
  height: 16px;
  display: inline-block;
  fill: currentColor;
}

.btn-link.danger {
  color: #dc2626;
}

.muted {
  color: #6b7280;
}

.form-hint {
  margin-top: 8px;
}

.form-actions {
  display: flex;
  padding-top: 10px;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}

.form-row .grow {
  flex: 1 1 300px;
}
.form-actions-import {
  display: contents;
}

.inline-form {
  display: inline;
}

.file-input {
  display: none;
}

.excel-right {
  margin-left: auto;
}

.btn-secondary {
  display: inline-block;
  text-decoration: none;
  background: #9ca3af;
  color:#fff;
  border: none;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-family: Arial, sans-serif;
  font-weight: 400;
}

.btn-secondary:hover {
  background: #6b7280;
  color: #fff;
  text-decoration: none;
}

.input-error {
  border-color: #dc2626;
}

.field-error {
  margin-top: 6px;
  font-size: 12px;
  color: #dc2626;
}

/* Модальное окно */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-overlay[hidden] {
  display: none;
}
.modal {
  background: #fff;
  border-radius: 8px;
  max-width: 440px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
}
.modal-header h3 {
  margin: 0;
  font-size: 18px;
}
.modal-close {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: #6b7280;
}
.modal-close:hover {
  color: #1f2937;
}
.modal form {
  padding: 20px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  grid-column: 1 / -1;
}
.btn-primary {
  background: #1d4ed8;
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.btn-primary:hover {
  background: #1e40af;
}

/* Ячейка Ед. в таблице документа */
.td-unit {
  min-width: 70px;
  white-space: nowrap;
}
.td-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.item-edit-btn {
  flex-shrink: 0;
  padding: 4px;
  color: #1d4ed8;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 4px;
}
.item-edit-btn:hover {
  background: #eef2ff;
  color: #1e40af;
}
.item-edit-btn .icon {
  width: 16px;
  height: 16px;
  display: block;
}
.item-add-btn {
  padding: 4px 8px;
  color: #059669;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
}
.item-add-btn:hover {
  background: #d1fae5;
  color: #047857;
}
.item-add-btn .icon {
  width: 18px;
  height: 18px;
}

.form-errors {
  margin-top: 10px;
  color: #dc2626;
  font-size: 13px;
}

.worker-dismissed td {
  color: #dc2626;
}

.item-archived td {
  color: #dc2626;
  text-decoration: underline;
}

.app-footer {
  background: #0f172a;
  color: #fff;
  font-size: 12px;
  padding: 6px 24px;
}

.item-name {
  width: 100%;
}
.qty-input {
  width: 100%;
}
.td-item {
  width: 50%;
}
.td-qty {
  width: 20%;
}

.card-toggle {
  display: none;
}

.menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.6);
  color: #fff;
  font-size: 20px;
  padding: 4px 8px;
  border-radius: 6px;
}

.menu-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
}

.mobile-home {
  display: none;
  background: #9ca3af;
  color: #fff;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  white-space: nowrap;
}

.mobile-home:hover {
  background: #6b7280;
  color: #fff;
  text-decoration: none;
}

@media (max-width: 900px) {
  .app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    padding: 14px 16px;
  }

  .app-header h1 {
    font-size: 16px;
  }

  .title-full {
    display: none;
  }

  .title-short {
    display: inline;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    position: fixed;
    top: 56px;
    left: 12px;
    right: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.2);
    transform: translateY(-140%);
    transition: transform 0.2s ease;
    z-index: 20;
  }

  .sidebar-nav {
    flex-direction: column;
    gap: 6px;
  }

  body.sidebar-open .app-sidebar {
    transform: translateY(0);
  }

  .menu-toggle,
  .mobile-home {
    display: inline-flex;
    align-items: center;
  }

  .app-content {
    padding: 16px;
  }

  .card {
    padding: 12px;
  }

  .form-row .grow {
    flex: 1 1 100%;
  }

  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  th,
  td {
    white-space: nowrap;
  }

  .doc-table {
    display: block;
    overflow: visible;
  }

  .doc-table thead {
    display: none;
  }

  .doc-table tbody,
  .doc-table tr,
  .doc-table td {
    display: block;
    width: 100%;
  }

  .doc-table tr {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 12px;
    background: #ffffff;
    box-shadow: 0 1px 6px rgba(15, 23, 42, 0.08);
  }

  .doc-table td {
    border-bottom: none;
    padding: 6px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    white-space: normal;
  }

  .doc-table td::before {
    content: attr(data-label);
    color: #6b7280;
    font-size: 12px;
    flex: 0 0 110px;
  }

  .doc-table td.actions {
    align-items: center;
    gap: 10px;
    justify-content: flex-start;
  }

  .doc-table td.actions::before {
    content: "Действия";
  }

  .doc-table td.actions form {
    display: inline;
  }

  .doc-table td .stock-value {
    width: 100%;
    text-align: right;
  }

  .doc-table td.hide-mobile {
    display: none;
  }

  .doc-table td.card-extra {
    display: none;
  }

  .doc-table tr.expanded td.card-extra {
    display: flex;
  }

  .doc-table td.card-main {
    position: relative;
  }

  .doc-table .cell-value {
    flex: 1 1 auto;
  }

  .card-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    border: 1px solid #cbd5f5;
    background: #fff;
    color: #1f2937;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 12px;
    line-height: 1;
  }

  .doc-table tr.expanded .card-toggle {
    transform: rotate(180deg);
  }

  .home-action {
    width: 100%;
    font-size: 18px;
  }

  .page-link {
    min-width: 40px;
    padding: 8px 12px;
  }
}

@media (max-width: 600px) {
  .app-header {
    padding: 12px 12px;
  }

  .app-content {
    padding: 12px;
  }

  .nav-grid {
    grid-template-columns: 1fr;
  }
}