body.owner { background: var(--surface-2); }
body.modal-open { overflow: hidden; }
body.owner .modal-backdrop { z-index: 80; }

.layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 24px; padding: 22px 14px; border-right: 1px solid var(--line); background: var(--surface); }
.sidebar .logo { padding: 0 10px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); text-decoration: none; color: var(--ink-2); font-weight: 500; }
.sidebar nav a svg { width: 18px; height: 18px; flex: none; }
.sidebar nav a:hover { background: var(--surface-2); color: var(--ink); }
.sidebar nav a.active { background: var(--ink); color: #fff; }
.sidebar .count { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--sale); color: #fff; font-size: 11px; line-height: 20px; text-align: center; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 0 10px; }
.owner-lang .lang-switch { margin: 0; }
.content { padding: 30px 32px 60px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 30px; }
.page-head select { width: auto; max-width: 100%; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { padding: 16px 18px; min-width: 0; }
.kpi .label { font-size: 13px; color: var(--ink-2); }
.kpi .value { font: 500 26px var(--serif); margin: 4px 0 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.delta { font-size: 12px; font-weight: 600; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--danger); }
.delta.flat { color: var(--ink-3); }

.dash-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 18px; margin-bottom: 18px; }
.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: #d9d6cf; cursor: pointer; transition: fill 0.15s; }
.chart .bar:hover { fill: #b3afa6; }
.chart .bar.sel { fill: var(--accent); }
.chart text { font: 11px var(--sans); fill: var(--ink-3); }
.chart .val { fill: var(--ink); font-weight: 600; }
.chart .grid-line { stroke: var(--line); }
.hbar { margin-bottom: 12px; }
.hbar .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.hbar .track { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.hbar .fill { height: 100%; background: var(--accent); border-radius: 99px; }
.attention li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.attention li:last-child { border-bottom: 0; }
.attention { list-style: none; margin: 0; padding: 0; }

table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 500; color: var(--ink-3); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; padding: 0 12px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #fafaf8; }
.table-wrap { overflow-x: auto; }
.item-mini { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.item-mini img { width: 30px; height: 36px; object-fit: cover; border-radius: 4px; flex: none; }
.thumb-sm { width: 48px; height: 60px; border-radius: 6px; object-fit: cover; background: var(--surface-2); flex: none; }
.pill-off { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-3); margin-left: 6px; }
.status-select { width: auto; padding: 6px 10px; font-size: 13px; }

/* Product list (works the same on desktop and phones) */
.product-list { display: flex; flex-direction: column; }
.product-row {
  display: grid; grid-template-columns: 48px minmax(0, 1fr) auto auto auto; gap: 16px; align-items: center; width: 100%;
  padding: 12px 6px; border: 0; border-bottom: 1px solid var(--line); background: none; font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.product-row:last-child { border-bottom: 0; }
.product-row:hover { background: #fafaf8; }
.pr-main { display: flex; flex-direction: column; min-width: 0; }
.pr-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pr-price { display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; }
.pr-stock { font-size: 13px; white-space: nowrap; }
.pr-edit { font: 500 13px var(--display); text-transform: uppercase; letter-spacing: 0.05em; }

/* Order detail */
.order-modal { max-width: 760px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 6px 0 18px; }
.detail-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; overflow-wrap: anywhere; }
.detail-box h4, .detail-h { margin: 0 0 8px; font: 600 12px var(--sans); text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-3); }
.contact-line { font-size: 14px; margin-top: 6px; }
.contact-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.order-products { border: 1px solid var(--line); border-radius: var(--radius); }
.op-row { display: grid; grid-template-columns: 72px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.op-row:last-child { border-bottom: 0; }
.op-row img, .op-img { width: 72px; height: 90px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.op-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.op-total { font-variant-numeric: tabular-nums; }
.order-sum { max-width: 320px; margin: 14px 0 0 auto; }

.inbox { display: grid; grid-template-columns: 300px minmax(0, 1fr); height: calc(100vh - 130px); min-height: 460px; overflow: hidden; }
.conv-list { border-right: 1px solid var(--line); overflow-y: auto; }
.conv { display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; font: inherit; color: inherit; cursor: pointer; }
.conv:hover { background: var(--bg); }
.conv.active { background: var(--accent-soft); }
.conv img { width: 42px; height: 50px; border-radius: 6px; object-fit: cover; flex: none; }
.conv-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.conv .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv-topic { font-size: 12px; font-weight: 600; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.conv .preview { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.conv.unread .name, .conv.unread .preview { font-weight: 600; color: var(--ink); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--sale); margin-right: 6px; }
.ti-icon { width: 42px; height: 42px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; flex: none; }
.ti-icon svg { width: 20px; height: 20px; }
.thread { display: flex; flex-direction: column; min-width: 0; background: #fff; }
.thread .chat-head { gap: 6px; padding: 10px 14px 10px 6px; }
.thread .chat-head .grow { flex: 1; min-width: 0; line-height: 1.35; }
.thread .chat-head .small, .thread .chat-head a { color: #d8d6d0; overflow-wrap: anywhere; }
.topic-bar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fff; }
.topic-bar img { width: 42px; height: 50px; border-radius: 6px; object-fit: cover; flex: none; }
.tb-main { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 14px; }
.tb-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic-bar .btn { flex: none; }
.contact-line { display: flex; align-items: center; gap: 8px; }
.contact-line svg { width: 16px; height: 16px; color: var(--ink-3); flex: none; }
.ship-box { margin-bottom: 18px; }
.ship-box .kv { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 10px; font-size: 14px; margin-bottom: 8px; }
.ship-box .kv > span:first-child { color: var(--ink-3); }
.ship-box .kv .link-btn { margin-left: 10px; }
.ship-box .resi { letter-spacing: 0.03em; }
.ship-form { display: grid; grid-template-columns: 180px minmax(0, 1fr) auto; gap: 8px; margin-top: 8px; }
.ship-form .btn { height: 44px; }

.upload { display: flex; gap: 14px; align-items: center; }
.upload .preview { width: 88px; height: 110px; border-radius: var(--radius-sm); background: var(--surface-2); object-fit: cover; flex: none; border: 1px dashed var(--line); }
.field-label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; color: var(--ink-2); }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.photo-tile { position: relative; aspect-ratio: 4 / 5; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; }
.photo-main { position: absolute; left: 6px; top: 6px; font: 600 10px/1 var(--sans); text-transform: uppercase; letter-spacing: 0.05em; background: var(--ink); color: #fff; padding: 4px 6px; border-radius: 4px; }
.photo-actions { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; padding: 4px; background: linear-gradient(transparent, rgba(0,0,0,0.55)); }
.photo-actions button { width: 28px; height: 28px; border: 0; border-radius: 999px; background: rgba(255,255,255,0.92); color: var(--ink); font-size: 15px; line-height: 1; cursor: pointer; }
.photo-actions button:disabled { opacity: 0.3; cursor: default; }
.photo-add {
  aspect-ratio: 4 / 5; border: 1.5px dashed #cfccc6; border-radius: 8px; background: #fff; color: var(--ink-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font: 300 30px/1 var(--sans); cursor: pointer;
}
.photo-add span { font: 500 12px var(--sans); }
.photo-add:hover { border-color: var(--ink); color: var(--ink); }
.new-cat { border: 1px dashed #cfccc6; border-radius: var(--radius); padding: 14px 14px 10px; margin: -4px 0 14px; }
.banner-preview { width: 100%; aspect-ratio: 16 / 6; border-radius: var(--radius-sm); background: var(--ink) center / cover; margin-bottom: 10px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 14px; }
.check input { width: auto; }

@media (max-width: 960px) {
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Phones: top bar with logo and language, bottom tab bar for the sections. */
@media (max-width: 760px) {
  .layout { display: block; min-height: 0; }
  .sidebar {
    position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; gap: 10px;
    padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .sidebar .logo { padding: 0; font-size: 20px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .side-foot { margin: 0; flex-direction: row; align-items: center; gap: 12px; padding: 0; }
  .side-foot #owner-who, .side-foot a.small { display: none; }
  .sidebar nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; flex-direction: row; gap: 0; background: #fff;
    border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -4px 20px rgba(0,0,0,0.05);
  }
  .sidebar nav a {
    flex: 1; flex-direction: column; gap: 3px; padding: 8px 2px 7px; border-radius: 0; font-size: 10.5px; text-align: center;
    color: var(--ink-3); min-width: 0;
  }
  .sidebar nav a span:not(.count) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .sidebar nav a svg { width: 22px; height: 22px; }
  .sidebar nav a.active { background: none; color: var(--ink); }
  .sidebar nav a.active::before { content: ''; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; background: var(--ink); border-radius: 0 0 3px 3px; }
  .sidebar .count { position: absolute; top: 4px; left: calc(50% + 6px); margin: 0; min-width: 18px; height: 18px; line-height: 18px; font-size: 10px; }

  .content { padding: 18px 14px 96px; }
  .page-head { margin-bottom: 16px; }
  .page-head h1 { font-size: 24px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi .value { font-size: 20px; }
  .card.pad { padding: 16px; }

  /* Tables become one card per row, each cell labelled. */
  .table.stack thead { display: none; }
  .table.stack, .table.stack tbody, .table.stack tr, .table.stack td { display: block; width: 100%; }
  .table.stack tr { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; background: #fff; }
  .table.stack td { border: 0; padding: 6px 0; text-align: left; overflow-wrap: anywhere; }
  .table.stack td::before { content: attr(data-label); display: block; margin-bottom: 2px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-3); }
  .table.stack td:first-child { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 4px; }
  .table.stack td:first-child::before { display: none; }
  .table.stack td.num { text-align: left; }
  .card.pad:has(> .table-wrap > .table.stack) { background: none; border: 0; padding: 0; }

  .product-row { grid-template-columns: 48px minmax(0, 1fr) auto; grid-template-areas: 'img main price' 'img stock edit'; row-gap: 4px; }
  .product-row .thumb-sm { grid-area: img; }
  .pr-main { grid-area: main; }
  .pr-price { grid-area: price; }
  .pr-stock { grid-area: stock; }
  .pr-edit { grid-area: edit; justify-self: end; }

  .modal-backdrop { padding: 0; }
  .modal-backdrop > .modal { max-width: none; min-height: 100%; border-radius: 0; border: 0; }
  .detail-grid { grid-template-columns: 1fr; }
  .op-row { grid-template-columns: 56px minmax(0, 1fr); }
  .op-row img, .op-img { width: 56px; height: 70px; }
  .op-total { grid-column: 2; }
  .order-sum { max-width: none; }

  .inbox { grid-template-columns: 1fr; height: auto; min-height: 0; }
  .inbox.has-thread .conv-list { display: none; }
  .inbox:not(.has-thread) .thread { display: none; }
  /* An open conversation fills the whole phone screen; "back" returns to the list. */
  body.thread-open { overflow: hidden; }
  body.thread-open .thread { position: fixed; inset: 0; z-index: 70; height: auto; padding-bottom: env(safe-area-inset-bottom); }
  .ship-form { grid-template-columns: 1fr; }
  .ship-box .kv { grid-template-columns: 100px minmax(0, 1fr); }
}
