/* CRM Suite - black and white, in the manner of Apple's own pages: the system San Francisco font (Inter elsewhere),
   near-black #1d1d1f on white and #f5f5f7, hairline borders, pill buttons, generous rounding. Colours that pages
   pass inline (chart bars, tile notes) are drawn in black / grey here. */
:root {
  --bg: #f5f5f7; --surface: #ffffff; --surface-alt: #fbfbfd; --subtle: #f5f5f7; --hover: #ececf0;
  --border: #e5e5ea; --border-strong: #d2d2d7; --text: #1d1d1f; --text-soft: #424245; --muted: #6e6e73;
  --placeholder: #a1a1a6; --ink: #1d1d1f; --ink-hover: #000000;
  --radius: 18px; --radius-sm: 12px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.04);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", "Inter", Helvetica,
          Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.47 var(--font); letter-spacing: -0.01em;
       -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
a { color: var(--text); text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--text); }
h1 { font-size: 32px; line-height: 1.1; font-weight: 700; letter-spacing: -0.03em; margin: 0 0 6px; }
h2 { font-size: 21px; font-weight: 600; letter-spacing: -0.02em; margin: 34px 0 2px; }
h3 { font-size: 16px; font-weight: 600; margin: 16px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.lede { color: var(--muted); font-size: 13px; margin: 0; max-width: 900px; }
.emoji, .brand, .nav .ic { filter: grayscale(1); }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 236px; flex: 0 0 236px; background: rgba(255,255,255,.82); backdrop-filter: saturate(180%) blur(20px);
           -webkit-backdrop-filter: saturate(180%) blur(20px); border-right: 1px solid var(--border);
           padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; padding: 2px 10px 16px; }
.sidebar label { margin-left: 10px; }
.nav-section { font-size: 11px; font-weight: 600; color: var(--muted); padding: 18px 10px 6px; }
.nav a { display: flex; gap: 8px; padding: 7px 10px; border-radius: 10px; color: var(--text-soft); text-decoration: none;
         font-size: 13px; }
.nav a:hover { background: var(--subtle); color: var(--text); }
.nav a.active { background: var(--ink); color: #fff; font-weight: 500; }
.nav a.active .ic { filter: grayscale(1) brightness(10); }
.side-foot { border-top: 1px solid var(--border); margin-top: 18px; padding: 14px 10px 0; font-size: 13px;
             overflow-wrap: anywhere; }
.main { flex: 1 1 auto; min-width: 0; padding: 32px 40px 56px; }
.topbar, .page-head { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; justify-content: space-between;
                      margin-bottom: 18px; }
.menu-toggle { display: none; }

/* Controls */
.btn, button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent;
       border-radius: 980px; padding: 8px 16px; background: var(--surface); border-color: var(--border-strong);
       color: var(--text); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
       text-decoration: none; transition: background .15s, border-color .15s; }
