/* Общие стили */
*,
*::after,
*::before {
  box-sizing: border-box;
  transition: all ease-in-out 0.3s;
}

html {
  background-color: skyblue;
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
}

body {
  width: 100%;
  font-size: 16px;
  padding: 0;
  margin: 0;
  overflow-x: hidden;
  background-color: skyblue;
  min-height: 100vh;
  font-family: Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

/* Быстрая загрузка контейнера */
.container {
  opacity: 0;
  animation: fadeIn 0.3s ease-in forwards;
  width: 100%;
  max-width: 1100px;
  background-color: rgb(78, 150, 245);
  padding: 15px;
  border: 3px solid #000000;
  border-radius: 20px;
  will-change: transform;
  backface-visibility: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  margin: 20px auto;
  align-self: center;
}

@keyframes fadeIn {
  to {
    opacity: 1;
  }
}

/* Заголовок с кнопками */
header {
  margin-bottom: 15px;
}

.header-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

h1 {
  margin: 0;
  text-align: center;
  border-bottom: 2px solid #000000;
  padding-bottom: 8px;
  color: #000;
  font-size: 1.5rem;
  flex: 1;
  min-width: 200px;
}

/* Контактные кнопки слева */
.contact-buttons-left {
  display: flex;
  gap: 8px;
  align-items: center;
}

.contact-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #000000;
  text-decoration: none;
  font-size: 12px;
  font-weight: bold;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.contact-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.telegram-btn {
  background-color: #0088cc;
  color: white;
}

.email-btn {
  background-color: #d44638;
  color: white;
}

.contact-icon {
  font-size: 14px;
}

.contact-text {
  display: inline;
}

/* Кнопки авторизации справа */
.auth-buttons-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.auth-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #000000;
  text-decoration: none;
  font-size: 12px;
  font-weight: bold;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.auth-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.login-btn {
  background-color: rgb(0, 108, 209);
  color: white;
}

.register-btn {
  background-color: rgb(0, 128, 21);
  color: white;
}

.auth-icon {
  font-size: 14px;
}

.auth-text {
  display: inline;
}

/* Основной контент */
.allAboutProducts {
  display: flex;
  flex-direction: column;
  width: 100%;
  border: 2px solid #000000;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 15px;
  background-color: rgba(255, 255, 255, 0.1);
}

.aboutProducts {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  margin-bottom: 12px;
}

/* Кнопки работы с типами - всегда в строке */
.types-control {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
}

.types-control button {
  flex: 1;
  min-width: 0;
  padding: 10px 8px;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid #000000;
  cursor: pointer;
  min-height: 44px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: bold;
}

.showTypesBtn {
  background-color: rgb(0, 108, 209);
  color: white;
}

.showTypesBtn:hover {
  background-color: rgb(0, 74, 143);
}

.confirmTypesBtn {
  background-color: rgb(0, 128, 21);
  color: white;
  display: none;
}

.confirmTypesBtn:hover {
  background-color: rgb(0, 194, 32);
}

.clearTypesBtn {
  background-color: rgb(212, 103, 0);
  color: white;
}

.clearTypesBtn:hover {
  background-color: rgb(156, 76, 0);
}

/* Контейнер типов - адаптивные колонки */
.types-container {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: 100%;
  max-height: none;
  overflow: visible;
  padding: 10px;
  border: 1px solid #000000;
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.9);
  will-change: transform;
}

.type {
  padding: 8px 6px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid #000000;
  cursor: pointer;
  background-color: rgb(211, 211, 211);
  color: black;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  will-change: transform;
  min-height: 36px;
}

.type:hover {
  background-color: rgb(180, 180, 180);
}

.type.selected {
  background-color: rgb(0, 195, 255);
  color: black;
}

/* Контейнер выбранных типов - grid с одинаковыми кнопками */
.selected-types-container {
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 6px;
  width: 100%;
  padding: 10px;
  border: 1px solid #000000;
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.8);
  overflow: visible;
  will-change: transform;
}

.selected-type {
  padding: 8px 6px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid #000000;
  background-color: rgb(132, 0, 255);
  color: white;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  will-change: transform;
  min-height: 36px;
  text-align: center;
  min-width: 0;
}

.selected-type:hover {
  background-color: rgb(98, 4, 187);
}

.selected-type.active {
  background-color: rgb(0, 156, 204);
  color: black;
}

.selected-type.active:hover {
  background-color: rgb(40, 202, 202);
}

/* Ввод данных */
.inputProducts {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.inputName {
  width: 100%;
}

#inputName {
  width: 100%;
  padding: 12px 8px;
  border: 2px solid #000000;
  border-radius: 8px;
  font-size: 15px;
  min-height: 48px;
  text-align: center;
  background-color: white;
}

.inputValues {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 10px;
  width: 100%;
}

.inputValue,
.inputUnit {
  width: 100%;
}

