/* Provenian PWA — v1 read-only inventory. Mobile-first; two-pane at >=800px. */
:root {
  --bg: #1a1a2e;
  --panel: #22223a;
  --panel2: #2a2a48;
  --text: #eee;
  --muted: #9a9ab5;
  --accent: #e63946;
  --green: #4caf7d;
  --blue: #5b8dd9;
  --orange: #d99a5b;
  --purple: #9a6fd9;
  --red: #d95b5b;
  --gray: #77778f;
  --radius: 10px;
}
* { box-sizing: border-box; }
a, a:visited { color: var(--accent); }
body {
  font-family: system-ui, -apple-system, sans-serif;
  margin: 0; background: var(--bg); color: var(--text);
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }

/* ---------- login + forced password change ---------- */
#view-login, #view-change-password {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 2rem;
}
#view-login img.logo, #view-change-password img.logo {
  width: min(44vw, 168px); border-radius: 50%;
}
#view-login h1, #view-change-password h1 { margin: 1.2rem 0 .3rem; font-size: 1.4rem; }
#view-login p, #view-change-password p { color: var(--muted); margin: 0 0 1.4rem; }
#view-change-password .muted { margin-bottom: 1.4rem; }
#login-form { display: flex; gap: .5rem; width: min(92vw, 340px); }
#login-form input {
  flex: 1; font-size: 1.05rem; padding: .7rem .9rem;
  border: 1px solid var(--panel2); border-radius: var(--radius);
  background: var(--panel); color: var(--text);
}
#login-error { color: var(--red); margin-top: .8rem; min-height: 1.4em; }
#change-password-form {
  display: flex; flex-direction: column; gap: .5rem; width: min(92vw, 340px);
}
#change-password-form input {
  font-size: 1.05rem; padding: .7rem .9rem;
  border: 1px solid var(--panel2); border-radius: var(--radius);
  background: var(--panel); color: var(--text);
}
#change-password-error { color: var(--red); margin-top: .8rem; min-height: 1.4em; }

/* ---------- header ---------- */
header {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .9rem; background: var(--panel);
  position: sticky; top: 0; z-index: 20;
  border-bottom: 1px solid var(--panel2);
}
header img.logo { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; }
header .brand { flex: 1; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header .brand strong { display: block; font-size: 1.05rem; }
header .brand em { display: block; font-size: .68rem; color: var(--muted); font-style: italic; }

/* system menu (⋮) */
.menuwrap { position: relative; }
#menu-dropdown {
  position: absolute; right: 0; top: calc(100% + .3rem);
  background: var(--panel2); border: 1px solid var(--panel2);
  border-radius: var(--radius); min-width: 10rem; z-index: 50;
  box-shadow: 0 .4rem 1rem rgba(0,0,0,.35);
}
#menu-dropdown button {
  display: block; width: 100%; text-align: left;
  background: transparent; color: var(--text); border-radius: 0;
}
#menu-dropdown button:hover { background: var(--panel); }
button {
  font-size: .95rem; padding: .55rem 1rem; border: 0; border-radius: var(--radius);
  background: var(--accent); color: #fff; cursor: pointer;
}
button.ghost { background: var(--panel2); }
button:active { transform: scale(.97); }

/* ---------- tile bar (status counts; financial tiles live on the future
   business-analysis page, not here) ---------- */
#tiles, #c-tiles {
  display: flex; gap: .6rem; padding: .7rem .9rem; overflow-x: auto;
  background: var(--panel); border-bottom: 1px solid var(--panel2);
}
.tile {
  flex: 1 0 auto; background: var(--panel2); border-radius: var(--radius);
  padding: .5rem .8rem; min-width: 7.5rem; text-align: left;
  border: 2px solid transparent; color: var(--text);
}
.tile .k { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; display: block; }
.tile .v { font-size: 1.15rem; font-weight: 600; }
.tile[aria-pressed="true"] { border-color: var(--accent); }

/* ---------- controls ---------- */
#controls, #c-controls, #o-controls {
  display: flex; flex-wrap: wrap; gap: .5rem; padding: .7rem .9rem;
  position: sticky; top: 61px; z-index: 10; background: var(--bg);
}
#controls input[type=search], #controls select,
#c-controls input[type=search], #c-controls select,
#o-controls input[type=search], #o-controls select {
  font-size: .95rem; padding: .55rem .7rem; border-radius: var(--radius);
  border: 1px solid var(--panel2); background: var(--panel); color: var(--text);
}
#q, #c-q, #o-q { flex: 1 1 12rem; }
#category-filter, #sort, #density, #tile-preset, #o-type { flex: 0 1 auto; }

