/* Commodity Trade Tracker — earth-tone, iPhone-first styles */
:root {
  --bg: #17120c;
  --bg-2: #1e1811;
  --card: #251e16;
  --card-2: #2d251b;
  --line: #3a3025;
  --line-2: #4a3e30;
  --text: #f3eadb;
  --muted: #a89a86;
  --faint: #7a6e5e;
  --sand: #d9b46f;
  --sand-2: #f0ddb0;
  --green: #86a957;
  --green-bg: rgba(134, 169, 87, 0.16);
  --ocean: #5aa5c2;
  --ocean-bg: rgba(90, 165, 194, 0.15);
  --clay: #d06d4f;
  --clay-bg: rgba(208, 109, 79, 0.15);
  --amber: #e0a43c;
  --amber-bg: rgba(224, 164, 60, 0.15);
  --radius: 14px;
  --tabbar: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; overscroll-behavior-y: none; }
a { color: var(--ocean); text-decoration: none; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.hidden { display: none !important; }

/* ---------- boot / auth ---------- */
.boot { min-height: 100vh; display: grid; place-items: center; }
.auth {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(var(--safe-top) + 24px) 22px calc(var(--safe-bottom) + 24px);
  background: radial-gradient(120% 80% at 50% 0%, #2c2318 0%, var(--bg) 60%);
}
.auth .logo { width: 168px; height: 168px; margin-bottom: 2px; }
.auth .wordmark { width: 118px; height: auto; margin-bottom: 14px; }
.auth h1 { font-size: 22px; text-align: center; }
.auth .sub { color: var(--muted); text-align: center; margin: 6px 0 22px; font-size: 14px; }
.auth form { width: 100%; max-width: 380px; }

/* ---------- shell ---------- */
.shell { min-height: 100vh; padding-bottom: calc(var(--tabbar) + var(--safe-bottom) + 12px); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: rgba(23, 18, 12, 0.88); backdrop-filter: saturate(150%) blur(14px); -webkit-backdrop-filter: saturate(150%) blur(14px);
  border-bottom: 1px solid rgba(74, 62, 48, 0.5);
  display: flex; align-items: center; gap: 10px; min-height: 52px;
}
.topbar .mini-logo { width: 36px; height: 36px; flex: none; margin: -2px -2px -2px -4px; }
.topbar h1 { font-size: 19px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .back { display: flex; align-items: center; gap: 2px; color: var(--sand); background: none; border: 0; padding: 6px 4px 6px 0; font-size: 16px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: var(--card); border: 1px solid var(--line); color: var(--sand);
}
.icon-btn svg, .tab svg, .btn svg { width: 20px; height: 20px; }
main { padding: 14px 16px 24px; max-width: 760px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(6, 1fr);
  padding: 6px 4px calc(var(--safe-bottom) + 4px);
  background: rgba(27, 21, 15, 0.94); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0;
  color: var(--faint); font-size: 10px; font-weight: 600; border: 0; background: none; letter-spacing: -0.01em; white-space: nowrap;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--sand); }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabbar) + var(--safe-bottom) + 16px); z-index: 25;
  width: 56px; height: 56px; border-radius: 18px; border: 0;
  background: linear-gradient(180deg, var(--sand-2), var(--sand)); color: #2a1f12;
  display: grid; place-items: center; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.fab svg { width: 26px; height: 26px; }

