:root {
  --ink: #1c2733;
  --paper: #f3f5f7;
  --card: #ffffff;
  --line: #d8dee5;
  --sapphire: #24527a;
  --sapphire-soft: #e3ecf5;
  --muted: #5f6c79;
  --gain: #1f7a4a;
  --loss: #b23a32;
  --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--sapphire); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .6rem; }
h3 { font-size: .9rem; margin: 0 0 .5rem; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .85rem; }

.top { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
  padding: .8rem 1.5rem; background: var(--ink); color: #fff; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.gem { color: #8fb8de; }
.top nav { display: flex; gap: .3rem; flex-wrap: wrap; }
.top nav a { color: #c9d4df; text-decoration: none; padding: .4rem .8rem; border-radius: 6px; }
.top nav a.on, .top nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1.2rem; }
.btn { display: inline-block; border: 1px solid var(--sapphire); background: #fff; color: var(--sapphire); padding: .55rem 1rem;
  border-radius: 7px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--sapphire); color: #fff; }
.btn.ghost { border-color: var(--line); color: var(--muted); }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn.wide { width: 100%; padding: .8rem; font-size: 1rem; margin-top: .8rem; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn:focus-visible, .chip:focus-visible, .size:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid #8fb8de; outline-offset: 1px; }

label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .7rem; }
input, textarea { display: block; width: 100%; margin-top: .25rem; padding: .55rem .65rem; border: 1px solid var(--line);
  border-radius: 7px; font: inherit; color: var(--ink); background: #fff; }

.flash { padding: .7rem 1rem; border-radius: 7px; margin: 0 0 1rem; }
.flash.ok { background: #e3f3ea; color: var(--gain); }
.flash.bad { background: #f8e5e3; color: var(--loss); }
.empty { padding: 1.5rem; background: var(--card); border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); }
.empty.small { padding: 1rem; font-size: .9rem; }

.hero { display: grid; grid-template-columns: 1fr minmax(280px, 380px); gap: 1.5rem; align-items: start; }
.hero .big { font-size: 2.2rem; font-weight: 700; margin: .4rem 0 0; letter-spacing: -.02em; }
.hero .btn { margin-top: 1rem; }
.upload h2 { margin-top: 0; }

.row-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
.actions { display: flex; gap: .5rem; }
.search { display: flex; gap: .5rem; }
.search input { margin: 0; min-width: 220px; }

.scroll { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
table.grid { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.grid th, .grid td { padding: .55rem .8rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.grid th { background: #eef2f6; font-size: .85rem; color: var(--muted); }
.grid tfoot td { font-weight: 700; border-bottom: 0; }
.grid.compact td, .grid.compact th { padding: .35rem .6rem; font-size: .88rem; }
.r { text-align: right !important; }
.pos { color: var(--gain); }
.neg { color: var(--loss); }

/* Sell screen */
.sell { display: grid; grid-template-columns: 1fr minmax(320px, 420px); gap: 1.5rem; align-items: start; }
.picker { margin-top: 1rem; }
.step { margin-bottom: 1.3rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { border: 1px solid var(--line); background: #fff; padding: .45rem .8rem; border-radius: 999px; font: inherit; cursor: pointer; color: var(--ink); }
.chip.on { background: var(--sapphire); border-color: var(--sapphire); color: #fff; }
.sizes { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; }
.size { display: flex; flex-direction: column; align-items: flex-start; gap: .1rem; padding: .65rem .75rem; border: 1px solid var(--line);
  background: #fff; border-radius: 8px; cursor: pointer; font: inherit; color: var(--ink); text-align: left; }
.size:hover { border-color: var(--sapphire); background: var(--sapphire-soft); }
.size .sz { font-weight: 700; font-size: 1.05rem; }
.size .pr { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }

.memo { position: sticky; top: 1rem; }
.memo h2 { margin-top: 0; }
.line { border: 1px solid var(--line); border-radius: 8px; padding: .7rem; margin-bottom: .7rem; background: #fafbfc; }
.line-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .4rem; }
.line-body { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.line-body label { margin-bottom: .3rem; }
.line-foot { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; gap: .5rem; }
.x { border: 0; background: none; font-size: 1.3rem; line-height: 1; cursor: pointer; color: var(--muted); }
.pl { font-weight: 700; font-variant-numeric: tabular-nums; }
.pl.big { font-size: 1.5rem; }
.totals { border-top: 2px solid var(--ink); padding-top: .6rem; margin-top: .4rem; }
.totals > div { display: flex; justify-content: space-between; padding: .2rem 0; font-variant-numeric: tabular-nums; }
.totals .result { align-items: baseline; margin-top: .3rem; padding-top: .5rem; border-top: 1px solid var(--line); }

@media (max-width: 860px) {
  .hero, .sell { grid-template-columns: 1fr; }
  .memo { position: static; }
  main { padding: 1rem; }
}

/* ---------- v2: login, users, multi-select, mobile ---------- */
.top { flex-direction: column; flex-wrap: nowrap; align-items: stretch; padding: .6rem 1.5rem 0; padding-top: calc(.6rem + env(safe-area-inset-top, 0px)); }
.top-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding-bottom: .5rem; }
.top nav { overflow-x: auto; flex-wrap: nowrap; padding-bottom: .5rem; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.top nav a { white-space: nowrap; }
.logout { display: flex; align-items: center; gap: .6rem; margin: 0; font-size: .9rem; }
.who { color: #c9d4df; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linkbtn { background: none; border: 0; padding: .3rem; font: inherit; color: var(--sapphire); cursor: pointer; }
.top .linkbtn { color: #fff; text-decoration: underline; }
.small { font-size: .85rem; }
.login, .narrow { max-width: 420px; margin: 2rem auto; }
.check { display: flex; gap: .5rem; align-items: flex-start; color: var(--ink); }
.check input { width: auto; margin-top: .25rem; }
.two { display: grid; grid-template-columns: 1fr minmax(280px, 380px); gap: 1.5rem; align-items: start; }
.userrow { margin-bottom: .7rem; padding: .9rem; }
.userhead { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; margin-bottom: .5rem; }
.inline { display: flex; gap: .5rem; }
.inline input { margin: 0; }
.saved { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }

/* picker */
.step-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.badge { display: inline-block; min-width: 1.3em; margin-left: .35rem; padding: 0 .35em; border-radius: 999px; background: var(--gain); color: #fff; font-size: .75rem; font-weight: 700; text-align: center; }
.size { position: relative; min-height: 64px; }
.size.on { border-color: var(--sapphire); background: var(--sapphire-soft); box-shadow: inset 0 0 0 1px var(--sapphire); }
.size .tick { position: absolute; top: .35rem; right: .5rem; color: var(--sapphire); font-weight: 700; }
.pick-step { padding-bottom: 6rem; }
.selbar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(28,39,51,.08); transform: translateY(110%); transition: transform .2s ease; z-index: 20;
  padding-bottom: env(safe-area-inset-bottom, 0px); }
.selbar.show { transform: none; }
.selbar-row { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; gap: .8rem; padding: .7rem 1.5rem; }
.selbar-row .btn { margin-left: auto; }
.sellist { max-width: 1200px; margin: 0 auto; max-height: 40vh; overflow-y: auto; padding: .5rem 1.5rem 0; }
.selitem { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .35rem 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.selitem span:first-child { flex: 1; }

/* memo step */
.back { padding-left: 0; margin-bottom: .4rem; }
.memo-grid { display: grid; grid-template-columns: 1fr minmax(280px, 360px); gap: 1.5rem; align-items: start; margin-top: 1rem; }
.memo-grid > div > .card { margin-bottom: 1rem; }
.fields.three { display: grid; grid-template-columns: 2fr 1.3fr 1fr; gap: 0 .8rem; }
.fields.three label { margin-bottom: 0; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; background: var(--sapphire-soft); border-color: #c7d7e8; }
.quick-row { display: flex; align-items: flex-end; gap: .5rem; }
.quick-row label { flex: 1; margin: 0; }
.line { background: var(--card); }
.num { display: inline-block; min-width: 1.6em; color: var(--muted); font-weight: 400; }
.summary { position: sticky; top: 1rem; }
.summary h2 { margin-top: 0; }
@media (prefers-reduced-motion: reduce) { .selbar { transition: none; } }

/* phones */
@media (max-width: 860px) {
  .top { padding-left: 1rem; padding-right: 1rem; }
  .two, .memo-grid { grid-template-columns: 1fr; }
  .summary { position: sticky; bottom: 0; top: auto; border-radius: 12px 12px 0 0; margin: 0 -1rem; box-shadow: 0 -4px 16px rgba(28,39,51,.1); padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px)); }
  .summary h2 { display: none; }
  .totals > div:not(.result) { font-size: .9rem; padding: .05rem 0; }
  .fields.three { grid-template-columns: 1fr; }
  .fields.three label { margin-bottom: .7rem; }
  .quick { grid-template-columns: 1fr; }
  .sizes { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .selbar-row, .sellist { padding-left: 1rem; padding-right: 1rem; }
  .hero .big { font-size: 1.7rem; }
  h1 { font-size: 1.35rem; }
  input, textarea, select { font-size: 16px; } /* stops iPhone zooming in */
  .chip, .btn, .size { min-height: 44px; }
  .search { width: 100%; } .search input { min-width: 0; flex: 1; }
  .actions { width: 100%; } .actions .btn { flex: 1; text-align: center; }
  /* tables become cards */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tfoot, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border-bottom: 1px solid var(--line); padding: .5rem .2rem; }
  table.stack td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .2rem .6rem; white-space: normal; text-align: right; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-weight: 400; text-align: left; }
  table.stack td.hide-sm { display: none; }
  .scroll:has(table.stack) { overflow: visible; }
}
.top > * { min-width: 0; }
.brand { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout { flex-shrink: 0; }
@media (max-width: 520px) { .who { display: none; } }
@media (max-width: 860px) {
  .summary { padding-top: .6rem; }
  .summary .totals { border-top: 0; padding-top: 0; margin-top: 0; }
  .summary .totals > div:nth-child(1), .summary .totals > div:nth-child(2), .summary .totals > div:nth-child(4) { display: none; }
  .summary .totals .result { margin-top: 0; padding-top: .2rem; }
  .summary .pl.big { font-size: 1.25rem; }
  .summary .btn.wide { margin-top: .5rem; padding: .7rem; }
  .summary .hint { display: none; }
}
.code { font-weight: 700; color: var(--sapphire); margin-right: .25rem; }
.size .cd { font-size: .78rem; color: var(--sapphire); font-weight: 600; }

/* ---------- v4: review, roles ---------- */
.flash.warn { background: #fdf3df; color: #7a5410; }
.flash.info { background: var(--sapphire-soft); color: var(--sapphire); }
.flash ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.flash div { margin-top: .2rem; }
.review-top { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; margin: 1rem 0; }
.stat { display: flex; flex-direction: column; padding: .9rem 1rem; }
.stat .big { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat span:last-child { color: var(--muted); font-size: .85rem; }
.stat.warn { border-color: #e7c27a; background: #fdf8ec; }
.stat.good { border-color: #a9d6bb; background: #f1f9f4; }
.savebar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem; margin: 1rem 0; position: sticky; top: .5rem; z-index: 5; }
.savebar label { flex: 1; min-width: 220px; margin: 0; }
td.chg, span.chg { background: #fde9c4; font-weight: 700; }
select { padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 7px; font: inherit; background: #fff; color: var(--ink); }
.role { display: inline-block; padding: 0 .5em; border-radius: 4px; background: #eef2f6; color: var(--muted); font-weight: 600; }
.role.admin { background: var(--sapphire-soft); color: var(--sapphire); }
.userrow.off { opacity: .65; }
details summary { cursor: pointer; color: var(--sapphire); font-size: .9rem; padding: .2rem 0; }
.stack-form { margin: .6rem 0; }
@media (max-width: 860px) {
  .savebar { position: static; }
  .search select { flex: 1; }
  .search { flex-wrap: wrap; }
  .inline { flex-wrap: wrap; } .inline input { flex: 1; min-width: 0; }
}

/* ---------- v5: Mumbai / Overseas ---------- */
.markets { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; margin: .8rem 0 0; }
.market { display: flex; flex-direction: column; gap: .15rem; padding: .9rem 1rem; }
.market .mk { font-size: .8rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--sapphire); }
.market .big { font-size: 1.35rem !important; margin: 0 !important; }
.seg { border: 0; padding: 0; margin: 0 0 .8rem; display: flex; flex-wrap: wrap; gap: .5rem; }
.seg legend { font-size: .85rem; color: var(--muted); margin-bottom: .3rem; padding: 0; }
.seg label { display: flex; align-items: center; gap: .4rem; margin: 0; padding: .5rem .9rem; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); cursor: pointer; }
.seg input { width: auto; margin: 0; }
.seg label:has(input:checked) { background: var(--sapphire); border-color: var(--sapphire); color: #fff; }
.tag { display: inline-block; padding: 0 .5em; border-radius: 4px; font-size: .8rem; font-weight: 700; }
.tag.mum { background: #f6e7d8; color: #8a4b12; }
.tag.ovs { background: var(--sapphire-soft); color: var(--sapphire); }
tr.old td { color: var(--muted); }
.savebar label.grow { flex: 2; }
.savebar select, .savebar input[type=month] { display: block; width: 100%; margin-top: .25rem; padding: .55rem .65rem; }
.blocks { margin: 1rem 0; padding: .8rem 1rem; }
.blocks .scroll { margin-top: .6rem; }
/* sell: price source picker */
.source { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem; padding: .9rem 1rem; margin: .8rem 0 1rem; }
.source .seg { margin: 0; }
.source label.month { margin: 0; min-width: 190px; }
.source select { display: block; width: 100%; margin-top: .25rem; padding: .55rem .65rem; min-height: 44px; }
.srcline { display: inline-flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

/* ---------- v6: two sites, calculator, code names, sending ---------- */
.site { display: inline-block; padding: .05rem .45rem; border-radius: 4px; font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; vertical-align: middle; }
.site.mum { background: #f6e7d8; color: #8a4b12; }
.site.ovs { background: #dce8f4; color: #24527a; }
.sendbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .8rem 1rem; margin: 0 0 1rem; }
.sendbar .hint { flex-basis: 100%; margin: .2rem 0 0; }
.calc { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; margin-top: 1rem; align-items: start; }
.calc h2 { margin-top: 0; }
.quick-pct { display: flex; flex-wrap: wrap; gap: .35rem; margin: -.2rem 0 .8rem; }
.quick-pct .chip { padding: .3rem .6rem; font-variant-numeric: tabular-nums; }
.result { padding: .7rem .8rem; border-radius: 8px; background: #f3f5f7; line-height: 1.6; font-variant-numeric: tabular-nums; }
.result:empty { display: none; }
.result.pos { background: #e3f3ea; color: var(--gain); }
.result.neg { background: #f8e5e3; color: var(--loss); }
.pickgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .6rem; margin-top: .6rem; }
.pickgrid select { display: block; width: 100%; margin-top: .25rem; min-height: 40px; }
.codeform { padding: 1rem; }
.codehead { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem; }
.codehead label { margin: 0; }
.codehead .btn { margin-left: auto; }
#codetable input { margin: 0; padding: .4rem .5rem; }
.history { margin-top: 1rem; padding: .8rem 1rem; }
@media (max-width: 860px) {
  .codehead .btn { margin-left: 0; width: 100%; }
  #codetable td[data-label="New name"] { display: block; }
  #codetable td[data-label="New name"]::before { display: block; margin-bottom: .2rem; }
}
.size .nm { font-size: .75rem; color: var(--ink); line-height: 1.2; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.nm-line { font-weight: 700; margin-right: .3rem; }
.totals .ro { font-size: .9rem; color: var(--muted); }
.totals .net strong { font-size: 1.05rem; }
.grid tfoot tr.subtot td { font-weight: 400; border-top: 0; padding-top: .2rem; padding-bottom: .2rem; }
@media (max-width: 860px) { .summary .totals > div.ro, .summary .totals > div.net { display: flex !important; } }
@media (max-width: 860px) { .summary .totals > div.lv { display: none !important; } }