@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600;700&display=swap');

/* ─── Reset & Base ────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f2f2f7;
  --surface:   #ffffff;
  --primary:   #000000;
  --dark:      #1c1c1e;
  --ozon:      #005bff;
  --wb:        #cb11ab;
  --danger:    #ff3b30;
  --text:      #1c1c1e;
  --text-sub:  #6e6e73;
  --border:    #e5e5ea;
  --radius:    14px;
  --nav-h:     68px;
  --header-h:  60px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── App Shell ───────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  background: var(--bg);
  overflow: hidden;
}

/* ─── Shared inner wrapper ────────────────────── */
.content-wrap {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

/* ─── Header ──────────────────────────────────── */
.header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header__title {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.header__title span {
  font-weight: 400;
  color: var(--text-sub);
}

.header__actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-sub);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn--danger:hover { color: var(--danger); }

/* ─── Main (scrollable) ───────────────────────── */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(var(--nav-h) + 16px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: none;        /* Firefox */
  -ms-overflow-style: none;     /* IE/Edge */
}

.main::-webkit-scrollbar {
  display: none;                /* Chrome/Safari */
}

/* ─── Cards ───────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

/* ─── Label / Hint ────────────────────────────── */
.label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.hint {
  font-size: 13px;
  color: var(--text-sub);
  line-height: 1.5;
}

.hint--center { text-align: center; }

.hint--link {
  color: var(--ozon);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: text-decoration-color 0.15s;
}
.hint--link:hover { text-decoration-color: var(--ozon); }

/* ─── Platform Tabs ───────────────────────────── */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #e5e5ea;
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.tab {
  padding: 9px 0;
  font-size: 15px;
  font-weight: 500;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: transparent;
  color: var(--text-sub);
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.tab--active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

/* WB tab accent when active */
.tab--active[data-platform="wb"],
.tab--active[data-table-platform="wb"] {
  color: var(--wb);
}

/* Ozon tab accent when active */
.tab--active[data-platform="ozon"],
.tab--active[data-table-platform="ozon"] {
  color: var(--ozon);
}

/* ─── Buttons ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 13px 20px;
  font-size: 15px;
  font-weight: 500;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  user-select: none;
}

.btn:active { transform: scale(0.97); opacity: 0.85; }

.btn--primary {
  background: var(--primary);
  color: #fff;
}

.btn--dark {
  background: #3a3a3c;
  color: #fff;
}

.btn--muted {
  background: #3a3a3c;
  color: #fff;
  border: none;
}

.btn--full {
  width: 100%;
}

.btn--upload {
  font-size: 16px;
  padding: 15px 20px;
}

/* ─── Section Header ──────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.1px;
}

.badge {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sub);
  background: var(--bg);
  padding: 3px 9px;
  border-radius: 20px;
}

/* ─── Textarea ────────────────────────────────── */
.input-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sub);
  margin-bottom: -4px;
}

.textarea {
  width: 100%;
  height: 120px;
  padding: 12px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid transparent;
  border-radius: 10px;
  resize: none;
  outline: none;
  line-height: 1.6;
  transition: border-color 0.2s, height 0.2s;
  overflow: hidden;
  cursor: pointer;
}

.textarea:focus {
  border-color: var(--primary);
}

.textarea::placeholder {
  color: #aeaeb2;
}

/* ─── Prompts Grid ────────────────────────────── */
.prompts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.prompt-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@media (max-width: 600px) {
  .prompts-grid {
    grid-template-columns: 1fr;
  }
}

/* ─── Actions Row ─────────────────────────────── */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ─── Tables page ─────────────────────────────── */
.main--table {
  padding: 16px 0 calc(var(--nav-h) + 16px);
  gap: 0;
  overflow-y: auto;
  display: block;
  height: auto;
  max-height: none;
}

body.table-page {
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
body.table-page::-webkit-scrollbar { display: none; }

body.table-page .app {
  height: auto;
  min-height: 100%;
  overflow: visible;
}
body.table-page .main--table {
  overflow-y: visible;
}

/* Scroll arrows */
.table-scroll-area {
  position: relative;
}

.scroll-arrow {
  display: none;
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 99;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  transition: opacity 0.15s, transform 0.1s;
}
.scroll-arrow:active { transform: translateY(-50%) scale(0.92); }

.scroll-arrow--left  { left: 8px; }
.scroll-arrow--right { right: 8px; }

@media (max-width: 860px) {
  .scroll-arrow { display: flex; }
}

/* Horizontal scrollbar for table on small screens */
.table-wrap {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.table-wrap::-webkit-scrollbar {
  display: block;
  height: 6px;
}
.table-wrap::-webkit-scrollbar-track {
  background: transparent;
}
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}
.table-wrap::-webkit-scrollbar-thumb:hover {
  background: #c7c7cc;
}

@media (min-width: 860px) {
  .table-wrap::-webkit-scrollbar { display: none; }
  .table-wrap { scrollbar-width: none; }
}

.table-toolbar {
  padding: 12px 16px;
}

.table-toolbar__inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 860px;
  margin: 0 auto;
}

.table-toolbar__inner .tabs {
  width: 100%;
}

.table-toolbar__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.table-toolbar__top .search-input {
  flex: 1;
  max-width: 360px;
}

.search-input {
  width: 100%;
  padding: 9px 14px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  outline: none;
  color: var(--text);
  transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--primary); }
