body {
  font-family: Arial, sans-serif;
  background: #f4f4f4;
  margin: 0;
  padding: 20px;
  color: #111;
}

.container,
.manage-container {
  max-width: 1100px;
  margin: 0 auto;
}

.card {
  background: white;
  padding: 16px;
  border-radius: 10px;
  margin-bottom: 16px;
  box-sizing: border-box;
}

input,
select,
textarea {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 10px;
  box-sizing: border-box;
  font: inherit;
}

button {
  margin: 8px 0;
  padding: 10px;
  box-sizing: border-box;
  font: inherit;
  cursor: pointer;
}

.card > button,
.card button[type="submit"],
#loginBtn,
#addBtn,
#refreshBtn {
  display: block;
  width: 100%;
}

li {
  margin: 8px 0;
}

#productsList {
  padding-left: 0;
}

#productsList h3 {
  margin-top: 16px;
  margin-bottom: 8px;
}

#productsList ul {
  padding-left: 12px;
  margin-left: 0;
}

#productsList li {
  margin-left: 0;
  padding-left: 0;
}

#productsList li button {
  display: inline-block;
  width: auto;
  min-width: 55px;
  margin-right: 10px;
  margin-left: 0;
  vertical-align: middle;
}

.page-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 20px;
}

.page-heading {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.page-heading h1 {
  margin: 0;
  line-height: 1.1;
}

.current-user {
  font-weight: bold;
  font-size: 18px;
  padding-top: 0;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 420px;
  max-width: 100%;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  text-decoration: none;
  font-weight: bold;
  text-align: center;
  color: #fff;
  box-sizing: border-box;
  margin: 0;
  width: 100%;
}

.action-btn.blue {
  background: #007bff;
}

.action-btn.gray {
  background: #6c757d;
}

.action-btn.red {
  background: #dc3545;
}

.manage-search-wrap {
  margin-bottom: 20px;
}

.manage-search {
  width: 100%;
  max-width: 520px;
  padding: 12px 14px;
  border: 1px solid #ced4da;
  border-radius: 8px;
  background: #fff;
  font-size: 16px;
  box-sizing: border-box;
}

.section {
  margin-bottom: 30px;
}

.section-products {
  margin-left: 0;
}

.loading {
  text-align: center;
  padding: 50px;
}

.product-row {
  display: grid;
  grid-template-columns: 56px minmax(320px, 1fr) 190px 90px 120px;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  margin-bottom: 8px;
  background: #fff;
}

.photo-container {
  width: 56px;
  height: 56px;
  flex: 0 0 56px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-upload-btn {
  position: absolute;
  bottom: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border: 1px solid #bbb;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.95);
  color: #111;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  margin: 0;
}

.photo-delete-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(220, 53, 69, 0.92);
  color: #fff;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  margin: 0;
}

.product-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.product-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.product-name {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
}

.product-comment {
  width: 100%;
  margin: 0;
}

.product-section {
  width: 190px;
  margin: 0;
}

.product-meta {
  flex: 0 0 150px;
  font-size: 0.875em;
  color: #6c757d;
  line-height: 1.3;
}

.save-status {
  width: 90px;
  margin: 0;
  font-size: 0.75em;
  text-align: center;
}

.saving {
  color: #ffc107;
}

.saved {
  color: #28a745;
}

.error {
  color: #dc3545;
}

.delete-btn {
  width: 120px;
  background: #dc3545;
  color: white;
  border: none;
  padding: 10px 12px;
  border-radius: 4px;
  cursor: pointer;
  margin: 0;
}

.product-list-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid transparent;
  flex: 0 0 auto;
}

.product-list-status.in-list {
  background: #e9f7ef;
  color: #1e7e34;
  border-color: #b7e4c7;
}

.product-list-status.out-list {
  background: #f1f3f5;
  color: #6c757d;
  border-color: #dee2e6;
}

.section-order-box {
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 24px;
}

.section-order-box h2 {
  margin: 0 0 12px 0;
  font-size: 1.1rem;
}

.section-order-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  background: #f8f9fa;
  margin-bottom: 8px;
}

.section-order-name {
  font-weight: 500;
}

.section-order-actions {
  display: flex;
  gap: 8px;
}

.section-move-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 6px;
  background: #007bff;
  color: white;
  cursor: pointer;
  font-size: 16px;
  margin: 0;
  padding: 0;
}

.section-move-btn:disabled {
  background: #adb5bd;
  cursor: not-allowed;
}

.section-delete-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 6px;
  background: #dc3545;
  color: white;
  cursor: pointer;
  font-size: 16px;
  margin: 0;
  padding: 0;
}

.section-delete-btn:hover {
  background: #c82333;
}

.user-table-card {
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 10px;
  padding: 14px;
}

.user-table-header,
.user-row {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 1fr 1.4fr;
  gap: 12px;
  align-items: center;
}

.user-table-header {
  padding: 10px 12px;
  border-bottom: 1px solid #dee2e6;
  font-weight: bold;
}

.user-row {
  padding: 16px 12px;
  border-bottom: 1px solid #eee;
  background: #fff;
}

.user-row:last-child {
  border-bottom: none;
}

