/* Shared design system for every marketplace-facing screen (login,
   onboarding, pending, dashboard). Dark trading-terminal look by default;
   [data-theme="light"] on <html> (set by the inline init script in
   base.html, toggled from the homepage) switches every token below to the
   light set. Flat throughout - subtle borders instead of shadows, gold
   accent reserved for interactive/emphasis moments only. */

:root {
    --bg: #0a0a10;
    --surface: #131319;
    --surface-raised: #1b1b24;
    --border: #232226;
    --text: #eeedf2;
    --text-muted: #8a8890;
    --text-faint: #59575e;
    --accent: #d8b158;
    --accent-hover: #e6c378;
    --accent-soft: rgba(216, 177, 88, 0.14);
    --accent-text: #1a1408;
    --success: #3ecf94;
    --success-bg: rgba(62, 199, 148, 0.12);
    --warning: #e2884c;
    --warning-bg: rgba(226, 136, 76, 0.14);
    --danger: #ea6f76;
    --danger-bg: rgba(234, 111, 118, 0.14);
    --radius: 10px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;
}

:root[data-theme="light"] {
    --bg: #f7f7f8;
    --surface: #ffffff;
    --surface-raised: #f2eff9;
    --border: #e6e5e8;
    --text: #18171a;
    --text-muted: #78767e;
    --text-faint: #a6a4ac;
    --accent: #8a6b1c;
    --accent-hover: #745a17;
    --accent-soft: rgba(138, 107, 28, 0.1);
    --accent-text: #ffffff;
    --success: #1f9d6b;
    --success-bg: #e4f6ee;
    --warning: #b5540f;
    --warning-bg: #faf0da;
    --danger: #c33f46;
    --danger-bg: #fbe9ea;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Centered single-card screens: login, onboarding, pending */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
}

.card .brand {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 20px;
}

.card h1 {
    font-size: 19px;
    font-weight: 600;
    margin: 0 0 6px;
    letter-spacing: -0.01em;
}

.card p.muted {
    color: var(--text-muted);
    font-size: 13.5px;
    margin: 0 0 24px;
}

/* Form fields */
.field { margin-bottom: 16px; }

.field label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.field input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s;
}

.field input:focus {
    outline: none;
    border-color: var(--accent);
}

.field .help {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 5px;
}

.field .errorlist {
    list-style: none;
    padding: 0;
    margin: 5px 0 0;
    color: var(--danger);
    font-size: 12px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); }

.btn-google {
    background: #fff;
    color: #1f1f1f;
    border: 1px solid #dcdcdc;
}
.btn-google:hover { background: #f4f4f4; }

.btn-text {
    background: none;
    color: var(--text-muted);
    width: auto;
    padding: 0;
    font-weight: 500;
}
.btn-text:hover { color: var(--text); }

/* Status badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 600;
}
.badge.pending { color: var(--warning); background: var(--warning-bg); }
.badge.verified { color: var(--success); background: var(--success-bg); }
.badge.rejected { color: var(--danger); background: var(--danger-bg); }

/* Simple app shell: header + centered column (quote history, history) */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 32px;
    border-bottom: 1px solid var(--border);
}

.app-header .org-name { font-weight: 600; font-size: 15px; }
.app-header .role-tag { color: var(--text-muted); font-size: 12px; margin-left: 8px; }
.app-header .actions { display: flex; align-items: center; gap: 16px; }

.app-header select {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    font-family: inherit;
}

.app-main {
    max-width: 960px;
    margin: 0 auto;
    padding: 32px 24px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
}

.panel h2 { font-size: 14px; font-weight: 600; margin: 0 0 16px; color: var(--text); }
.panel .empty { color: var(--text-muted); font-size: 13px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

th {
    text-align: left;
    padding: 0 10px 10px 0;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
}

td { padding: 10px 10px 10px 0; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }

.panel-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}
.panel-header-row h2 { margin: 0; }
.unit-note { color: var(--text-muted); font-size: 12px; font-weight: 400; }

/* Back link (icon + text, baseline-aligned) */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
}
.back-link:hover { color: var(--text); }
.back-link svg { flex-shrink: 0; }

/* Collapsible company details (quote history page) */
.details-panel {
    margin-top: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 16px;
}
.details-panel summary {
    cursor: pointer;
    padding: 12px 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    list-style: none;
}
.details-panel summary::-webkit-details-marker { display: none; }
.details-panel summary::after { content: '+'; float: right; color: var(--text-muted); font-weight: 400; }
.details-panel[open] summary::after { content: '\2212'; }

.detail-list { margin: 0 0 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.detail-list dt { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; margin-top: 12px; }
.detail-list dt:first-child { margin-top: 0; }
.detail-list dd { margin: 2px 0 0; font-size: 13.5px; color: var(--text); }

/* Price history chart */
.price-chart { margin: 4px 0 8px; }
.price-chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-axis-label { fill: var(--text-muted); font-size: 10px; font-family: var(--font); }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-fill-stop-start { stop-color: var(--accent); stop-opacity: 0.22; }
.chart-fill-stop-end { stop-color: var(--accent); stop-opacity: 0; }
.chart-end-ring { fill: var(--surface); stroke: none; }
.chart-end-dot { fill: var(--accent); }
.chart-hover-dot { fill: var(--accent); }
.chart-crosshair { stroke: var(--border); stroke-width: 1; }

.chart-tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 1;
}
.chart-tooltip-value { font-weight: 700; color: var(--text); }
.chart-tooltip-label { color: var(--text-muted); font-size: 11px; margin-top: 2px; }