.search-input::placeholder { color: #aeaeb2; }

.table-wrap {
  overflow-x: auto;
  overflow-y: visible;
}

.products-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 860px;
}

.products-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  z-index: 2;
}

.products-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.products-table tbody tr:hover { background: #f7f7fa; }
.products-table tbody td {
  padding: 6px 14px;
  vertical-align: top;
  color: var(--text);
}

/* Column widths */
.col-gen      { width: 36px; padding: 0 4px !important; }
.col-photo    { width: 60px; }
.col-article  { width: 110px; }
.col-name     { width: 200px; }
.col-name-new { width: 200px; }
.col-desc     { min-width: 180px; }
.col-desc-new { min-width: 180px; }

/* Photo thumb (single square) */
.photo-thumb {
  position: relative;
  width: 48px;
  height: 48px;
  cursor: pointer;
  border-radius: 8px;
  overflow: visible;
}
.photo-thumb .product-photo {
  width: 48px;
  height: 48px;
  border-radius: 8px;
}
.photo-count {
  position: absolute;
  bottom: -4px;
  right: -4px;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 10px;
  line-height: 1.6;
  pointer-events: none;
}

/* Photo thumbnail */
.product-photo {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--bg);
  display: block;
}
.product-photo-empty {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ccc;
}

/* Photo modal (expanded gallery) */
.photo-modal {
  position: absolute;
  right: 60px;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  max-height: 400px;
  overflow-y: auto;
  scrollbar-width: none;
  width: 160px;
}
.photo-modal::-webkit-scrollbar { display: none; }
.photo-modal img {
  width: 144px;
  height: 144px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

.col-photo {
  position: relative;
}

/* Editable cells */
.cell-editable {
  min-width: 160px;
  max-width: 240px;
}
.cell-editable textarea {
  width: 100%;
  height: 52px;
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid transparent;
  border-radius: 7px;
  resize: none;
  outline: none;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s;
}
.cell-editable textarea.expanded {
  height: auto;
  min-height: 52px;
  overflow: hidden;
  resize: none;
  cursor: text;
  border-color: var(--primary);
  background: #fff;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.cell-editable textarea.expanded::-webkit-scrollbar { display: none; }

/* Text cells (truncate long content) */
.cell-text {
  max-width: 200px;
}
.cell-text p {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.5;
  color: var(--text);
  cursor: pointer;
  transition: opacity 0.15s;
}
.cell-text p:hover {
  opacity: 0.75;
}
.cell-text p.expanded {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}

/* Gen button */
.gen-btn {
  width: 30px;
  height: 30px;
  border: none;
  background: #1c1c1e;
  border-radius: 8px;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.gen-btn:hover {
  background: #3a3a3c;
}
.gen-btn:disabled { opacity: 0.35; cursor: default; pointer-events: none; }
.gen-btn.loading {
  background: #1c1c1e;
}

.gen-btn svg {
  transition: transform 0.15s;
}
.gen-btn.loading svg {
  animation: spin 0.8s linear infinite;
}

/* Article */
.cell-article {
  font-size: 12px;
  color: var(--text-sub);
  font-family: monospace;
}

/* Empty state */
.table-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 60px 0;
  color: #aeaeb2;
  font-size: 14px;
}

.table-empty-row td { padding: 0; }

/* ─── Bottom Navigation ───────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav .content-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 0;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-sub);
  font-size: 11px;
  font-weight: 500;
  padding: 6px 0 8px;
  transition: color 0.15s;
}

.nav-item--active {
  color: var(--text);
}

.nav-item--active svg {
  stroke: var(--text);
}

/* ─── Loading state ───────────────────────────── */
.btn--loading {
  opacity: 0.6;
  pointer-events: none;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ─── Toast ───────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: min(calc(100% - 32px), 360px);
}

.toast {
  background: #1c1c1e;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  padding: 11px 18px;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  animation: toast-in 0.25s ease, toast-out 0.3s ease 2.7s forwards;
  width: 100%;
  text-align: center;
}

.toast--success { background: #34c759; }
.toast--error   { background: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(8px); }
}

/* ─── Modal ───────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 24px 24px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.2);
}

.modal__text {
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  text-align: center;
}

.modal__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ─── Pagination ──────────────────────────────────── */
.pagination {
  padding: 12px 16px;
  flex-shrink: 0;
}

.pagination__inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
}

.page-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.page-btn:hover:not(:disabled) {
  background: var(--bg);
  border-color: var(--primary);
}

.page-btn--active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.page-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.page-ellipsis {
  color: var(--text-sub);
  padding: 0 4px;
  font-size: 14px;
}

/* ─── Desktop ─────────────────────────────────── */
@media (min-width: 768px) {
  .content-wrap {
    padding: 0 40px;
  }

  .main {
    padding: 24px 40px calc(var(--nav-h) + 24px);
    gap: 16px;
    max-width: 860px;
    margin: 0 auto;
    width: 100%;
  }

  .main--table {
    max-width: 100%;
    padding: 20px 0 calc(var(--nav-h) + 20px);
  }

  .table-toolbar {
    padding: 0 40px 14px;
  }

  .table-toolbar__top .search-input {
    max-width: 420px;
  }

  .card {
    padding: 24px;
  }

  .header__title {
    font-size: 21px;
  }
}