/* ---------- cards & lists ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card + .card { margin-top: 10px; }
.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 22px 2px 8px; display: flex; justify-content: space-between; align-items: center; }
.section-title:first-child { margin-top: 4px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.row-card {
  display: block; width: 100%; text-align: left; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px;
}
.row-card:active { background: var(--card-2); }
.row-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.row-name { font-weight: 700; font-size: 16px; }
.row-sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.row-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; align-items: center; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .big { font-size: 40px; margin-bottom: 8px; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; background: var(--card-2); color: var(--muted); border: 1px solid var(--line); }
.pill.sand { background: rgba(217, 180, 111, 0.15); color: var(--sand); border-color: rgba(217, 180, 111, 0.3); }
.pill.green { background: var(--green-bg); color: var(--green); border-color: rgba(134, 169, 87, 0.35); }
.pill.ocean { background: var(--ocean-bg); color: var(--ocean); border-color: rgba(90, 165, 194, 0.35); }
.pill.clay { background: var(--clay-bg); color: var(--clay); border-color: rgba(208, 109, 79, 0.35); }
.pill.amber { background: var(--amber-bg); color: var(--amber); border-color: rgba(224, 164, 60, 0.35); }
.stars { color: var(--sand); letter-spacing: 1px; font-size: 13px; }
.stars .off { color: var(--line-2); }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-align: left; color: var(--text); }
.stat .n { font-size: 28px; font-weight: 800; color: var(--sand-2); line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 13px; font-weight: 600; }
.pipe-row { display: grid; grid-template-columns: 78px 1fr 34px; align-items: center; gap: 10px; padding: 6px 0; font-size: 13.5px; }
.pipe-row .lbl { color: var(--muted); font-weight: 600; }
.pipe-bar { height: 10px; border-radius: 6px; background: var(--bg-2); overflow: hidden; display: flex; }
.pipe-bar .s { background: var(--green); height: 100%; }
.pipe-bar .b { background: var(--ocean); height: 100%; }
.pipe-row .n { text-align: right; font-weight: 700; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.feed-item { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.feed-item:first-child { border-top: 0; padding-top: 0; }
.feed-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sand); margin-top: 7px; flex: none; }
.feed-item .when { color: var(--faint); font-size: 12px; }

/* ---------- search / filters ---------- */
.searchbar { display: flex; gap: 8px; margin-bottom: 10px; }
.search { flex: 1; position: relative; }
.search input { padding-left: 38px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--faint); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 13px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--muted); font-size: 13px; font-weight: 600; }
.chip.on { background: var(--sand); color: #2a1f12; border-color: var(--sand); }

/* ---------- forms ---------- */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 12.5px; font-weight: 650; color: var(--muted); margin: 0 0 5px 2px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; /* 16px stops iPhone auto-zoom */
  color: var(--text); background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 13px; outline: none; -webkit-appearance: none; appearance: none;
}
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%23a89a86' stroke-width='2'%3E%3Cpath d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 13px center; padding-right: 34px; }
input:focus, select:focus, textarea:focus { border-color: var(--sand); box-shadow: 0 0 0 3px rgba(217, 180, 111, 0.18); }
input[type='date'] { min-height: 48px; }
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.form-group { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 14px 2px; margin-bottom: 12px; }
.form-group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--sand); margin-bottom: 12px; }
.hint { font-size: 12.5px; color: var(--faint); margin: -6px 2px 12px; }
.err { color: var(--clay); font-size: 14px; margin: 4px 2px 12px; min-height: 1px; }
.rating-input { display: flex; gap: 6px; }
.rating-input button { flex: 1; padding: 10px 0; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); color: var(--line-2); font-size: 20px; }
.rating-input button.on { color: var(--sand); border-color: rgba(217, 180, 111, 0.45); }
.check-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-2); }
.check-list label { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-top: 1px solid var(--line); font-size: 14.5px; }
.check-list label:first-child { border-top: 0; }
.check-list input { width: 20px; height: 20px; padding: 0; flex: none; -webkit-appearance: checkbox; appearance: auto; accent-color: var(--sand); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 46px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line-2);
  background: var(--card-2); color: var(--text); font-weight: 650; font-size: 15px;
}
.btn.primary { background: linear-gradient(180deg, var(--sand-2), var(--sand)); color: #2a1f12; border-color: transparent; }
.btn.ai { background: linear-gradient(135deg, #3d6b4a, #2f5a6b); border-color: transparent; color: #f3eadb; }
.btn.danger { color: var(--clay); border-color: rgba(208, 109, 79, 0.4); background: var(--clay-bg); }
.btn.ghost { background: none; border-color: transparent; color: var(--sand); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13.5px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; }
.btn-row { display: flex; gap: 10px; margin-top: 6px; }
.btn-row .btn { flex: 1; }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- detail page ---------- */
.hero { padding: 4px 2px 12px; }
.hero h2 { font-size: 24px; }
.hero .sub { color: var(--muted); margin-top: 3px; }
.hero .row-meta { margin-top: 10px; }
.stepper { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px; padding: 4px 16px 12px; scrollbar-width: none; }
.stepper::-webkit-scrollbar { display: none; }
.step { flex: none; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 64px; padding: 9px 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--faint); font-size: 11.5px; font-weight: 700; }
.step .num { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--bg-2); font-size: 11px; }
.step.done { color: var(--green); border-color: rgba(134, 169, 87, 0.35); }
.step.done .num { background: var(--green-bg); }
.step.current { color: #2a1f12; background: var(--sand); border-color: var(--sand); }
.step.current .num { background: rgba(0, 0, 0, 0.15); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin: 6px 0 14px; position: sticky; top: calc(var(--safe-top) + 64px); z-index: 10; }
.seg button { border: 0; background: none; color: var(--muted); font-weight: 650; font-size: 13.5px; padding: 8px 0; border-radius: 9px; }
.seg button.on { background: var(--card-2); color: var(--sand-2); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); }
.kv { display: grid; grid-template-columns: 112px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14.5px; }
.kv:first-of-type { border-top: 0; padding-top: 2px; }
.kv .k { color: var(--muted); font-weight: 600; font-size: 13px; }
.kv .v { word-break: break-word; white-space: pre-wrap; }
.quick-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.quick-actions a, .quick-actions button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); color: var(--sand); font-size: 12px; font-weight: 650; }
.quick-actions .disabled { opacity: 0.35; pointer-events: none; }
.quick-actions svg { width: 20px; height: 20px; }