.user-cell {
  min-width: 0;
  word-break: break-word;
}

.user-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.user-actions button {
  margin: 0;
}

.small-btn {
  padding: 10px 12px;
  border: none;
  border-radius: 6px;
  color: #fff;
}

.small-btn.blue {
  background: #6c757d;
}

.small-btn.red {
  background: #e07b88;
}

.product-photo {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  margin-right: 8px;
  border: 1px solid #ddd;
  vertical-align: middle;
}

.photo-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.photo-modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 20px;
  max-width: 95vw;
  max-height: 90vh;
}

#photoLarge {
  display: block;
  max-width: min(70vw, 900px);
  max-height: 80vh;
  border-radius: 8px;
  object-fit: contain;
}

.photo-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 160px;
}

.photo-meta {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid #eee;
  text-align: center;
  font-size: 14px;
  color: #666;
}

#photoAuthor {
  display: block;
  color: #007bff;
  font-weight: bold;
  margin-bottom: 6px;
}

#photoDate {
  display: block;
  color: #666;
}

#photoDelete,
#photoClose {
  width: 100%;
  height: 56px;
  cursor: pointer;
  font-size: 18px;
  font-weight: bold;
  border: none;
  border-radius: 10px;
}

#photoDelete {
  background: #dc3545;
  color: white;
}

#photoClose {
  background: #666;
  color: white;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
}

.app-page {
  display: none;
}

.password-box {
  display: flex;
  gap: 8px;
  align-items: center;
}

.password-box input {
  margin: 0;
}

.password-box button {
  width: auto;
  margin: 0;
}

.section-edit-area {
  flex: 1;
  min-width: 0;
}

.section-name-input {
  margin: 0;
}

.section-edit-btn,
.section-save-btn,
.section-cancel-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 6px;
  color: white;
  cursor: pointer;
  font-size: 16px;
  margin: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.section-edit-btn {
  background: #6c757d;
}

.section-save-btn {
  background: #28a745;
}

.section-cancel-btn {
  background: #fd7e14;
}

.section-list-item {
  list-style: none;
  margin-bottom: 8px;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 6px 10px;
  background: #f8f9fa;
  border-radius: 6px;
}

.section-toggle {
  width: 38px;
  height: 38px;
  border: 1px solid #ced4da;
  border-radius: 6px;
  background: #fff;
  color: #111;
  font-size: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin: 0;
  padding: 0;
}

.section-toggle:hover {
  background: #f1f3f5;
}

.section-title {
  flex: 1;
  font-weight: bold;
  margin: 0;
  background: transparent;
  padding: 0;
}

.section-count {
  font-size: 0.875em;
  color: #6c757d;
}

.products-list {
  margin: 0;
  padding-left: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.products-list.open {
  max-height: 1000px;
}

.product-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 0;
  border-bottom: 1px solid #eee;
  margin: 0;
}

.product-list-item:last-child {
  border-bottom: none;
}

.product-info {
  order: 2;
  flex: 1;
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.product-details {
  flex: 1;
  min-width: 0;
  line-height: 1.2;
}

.product-name strong {
  font-weight: 700;
  color: #111;
}

.photo-credit {
  font-size: 0.75em;
  color: #28a745;
  font-style: italic;
  line-height: 1.1;
}

.product-meta-inline {
  font-size: 12px;
  color: #111;
  font-weight: 400;
  line-height: 1.1;
  margin-top: 2px;
}

.product-actions {
  order: 1;
  flex-shrink: 0;
}

.buy-btn {
  min-width: 64px;
  padding: 4px 10px;
  background: #28a745;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  margin: 0;
}

.buy-btn:hover {
  background: #218838;
}

.app-page .card {
  padding-left: 20px;
}

.photo-count {
  display: inline-block;
  margin-left: 8px;
  font-size: 12px;
  color: #666;
  vertical-align: middle;
}

.photo-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 8px;
}

.photo-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
}

.photo-thumb.active {
  border-color: #007bff;
}

.suggested-photo-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  padding: 8px 12px;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  background: #f8f9fa;
}

.suggested-product-photo {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #ddd;
  cursor: pointer;
  flex-shrink: 0;
}

.suggested-photo-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.suggested-photo-label {
  font-size: 13px;
  font-weight: 600;
  color: #111;
}

.suggested-photo-count {
  font-size: 12px;
  color: #6c757d;
}

@media (max-width: 900px) {
  .product-row {
    grid-template-columns: 56px 1fr;
    align-items: start;
  }

  .product-main,
  .product-section,
  .save-status,
  .delete-btn {
    grid-column: 2;
    width: 100%;
  }

  .product-line {
    flex-wrap: wrap;
  }

  .user-table-header,
  .user-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  body {
    padding: 12px;
  }

  .page-topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .page-heading {
    gap: 8px;
  }

  .action-grid {
    width: 100%;
    grid-template-columns: 1fr 1fr;
  }

  .manage-search {
    max-width: 100%;
  }

  .photo-modal-content {
    flex-direction: column;
    align-items: center;
  }

  #photoLarge {
    max-width: 85vw;
    max-height: 60vh;
  }

  .photo-actions {
    width: 100%;
  }
}
