/* Chemportal CRM Transfer — white, quiet, one accent per meaning */
:root {
  --paper: #ffffff;
  --wash: #f7f8fa;
  --ink: #1b2433;
  --ink-2: #4a5566;
  --muted: #7b8594;
  --line: #e3e7ed;
  --line-2: #eef1f5;
  --brand: #0a3051;
  --brand-ink: #061f36;
  --supplier: #0e7c66;
  --supplier-bg: #e8f5f1;
  --buyer: #2f48c4;
  --buyer-bg: #ecefFC;
  --amber: #c4570f;
  --amber-bg: #fdeee3;
  --red: #c2352b;
  --red-bg: #fdecea;
  --radius: 8px;
  --font: "Schibsted Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-ink); text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
h1 { font-size: 26px; line-height: 1.2; font-weight: 700; letter-spacing: -0.015em; margin: 0; }
h2 { font-size: 17px; font-weight: 650; margin: 0 0 12px; letter-spacing: -0.005em; }
h3 { font-size: 15px; font-weight: 650; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }

/* shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--line); padding: 22px 14px; position: sticky; top: 0; height: 100vh;
        display: flex; flex-direction: column; gap: 4px; background: var(--paper); }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 10px 20px; }
.brand-logo { width: 36px; height: 36px; flex: none; object-fit: contain; }
.brand b { display: block; font-size: 14px; line-height: 1.15; }
.brand span { font-size: 12px; color: var(--muted); }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 6px;
         color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--wash); color: var(--ink); text-decoration: none; }
.nav a.on { background: var(--wash); color: var(--ink); font-weight: 650; }
.nav .count { font-size: 12px; font-weight: 650; padding: 1px 7px; border-radius: 10px; background: var(--amber-bg); color: var(--amber); }
.nav-group { margin-top: 18px; padding: 0 10px 6px; font-size: 12px; color: var(--muted); }
.side-foot { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); }
.side-foot form { display: inline; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--brand); font: inherit; cursor: pointer; }
main { padding: 28px 40px 60px; max-width: 1320px; width: 100%; min-width: 0; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.head p { color: var(--muted); margin: 6px 0 0; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 7px;
       border: 1px solid var(--line); background: var(--paper); color: var(--ink); font: 550 14px var(--font);
       cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #cdd3dc; background: var(--wash); text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); }
.btn.go { background: var(--supplier); border-color: var(--supplier); color: #fff; }
.btn.go:hover { filter: brightness(.94); }
.btn.danger { color: var(--red); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* flashes */
.flash { padding: 10px 14px; border-radius: 7px; margin-bottom: 10px; font-size: 14px; border: 1px solid; }
.flash.ok { background: var(--supplier-bg); border-color: #c4e6dc; color: #0b5e4e; }
.flash.warn { background: var(--amber-bg); border-color: #f3dfa6; color: #7d5300; }
.flash.error { background: var(--red-bg); border-color: #f5c9c4; color: #93241b; }

/* tags */
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 2px 9px;
       border-radius: 20px; background: var(--wash); color: var(--ink-2); white-space: nowrap; }
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag.supplier { background: var(--supplier-bg); color: var(--supplier); }
.tag.purchase_request { background: var(--buyer-bg); color: var(--buyer); }
.tag.ready { background: var(--amber-bg); color: var(--amber); }
.tag.sent { background: var(--supplier-bg); color: var(--supplier); }
.tag.error { background: var(--red-bg); color: var(--red); }
.tag.processing, .tag.new { background: #e9eef4; color: var(--brand); }

/* panels and tables */
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
.panel > .ph { padding: 14px 18px; border-bottom: 1px solid var(--line-2); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.panel > .ph h2 { margin: 0; }
.panel > .pb { padding: 16px 18px; }
table.list { width: 100%; border-collapse: collapse; }
.list th { text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 550; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.list td { padding: 12px 14px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.list tr:last-child td { border-bottom: 0; }
.list tr.click { cursor: pointer; }
.list tr.click:hover td { background: var(--wash); }
.subj { font-weight: 600; color: var(--ink); display: block; max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.from { color: var(--muted); font-size: 13px; }
.empty { padding: 40px 18px; text-align: center; color: var(--muted); }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 24px; }
.stat { padding: 16px 20px; border-right: 1px solid var(--line-2); }
.stat:last-child { border-right: 0; }
.stat b { display: block; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.stat span { font-size: 13px; color: var(--muted); }
.stat a { color: inherit; }
.grid2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 20px; }
.check { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line-2); font-size: 14px; }
.check:last-child { border-bottom: 0; }
.ok-dot { color: var(--supplier); font-weight: 650; }
.no-dot { color: var(--amber); font-weight: 650; }

/* filters */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.chip { padding: 5px 12px; border-radius: 20px; border: 1px solid var(--line); font-size: 13px; color: var(--ink-2); }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip:hover { text-decoration: none; border-color: #c9cfd8; }
.filters input[type=search] { margin-left: auto; width: 260px; }
.filters .chips { display: contents; }

/* forms */
label.f { display: block; font-size: 13px; color: var(--ink-2); font-weight: 550; margin-bottom: 5px; }
label.f .req { color: var(--red); }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=email], input[type=search],
input[type=date], input[type=time], select, textarea {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
  font: 14px var(--font); color: var(--ink); }
textarea { height: auto; min-height: 76px; padding: 8px 10px; resize: vertical; line-height: 1.45; }
select[multiple] { height: auto; min-height: 90px; padding: 4px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px #0a305120; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.fgrid .wide { grid-column: 1 / -1; }
.sub3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 6px; }
.sub2 { display: grid; grid-template-columns: 90px 1fr 1fr; gap: 6px; }
.phone-row { display: grid; grid-template-columns: 1fr 110px; gap: 6px; margin-bottom: 6px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 6px 0; }
.checks label { font-size: 14px; display: inline-flex; gap: 6px; align-items: center; }
.ai-filled { box-shadow: inset 3px 0 0 #8fd3c2; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.formfoot { display: flex; gap: 10px; justify-content: flex-end; padding-top: 6px; }

/* e-mail page */
.mail-top { border-top: 4px solid var(--line); padding-top: 18px; margin: -28px -40px 22px; padding: 22px 40px 0; }
.mail-top.supplier { border-top-color: var(--supplier); }
.mail-top.purchase_request { border-top-color: var(--buyer); }
.mail-top.other { border-top-color: #b8c0cc; }
.mail-meta { color: var(--muted); font-size: 14px; margin-top: 6px; }
.reason { margin-top: 10px; font-size: 14px; color: var(--ink-2); }
.split { display: grid; grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.25fr); gap: 22px; align-items: start; }
.body-text { white-space: pre-wrap; font-size: 14px; line-height: 1.6; color: var(--ink); max-height: 520px; overflow: auto; overflow-wrap: anywhere; }
.sig { white-space: pre-wrap; font-size: 13.5px; background: var(--wash); border-radius: 6px; padding: 10px 12px; margin-top: 12px; color: var(--ink-2); overflow-wrap: anywhere; }
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.file { border: 1px solid var(--line); border-radius: 7px; overflow: hidden; font-size: 12.5px; display: flex; flex-direction: column; }
.file .th { height: 96px; background: var(--wash); display: flex; align-items: center; justify-content: center; color: var(--muted); font-weight: 650; }
.file .th img { width: 100%; height: 100%; object-fit: cover; }
.file .fi { padding: 7px 9px; display: flex; flex-direction: column; gap: 3px; }
.file .fn { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .dt { color: var(--supplier); font-weight: 600; }
.file label { display: flex; gap: 6px; align-items: center; color: var(--ink-2); }
.file.off { opacity: .55; }
.match { border: 1px solid var(--line); border-radius: 7px; padding: 10px 12px; margin-bottom: 14px; font-size: 14px; background: #fbfcfd; }
.match label { display: flex; gap: 8px; align-items: center; padding: 3px 0; }
.missing { color: var(--red); font-size: 13px; margin-bottom: 10px; }
.crm-done { padding: 12px 14px; border-radius: 7px; background: var(--supplier-bg); color: #0b5e4e; margin-bottom: 16px; font-size: 14px; }
.sticky-actions { position: sticky; bottom: 0; background: #fffffff2; border-top: 1px solid var(--line); padding: 12px 18px;
                  display: flex; gap: 10px; justify-content: flex-end; border-radius: 0 0 var(--radius) var(--radius); }
.error-box { background: var(--red-bg); color: #93241b; border-radius: 7px; padding: 10px 14px; margin-bottom: 16px; font-size: 14px; overflow-wrap: anywhere; }
.processing-box { background: #eef4fd; color: var(--brand-ink); border-radius: 7px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px; }

/* processing log */
.log { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.log li { display: grid; grid-template-columns: 128px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-2); }
.log li:last-child { border-bottom: 0; }
.log .who { color: var(--ink-2); font-weight: 600; }
.log .who small { display: block; color: var(--muted); font-weight: 400; }
.log .what { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 220px; overflow: auto; }
.log li.error .what { color: var(--red); }
.log li.ask .what { color: var(--muted); }
details.more summary { cursor: pointer; color: var(--brand); font-size: 14px; }

/* e-mail list bulk bar */
.bulkbar { flex-wrap: wrap; }
.bulkbar .checks { padding: 0; }
.rowcheck, [data-select-all] { width: 16px; height: 16px; cursor: pointer; }

/* AI provider: connect / test */
.probe { padding: 10px 12px; background: var(--wash); border-radius: 7px; }
.model-pick { margin-bottom: 6px; }
.good { color: var(--supplier); }
.bad { color: var(--red); }
.try-result { margin-top: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 7px; font-size: 13.5px; display: grid; gap: 4px; }

/* settings */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.tabs a { padding: 9px 14px; color: var(--ink-2); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--ink); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.narrow { max-width: 720px; }
.ftable td, .ftable th { padding: 8px 10px; }
.ftable td select, .ftable td input { height: 32px; }
.type { font-size: 12px; color: var(--muted); }
.times { display: flex; gap: 8px; flex-wrap: wrap; }
.times input { width: 120px; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; background: var(--wash); padding: 20px; }
.auth-card { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 30px; }
.auth-card .brand { padding: 0 0 22px; }
.auth-card .brand-logo { width: 48px; height: 48px; }
.auth-card .field { margin-bottom: 14px; }

/* phone top bar (hidden on wide screens) */
.topbar { display: none; }
.menu-btn { height: 38px; padding: 0 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--paper);
            font: 600 14px var(--font); color: var(--ink); cursor: pointer; }
.top-review { margin-left: auto; font-size: 13px; font-weight: 650; padding: 4px 10px; border-radius: 20px;
              background: var(--amber-bg); color: var(--amber); white-space: nowrap; }
.top-review:hover { text-decoration: none; color: var(--amber); }

@media (max-width: 1100px) { .split, .grid2 { grid-template-columns: 1fr; } }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30; padding: 10px 14px;
            background: #fffffff5; border-bottom: 1px solid var(--line); }
  .topbar .brand { padding: 0; color: var(--ink); }
  .topbar .brand:hover { text-decoration: none; }
  .topbar .brand-logo { width: 30px; height: 30px; }
  .topbar .menu-btn { margin-left: 8px; }
  .topbar .top-review + .menu-btn { margin-left: 0; }
  .topbar .brand + .menu-btn { margin-left: auto; }
  /* the side menu becomes a panel under the top bar */
  .side { display: none; position: fixed; top: 59px; left: 0; right: 0; bottom: 0; z-index: 29; height: auto;
          overflow-y: auto; border-right: 0; padding: 10px 14px 24px; }
  .side > .brand { display: none; }
  body.nav-open { overflow: hidden; }
  body.nav-open .side { display: flex; }
  .nav a { padding: 12px 12px; font-size: 16px; }
  .side-foot { margin-top: 18px; font-size: 13px; }
  main { padding: 18px 14px 60px; }
  h1 { font-size: 22px; overflow-wrap: anywhere; }
  .head { margin-bottom: 16px; align-items: flex-start; }
  .head > .row, .head > div:last-child:not(:first-child) { width: 100%; }
  .mail-top { margin: -18px -14px 16px; padding: 16px 14px 0; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat:nth-child(2) { border-right: 0; }
  .stat:nth-child(-n+2) { border-bottom: 1px solid var(--line-2); }
  .fgrid { grid-template-columns: 1fr; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters .chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none;
                    width: 100%; max-width: calc(100vw - 28px); min-width: 0; }
  .filters .chips::-webkit-scrollbar { display: none; }
  .filters .chip { flex: none; padding: 7px 13px; }
  .filters input[type=search] { width: 100%; margin-left: 0; }
  .head .import-form { flex-wrap: nowrap; width: 100%; }
  .head .import-form input[type=file] { flex: 1 1 auto; min-width: 0; }
  .head .run-form, .head .run-form .btn { width: 100%; justify-content: center; }
  .mail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .mail-actions > * { width: 100%; }
  .mail-actions .btn { width: 100%; justify-content: center; }
  .mail-actions .reprocess { grid-column: 1 / -1; display: flex; flex-wrap: nowrap; }
  .mail-actions .reprocess select { flex: 1 1 auto; min-width: 0; width: auto !important; height: 36px !important; }
  .mail-actions .reprocess .btn { width: auto; flex: none; }
  .bulkbar .checks { flex-wrap: nowrap; align-items: flex-start; }
  .bulkbar .checks input { flex: none; margin-top: 1px; }
  .tabs { overflow-x: auto; scrollbar-width: none; }
  .tabs a { flex: none; white-space: nowrap; }
  /* 16px inputs: phones do not zoom in when a field is tapped */
  input[type=text], input[type=password], input[type=number], input[type=url], input[type=email], input[type=search],
  input[type=date], input[type=time], select, textarea { font-size: 16px; height: 42px; }
  textarea { height: auto; }
  select[multiple] { height: auto; }
  .btn { height: 40px; }
  .btn.sm { height: 36px; }
  .panel > .ph { flex-wrap: wrap; padding: 12px 14px; }
  .panel > .pb { padding: 14px; }
  .sticky-actions { flex-wrap: wrap; padding: 10px 14px; }
  .sticky-actions { flex-wrap: nowrap; gap: 8px; }
  .sticky-actions .btn, .formfoot .btn { flex: 1 1 0; justify-content: center; padding: 0 8px; min-width: 0;
                                          white-space: normal; text-align: center; line-height: 1.2;
                                          height: auto; min-height: 44px; padding-block: 6px; }
  .sticky-actions .btn.go, .sticky-actions .btn.primary { flex-grow: 1.6; }
  .log li { grid-template-columns: 1fr; gap: 2px; }
  .files { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .phone-row { grid-template-columns: 1fr 96px; }
  input[type=file] { max-width: 100% !important; font-size: 14px; }

  /* tables become stacked rows */
  table.list, .list tbody, .list tr, .list td { display: block; }
  .list thead { display: none; }
  .list tr { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 12px 14px;
             border-bottom: 1px solid var(--line-2); }
  .list tr:last-child { border-bottom: 0; }
  .list td { padding: 0; border: 0; max-width: 100% !important; }
  .list td.full, .list td:has(.subj), .list td:has(b) { flex-basis: 100%; }
  .list td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 12.5px; }
  .list tr.click:hover td { background: none; }
  .subj { max-width: 100%; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  /* e-mail list: tick box on the left, subject, then type · status · date */
  .list.mail tr { position: relative; padding-left: 50px; gap: 6px 8px; }
  .list.mail td:first-child { position: absolute; left: 14px; top: 13px; }
  .list.mail td:nth-child(5) { margin-left: auto; }
  .list td:has(.subj) { min-width: 0; }
  .subj { overflow-wrap: anywhere; }
  .rowcheck, [data-select-all] { width: 20px; height: 20px; }
  .list.mini td:has(.subj) { flex-basis: 100%; }
  .ftable td.defcell, .ftable td.aicell { flex-basis: 100%; }
  .ftable td.aicell { display: flex; align-items: center; gap: 8px; }
  .ftable td.aicell::before { content: "AI fills it"; }
  .ftable td.aicell:has(select)::before { content: "Files"; }
  .ftable td.defcell::before { display: block; margin-bottom: 4px; content: "Default value"; }
  .ftable td.aicell input[type=checkbox] { width: 20px; height: 20px; }
  .bulkbar > .row { width: 100%; }
  .bulkbar > .row .btn { flex: 1 1 0; justify-content: center; }
}
@media (max-width: 480px) {
  .sub2, .sub3 { grid-template-columns: 1fr; }
  .stat { padding: 12px 14px; }
  .stat b { font-size: 24px; }
  .topbar .brand span { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.bulk-fail { margin-top: 6px; font-size: 13px; }
