/* Optional Portal: one hand-written stylesheet (PoC). Monochrome, after Niel's prototype. */

:root {
  --ink: #171717;
  --ink-soft: #3a3a3a;
  --muted: #6b6b6b;
  --line: #d9d9d9;
  --line-soft: #ebebeb;
  --header: #f2f2f2;
  --hover: #f7f7f7;
  --page: #ffffff;
  --danger: #8a1c1c;
  --radius: 4px;
  --sidebar: 300px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 15px/1.5 var(--font); }
p { margin: 0; }
a { color: inherit; }
h1, h2 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 36px; line-height: 1.15; }
h2 { font-size: 18px; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 600; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 20px; height: 20px; flex: none; }

/* --- shell ------------------------------------------------------------------------- */

.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--page); }
.sidebar__head { display: flex; align-items: center; gap: var(--s3); height: 72px; padding: 0 var(--s5); border-bottom: 1px solid var(--line); }
.product-name { font-weight: 700; text-transform: uppercase; letter-spacing: 0.14em; font-size: 15px; }
.nav { flex: 1; overflow-y: auto; padding: var(--s4) var(--s3); }
.nav__label { margin: var(--s4) var(--s3) var(--s2); font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.nav__label:first-child { margin-top: var(--s2); }
.nav__item { display: flex; align-items: center; gap: var(--s3); padding: 10px var(--s3); border-radius: var(--radius); text-decoration: none; color: var(--ink-soft); }
.nav__item:hover { background: var(--hover); color: var(--ink); }
.nav__item.is-active { background: var(--header); color: var(--ink); font-weight: 600; }
.nav__note { margin: var(--s5) var(--s3) 0; font-size: 12px; color: var(--muted); }
.sidebar__foot { padding: var(--s4) var(--s5); border-top: 1px solid var(--line); display: grid; gap: 2px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: var(--s3); height: 72px; padding: 0 var(--s6); border-bottom: 1px solid var(--line); }
.crumb { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb a { text-decoration: none; }
.crumb a:hover { text-decoration: underline; }
.crumb a:not(:first-child) { text-decoration: underline; text-underline-offset: 3px; }
.topbar__search input { width: 340px; max-width: 100%; height: 40px; padding: 0 var(--s3); border: 1px solid var(--line); border-radius: var(--radius); font: inherit; }
.content { padding: var(--s6); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s5); align-content: start; max-width: 1400px; width: 100%; }
/* Grid items default to min-width:auto, so a wide table would push the page wider instead of
   scrolling inside its panel. */
.content > * { min-width: 0; }

/* --- menus (<details>, no JS) ---------------------------------------------------------- */

.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu__panel { position: absolute; z-index: 10; top: calc(100% + 6px); left: 0; min-width: 240px; padding: var(--s3); background: var(--page); border: 1px solid var(--line); border-radius: var(--radius); display: grid; gap: var(--s2); }
.menu--right .menu__panel { left: auto; right: 0; }
.menu__label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin-top: var(--s2); }
.menu__item { display: flex; justify-content: space-between; gap: var(--s3); padding: var(--s2); border-radius: var(--radius); text-decoration: none; }
.menu__item:hover { background: var(--hover); }
.menu__item.is-active { background: var(--header); font-weight: 600; }
.menu__item.is-disabled { color: var(--muted); cursor: not-allowed; }
.menu__item.is-disabled:hover { background: none; }

.icon-button { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--page); color: var(--ink); text-decoration: none; }
.icon-button:hover, .icon-button.is-active { background: var(--header); }
.avatar-button { display: inline-flex; align-items: center; gap: var(--s1); }
.avatar { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--header); border: 1px solid var(--line); font-weight: 600; }
.caret { font-size: 11px; color: var(--muted); }

/* --- page parts -------------------------------------------------------------------- */

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s4); flex-wrap: wrap; }
.page-head > * { min-width: 0; max-width: 100%; }
.subtitle { margin-top: var(--s2); color: var(--muted); font-size: 16px; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); height: 40px; padding: 0 var(--s4); border: 1px solid var(--ink); border-radius: var(--radius); background: var(--page); color: var(--ink); font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap; }
.button:hover { background: var(--header); }
.button--primary { background: var(--ink); color: #fff; height: 48px; padding: 0 var(--s5); font-size: 16px; }
.button--primary:hover { background: #000; }
.sell-form .button--primary { height: 40px; padding: 0 var(--s4); font-size: 15px; }
.button--block { width: 100%; }

.input { height: 40px; padding: 0 var(--s3); border: 1px solid var(--line); border-radius: var(--radius); font: inherit; background: var(--page); color: var(--ink); min-width: 0; }
.input:focus-visible { border-color: var(--ink); }
.input--qty { width: 72px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s4); }
.stats--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s5); display: grid; gap: var(--s2); }
.stat__label { color: var(--muted); }
.stat__value { font-size: 30px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat__value--text { font-size: 22px; }
.stat__caption { font-size: 13px; color: var(--muted); }

/* position: relative keeps visually-hidden text inside a scrolled table from widening the page. */
.panel { position: relative; border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; min-width: 0; }
/* Panels whose rows open "…" menus: a scrolling panel would clip them, so they only scroll on
   narrow screens, where the menus fit anyway. */
.panel--menus { overflow: visible; }
.panel__head { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); padding: var(--s4) var(--s5); background: var(--header); border-bottom: 1px solid var(--line); }
.panel__head a { text-decoration: underline; text-underline-offset: 3px; }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); padding: var(--s3) var(--s5); border-bottom: 1px solid var(--line); white-space: nowrap; }
.panel > .table:first-child th { background: var(--header); }
.table td { padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--hover); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Codes, money, dates and badges never wrap; names wrap to two lines at most. */
.table td.mono, .table td .mono, .table .nowrap, .table .badge { white-space: nowrap; }
.table .cell-name { min-width: 160px; }
.table--compact th, .table--compact td { padding-left: var(--s3); padding-right: var(--s3); }
.table--compact th:first-child, .table--compact td:first-child { padding-left: var(--s5); }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.table .empty { text-align: center; color: var(--muted); padding: var(--s6) var(--s5); }
.table .empty:hover, .table tbody tr:hover td.empty { background: none; }
.link { text-decoration: underline; text-underline-offset: 3px; }
.row-action { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--muted); }
.row-action:hover { background: var(--header); color: var(--ink); }

