:root {
    --brand: #0f766e;
    --brand-dark: #115e59;
    --brand-soft: #f0fdfa;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --warn: #b45309;
    --warn-soft: #fffbeb;
    --ok: #15803d;
    --ok-soft: #f0fdf4;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Microsoft JhengHei", "PingFang TC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.num { font-variant-numeric: tabular-nums; text-align: right; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

/* Login Page */
.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, #0f766e 0%, #134e4a 100%);
}
.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border-radius: 14px;
    padding: 32px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}
.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}
.brand-badge {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--brand);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 18px;
    flex-shrink: 0;
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

/* App Shell */
.app-shell {
    display: grid;
    grid-template-columns: 236px 1fr;
    min-height: 100vh;
}
.sidebar {
    background: #0f172a;
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
}
.sidebar-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 12px;
}
.sidebar-title { color: #fff; font-weight: 700; font-size: 15px; line-height: 1.2; }
.sidebar-sub { color: #94a3b8; font-size: 11px; }

.nav-list { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    color: #cbd5e1;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.07); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--brand); color: #fff; font-weight: 600; }

.sidebar-foot {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 12px;
    margin-top: 12px;
    font-size: 12px;
}
.user-meta { color: #e2e8f0; font-weight: 600; }
.user-role { color: #94a3b8; margin-bottom: 10px; }

.main-area {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 700; }
.topbar-meta { color: var(--muted); font-size: 12px; }

.content {
    padding: 20px 24px 36px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    max-width: 1480px;
    width: 100%;
}
body.desktop-embed .content-embed {
    padding: 14px 18px 28px;
    max-width: 100%;
}

/* Cards & Grids */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px;
}
.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}
.kpi-label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.kpi-value { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi-hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.card-title { margin: 0; font-size: 15px; font-weight: 700; }

/* Alerts */
.alert {
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 13px;
    border: 1px solid transparent;
}
.alert-ok { background: var(--ok-soft); border-color: #bbf7d0; color: var(--ok); }
.alert-err { background: var(--danger-soft); border-color: #fecaca; color: var(--danger); }
.alert-warn { background: var(--warn-soft); border-color: #fde68a; color: var(--warn); }

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    align-items: end;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: #334155; }
.field input, .field select {
    padding: 9px 11px;
    min-height: 40px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    font-size: 14px;
    background: #fff;
    color: var(--text);
    touch-action: manipulation;
}
.field input:focus, .field select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 15px;
    min-height: 40px;
    border-radius: 7px;
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    touch-action: manipulation;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); text-decoration: none; }
.btn-secondary { background: #fff; color: var(--text); border-color: #cbd5e1; }
.btn-secondary:hover { background: #f8fafc; text-decoration: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: 12px; }
.btn-block { width: 100%; }

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}
th {
    background: #f8fafc;
    color: #475569;
    font-weight: 700;
    font-size: 12px;
    white-space: nowrap;
}
tbody tr:hover { background: #f8fafc; }

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-neutral { background: #e2e8f0; color: #334155; }
.badge-info { background: #e0f2fe; color: #0369a1; }

.item-rows {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 12px 0;
}
.item-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 8px 10px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.item-row select, .item-row input {
    padding: 7px 9px;
    min-height: 36px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
}
.item-row .grow { flex: 1 1 240px; min-width: 180px; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }

.token-box {
    background: #0f172a;
    color: #5eead4;
    padding: 12px 14px;
    border-radius: 8px;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 13px;
    word-break: break-all;
    margin-top: 8px;
}

@media (max-width: 960px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; }
    .nav-list { flex-direction: row; flex-wrap: wrap; }
    .grid-2 { grid-template-columns: 1fr; }
}

/* ============================================================================
   升級包 6：類百威高密度「商品檔案工作台」與「商品庫存查詢估值中心」樣式
   ============================================================================ */
.wb-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
}
.wb-toolbar-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.wb-filter-bar {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px 12px;
    align-items: flex-end;
}
.wb-filter-item { display: flex; flex-direction: column; gap: 4px; min-width: 126px; }
.wb-filter-item label { font-size: 11px; font-weight: 700; color: #475569; }
.wb-filter-item input, .wb-filter-item select {
    padding: 6px 9px;
    min-height: 34px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
}
.wb-check-inline {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 34px;
    font-size: 12px;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    user-select: none;
}
.wb-check-inline input { width: 16px; height: 16px; margin: 0; }

.wb-shell {
    display: grid;
    grid-template-columns: 224px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
}
.wb-tree {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.wb-tree-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: #f1f5f9;
    border-bottom: 1px solid var(--border);
}
.wb-tree-tab {
    padding: 8px 4px;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    color: #475569;
    border-bottom: 2px solid transparent;
    text-decoration: none;
}
.wb-tree-tab:hover { background: #e2e8f0; text-decoration: none; }
.wb-tree-tab.active { background: #fff; color: var(--brand); border-bottom-color: var(--brand); }

.wb-tree-list {
    max-height: 540px;
    overflow-y: auto;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.wb-tree-node {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 12.5px;
    color: #1e293b;
    text-decoration: none;
}
.wb-tree-node:hover { background: #f1f5f9; text-decoration: none; }
.wb-tree-node.active { background: var(--brand); color: #fff; font-weight: 700; }
.wb-tree-count {
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 999px;
    background: #e2e8f0;
    color: #475569;
    font-variant-numeric: tabular-nums;
}
.wb-tree-node.active .wb-tree-count { background: rgba(255,255,255,0.22); color: #fff; }

.wb-main-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.wb-grid-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.wb-grid-scroll {
    max-height: 410px;
    overflow: auto;
}
.wb-grid-scroll-tall {
    max-height: 540px;
    overflow: auto;
}
.wb-dense-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.wb-dense-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #eef2f6;
    color: #334155;
    padding: 7px 8px;
    border-bottom: 1px solid #cbd5e1;
    border-right: 1px solid #e2e8f0;
    font-size: 12px;
    white-space: nowrap;
}
.wb-dense-table tbody td {
    padding: 6px 8px;
    border-bottom: 1px solid #edf2f7;
    border-right: 1px solid #f1f5f9;
    white-space: nowrap;
}
.wb-dense-table tbody tr { cursor: pointer; }
.wb-dense-table tbody tr:hover { background: #f0fdfa; }
.wb-dense-table tbody tr.wb-row-selected {
    background: #0ea5e9 !important;
    color: #fff;
}
.wb-dense-table tbody tr.wb-row-selected td,
.wb-dense-table tbody tr.wb-row-selected a,
.wb-dense-table tbody tr.wb-row-selected .muted-cell { color: #fff !important; }
.wb-dense-table tfoot td {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: #fefce8;
    border-top: 2px solid #cbd5e1;
    font-weight: 800;
    color: #0f172a;
    padding: 8px 8px;
    white-space: nowrap;
}

.wb-tabs-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    background: #eef2f6;
    border-bottom: 1px solid #cbd5e1;
    padding: 6px 10px 0;
}
.wb-tab-btn {
    padding: 7px 14px;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    background: transparent;
    color: #475569;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
}
.wb-tab-btn:hover { background: #e2e8f0; color: #0f172a; text-decoration: none; }
.wb-tab-btn.active {
    background: #fff;
    color: var(--brand);
    border-color: #cbd5e1;
    margin-bottom: -1px;
    padding-bottom: 8px;
}

.wb-detail-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.wb-detail-body { padding: 12px 14px; min-height: 170px; max-height: 290px; overflow: auto; }
.wb-detail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

/* Modal Dialog (類百威商品檔案彈窗 / 快速入庫彈窗) */
.wb-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: 999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.wb-modal-backdrop.open { display: flex; }
.wb-modal {
    background: #fff;
    border-radius: 12px;
    width: 100%;
    max-width: 960px;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
    overflow: hidden;
}
.wb-modal-head {
    background: var(--brand);
    color: #fff;
    padding: 12px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.wb-modal-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.wb-modal-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
.wb-modal-foot {
    padding: 12px 18px;
    background: #f8fafc;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.wb-modal-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 236px;
    gap: 16px;
}
.wb-form-2col {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 14px;
}
.wb-form-3col {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px 12px;
}
.wb-section-title {
    font-size: 12px;
    font-weight: 800;
    color: var(--brand);
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 4px;
    margin: 12px 0 8px;
}
.wb-margin-pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 800;
    font-size: 13px;
    background: #f0fdf4;
    color: #15803d;
    border: 1px solid #bbf7d0;
}
.wb-barcode-box {
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #f8fafc;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.wb-barcode-list {
    min-height: 150px;
    max-height: 240px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.wb-barcode-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    background: #f1f5f9;
    border-radius: 5px;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 12px;
}
.cell-zero { color: #94a3b8; }
.cell-low { background: #fef2f2; color: #dc2626; font-weight: 800; }
.cell-pos { color: #0f172a; font-weight: 700; }

@media (max-width: 960px) {
    .wb-shell { grid-template-columns: 1fr; }
    .wb-modal-layout { grid-template-columns: 1fr; }
    .wb-form-2col, .wb-form-3col { grid-template-columns: 1fr; }
}