#inputValue,
#inputUnit {
  width: 100%;
  padding: 12px 8px;
  border: 2px solid #000000;
  border-radius: 8px;
  font-size: 15px;
  min-height: 48px;
  text-align: center;
  background-color: white;
}

#inputUnit {
  background-color: white;
  cursor: pointer;
}

/* Кнопки */
.compact-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.sortBtn,
.addToTableBtn {
  padding: 12px;
  font-size: 15px;
  border-radius: 8px;
  border: 1px solid #000000;
  cursor: pointer;
  min-height: 48px;
  will-change: transform;
  font-weight: bold;
}

.sortBtn {
  background-color: rgb(224, 146, 1);
  color: white;
}

.sortBtn:hover {
  background-color: rgb(179, 116, 0);
}

.addToTableBtn {
  background-color: #009926;
  color: white;
}

.addToTableBtn:hover {
  background-color: #004e23;
}

.addBtn {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.excelBtn,
.clearTable {
  padding: 12px 8px;
  font-size: 15px;
  border-radius: 8px;
  border: 1px solid #000000;
  cursor: pointer;
  min-height: 48px;
  will-change: transform;
  font-weight: bold;
}

.excelBtn {
  background-color: #008d18;
  color: white;
}

.excelBtn:hover {
  background-color: #005e10;
}

.clearTable {
  background-color: rgb(192, 0, 0);
  color: white;
}

.clearTable:hover {
  background-color: rgb(128, 1, 1);
}

/* Таблица - базовая стилизация */
.table {
  width: 100%;
  font-size: 15px;
  table-layout: fixed;
  will-change: transform;
  background-color: #4e96f5;
  margin-top: 10px;
  border: 1px solid #000;
}

.table thead {
  display: table-header-group;
  background-color: #4e96f5;
  border: 1px solid #000;
}

.table tbody {
  display: table-row-group;
  border: 1px solid #000;
}

th,
td {
  border: 1px solid #000000;
  padding: 8px 6px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  will-change: transform;
  background-color: #4e96f5;
  word-wrap: break-word;
  hyphens: auto;
  line-height: 1.3;
  border: 1px solid #000;
}

.t-name {
  width: 40%;
}

.t-type {
  width: 25%;
}

.t-value {
  width: 25%;
}

.t-delete {
  width: 10%;
  padding: 0;
}

.deleteBtn {
  width: 100%;
  height: 100%;
  min-height: 36px;
  border-radius: 6px;
  border: 1px solid #000000;
  font-size: 14px;
  background-color: rgb(192, 0, 0);
  color: white;
  cursor: pointer;
  padding: 8px 10px;
  will-change: transform;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  box-sizing: border-box;
}

.deleteBtn:hover {
  background-color: rgb(128, 1, 1);
}

.delete-text {
  display: inline;
}

.delete-icon {
  display: none;
  font-size: 16px;
  font-weight: bold;
  line-height: 1;
  color: white;
}

.textWarn {
  text-align: center;
  margin: 15px 10px;
  font-size: 15px;
  display: block;
  color: #000;
}

/* Контакты внизу */
.contact-links-bottom {
  display: none;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

.contact-link {
  padding: 12px;
  border-radius: 10px;
  border: 2px solid #000000;
  text-decoration: none;
  text-align: center;
  font-weight: bold;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.contact-link.telegram {
  background-color: #0088cc;
  color: white;
}

.contact-link.telegram:hover {
  background-color: #0077b3;
}

.contact-link.email {
  background-color: #d44638;
  color: white;
}

.contact-link.email:hover {
  background-color: #c1351d;
}

/* Оптимизация анимаций */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Большие устройства (8 колонок для типов) - 1025px+ */
@media (min-width: 1025px) {
  .types-container {
    grid-template-columns: repeat(8, 1fr);
  }

  .container {
    margin: 25px auto;
  }
}

/* Средние устройства (5 колонок для типов) - 769px-1024px */
@media (min-width: 769px) and (max-width: 1024px) {
  .types-container {
    grid-template-columns: repeat(5, 1fr);
  }

  .container {
    max-width: 95%;
    margin: 20px auto;
  }

  .table {
    font-size: 14px;
  }

  th,
  td {
    padding: 6px 4px;
    font-size: 13px;
  }

  .t-name {
    width: 38%;
  }

  .t-type {
    width: 27%;
  }

  .t-value {
    width: 25%;
  }

  .t-delete {
    width: 10%;
  }
}

/* Планшеты - 481px-768px */
@media (min-width: 481px) and (max-width: 768px) {
  .container {
    width: 95%;
    max-width: 95%;
    margin: 15px auto;
    padding: 12px;
  }

  .header-container {
    flex-direction: column;
    gap: 10px;
  }

  .contact-buttons-left,
  .auth-buttons-right {
    width: 100%;
    justify-content: center;
  }

  h1 {
    order: -1;
    width: 100%;
  }

  .types-container {
    grid-template-columns: repeat(4, 1fr);
  }

  h1 {
    font-size: 1.4rem;
    margin-bottom: 12px;
  }

  .types-control button {
    padding: 8px 6px;
    font-size: 13px;
    min-height: 40px;
  }

  .type,
  .selected-type {
    font-size: 11px;
    padding: 7px 5px;
    min-height: 32px;
  }

  #inputName,
  #inputValue,
  #inputUnit {
    font-size: 14px;
    padding: 10px 7px;
    min-height: 44px;
  }

  .sortBtn,
  .addToTableBtn,
  .excelBtn,
  .clearTable {
    font-size: 14px;
    padding: 10px 6px;
    min-height: 44px;
  }

  .table {
    font-size: 13px;
  }

  th,
  td {
    padding: 6px 4px;
    font-size: 12px;
  }

  .t-name {
    width: 38%;
  }

  .t-type {
    width: 27%;
  }

  .t-value {
    width: 25%;
  }

  .t-delete {
    width: 10%;
  }

  .t-delete-header {
    display: table-cell;
  }

  /* На планшетах показываем большие кнопки связи внизу */
  .contact-links-bottom {
    display: flex;
  }
}

/* Мобильные телефоны - до 480px */
@media (max-width: 480px) {
  body {
    padding: 0;
  }

  .container {
    width: calc(100% - 20px);
    max-width: calc(100% - 20px);
    margin: 12px auto;
    padding: 10px;
    border-radius: 15px;
  }

  .header-container {
    flex-direction: column;
    gap: 8px;
  }

  h1 {
    order: -1;
    font-size: 1.3rem;
    margin-bottom: 8px;
    padding-bottom: 6px;
    width: 100%;
  }

  .contact-buttons-left,
  .auth-buttons-right {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
  }

  .contact-btn,
  .auth-btn {
    padding: 5px 8px;
    font-size: 11px;
  }

  .contact-text,
  .auth-text {
    display: none; /* Скрываем текст на мобильных */
  }

  .contact-icon,
  .auth-icon {
    font-size: 16px;
  }

  .types-control {
    gap: 6px;
  }

  .types-control button {
    padding: 8px 4px;
    font-size: 12px;
    min-height: 38px;
  }

  .types-container {
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    padding: 8px;
  }

  .type {
    font-size: 10px;
    padding: 6px 3px;
    min-height: 30px;
  }

  .selected-types-container {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    padding: 8px;
    gap: 5px;
  }

  .selected-type {
    font-size: 10px;
    padding: 6px 3px;
    min-height: 30px;
  }

  #inputName,
  #inputValue,
  #inputUnit {
    font-size: 13px;
    padding: 10px 6px;
    min-height: 42px;
  }

  .compact-buttons,
  .addBtn {
    gap: 8px;
  }

  .sortBtn,
  .addToTableBtn,
  .excelBtn,
  .clearTable {
    font-size: 13px;
    padding: 10px 5px;
    min-height: 42px;
  }

  .table {
    font-size: 12px;
  }

  th,
  td {
    padding: 4px 3px;
    font-size: 11px;
  }

  .t-name {
    width: 35%;
  }

  .t-type {
    width: 30%;
  }

  .t-value {
    width: 27%;
  }

  .t-delete {
    width: 8%;
  }

  .deleteBtn {
    padding: 4px;
    min-height: 30px;
    font-size: 11px;
  }

  .delete-text {
    display: none;
  }

  .delete-icon {
    display: inline;
  }

  /* На мобильных показываем большие кнопки связи внизу */
  .contact-links-bottom {
    display: flex;
  }
}

/* Маленькие мобильные - до 375px */
@media (max-width: 375px) {
  body {
    padding: 0;
  }

  .container {
    width: calc(100% - 20px);
    max-width: calc(100% - 20px);
    margin: 10px auto;
    padding: 8px;
    border-radius: 12px;
  }

  h1 {
    font-size: 1.2rem;
    margin-bottom: 8px;
  }

  .types-control button {
    padding: 6px 3px;
    font-size: 11px;
    min-height: 36px;
  }

  .types-container {
    grid-template-columns: repeat(2, 1fr);
  }

  .type,
  .selected-type {
    font-size: 9px;
    padding: 5px 2px;
    min-height: 28px;
  }

  #inputName,
  #inputValue,
  #inputUnit {
    font-size: 12px;
    padding: 8px 5px;
    min-height: 40px;
  }

  .compact-buttons,
  .addBtn {
    gap: 6px;
  }

  .sortBtn,
  .addToTableBtn,
  .excelBtn,
  .clearTable {
    font-size: 12px;
    padding: 8px 4px;
    min-height: 40px;
  }

  .table {
    font-size: 11px;
  }

  th,
  td {
    padding: 3px 2px;
    font-size: 10px;
  }

  .t-name {
    width: 35%;
  }

  .t-type {
    width: 30%;
  }

  .t-value {
    width: 25%;
  }

  .t-delete {
    width: 10%;
  }

  .deleteBtn {
    padding: 3px;
    min-height: 26px;
    font-size: 10px;
  }
}