.btn:hover, button:hover { background: var(--subtle); border-color: var(--muted); text-decoration: none; }
.btn.primary, button.primary, .btn.success, button.success, .btn.accent, button.accent, .btn.on {
       background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover, button.primary:hover, .btn.success:hover, button.success:hover, .btn.accent:hover,
button.accent:hover { background: var(--ink-hover); border-color: var(--ink-hover); }
.btn.danger, button.danger { background: var(--surface); border-color: var(--ink); color: var(--ink); }
.btn.ghost, button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover, button.ghost:hover { color: var(--text); background: var(--subtle); }
.btn.small, button.small { padding: 4px 11px; font-size: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.spacer { flex: 1 1 auto; }
input[type=text], input[type=password], input[type=url], input[type=number], input[type=date], input[type=search],
select, textarea { width: 100%; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 9px 12px;
       font: inherit; background: var(--surface); color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(0,0,0,.08); }
input[type=checkbox], input[type=radio] { accent-color: var(--ink); }
input[type=file] { font: inherit; font-size: 12px; max-width: 100%; }
textarea { resize: vertical; }
label { display: block; font-size: 12px; font-weight: 500; color: var(--text-soft); margin: 10px 0 4px; }
label.inline { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; color: var(--text); margin: 6px 12px 6px 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 16px; }
form.inline { display: inline; margin: 0; }
.segmented, .seg { display: inline-flex; background: var(--subtle); border-radius: 980px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented a, .seg a { padding: 4px 12px; border-radius: 980px; color: var(--text-soft); text-decoration: none; font-size: 12px; font-weight: 500; }
.segmented a.on, .seg a.on { background: var(--ink); color: #fff; }
.segmented a:hover, .seg a:hover { color: var(--text); }
.segmented a.on:hover, .seg a.on:hover { color: #fff; }
.seg.block { display: flex; width: 100%; }
.seg.block a { flex: 1 1 0; text-align: center; padding: 6px 4px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px;
        margin: 10px 0; box-shadow: var(--shadow); }
.card.soft { background: var(--surface-alt); }
details.card > summary { cursor: pointer; font-weight: 600; }
details.card[open] > summary { margin-bottom: 10px; }
.flash { border-radius: var(--radius-sm); padding: 12px 16px; margin: 8px 0; border: 1px solid var(--border-strong);
         background: var(--surface); white-space: pre-line; }
.flash.error, .flash.warning { border-color: var(--ink); }
.flash.error::before { content: "⚠︎  "; }
.flash.success::before { content: "✓  "; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 980px; font-size: 11px; font-weight: 600; color: #fff;
        background: var(--ink) !important; }
.empty { background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 40px;
         text-align: center; color: var(--muted); }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 10px 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.tile .l { color: var(--muted); font-size: 12px; font-weight: 500; filter: grayscale(1); }
.tile .v { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin: 4px 0 2px; white-space: nowrap;
           overflow: hidden; text-overflow: ellipsis; }
.tile .s { font-size: 12px; color: var(--muted) !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Charts - monochrome */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
.charts .wide { grid-column: 1 / -1; }
.chart-cap { color: var(--text); font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; }
.bars .c { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; min-width: 0; height: 100%; }
.bars .n { font-size: 10px; color: var(--muted); white-space: nowrap; }
.bars .b { width: 70%; max-width: 28px; border-radius: 4px 4px 0 0; background: var(--ink) !important; }
.bars .c:hover .b { background: var(--muted) !important; }
.bars .x { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; max-width: 100%; height: 14px; }
.share { display: flex; align-items: center; gap: 10px; font-size: 13px; padding: 3px 0; }
.share .nm { flex: 0 0 34%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-soft); }
.share .tr { flex: 1 1 auto; background: var(--subtle); height: 6px; border-radius: 3px; overflow: hidden; }
.share .fl { display: block; height: 100%; border-radius: 3px; background: var(--ink) !important; }
.share .val { flex: 0 0 auto; font-weight: 600; text-align: right; min-width: 70px; font-variant-numeric: tabular-nums; }
.share .pc { flex: 0 0 40px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

/* Tables */
.table-tools { display: flex; gap: 10px; align-items: center; margin: 6px 0; }
.table-tools input { max-width: 280px; }
.table-wrap { overflow: auto; max-height: 560px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th { position: sticky; top: 0; background: rgba(251,251,253,.95); backdrop-filter: blur(8px); text-align: left;
                padding: 9px 10px; border-bottom: 1px solid var(--border); cursor: pointer; white-space: nowrap;
                user-select: none; font-size: 12px; font-weight: 600; color: var(--text-soft); }
table.data th.r, table.data td.r { text-align: right; }
table.data td { padding: 7px 10px; border-bottom: 1px solid var(--subtle); vertical-align: top; }
table.data tr:hover td { background: var(--surface-alt); }
table.data td.act { white-space: nowrap; text-align: right; }
th.sorted-asc::after { content: " ↑"; }
th.sorted-desc::after { content: " ↓"; }

/* Tabs */
.tabs { margin-top: 10px; }
.tabs > input { display: none; }
.tabs > .tab-labels { display: inline-flex; flex-wrap: wrap; gap: 2px; background: var(--hover); padding: 3px; border-radius: 980px; }
.tabs > .tab-labels label { margin: 0; padding: 5px 14px; border-radius: 980px; cursor: pointer; font-size: 13px; color: var(--text); }
.tabs > .tab-panel { display: none; padding-top: 10px; }

.tree { font-size: 13px; line-height: 1.7; }
.tree .line { display: flex; align-items: center; gap: 8px; }
.tree .pg { flex: 0 0 380px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree .tr { flex: 0 0 160px; background: var(--subtle); height: 6px; border-radius: 3px; overflow: hidden; }
.tree .fl { display: block; height: 100%; background: var(--ink) !important; }
.preview { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 16px; max-height: 620px; overflow: auto; background: #fff; }
.preview img { max-width: 100%; height: auto; }
.thumb { width: 132px; height: 88px; object-fit: cover; border-radius: 10px; background: var(--subtle); }
.two-col { display: grid; grid-template-columns: minmax(0, 2.3fr) minmax(260px, 1fr); gap: 24px; }
.login-box { max-width: 380px; margin: 14vh auto; padding: 32px; }

/* Export Data: filters on the left, results on the right */
.workspace { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 28px; align-items: start; }
.filters { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface);
           border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
           scrollbar-width: thin; }
.filters .search { margin-bottom: 6px; border-radius: 980px; background: var(--subtle); border-color: transparent; padding-left: 16px; }
.filters .search:focus { background: var(--surface); border-color: var(--ink); }
.fsection { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
            padding: 16px 4px 4px; }
.fgroup { border-top: 1px solid var(--border); padding: 10px 4px; }
.fgroup.open { border-top: 0; padding-top: 12px; }
.fgroup + .fgroup.open { border-top: 1px solid var(--border); }
.fhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px;
         font-weight: 600; font-size: 13px; }
details.fgroup > summary { list-style: none; cursor: pointer; font-weight: 500; font-size: 13px; display: flex;
                           align-items: center; gap: 6px; }
details.fgroup > summary::-webkit-details-marker { display: none; }
details.fgroup > summary::after { content: "+"; margin-left: auto; color: var(--muted); font-size: 16px; line-height: 1; }
details.fgroup[open] > summary::after { content: "–"; }
details.fgroup[open] > summary { margin-bottom: 8px; }
.badge { background: var(--ink); color: #fff; border-radius: 980px; font-size: 10px; font-weight: 600; padding: 1px 7px; }
.opt-find { padding: 6px 10px !important; font-size: 12px !important; margin-bottom: 6px; }
.opt-list { max-height: 220px; overflow-y: auto; margin: 0 -4px; scrollbar-width: thin; }
.opt { display: flex; align-items: center; gap: 8px; margin: 0; padding: 4px; border-radius: 8px; cursor: pointer;
       font-size: 13px; font-weight: 400; color: var(--text); }
.opt:hover { background: var(--subtle); }
.opt input { margin: 0; flex: 0 0 auto; }
.opt-label { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opt-n { flex: 0 0 auto; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.apply-bar { position: sticky; bottom: -14px; display: flex; gap: 8px; background: linear-gradient(transparent, var(--surface) 30%);
             padding: 16px 0 14px; margin-top: 4px; }
.apply-bar .primary { flex: 1 1 auto; }
.source { margin-top: 6px; }
.source .path { word-break: break-all; }
.results { min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.chip-link { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px 5px 12px; border-radius: 980px;
             background: var(--ink); color: #fff; text-decoration: none; font-size: 12px; font-weight: 500; }
.chip-link span { opacity: .6; font-size: 14px; line-height: 1; }
.chip-link:hover span { opacity: 1; }
.chip-clear { font-size: 12px; color: var(--muted); }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .filters { position: static; max-height: none; }
}
@media (max-width: 900px) {
  .layout { display: block; }
  .sidebar { position: static; width: auto; height: auto; display: none; }
  .sidebar.open { display: block; }
  .menu-toggle { display: inline-flex; margin-bottom: 12px; }
  .main { padding: 18px 16px 36px; }
  h1 { font-size: 26px; }
  .charts, .two-col { grid-template-columns: minmax(0, 1fr); }
  .share .nm { flex-basis: 45%; }
  .share .pc { display: none; }
  .tree .pg { flex-basis: 200px; }
}

/* Buyer comments (export_buyer.html) */
.comments textarea { min-height: 110px; line-height: 1.5; }
.history { list-style: none; padding: 0; margin: 8px 0 0; }
.history li { border-top: 1px solid var(--border); padding: 8px 0; }
.history li div { white-space: pre-line; margin-top: 2px; }
