/* OrderLink application shell — professional B2B operations UI */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --brand: #0d9488;
  --brand-dark: #0f766e;
  --brand-ink: #042f2e;
  --navy: #0b1726;
  --navy-2: #14273d;
  --accent: #2563eb;
  --ok: #15803d; --ok-bg: #dcfce7;
  --warn: #b45309; --warn-bg: #fef3c7;
  --bad: #b91c1c; --bad-bg: #fee2e2;
  --info: #1d4ed8; --info-bg: #dbeafe;
  --muted-bg: #eef2f7;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.05);
  --shadow-sm: 0 1px 2px rgba(15,23,42,.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 14px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 15px; margin: 0; }
small { font-size: 12px; }
.muted { color: var(--muted); }

/* Layout shell */
.shell { display: grid; grid-template-columns: 256px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--navy); color: #cbd5e1; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px; color: #fff; font-weight: 700; font-size: 18px; }
.side-brand:hover { text-decoration: none; }
.brand-mark { background: var(--brand); color: #fff; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.side-nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; flex: 1; }
.nav-group { color: #64748b; text-transform: uppercase; font-size: 10px; letter-spacing: .08em; margin: 14px 12px 4px; font-weight: 700; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 8px; color: #cbd5e1; font-weight: 500; }
.nav-item:hover { background: var(--navy-2); color: #fff; text-decoration: none; }
.nav-item.is-active { background: var(--brand); color: #fff; }
.nav-item i { width: 18px; height: 18px; }
.org-switch { padding: 12px; border-top: 1px solid var(--navy-2); }
.org-switch label { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: #64748b; margin-bottom: 4px; }
.org-switch select { width: 100%; background: var(--navy-2); color: #fff; border: 1px solid #1e3a52; border-radius: 8px; padding: 8px; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 12px 22px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-search { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; flex: 1; max-width: 520px; }
.topbar-search i { width: 16px; height: 16px; color: var(--muted); }
.topbar-search input { border: 0; background: transparent; outline: none; width: 100%; font-size: 14px; color: var(--ink); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.icon-btn { position: relative; display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); text-decoration: none; }
.icon-btn i { width: 18px; height: 18px; }
.badge-dot { position: absolute; top: -4px; right: -4px; background: var(--bad); color: #fff; border-radius: 999px; min-width: 18px; height: 18px; font-size: 10px; display: grid; place-items: center; padding: 0 4px; font-weight: 700; }
.menu-toggle { display: none; }

.user-menu { position: relative; }
.user-chip { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 5px 10px 5px 5px; cursor: pointer; }
.avatar { width: 32px; height: 32px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.user-meta { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.user-meta strong { font-size: 13px; } .user-meta small { color: var(--muted); }
.menu-pop { position: absolute; right: 0; top: 48px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); min-width: 200px; padding: 6px; z-index: 30; }
.menu-pop a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--ink-2); }
.menu-pop a:hover { background: var(--surface-2); text-decoration: none; }
.menu-pop i { width: 16px; height: 16px; }

.content { padding: 24px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* Flash */
.flash-stack { padding: 12px 24px 0; max-width: 1280px; margin: 0 auto; width: 100%; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 11px 14px; border-radius: 10px; font-weight: 500; border: 1px solid; }
.flash-success { background: var(--ok-bg); color: var(--ok); border-color: #bbf7d0; }
.flash-error { background: var(--bad-bg); color: var(--bad); border-color: #fecaca; }
.flash-warning { background: var(--warn-bg); color: var(--warn); border-color: #fde68a; }
.flash-info { background: var(--info-bg); color: var(--info); border-color: #bfdbfe; }

/* Page header */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px; border-radius: 9px; border: 1px solid transparent; font-weight: 600; font-size: 13px; cursor: pointer; background: var(--surface); color: var(--ink); }
.btn:hover { text-decoration: none; }
.btn i { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: var(--navy); color: #fff; }
.btn-secondary:hover { background: var(--navy-2); }
.btn-ghost { background: var(--surface); color: var(--ink-2); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: #fff; color: var(--bad); border-color: #fecaca; }
.btn-danger:hover { background: var(--bad-bg); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn.is-disabled { opacity: .5; pointer-events: none; }
.inline-form { display: inline; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 18px; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h3 { display: flex; align-items: center; gap: 8px; }
.card-head h3 i { width: 17px; height: 17px; color: var(--brand); }
.card-body { padding: 18px; }
.card-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 980px) { .card-grid { grid-template-columns: 1fr; } }

/* KPIs */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 4px; }
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi-value { font-size: 26px; font-weight: 800; color: var(--ink); }
.kpi-sub { font-size: 12px; color: var(--muted); }
.kpi-warn { border-left: 3px solid var(--warn); }
.kpi-bad { border-left: 3px solid var(--bad); }
.kpi-ok { border-left: 3px solid var(--ok); }
@media (max-width: 980px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }

/* Tables */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow-sm); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; padding: 11px 14px; background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-variant-numeric: tabular-nums; font-weight: 600; }
.link-strong { font-weight: 700; color: var(--ink); }
.link-strong:hover { color: var(--brand); }

/* Badges */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-muted { background: var(--muted-bg); color: var(--ink-2); }
.tag { display: inline-block; background: var(--muted-bg); color: var(--ink-2); border-radius: 6px; padding: 1px 7px; font-size: 11px; font-weight: 600; }

/* Forms */
.form-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 22px; max-width: 920px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-weight: 600; font-size: 12.5px; color: var(--ink-2); }
.input { width: 100%; padding: 9px 11px; border: 1px solid var(--line-2); border-radius: 9px; font-size: 14px; font-family: inherit; background: var(--surface); color: var(--ink); }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(13,148,136,.12); }
textarea.input { min-height: 84px; resize: vertical; }
.input-sm { padding: 6px 9px; font-size: 13px; }
.input-error { border-color: var(--bad); }
.field-help { color: var(--muted); }
.field-error { color: var(--bad); font-weight: 600; }
.check-field { flex-direction: row; align-items: center; gap: 9px; }
.checkbox { width: 17px; height: 17px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

/* Detail rows */
.drow { display: grid; grid-template-columns: 180px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.drow:last-child { border-bottom: 0; }
.drow-label { color: var(--muted); font-weight: 600; font-size: 12.5px; }
.drow-value { color: var(--ink); }
@media (max-width: 640px) { .drow { grid-template-columns: 1fr; gap: 2px; } }

/* Detail header */
.doc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.doc-title { display: flex; align-items: center; gap: 12px; }
.doc-title h1 { font-size: 24px; }
.doc-meta { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-top: 4px; }

/* Empty state */
.empty { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty i { width: 38px; height: 38px; opacity: .5; }
.empty p { margin: 10px 0 0; }

/* Pager */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 16px; }
.pager-info { color: var(--muted); font-size: 13px; }

/* Filters */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { padding: 6px 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font-weight: 600; font-size: 13px; }
.chip:hover { background: var(--surface-2); text-decoration: none; }
.chip.is-active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* File list */
.file-list { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; }
.file-list a { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink); }
.file-list i { width: 16px; height: 16px; }
.file-meta { margin-left: auto; color: var(--muted); font-size: 12px; display: flex; gap: 8px; align-items: center; }
.upload-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; border-top: 1px dashed var(--line); padding-top: 12px; }
.upload-form .input { width: auto; flex: 1; min-width: 160px; }

/* Pipeline / progress */
.pipeline { display: flex; gap: 10px; flex-wrap: wrap; }
.pipe-step { flex: 1; min-width: 120px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; text-align: center; }
.pipe-step strong { font-size: 24px; display: block; }
.pipe-step span { color: var(--muted); font-size: 12px; font-weight: 600; }
.progress { height: 8px; background: var(--muted-bg); border-radius: 999px; overflow: hidden; min-width: 80px; }
.progress > span { display: block; height: 100%; background: var(--brand); }

/* Sub-table inside cards */
.subtable { width: 100%; border-collapse: collapse; font-size: 13px; }
.subtable th { text-align: left; padding: 8px 10px; color: var(--muted); font-size: 11px; text-transform: uppercase; border-bottom: 1px solid var(--line); }
.subtable td { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.inline-add { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; align-items: end; margin-top: 12px; }
.inline-add .field { gap: 3px; }
.inline-add .field-label { font-size: 11px; }
@media (max-width: 900px) { .inline-add { grid-template-columns: repeat(2, 1fr); } }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 820px) { .two-col { grid-template-columns: 1fr; } }
.stars { color: #f59e0b; letter-spacing: 1px; }
.warn-box { background: var(--warn-bg); border: 1px solid #fde68a; color: var(--warn); border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; }
.warn-box ul { margin: 6px 0 0; padding-left: 18px; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.token-box { font-family: ui-monospace, monospace; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; word-break: break-all; font-size: 13px; }

/* Auth pages */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg, #0b1726, #0f766e); }
.auth-card { background: var(--surface); border-radius: 16px; box-shadow: 0 24px 60px rgba(2,6,23,.35); padding: 32px; width: 100%; max-width: 440px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; margin-bottom: 6px; }
.auth-card h1 { font-size: 20px; margin: 14px 0 4px; }
.auth-card .field { margin-bottom: 14px; }
.auth-foot { margin-top: 18px; text-align: center; color: var(--muted); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; width: 256px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.is-open { transform: translateX(0); }
  .menu-toggle { display: inline-grid; }
}


/* --- Product topology ------------------------------------------------ */
.topo-wrap { padding: 0; overflow: hidden; }
.topo-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.topo-legend { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.topo-key { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-2); }
.topo-swatch { width: 14px; height: 14px; border-radius: 4px; border: 2px solid var(--line-2); background: var(--surface); }
.topo-swatch.is-focus { border-color: var(--brand); background: #ccfbf1; }
.topo-swatch.is-bom { border-color: var(--accent); background: #eff6ff; }
.topo-line { width: 22px; height: 0; border-top: 2px solid var(--line-2); }
.topo-line.is-bom { border-top-color: var(--accent); }
.topo-line.is-similar { border-top-style: dashed; border-top-color: #9333ea; }
.topo-zoom { display: flex; gap: 6px; }
.topo-zoom .icon-btn { width: 34px; height: 34px; }
.topo-canvas { position: relative; height: 70vh; min-height: 420px; background:
  radial-gradient(circle, var(--line) 1px, transparent 1px) 0 0 / 22px 22px, var(--surface-2); }
.topo-loading { padding: 40px; text-align: center; }
.topo-hint { padding: 10px 16px; border-top: 1px solid var(--line); margin: 0; font-size: 12px; }
.topo-svg { display: block; width: 100%; height: 100%; cursor: grab; }
.topo-svg.is-grabbing { cursor: grabbing; }
.topo-edge { stroke: var(--line-2); stroke-width: 1.6; }
.topo-edge.is-bom { stroke: #93c5fd; }
.topo-edge.is-similar { stroke: #c084fc; stroke-dasharray: 5 4; }
.topo-arrow-head { fill: #93c5fd; }
.topo-edge-label { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.topo-node { cursor: pointer; }
.topo-box { fill: var(--surface); stroke: var(--line-2); stroke-width: 1.5; transition: stroke .12s, filter .12s; }
.topo-node:hover .topo-box { stroke: var(--accent); filter: drop-shadow(0 4px 10px rgba(37,99,235,.18)); }
.topo-node:focus { outline: none; }
.topo-node:focus .topo-box { stroke: var(--accent); }
.topo-node.is-focus .topo-box { fill: #f0fdfa; stroke: var(--brand); stroke-width: 2.5; }
.topo-code { fill: var(--ink); font-size: 13px; font-weight: 700; font-family: var(--font); }
.topo-name { fill: var(--ink-2); font-size: 12px; font-family: var(--font); }
.topo-supplier { fill: var(--muted); font-size: 10.5px; font-family: var(--font); }


/* --- Reports --------------------------------------------------------- */
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.report-card { display: flex; flex-direction: column; gap: 6px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); color: var(--ink); }
.report-card:hover { text-decoration: none; border-color: var(--brand); box-shadow: var(--shadow); transform: translateY(-1px); transition: .12s; }
.report-card strong { font-size: 15px; }
.report-ico { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--muted-bg); color: var(--brand-dark); margin-bottom: 4px; }
.report-ico i { width: 20px; height: 20px; }
.report-filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }
.report-filters .field { margin: 0; min-width: 160px; }
.report-filter-actions { display: flex; gap: 8px; margin-left: auto; }
.report-summary { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; padding: 10px 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 13px; color: var(--ink-2); }
.report-table th, .report-table td { white-space: nowrap; }
.row-overdue { background: #fff7f7; }


/* --- Required actions + wizard -------------------------------------- */
.action-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.action-cat-head { display: flex; align-items: center; justify-content: space-between; }
.action-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.action-list li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.action-list li:last-child { border-bottom: 0; }
.action-link { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.action-link:hover { text-decoration: none; }
.action-label { font-weight: 600; color: var(--ink); }
.action-link:hover .action-label { color: var(--accent); }
.action-sub { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.action-more { display: inline-block; margin-top: 10px; font-size: 13px; font-weight: 600; }

.wizard-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.wizard-tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 8px; border-top: 3px solid var(--line-2); }
.wizard-tile h3 { font-size: 17px; display: flex; align-items: center; gap: 8px; }
.wizard-tile p { margin: 0 0 6px; font-size: 13px; }
.wizard-tile .btn { align-self: flex-start; margin-top: 4px; }
.wizard-tile.is-buy { border-top-color: var(--accent); }
.wizard-tile.is-sell { border-top-color: var(--brand); }
.wizard-tile.is-update { border-top-color: #9333ea; }
.wizard-tile.is-report { border-top-color: #0891b2; }
.wizard-tile.is-action { border-top-color: var(--bad); }
.wizard-ico { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; background: var(--muted-bg); color: var(--ink-2); }
.wizard-ico i { width: 22px; height: 22px; }
.wizard-links { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; font-size: 13px; }


/* --- Connections / info box ----------------------------------------- */
.info-box { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; background: var(--info-bg); border: 1px solid #bfdbfe; border-radius: var(--radius-sm); color: var(--info); margin-bottom: 16px; font-size: 13px; }
.info-box i { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
