*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:       #f5f5f3;
    --surface:  #ffffff;
    --surface2: #f8f8f6;
    --border:   rgba(0,0,0,0.08);
    --border2:  rgba(0,0,0,0.14);
    --text:     #1a1a18;
    --muted:    #6b6b66;
    --dim:      #9e9e98;
    --accent:   #185fa5;
    --green:    #1a7a4a;
    --amber:    #a05a00;
    --red:      #a32d2d;
    --green-bg: #eaf3de;
    --amber-bg: #faeeda;
    --red-bg:   #fcebeb;
    --d365-bg:  #e6f1fb;
    --d365-txt: #185fa5;
    --amz-bg:   #faeeda;
    --amz-txt:  #854f0b;
    --nam-bg:   #eaf3de;
    --nam-txt:  #3b6d11;
    --radius:   8px;
    --radius-lg:12px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:       #111318;
        --surface:  #181b22;
        --surface2: #1f2230;
        --border:   rgba(255,255,255,0.08);
        --border2:  rgba(255,255,255,0.14);
        --text:     #e8eaf0;
        --muted:    #8890a8;
        --dim:      #555e78;
        --accent:   #4f8eff;
        --green:    #1de9b6;
        --amber:    #f5a623;
        --red:      #ff5f6d;
        --green-bg: #0d2e1d;
        --amber-bg: #2e1e05;
        --red-bg:   #2e0d0d;
        --d365-bg:  #0c2540;
        --d365-txt: #85b7eb;
        --amz-bg:   #2e1e05;
        --amz-txt:  #fac775;
        --nam-bg:   #0d2e1d;
        --nam-txt:  #97c459;
    }
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* ── Shell ── */
.app-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar { background: var(--surface); border-right: 0.5px solid var(--border2); display: flex; flex-direction: column; }
.sidebar-logo { padding: 16px; border-bottom: 0.5px solid var(--border); display: flex; align-items: center; gap: 10px; }
.logo-icon { width: 30px; height: 30px; background: var(--d365-bg); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 500; color: var(--d365-txt); flex-shrink: 0; }
.logo-title { font-size: 13px; font-weight: 500; }
.logo-sub { font-size: 10px; color: var(--muted); }

.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-group { padding: 10px 14px 4px; font-size: 9px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--dim); }
.nav-item { display: flex; align-items: center; gap: 8px; padding: 8px 14px; font-size: 12px; color: var(--muted); text-decoration: none; border-left: 2px solid transparent; transition: background .1s; }
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--surface2); color: var(--accent); border-left-color: var(--accent); }
.nav-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.nav-dot.live { background: var(--green); }
.nav-dot.muted { background: var(--border2); }
.nav-badge { margin-left: auto; font-size: 10px; padding: 1px 6px; border-radius: 10px; background: var(--red-bg); color: var(--red); }

.sidebar-footer { padding: 12px 14px; border-top: 0.5px solid var(--border); }
.conn-status { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
.conn-dot { width: 6px; height: 6px; border-radius: 50%; }
.conn-connected    { background: var(--green); }
.conn-reconnecting { background: var(--amber); }
.conn-disconnected { background: var(--red); }

/* ── Main content ── */
.main-content { display: flex; flex-direction: column; min-height: 100vh; }
.page-topbar { padding: 14px 24px; background: var(--surface); border-bottom: 0.5px solid var(--border); display: flex; align-items: center; gap: 12px; }
.page-title { font-size: 15px; font-weight: 500; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.page-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }

/* ── Stats ── */
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px; }
.stat-card { background: var(--surface2); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 4px; }
.stat-value { font-size: 24px; font-weight: 500; }
.stat-value.warn { color: var(--amber); }
.stat-value.ok { color: var(--green); }
.stat-sub { font-size: 10px; color: var(--muted); margin-top: 2px; }
.stat-sub.ok { color: var(--green); }
.stat-sub.warn { color: var(--amber); }

/* ── Panels ── */
.panel { background: var(--surface); border: 0.5px solid var(--border2); border-radius: var(--radius-lg); overflow: hidden; }
.panel-head { padding: 10px 16px; border-bottom: 0.5px solid var(--border); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel-title { font-size: 12px; font-weight: 500; flex: 1; }
.panel-body { padding: 14px 16px; }
.panel-body.p0 { padding: 0; }
.panel-footer { padding: 10px 16px; border-top: 0.5px solid var(--border); display: flex; align-items: center; justify-content: space-between; }

/* ── Grids ── */
.two-col   { display: grid; grid-template-columns: 1fr 1fr;       gap: 16px; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr;   gap: 16px; }

/* ── Flow strip ── */
.flow-body { padding: 14px 16px; }
.flow-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.flow-node { padding: 7px 12px; border: 0.5px solid var(--border2); border-radius: var(--radius); font-size: 11px; display: flex; flex-direction: column; }
.flow-sub { font-size: 9px; color: var(--muted); margin-top: 2px; }
.flow-arrow { font-size: 13px; color: var(--dim); padding: 0 2px; }
.node-d365    { border-color: var(--accent); background: var(--d365-bg); color: var(--d365-txt); }
.node-amz     { border-color: var(--amber); background: var(--amz-bg); color: var(--amz-txt); }
.node-nam     { border-color: var(--green); background: var(--nam-bg); color: var(--nam-txt); }
.node-neutral { background: var(--surface2); }

/* ── Store bars ── */
.store-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 0.5px solid var(--border); font-size: 12px; }
.store-row:last-child { border-bottom: none; }
.store-name { color: var(--text); flex: 1; }
.store-right { display: flex; align-items: center; gap: 8px; }
.bar-wrap { width: 80px; height: 4px; background: var(--surface2); border-radius: 2px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 2px; }
.store-qty { font-size: 11px; font-weight: 500; min-width: 50px; text-align: right; font-family: monospace; }
.progress-bar-wrap { height: 3px; background: var(--surface2); border-radius: 2px; margin-top: 10px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--green); border-radius: 2px; }

