/* =================================================
   Base
================================================= */

* { box-sizing: border-box; }

html { color-scheme: light; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

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


/* =================================================
   Page & header
================================================= */

.page {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: clamp(28px, 5vw, 56px) clamp(16px, 4vw, 32px) 64px;
}

.header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--rule-strong);
}

.header__eyebrow {
  display: block;
  margin-bottom: 7px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(28px, 4vw, 38px);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.025em;
}


/* =================================================
   Search
================================================= */

.search--hero {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 58px;
  margin: 24px 0 7px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: 0 1px 2px rgba(0,0,0,.03), 0 5px 18px rgba(0,0,0,.035);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.search--hero:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent),
              0 5px 18px rgba(0,0,0,.035);
}

.search__icon { flex: 0 0 auto; margin-left: 17px; color: var(--ink-soft); }

.search--hero input {
  flex: 1;
  min-width: 0;
  height: 56px;
  padding: 0 14px;
  color: var(--ink);
  background: transparent;
  border: 0;
  font-size: 16px;
}

.search--hero input:focus { outline: none; }
.search--hero input::placeholder { color: var(--ink-soft); }

.search__spinner {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  margin-right: 16px;
  border: 2px solid var(--rule-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.search--hero button {
  flex: 0 0 auto;
  align-self: stretch;
  padding: 0 24px;
  color: var(--surface);
  background: var(--ink);
  border: 0;
  border-left: 1px solid var(--ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, transform .1s ease;
}

.search--hero button:hover { background: #151515; }
.search--hero button:active { transform: scale(.98); }

.search-hint { margin: 0 0 28px; color: var(--ink-soft); font-size: 12px; }


/* =================================================
   Layout & panels
================================================= */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(270px, 310px);
  align-items: start;
  gap: 24px;
  margin-top: 24px;
}

.panel {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: 0 1px 2px rgba(0,0,0,.025), 0 8px 24px rgba(0,0,0,.035);
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--rule);
}

.panel__head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  line-height: 1.2;
}

.count { flex-shrink: 0; color: var(--ink-soft); font-family: var(--font-mono); font-size: 12px; }


/* =================================================
   Product table
================================================= */

.catalog-table { width: 100%; border-collapse: collapse; }

.catalog-table th {
  padding: 12px 22px;
  color: var(--ink-soft);
  background: color-mix(in srgb, var(--paper) 45%, var(--surface));
  border-bottom: 1px solid var(--rule);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
}

.catalog-table td {
  padding: 15px 22px;
  border-bottom: 1px solid var(--rule);
  font-size: 14px;
  vertical-align: middle;
}

.catalog-table tbody tr { transition: background .12s ease; }
.catalog-table tbody tr:hover { background: color-mix(in srgb, var(--paper) 65%, var(--surface)); }
.catalog-table tbody tr:last-child td { border-bottom: 0; }

.col-id { width: 70px; }
.col-price { width: 105px; }
.col-date { width: 135px; color: var(--ink-soft); }

.mono { color: var(--ink-soft); font-family: var(--font-mono); font-size: 12.5px; }
.product-name { color: var(--ink); font-weight: 550; }

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 3px 10px;
  color: var(--ink);
  background: var(--tag-bg);
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}

.empty-hint { margin: 0; padding: 20px 22px; color: var(--ink-soft); font-size: 13px; }


/* =================================================
   Add product form
================================================= */

.add-form { display: flex; flex-direction: column; gap: 17px; padding: 22px; }

.field { display: flex; flex-direction: column; gap: 7px; width: 100%; min-width: 0; }
.field label { color: var(--ink); font-size: 13px; font-weight: 600; }

.field input {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  font-size: 14px;
}

.field input:hover { border-color: var(--ink-soft); }

.field input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 10%, transparent);
}

.field input::placeholder { color: #a39d8a; }


.field-note { margin: -4px 0 0; color: var(--ink-soft); font-size: 12px; line-height: 1.45; }


/* =================================================
   Footer
================================================= */

.footer { margin-top: 40px; padding-top: 18px; color: var(--ink-soft); border-top: 1px solid var(--rule); font-size: 12px; }

.footer code {
  padding: 2px 6px;
  color: var(--ink);
  background: var(--tag-bg);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
}


/* =================================================
   Tablet (≤ 860px)
================================================= */

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

  .add-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
  }

  .add-form .btn-primary,
  .add-form .field-note { grid-column: span 2; }
}


/* =================================================
   Mobile (≤ 600px)
================================================= */

@media (max-width: 600px) {
  .page { padding-top: 24px; padding-bottom: 40px; }

  .header { align-items: flex-start; gap: 12px; padding-bottom: 18px; }
  .header h1 { font-size: 30px; }

  .search--hero { min-height: 52px; margin-top: 18px; }
  .search--hero input { height: 52px; padding: 0 10px; font-size: 15px; }
  .search__icon { margin-left: 14px; }
  .search--hero button { padding: 0 16px; font-size: 13px; }
  .search-hint { margin-bottom: 22px; }

  .layout { gap: 18px; margin-top: 18px; }
  .panel__head { padding: 16px 17px; }

  .add-form { display: flex; padding: 18px 17px; }
  .add-form .btn-primary,
  .add-form .field-note { grid-column: auto; }

  /* Table -> cards */
  .catalog-table,
  .catalog-table tbody { display: block; width: 100%; }
  .catalog-table thead { display: none; }

  .catalog-table tr {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px 14px;
    padding: 15px 17px;
    border-bottom: 1px solid var(--rule);
  }
  .catalog-table tbody tr:last-child { border-bottom: 0; }
  .catalog-table tbody tr:hover { background: transparent; }

  .catalog-table td { display: block; width: auto; padding: 0; border: 0; }
  .catalog-table td:nth-child(1) { display: none; }
  .catalog-table td:nth-child(2) { grid-column: 1; grid-row: 1; font-size: 15px; }
  .catalog-table td:nth-child(3) { grid-column: 1; grid-row: 2; }
  .catalog-table td:nth-child(4) { grid-column: 2; grid-row: 1 / span 2; align-self: center; text-align: right; }
  .catalog-table td:nth-child(5) { grid-column: 1; grid-row: 3; margin-top: 2px; font-size: 12px; }

  .mono { font-size: 11.5px; }
  .tag { min-height: 24px; }
  .empty-hint { padding: 18px 17px; }
  .footer { margin-top: 28px; }
}


/* =================================================
   Very small screens (≤ 390px)
================================================= */

@media (max-width: 390px) {
  .page { padding-left: 12px; padding-right: 12px; }
  .search--hero button { padding: 0 13px; }
  .search__icon { margin-left: 12px; }
  .search--hero input { min-width: 0; }
  .panel__head { padding-left: 15px; padding-right: 15px; }
  .catalog-table tr { padding-left: 15px; padding-right: 15px; }
}


/* =================================================
   Reduced motion
================================================= */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}