.badge { display: inline-block; padding: 1px var(--s2); border: 1px solid var(--ink); border-radius: var(--radius); font-size: 13px; line-height: 1.5; white-space: nowrap; }
.badge--dashed { border-style: dashed; border-color: var(--muted); color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip { display: inline-block; padding: 2px var(--s2); border: 1px solid var(--line); border-radius: var(--radius); font-size: 13px; }
.chip-button { display: inline-flex; align-items: center; gap: var(--s2); height: 40px; padding: 0 var(--s4); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; }
.chip-button:hover { background: var(--hover); }
.chip-button.is-selected { background: var(--header); border-color: var(--ink); font-weight: 600; }
.chip-button .count { color: var(--muted); font-size: 13px; font-weight: 400; }

.searchbar, .filters { display: flex; gap: var(--s3); flex-wrap: wrap; }
.searchbar .input { flex: 1; height: 48px; border-color: var(--ink); }
.searchbar .button { height: 48px; }
.filters .input[type="search"] { flex: 1 1 280px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--s4); }
.card { border: 1px solid var(--line); border-top-width: 8px; border-top-color: var(--header); border-radius: var(--radius); padding: var(--s5); display: grid; gap: var(--s3); align-content: start; }
.card:hover { border-color: var(--ink); border-top-color: var(--ink); }
.card__title { font-size: 19px; }
.card__title a { text-decoration: none; }
.card__title a:hover { text-decoration: underline; }
.card__price { font-size: 18px; font-weight: 600; padding-top: var(--s3); border-top: 1px solid var(--line-soft); }
.sell-form, .inline-form { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.sell-form .button--primary { flex: 1; }
.inline-form .input { flex: 1 1 220px; }

.empty-state { grid-column: 1 / -1; border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s7) var(--s5); text-align: center; display: grid; gap: var(--s2); }
.empty-state--dashed { border-style: dashed; }

.messages { display: grid; gap: var(--s2); }
.message { padding: var(--s3) var(--s4); border: 1px solid var(--ink); border-radius: var(--radius); }
.message--error { border-color: var(--danger); color: var(--danger); }

/* --- sign in ----------------------------------------------------------------------- */

.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--s4); }
.auth__card { width: 100%; max-width: 400px; border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s6); display: grid; gap: var(--s4); }
.auth__card h1 { font-size: 28px; }
.auth__card label { display: grid; gap: var(--s1); font-weight: 500; }
.auth__card .input { width: 100%; height: 44px; }
.auth__card .button--primary { width: 100%; }

/* --- phone ------------------------------------------------------------------------- */

@media (max-width: 1440px) {
  .table th, .table td { padding-left: var(--s4); padding-right: var(--s4); }
  .table--compact th, .table--compact td { padding-left: var(--s3); padding-right: var(--s3); }
  .table th:first-child, .table td:first-child { padding-left: var(--s5); }
}
@media (max-width: 1360px) {
  .panel--menus { overflow-x: auto; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar__head { height: 60px; padding: 0 var(--s4); }
  .nav { display: flex; flex-wrap: wrap; gap: var(--s1); padding: var(--s2) var(--s3); }
  .nav__label, .nav__note { display: none; }
  .nav__item { padding: 6px var(--s2); }
  .sidebar__foot { display: none; }
  .topbar { height: auto; flex-wrap: wrap; padding: var(--s3) var(--s4); }
  .crumb { flex-basis: 100%; }
  .topbar__search { flex: 1; }
  .topbar__search input { width: 100%; }
  .content { padding: var(--s5) var(--s4); }
  h1 { font-size: 28px; }
  .stats, .stats--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table th, .table td { padding-left: var(--s3); padding-right: var(--s3); }
}
@media (max-width: 480px) {
  .stats, .stats--3 { grid-template-columns: 1fr; }
}

/* --- error pages (403, 404, 500) ---------------------------------------------------- */

.error-page { display: grid; gap: var(--s3); justify-items: start; max-width: 560px; }
.content > .error-page { padding: var(--s6) 0; }
.error-page__code { font-size: 14px; color: var(--muted); letter-spacing: 0.1em; }