/* ── Marketplace rows ── */
.mp-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 0.5px solid var(--border); font-size: 12px; }
.mp-row:last-child { border-bottom: none; }
.mp-key { color: var(--muted); }
.mp-val { font-weight: 500; }
.mp-val.ok   { color: var(--green); }
.mp-val.warn { color: var(--amber); }
.mp-val.err  { color: var(--red); }
.err { color: var(--red); }

/* ── Activity feed ── */
#activity-feed { max-height: 280px; overflow-y: auto; }
.feed-item { display: flex; gap: 10px; padding: 9px 16px; border-bottom: 0.5px solid var(--border); align-items: flex-start; }
.feed-item:last-child { border-bottom: none; }
.feed-icon { width: 24px; height: 24px; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 500; flex-shrink: 0; margin-top: 1px; }
.icon-d365, .icon-d365{ background: var(--d365-bg); color: var(--d365-txt); }
.icon-amazon, .icon-amz { background: var(--amz-bg); color: var(--amz-txt); }
.icon-namshi, .icon-nam { background: var(--nam-bg); color: var(--nam-txt); }
.icon-error, .icon-err  { background: var(--red-bg); color: var(--red); }
.feed-body { flex: 1; min-width: 0; }
.feed-title { font-size: 12px; font-weight: 500; margin-bottom: 2px; }
.feed-detail { font-size: 10px; color: var(--muted); font-family: monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed-time { font-size: 10px; color: var(--dim); white-space: nowrap; }

/* ── Tables ── */
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table.full-table { min-width: 100%; }
.data-table th { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); text-align: left; padding: 8px 14px; border-bottom: 0.5px solid var(--border2); font-weight: 400; background: var(--surface2); }
.data-table td { padding: 8px 14px; border-bottom: 0.5px solid var(--border); color: var(--text); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }
.mono { font-family: monospace; font-size: 11px; }
.truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Badges & pills ── */
.badge { font-size: 10px; padding: 2px 8px; border-radius: 4px; font-weight: 500; }
.badge-d365 { background: var(--d365-bg); color: var(--d365-txt); }
.badge-amz  { background: var(--amz-bg);  color: var(--amz-txt); }
.badge-nam  { background: var(--nam-bg);  color: var(--nam-txt); }
.tag { font-size: 10px; padding: 2px 7px; border-radius: 4px; background: var(--surface2); border: 0.5px solid var(--border); }

.method { font-size: 9px; padding: 2px 5px; border-radius: 3px; font-family: monospace; font-weight: 500; text-transform: uppercase; }
.method-get   { background: var(--d365-bg); color: var(--d365-txt); }
.method-post  { background: var(--nam-bg);  color: var(--nam-txt); }
.method-patch { background: var(--amz-bg);  color: var(--amz-txt); }

.status-pill { font-size: 10px; padding: 2px 8px; border-radius: 10px; }
.status-ok   { background: var(--green-bg); color: var(--green); }
.status-warn { background: var(--amber-bg); color: var(--amber); }
.status-err  { background: var(--red-bg);   color: var(--red); }

/* ── Live pill ── */
.live-pill { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--green); background: var(--green-bg); padding: 4px 10px; border-radius: 10px; }
.live-pill.small { font-size: 10px; padding: 2px 8px; }
.pulse-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--green); animation: pulse 1.5s infinite; flex-shrink: 0; }
@keyframes pulse { 0%,100%{ opacity:1 } 50%{ opacity:.3 } }

/* ── Buttons & inputs ── */
.btn-primary { font-size: 12px; padding: 6px 14px; border: 0.5px solid var(--accent); border-radius: var(--radius); background: var(--d365-bg); color: var(--d365-txt); cursor: pointer; }
.btn-primary:hover { opacity: .85; }
.btn-ghost { font-size: 12px; padding: 6px 12px; border: 0.5px solid var(--border2); border-radius: var(--radius); background: transparent; color: var(--muted); cursor: pointer; }
.btn-ghost:hover { background: var(--surface2); }
.select-input { font-size: 12px; padding: 5px 10px; border: 0.5px solid var(--border2); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.search-input { font-size: 12px; padding: 5px 10px; border: 0.5px solid var(--border2); border-radius: var(--radius); background: var(--surface); color: var(--text); width: 200px; }
.pager { display: flex; align-items: center; gap: 4px; }

/* ── Workflow steps ── */
.workflow-steps { display: flex; flex-direction: column; gap: 1px; }
.workflow-step { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 0.5px solid var(--border); }
.workflow-step:last-child { border-bottom: none; }
.workflow-step.active .step-num { background: var(--amz-bg); color: var(--amz-txt); }
.workflow-step.done  .step-num { background: var(--nam-bg); color: var(--nam-txt); }
.step-num { width: 22px; height: 22px; border-radius: 50%; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 500; flex-shrink: 0; }
.step-body { flex: 1; }
.step-title { font-size: 12px; font-weight: 500; }
.step-detail { font-size: 10px; color: var(--muted); font-family: monospace; }

/* ── Animations ── */
@keyframes slideIn { from { opacity:0; transform:translateX(-6px); } to { opacity:1; transform:none; } }
.new-row { animation: slideIn .25s ease; }
@keyframes highlight { 0%{ background:var(--amz-bg); } 100%{ background:transparent; } }
.highlight td { animation: highlight 2s ease; }