/* ---------------------------------------------------------------------
   Homepage (marketplace/home.html): flush, minimal single-column layout.
   Two visual registers on purpose - the price list is a quiet, flat
   reference you scan; "Ongoing deals" is the one thing that gets a
   contained surface, because it's where something might need you to act.
   --------------------------------------------------------------------- */

.shell {
    max-width: 420px;
    margin-inline: auto;
    padding-inline: 16px;
    padding-block: 18px 48px;
    display: flex;
    flex-direction: column;
    gap: 36px;
}

.topbar {
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg);
    padding-block: 2px 4px;
}
.topbar .who { display: flex; flex-direction: column; gap: 2px; }
.topbar .org { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.topbar .role { font-size: 12px; color: var(--text-muted); }
.topbar .controls { display: flex; align-items: center; gap: 2px; }

.icon-btn {
    position: relative;
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    background: transparent;
    border: none;
    border-radius: 100px;
    color: var(--text-muted);
}
.icon-btn:hover { color: var(--text); background: var(--accent-soft); }
.icon-btn .dot {
    position: absolute;
    top: 8px; right: 9px;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--warning);
    border: 2px solid var(--bg);
}

/* Account menu (org switcher + sign out), tucked behind one icon */
.menu-drop { position: relative; }
.menu-drop > summary { list-style: none; }
.menu-drop > summary::-webkit-details-marker { display: none; }

.menu-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 220px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 10;
}

.menu-label {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 5px;
}

.menu-panel select {
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
}

.menu-panel .btn-text { font-size: 13px; width: 100%; text-align: left; }

.home-section { display: flex; flex-direction: column; }

.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
}
.section-head h2 { font-size: 15px; font-weight: 600; margin: 0; }

.sort-row { display: flex; align-items: baseline; gap: 6px; font-size: 12px; flex-shrink: 0; }
.sort-row a { color: var(--text-muted); }
.sort-row a:hover { color: var(--text); }
.sort-row a.active { color: var(--accent); font-weight: 600; }
.sort-row .sep { color: var(--text-faint); }

/* Commodity chips */
.chip-row { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 8px; }
.chip-row::-webkit-scrollbar { display: none; }

.chip {
    flex: 0 0 auto;
    padding: 9px 15px;
    border-radius: 100px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 13.5px;
    font-weight: 500;
    min-height: 40px;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Buyer rows */
.row-list { display: flex; flex-direction: column; }

.buyer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 2px;
    border-bottom: 1px solid var(--border);
    min-height: 44px;
    color: var(--text);
}
.row-list .buyer-row:last-child { border-bottom: none; }

.buyer-name { font-size: 14.5px; font-weight: 500; }
.buyer-city { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.buyer-price {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    font-size: 15px;
    flex-shrink: 0;
    text-align: right;
    color: var(--text);
}
.buyer-price .unit { display: block; font-family: var(--font); font-weight: 400; font-size: 10.5px; color: var(--text-muted); margin-top: 2px; }

.buyer-row.stale .buyer-name { color: var(--text-muted); }
.buyer-row.stale .buyer-price { color: var(--text-muted); font-weight: 500; }

.empty-note { font-size: 13px; color: var(--text-muted); padding: 14px 2px; }

/* Stale-buyers dropdown */
.stale-drop { margin-top: 4px; }
.stale-drop summary {
    list-style: none;
    cursor: pointer;
    padding: 12px 2px;
    font-size: 12.5px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid var(--border);
}
.stale-drop summary::-webkit-details-marker { display: none; }
.stale-drop summary .chev { transition: transform 0.15s; flex-shrink: 0; }
.stale-drop[open] summary .chev { transform: rotate(180deg); }
.stale-drop summary:hover { color: var(--text); }

/* Ongoing deals - the one contained surface on the page */
.deal-list {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px 16px;
}
.deal { border-bottom: 1px solid var(--border); }
.deal:last-child { border-bottom: none; }

.deal-head {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 0;
    background: transparent;
    border: none;
    color: inherit;
    text-align: left;
    min-height: 44px;
    font-family: inherit;
    cursor: pointer;
}

.deal-head .id-col { display: flex; align-items: flex-start; gap: 9px; min-width: 0; }

.flag-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--warning);
    flex-shrink: 0;
    margin-top: 6px;
}

.deal-head .name-block { min-width: 0; }
.deal-head .name { font-size: 14.5px; font-weight: 500; color: var(--text); }
.deal-head .sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.deal-head .sub.flagged { color: var(--warning); font-weight: 500; }

.deal-head .chev { color: var(--text-faint); flex-shrink: 0; transition: transform 0.15s; }
.deal.open .chev { transform: rotate(180deg); }

.deal-body { padding: 0 0 20px 0; }

.deal-figures {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 12.5px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.timeline { display: flex; flex-direction: column; }

.tl-item { position: relative; padding-left: 20px; padding-bottom: 16px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before {
    content: '';
    position: absolute;
    left: 3px; top: 4px;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--text-faint);
}
.tl-item::after {
    content: '';
    position: absolute;
    left: 5.5px; top: 13px;
    width: 1px;
    bottom: -3px;
    background: var(--border);
}
.tl-item:last-child::after { display: none; }
.tl-item.needs::before { background: var(--warning); }

.tl-title { font-size: 13px; font-weight: 500; color: var(--text); }
.tl-time { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }
.tl-note { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.tl-note.warn { color: var(--warning); }

.empty-tl { font-size: 12.5px; color: var(--text-muted); }

.footer-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    min-height: 44px;
}
.footer-link:hover { color: var(--accent); }