/* ---------- layout: list + detail ---------- */
#layout { display: block; }
#list, #c-list, #o-list { list-style: none; margin: 0; padding: .4rem .9rem 4rem; }
#list li, #c-list li, #o-list li {
  background: var(--panel); border-radius: var(--radius);
  padding: .7rem .9rem; margin-bottom: .5rem; cursor: pointer;
  border: 1px solid transparent;
}
#list li:active, #c-list li:active, #o-list li:active { border-color: var(--accent); }
#list li.selected, #c-list li.selected, #o-list li.selected { border-color: var(--blue); }
.item-top { display: flex; gap: .5rem; align-items: baseline; }
.item-desc { font-weight: 600; flex: 1; }
.item-meta { color: var(--muted); font-size: .82rem; margin-top: .25rem; }
.item-money { font-size: .85rem; margin-top: .3rem; display: flex; gap: .9rem; flex-wrap: wrap; }
.badge {
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  padding: .18rem .55rem; border-radius: 99px; white-space: nowrap;
}
.st0 { background: #274060; color: #9ec5ff; }
.st1 { background: #1f4433; color: #7fd6a4; }
.st2 { background: #3a3a48; color: #b9b9cc; }
.st3 { background: #3d2b52; color: #c4a5f0; }
.st4 { background: #4d3a22; color: #f0c48f; }
.st5 { background: #4d2222; color: #f09a9a; }
#more, #c-more, #o-more { display: block; margin: 0 auto 3rem; }

/* ---------- list density: compact = single-line rows ---------- */
body.density-compact #list li, body.density-compact #c-list li,
body.density-compact #o-list li { padding: .4rem .7rem; }
body.density-compact #list .item-meta,
body.density-compact #list .item-money,
body.density-compact #c-list .item-meta,
body.density-compact #c-list .item-money,
body.density-compact #o-list .item-meta,
body.density-compact #o-list .item-money { display: none; }
body.density-compact #list .item-desc,
body.density-compact #c-list .item-desc,
body.density-compact #o-list .item-desc {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

#detail, #c-detail, #o-detail {
  padding: .9rem; background: var(--bg);
}
#detail .card, #c-detail .card, #o-detail .card {
  background: var(--panel); border-radius: var(--radius); padding: 1rem; margin-bottom: .7rem;
}
#detail h2, #c-detail h2, #o-detail h2 { margin: 0 0 .4rem; font-size: 1.15rem; }
#detail h3, #c-detail h3, #o-detail h3 { margin: 0 0 .5rem; font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .3rem .9rem; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.money-grid { display: flex; gap: 1.4rem; flex-wrap: wrap; font-size: .92rem; }
.money-grid .amt { font-size: 1.25rem; font-weight: 700; }
#back-btn, #c-back-btn, #o-back-btn { margin-bottom: .7rem; }
#detail-empty, #c-detail-empty, #o-detail-empty {
  color: var(--muted); text-align: center; padding: 4rem 2rem; display: none;
}

/* ---------- two-pane >= 800px (foldables unfolded / tablet / desktop) ----------
   Catches Pixel Fold unfolded (~884px) and iPhone Duo unfolded (~890pt);
   folded states and phones stay single-column. Width-only: no hinge APIs. */
@media (min-width: 800px) {
  #layout, #c-layout, #o-layout { display: grid; grid-template-columns: minmax(340px, 430px) 1fr; align-items: start; }
  #list-pane, #c-list-pane, #o-list-pane { max-height: calc(100dvh - 220px); overflow-y: auto; }
  #detail, #c-detail, #o-detail { max-height: calc(100dvh - 220px); overflow-y: auto; }
  #detail-empty, #c-detail-empty, #o-detail-empty { display: block; }
  #back-btn, #c-back-btn, #o-back-btn { display: none; }
  #detail .kv, #c-detail .kv, #o-detail .kv { grid-template-columns: 11rem 1fr; }
}
/* on narrow screens the detail pane is hidden until an item is picked */
@media (max-width: 799px) {
  body.showing-detail #list-pane, body.showing-detail #controls, body.showing-detail #tiles { display: none; }
  body.showing-c-detail #c-list-pane, body.showing-c-detail #c-controls, body.showing-c-detail #c-tiles { display: none; }
  body.showing-o-detail #o-list-pane, body.showing-o-detail #o-controls { display: none; }
  body:not(.showing-detail) #detail-pane { display: none; }
  body:not(.showing-c-detail) #c-detail-pane { display: none; }
  body:not(.showing-o-detail) #o-detail-pane { display: none; }
}

/* ---------- contacts + organizations views ---------- */
#mainnav { display: flex; gap: .35rem; }
.navbtn {
  background: transparent; color: var(--muted);
  border: 1px solid var(--panel2); padding: .45rem .8rem;
  font-size: .85rem;
}
.navbtn.active { color: var(--text); border-color: var(--accent); background: var(--panel2); }

/* role badges (derived, never entered) */
.r-buyer { background: #1f4433; color: #7fd6a4; }
.r-seller { background: #274060; color: #9ec5ff; }
.r-trader { background: #3d2b52; color: #c4a5f0; }
.r-prospect { background: #3a3a48; color: #b9b9cc; }
.r-customer { background: #1f4433; color: #7fd6a4; }

/* want status badges */
.w-active { background: #1f4433; color: #7fd6a4; }
.w-fulfilled { background: #274060; color: #9ec5ff; }
.w-withdrawn { background: #3a3a48; color: #b9b9cc; }

/* readable links: body-text color + underline, never default blue */
#c-detail a[href], #o-detail a[href], .hist a[href] {
  color: var(--text); text-decoration: underline;
}

/* contact detail header: name + prominent Edit */
.chead { display: flex; justify-content: space-between; align-items: flex-start; gap: .6rem; }
.chead h2 { margin: 0 0 .3rem; }

/* listing price visible in compact rows (secondary meta stays hidden) */
.item-price { display: none; font-size: .85rem; color: var(--muted); margin-left: auto; }
body.density-compact .item-price { display: inline; }

/* wants */
.want { border-top: 1px solid var(--panel2); padding: .5rem 0; }
.want:first-child { border-top: 0; }
.want-top { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.want-desc { font-weight: 600; }
.want-meta { font-size: .8rem; margin: .15rem 0 .3rem; }

/* merge conflict resolution */
.merge-field { border-top: 1px solid var(--panel2); padding: .5rem 0; }
.merge-label { font-size: .75rem; color: var(--muted); text-transform: uppercase;
  letter-spacing: .04em; margin-bottom: .25rem; }
.merge-field label { display: block; padding: .2rem 0; cursor: pointer; }
.merge-who { font-size: .75rem; color: var(--muted); text-transform: uppercase;
  letter-spacing: .04em; margin: 0 .35rem 0 .3rem; }

/* organization type badges */
.t-repair { background: #4d3a22; color: #f0c48f; }
.t-retail { background: #274060; color: #9ec5ff; }
.t-platform { background: #3d2b52; color: #c4a5f0; }
.t-band { background: #1f4433; color: #7fd6a4; }
.t-other { background: #3a3a48; color: #b9b9cc; }

/* transaction history rows */
.hist { list-style: none; margin: .6rem 0 0; padding: 0; }
.hist li {
  display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap;
  padding: .45rem 0; border-top: 1px solid var(--panel2); font-size: .88rem;
}
.hist .hdate { color: var(--muted); min-width: 5.5rem; }
.hist .hitem { flex: 1; min-width: 10rem; }
.hist .hamt { font-weight: 600; }
.hist .hnote { color: var(--muted); font-size: .8rem; flex-basis: 100%; }

/* duplicate-pair rows */
.dup { border-top: 1px solid var(--panel2); padding: .6rem 0; font-size: .9rem; }
.dup .dreason { color: var(--muted); font-size: .78rem; }
.dup .dbtns { display: flex; gap: .5rem; margin-top: .4rem; flex-wrap: wrap; }

/* inline forms */
.form { display: grid; gap: .5rem; margin-top: .6rem; }
.form label { font-size: .78rem; color: var(--muted); display: grid; gap: .25rem; }
.form input, .form select, .form textarea {
  font-size: .95rem; padding: .55rem .7rem; border-radius: var(--radius);
  border: 1px solid var(--panel2); background: var(--panel2); color: var(--text);
  width: 100%;
}
.form textarea { min-height: 4rem; resize: vertical; }
.form .row { display: flex; gap: .5rem; }
.chiprow { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }
.handle, .member {
  display: flex; gap: .5rem; align-items: baseline; justify-content: space-between;
  padding: .35rem 0; border-top: 1px solid var(--panel2); font-size: .88rem;
}
.handle .hval, .member .mname { flex: 1; overflow-wrap: anywhere; }
.linklike { background: none; border: 0; color: var(--red); padding: .2rem .4rem; font-size: .8rem; }
.danger { border: 1px solid var(--red); }

/* ---------- workbook sync status ---------- */
.sync-ok { color: var(--green); font-weight: 600; }
.sync-fail { color: var(--red); font-weight: 600; }
.sync-warn { color: #d9a53b; font-weight: 600; }
.sync-idle { color: var(--muted); }
.sync-err { margin-top: .4rem; font-size: .82rem; color: var(--muted); overflow-wrap: anywhere; }
.small { font-size: .82rem; }
.syncdot {
  width: .7rem; height: .7rem; border-radius: 50%;
  border: 0; padding: 0; margin-left: .35rem; cursor: pointer;
}
.syncdot.sync-ok { background: var(--green); }
.syncdot.sync-fail { background: var(--red); animation: syncpulse 1.6s infinite; }
.syncdot.sync-warn { background: #d9a53b; }
.syncdot.sync-idle { background: var(--muted); }
@keyframes syncpulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

/* ---------- sync log viewer ---------- */
.sync-log-head { display: flex; align-items: center; justify-content: space-between; margin-top: 1rem; }
.sync-log-head h4 { margin: 0; font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.sync-log {
  max-height: 16rem; overflow-y: auto; white-space: pre-wrap;
  font-size: .75rem; line-height: 1.45; color: var(--muted);
  background: var(--panel2); border-radius: .4rem; padding: .6rem .8rem; margin: .5rem 0 0;
}

/* transaction (deal) cards in contact history + deal detail */
.txn-list { display: flex; flex-direction: column; gap: .7rem; margin-top: .6rem; }
.txn-empty { color: var(--muted); font-size: .88rem; }
.txn-card {
  border: 1px solid var(--panel2); border-radius: .6rem; padding: .6rem .8rem;
  cursor: pointer; background: var(--panel);
}
.txn-card:hover, .txn-card:focus-visible { border-color: var(--accent); outline: none; }
.txn-head {
  display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap;
}
.tbadge {
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  padding: .18rem .55rem; border-radius: 99px; white-space: nowrap;
}
.t-sale { background: #1f4433; color: #7fd6a4; }
.t-purchase { background: #274060; color: #9ec5ff; }
.t-trade { background: #3d2b52; color: #c4a5f0; }
.txn-ids { font-weight: 600; font-size: .85rem; }
.txn-date { color: var(--muted); font-size: .8rem; }
.txn-total { margin-left: auto; font-weight: 700; font-size: .88rem; }
.txn-lines { list-style: none; margin: .5rem 0 0; padding: 0; }
.txn-lines li {
  display: flex; gap: .6rem; align-items: baseline;
  padding: .3rem 0; border-top: 1px solid var(--panel2); font-size: .86rem;
}
.txn-lines.big li { font-size: .95rem; padding: .45rem 0; }
.txn-lines .hitem { flex: 1; min-width: 8rem; }
.txn-lines .cash-line { color: var(--muted); }
.pill {
  font-size: .64rem; font-weight: 700; letter-spacing: .06em;
  padding: .12rem .45rem; border-radius: 99px; white-space: nowrap;
}
.p-in { background: #1f4433; color: #7fd6a4; }
.p-out { background: #4a2b2b; color: #f0a5a5; }
.thread-link {
  display: inline-block; margin-top: .5rem; font-size: .82rem;
  color: var(--text); text-decoration: underline;
}
.thread-btn {
  display: inline-block; margin-top: .8rem; padding: .55rem 1.1rem;
  border-radius: .5rem; background: var(--accent); color: #fff;
  font-weight: 600; text-decoration: none;
}
.txn-totals {
  display: flex; gap: 1.2rem; margin-top: .6rem; padding-top: .6rem;
  border-top: 1px solid var(--panel2); font-size: .9rem;
}
/* readable links inside the deal views, never default blue */
#txn-detail a[href], .txn-card a[href] { color: var(--text); }
#txn-detail a.thread-btn[href] { color: #fff; }

