/* DS — Smart Product Monitoring */
:root {
    --ds-sidebar-w: 232px;
    --ds-sidebar-w-collapsed: 64px;
    --ds-bg: #f5f7fb;
    --ds-surface: #ffffff;
    --ds-border: #e6e9f0;
    --ds-text: #1f2937;
    --ds-muted: #6b7280;
    --ds-primary: #2563eb;
    --ds-primary-soft: #eef3ff;
    --ds-green: #15803d;
    --ds-green-bg: #dcfce7;
    --ds-red: #b91c1c;
    --ds-red-bg: #fee2e2;
    --ds-amber-bg: #fef3c7;
    --ds-radius: 10px;
    --bs-body-font-size: .9rem;
}

body { background: var(--ds-bg); color: var(--ds-text); font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.min-w-0 { min-width: 0; }
.ds-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Shell ---------- */
.ds-shell { display: flex; min-height: 100vh; }
.ds-sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--ds-sidebar-w); z-index: 1040;
    background: #0f172a; color: #cbd5e1; display: flex; flex-direction: column;
    transition: width .18s ease, transform .18s ease;
}
.ds-brand { display: flex; align-items: center; gap: .7rem; padding: 1rem 1rem .9rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.06); }
.ds-brand:hover { color: #fff; }
.ds-logo {
    display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
    width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #2563eb, #4f46e5);
    color: #fff; font-weight: 800; font-size: .85rem; letter-spacing: .5px;
}
.ds-logo-lg { width: 52px; height: 52px; font-size: 1.15rem; border-radius: 13px; }
.ds-brand-text { display: flex; flex-direction: column; line-height: 1.1; white-space: nowrap; overflow: hidden; }
.ds-brand-text strong { font-size: 1.05rem; }
.ds-brand-text small { color: #94a3b8; font-size: .72rem; }
.ds-nav { padding: .75rem .5rem; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.ds-nav-link {
    display: flex; align-items: center; gap: .75rem; padding: .55rem .75rem; border-radius: 8px;
    color: #cbd5e1; text-decoration: none; white-space: nowrap; overflow: hidden; font-size: .88rem;
}
.ds-nav-link i { font-size: 1.05rem; width: 20px; text-align: center; }
.ds-nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.ds-nav-link.active { background: var(--ds-primary); color: #fff; }
.ds-sidebar-foot { padding: .5rem; border-top: 1px solid rgba(255,255,255,.06); }
.ds-collapse-btn { width: 100%; display: flex; align-items: center; gap: .75rem; background: none; border: 0; color: #94a3b8; padding: .5rem .75rem; border-radius: 8px; font-size: .85rem; }
.ds-collapse-btn:hover { background: rgba(255,255,255,.06); color: #fff; }
.ds-collapse-btn i { width: 20px; transition: transform .18s; }

.ds-main { flex: 1; min-width: 0; margin-left: var(--ds-sidebar-w); transition: margin-left .18s ease; display: flex; flex-direction: column; }
.ds-topbar {
    position: sticky; top: 0; z-index: 1030; display: flex; align-items: center; gap: .75rem;
    height: 56px; padding: 0 1.25rem; background: rgba(255,255,255,.92); backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--ds-border);
}
.ds-page-title { font-size: 1.05rem; font-weight: 600; margin: 0; }
.ds-content { padding: 1.25rem; flex: 1; min-width: 0; }
.ds-avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--ds-primary-soft); color: var(--ds-primary); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .75rem; }

body.sidebar-collapsed .ds-sidebar { width: var(--ds-sidebar-w-collapsed); }
body.sidebar-collapsed .ds-main { margin-left: var(--ds-sidebar-w-collapsed); }
body.sidebar-collapsed .ds-brand-text, body.sidebar-collapsed .ds-nav-link span, body.sidebar-collapsed .ds-collapse-btn span { display: none; }
body.sidebar-collapsed .ds-brand { justify-content: center; padding-inline: .5rem; }
body.sidebar-collapsed .ds-nav-link { justify-content: center; padding-inline: .5rem; }
body.sidebar-collapsed .ds-collapse-btn { justify-content: center; }
body.sidebar-collapsed .ds-collapse-btn i { transform: rotate(180deg); }
body.sidebar-collapsed .ds-nav-badge { position: absolute; margin-left: 22px; margin-top: -18px; font-size: .6rem; }

.ds-backdrop { display: none; }
@media (max-width: 991.98px) {
    .ds-sidebar { transform: translateX(-100%); width: var(--ds-sidebar-w) !important; }
    .ds-main { margin-left: 0 !important; }
    body.sidebar-open .ds-sidebar { transform: none; }
    body.sidebar-open .ds-backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 1035; }
    body.sidebar-collapsed .ds-brand-text, body.sidebar-collapsed .ds-nav-link span { display: inline; }
    .ds-sidebar-foot { display: none; }
    .ds-content { padding: 1rem; }
    .ds-topbar { padding: 0 1rem; }
}

/* ---------- Cards & stats ---------- */
.card { border: 1px solid var(--ds-border); border-radius: var(--ds-radius); box-shadow: 0 1px 2px rgba(16,24,40,.03); }
.card-header { background: var(--ds-surface); border-bottom: 1px solid var(--ds-border); }
.ds-stat { color: inherit; transition: border-color .15s, box-shadow .15s, transform .15s; }
.ds-stat:hover { border-color: #c7d2fe; box-shadow: 0 4px 14px rgba(37,99,235,.08); transform: translateY(-1px); }
.ds-stat-label { font-size: .75rem; color: var(--ds-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .03em; }
.ds-stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.ds-stat-sub { font-size: .75rem; color: var(--ds-muted); margin-top: .15rem; }
.ds-stat-icon { width: 34px; height: 34px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.05rem; flex: 0 0 auto; }
.ds-activity { max-height: 520px; overflow: auto; }

/* ---------- Badges ---------- */
.ds-stock { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.ds-stock::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.ds-stock-in { background: var(--ds-green-bg); color: var(--ds-green); }
.ds-stock-out { background: var(--ds-red-bg); color: var(--ds-red); }
.ds-stock-unknown { background: #f1f5f9; color: #64748b; }
.ds-mon { display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .5rem; border-radius: 6px; font-size: .72rem; font-weight: 600; white-space: nowrap; }
.ds-mon-ok { background: var(--ds-green-bg); color: var(--ds-green); }
.ds-mon-active { background: var(--ds-primary-soft); color: var(--ds-primary); }
.ds-mon-failed { background: var(--ds-red-bg); color: var(--ds-red); }
.ds-mon-paused { background: #f1f5f9; color: #64748b; }
.ds-src { font-weight: 600; font-size: .68rem; border-radius: 5px; }
.ds-src-cron, .ds-src-check { background: #ede9fe; color: #6d28d9; }
.ds-src-manual { background: #e0f2fe; color: #0369a1; }
.ds-src-initial { background: #f1f5f9; color: #64748b; }
.ds-src-import { background: var(--ds-amber-bg); color: #92400e; }

/* ---------- Products grid ---------- */
.ds-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .75rem; }
.ds-toolbar .form-control, .ds-toolbar .form-select { font-size: .85rem; }
.ds-search { position: relative; flex: 1 1 240px; max-width: 360px; }
.ds-search i { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--ds-muted); }
.ds-search input { padding-left: 2rem; }
.ds-filter-select { width: auto; max-width: 170px; }
.ds-grid-card { background: var(--ds-surface); border: 1px solid var(--ds-border); border-radius: var(--ds-radius); overflow: hidden; }
.ds-chip { display: inline-flex; align-items: center; gap: .35rem; background: var(--ds-primary-soft); color: var(--ds-primary); border-radius: 999px; padding: .2rem .4rem .2rem .7rem; font-size: .78rem; font-weight: 600; }
.ds-chip button { border: 0; background: none; color: inherit; padding: 0 .2rem; line-height: 1; }
.ds-selection-bar { font-size: .82rem; }

#productsTable.tabulator { border: 0; font-size: .84rem; background: var(--ds-surface); }
#productsTable .tabulator-header { background: #f8fafc; border-bottom: 1px solid var(--ds-border); }
#productsTable .tabulator-header .tabulator-col { background: #f8fafc; border-right: 1px solid #eef1f6; }
#productsTable .tabulator-header .tabulator-col .tabulator-col-content { padding: 6px 8px; }
#productsTable .tabulator-col-title { font-weight: 600; font-size: .78rem; color: #475569; }
#productsTable .tabulator-row { min-height: 44px; border-bottom: 1px solid #f0f2f7; }
#productsTable .tabulator-row.tabulator-row-even { background: #fcfdff; }
#productsTable .tabulator-row:hover { background: #f5f8ff; }
#productsTable .tabulator-row.ds-selected { background: #eef3ff; }
#productsTable .tabulator-cell { padding: 4px 8px; border-right: 1px solid #f3f4f8; display: inline-flex; align-items: center; height: 44px; }
#productsTable .tabulator-cell.tabulator-editable { cursor: cell; }
#productsTable .tabulator-cell.tabulator-editable:hover { box-shadow: inset 0 0 0 1px #c7d2fe; }
#productsTable .tabulator-cell.tabulator-editing { box-shadow: inset 0 0 0 2px var(--ds-primary); background: #fff; padding: 0; }
#productsTable .tabulator-cell.tabulator-editing input,
#productsTable .tabulator-cell.tabulator-editing select { padding: 4px 8px !important; height: 100%; font-size: .84rem; }
#productsTable .tabulator-footer { background: #f8fafc; border-top: 1px solid var(--ds-border); font-size: .8rem; }
#productsTable .tabulator-cell.cell-saving { background: #fffbeb !important; }
#productsTable .tabulator-cell.cell-saved { animation: dsSaved 1.4s ease; }
#productsTable .tabulator-cell.cell-error { animation: dsError 2s ease; }
@keyframes dsSaved { 0% { background: #bbf7d0; } 100% { background: transparent; } }
@keyframes dsError { 0%, 60% { background: #fecaca; } 100% { background: transparent; } }

.ds-thumb { width: 38px; height: 38px; border-radius: 6px; object-fit: cover; border: 1px solid var(--ds-border); background: #f8fafc; cursor: pointer; display: block; }
.ds-thumb-empty { display: flex; align-items: center; justify-content: center; color: #94a3b8; font-size: 1rem; }
.ds-cell-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-url { display: flex; align-items: center; gap: .35rem; min-width: 0; width: 100%; }
.ds-url a { color: var(--ds-primary); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-url a:hover { text-decoration: underline; }
.ds-hist-wrap { display: flex; align-items: center; gap: .4rem; width: 100%; min-width: 0; }
.ds-hist-btn { margin-left: auto; color: #94a3b8; cursor: pointer; padding: 2px 4px; border-radius: 5px; font-size: .85rem; }
.ds-hist-btn:hover, .ds-hist-btn.active { color: var(--ds-primary); background: var(--ds-primary-soft); }
.ds-price { font-variant-numeric: tabular-nums; font-weight: 600; }
.ds-trend-up { color: var(--ds-red); font-size: .75rem; }
.ds-trend-down { color: var(--ds-green); font-size: .75rem; }
.ds-muted { color: var(--ds-muted); }
.ds-actions { display: flex; gap: 2px; }
.ds-actions button { border: 0; background: none; color: #64748b; padding: 3px 6px; border-radius: 6px; }
.ds-actions button:hover { background: #eef2ff; color: var(--ds-primary); }
.ds-actions button.danger:hover { background: var(--ds-red-bg); color: var(--ds-red); }
.ds-actions button .spinner-border { width: .85rem; height: .85rem; border-width: .15em; }
.ds-check { width: 16px; height: 16px; cursor: pointer; accent-color: var(--ds-primary); }

/* ---------- History popup ---------- */
.ds-hist-pop {
    position: fixed; z-index: 1080; width: 400px; max-width: calc(100vw - 16px);
    background: #fff; border: 1px solid var(--ds-border); border-radius: 10px;
    box-shadow: 0 12px 32px rgba(15,23,42,.16); font-size: .8rem; display: none;
}
.ds-hist-pop.show { display: block; }
.ds-hist-pop-head { padding: .55rem .75rem; border-bottom: 1px solid var(--ds-border); display: flex; align-items: center; gap: .5rem; font-weight: 600; }
.ds-hist-pop-body { max-height: 260px; overflow: auto; }
.ds-hist-pop table { width: 100%; margin: 0; }
.ds-hist-pop td { white-space: nowrap; padding: .4rem .75rem; border-bottom: 1px solid #f1f3f8; vertical-align: middle; }
.ds-hist-pop tr:last-child td { border-bottom: 0; }
.ds-hist-pop .ds-hist-date { color: var(--ds-muted); white-space: nowrap; font-size: .74rem; }
.ds-hist-pop-foot { padding: .45rem .75rem; border-top: 1px solid var(--ds-border); display: flex; justify-content: space-between; font-size: .75rem; }

/* ---------- Add product ---------- */
.ds-fetch-box { background: linear-gradient(135deg, #eef3ff, #f8faff); border: 1px solid #dbe4ff; border-radius: var(--ds-radius); padding: 1.1rem; }
.ds-fetch-box .form-control-lg { font-size: .95rem; }
.ds-image-preview { aspect-ratio: 1/1; width: 100%; border: 1px dashed #cbd5e1; border-radius: var(--ds-radius); background: #f8fafc; display: flex; align-items: center; justify-content: center; overflow: hidden; color: #94a3b8; }
.ds-image-preview img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.ds-gallery { display: flex; flex-wrap: wrap; gap: .4rem; }
.ds-gallery img { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; border: 2px solid transparent; cursor: pointer; background: #fff; }
.ds-gallery img.active { border-color: var(--ds-primary); }
.ds-filled { animation: dsFilled 1.6s ease; }
@keyframes dsFilled { 0% { background: #dcfce7; } 100% { background: #fff; } }

/* ---------- Misc ---------- */
.ds-auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: radial-gradient(circle at 20% 10%, #e0e7ff, transparent 40%), var(--ds-bg); }
.ds-auth-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--ds-border); border-radius: 14px; padding: 2rem; box-shadow: 0 10px 30px rgba(15,23,42,.06); }
.table-ds { font-size: .84rem; }
.table-ds th { font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; color: #64748b; font-weight: 600; background: #f8fafc !important; white-space: nowrap; }
.table-ds td { vertical-align: middle; }
.ds-progress-card { border: 1px solid #c7d2fe; background: #f5f8ff; border-radius: var(--ds-radius); padding: .6rem .9rem; margin-bottom: .75rem; font-size: .85rem; }
.toast { font-size: .85rem; }
code.ds-code { display: block; white-space: pre-wrap; word-break: break-all; background: #0f172a; color: #e2e8f0; padding: .6rem .8rem; border-radius: 8px; font-size: .78rem; }
.tabulator-popup-container, .tabulator-edit-list { z-index: 1070 !important; font-size: .84rem; }
.tabulator-menu .tabulator-menu-item { font-size: .84rem; }