/* ---------- contracts ---------- */
.contract-sum { display: block; width: 100%; text-align: left; color: var(--text); }
.contract-sum .n { font-size: 28px; font-weight: 800; color: var(--sand-2); line-height: 1.1; }
.contract-sum .l { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.contract-sum .v { font-weight: 800; color: var(--green); font-size: 16px; }
.figures { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.fig { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 13px; min-width: 0; }
.fig.wide { grid-column: 1 / -1; background: linear-gradient(135deg, rgba(217, 180, 111, 0.16), rgba(134, 169, 87, 0.1)); border-color: rgba(217, 180, 111, 0.35); }
.fig .l { color: var(--muted); font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em; }
.fig .v { font-size: 18px; font-weight: 750; margin-top: 3px; overflow-wrap: anywhere; }
.fig .v.big { font-size: 26px; color: var(--sand-2); }
.fig .v.sm { font-size: 14.5px; }
.fig .s { color: var(--faint); font-size: 12px; }
.total-box { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 13px; margin-bottom: 14px; border-radius: 12px; background: rgba(217, 180, 111, 0.1); border: 1px solid rgba(217, 180, 111, 0.3); }
.total-box span { color: var(--muted); font-size: 13px; font-weight: 650; }
.total-box strong { color: var(--sand-2); font-size: 19px; }
.seg-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg-pick button { padding: 10px 0; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); color: var(--muted); font-weight: 700; font-size: 14px; }
.seg-pick button.on { background: var(--sand); color: #2a1f12; border-color: var(--sand); }
.section-title .btn.small { min-height: 30px; text-transform: none; letter-spacing: 0; }

/* ---------- notes ---------- */
.composer textarea { min-height: 120px; }
.polished-box { border: 1px solid rgba(90, 165, 194, 0.45); background: linear-gradient(180deg, rgba(61, 107, 74, 0.14), rgba(47, 90, 107, 0.14)); border-radius: 12px; padding: 12px; margin-top: 10px; }
.polished-box .lbl { font-size: 12px; font-weight: 700; color: var(--ocean); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px; }
.polished-box textarea { background: rgba(0, 0, 0, 0.2); min-height: 200px; }
.note { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; margin-top: 10px; }
.note-body { white-space: pre-wrap; word-break: break-word; font-size: 14.5px; }
.note-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 7px; font-size: 12.5px; color: var(--faint); }
.note-actions { display: flex; gap: 2px; }
.note-actions button { background: none; border: 0; color: var(--muted); padding: 4px 7px; font-size: 13px; font-weight: 600; }
.note .original { margin-top: 10px; padding: 10px; border-radius: 10px; background: var(--bg-2); color: var(--muted); font-size: 13.5px; white-space: pre-wrap; }

/* ---------- documents ---------- */
.dropzone { border: 2px dashed var(--line-2); border-radius: var(--radius); padding: 22px 16px; text-align: center; color: var(--muted); background: var(--bg-2); transition: all 0.15s; }
.dropzone.over { border-color: var(--sand); background: rgba(217, 180, 111, 0.08); color: var(--sand); }
.dropzone svg { width: 34px; height: 34px; color: var(--sand); margin-bottom: 6px; }
.dropzone strong { color: var(--text); display: block; margin-bottom: 3px; }
.progress { height: 6px; border-radius: 4px; background: var(--bg-2); overflow: hidden; margin-top: 8px; }
.progress div { height: 100%; background: var(--sand); width: 0; transition: width 0.15s; }
.file { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-top: 8px; }
.file .ic { width: 40px; height: 40px; border-radius: 10px; flex: none; display: grid; place-items: center; font-size: 10.5px; font-weight: 800; background: var(--ocean-bg); color: var(--ocean); }
.file .ic.pdf { background: var(--clay-bg); color: var(--clay); }
.file .ic.img { background: var(--green-bg); color: var(--green); }
.file .info { flex: 1; min-width: 0; }
.file .name { font-weight: 650; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .meta { color: var(--faint); font-size: 12px; }
.file .more { background: none; border: 0; color: var(--muted); padding: 8px; }

/* ---------- sheets & toast ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 60; display: flex; align-items: flex-end; justify-content: center; animation: fade 0.15s; }
.sheet { width: 100%; max-width: 560px; background: var(--bg-2); border: 1px solid var(--line); border-bottom: 0; border-radius: 20px 20px 0 0; padding: 10px 16px calc(var(--safe-bottom) + 16px); max-height: 88vh; overflow-y: auto; animation: up 0.2s ease-out; }
.sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 0 auto 12px; }
.sheet h3 { font-size: 18px; margin-bottom: 6px; }
.sheet p { color: var(--muted); margin: 0 0 14px; }
.sheet .btn { width: 100%; margin-top: 8px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
#toast { position: fixed; left: 50%; bottom: calc(var(--tabbar) + var(--safe-bottom) + 14px); transform: translate(-50%, 220%); z-index: 100; background: var(--card-2); border: 1px solid var(--line-2); color: var(--text); padding: 11px 16px; border-radius: 14px; font-weight: 600; font-size: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); transition: transform 0.25s; max-width: 90vw; }
#toast.show { transform: translate(-50%, 0); }
#toast { pointer-events: none; }
#toast:not(.show) { opacity: 0; }
#toast.error { border-color: rgba(208, 109, 79, 0.6); color: #f2b8a6; }
.update-banner { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar) + var(--safe-bottom) + 84px); z-index: 40; background: var(--ocean-bg); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid rgba(90, 165, 194, 0.5); color: var(--text); border-radius: 14px; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 600; font-size: 14px; }

@media (min-width: 700px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
  .tab { flex-direction: row; justify-content: center; gap: 8px; font-size: 13px; }
}
